Promote artifact registration to a primary run outcome

Per-tool `afterToolCall` projection stays the primary write path but is
now backed by an end-of-run reconciliation sweep on `RuntimeBridge`.
`reconcileWorkspaceArtifacts` re-scans the workspace via `git status`
before the run's resources are released, idempotently upserting any
file the per-tool hook skipped — the exact gap that was leaving the
DocumentCenter empty while the disk filled up.

Projection failures stop being swallowed silently: the hook now logs
a tool-level summary at INFO and throws are routed to ERROR so they are
visible in the desktop log tail. The reconciliation sweep surfaces its
own failures the same way, so an operator can tell the difference
between "no files produced" and "files produced but registration
broken".
This commit is contained in:
ZacharyZhang-NY committed 2026-04-19 14:55:23 -04:00
1 parent db9375fdfe
commit 23a19a8180
3 files changed
+91 -3

No files matched your search

+16 -3
View File
@@ -158,6 +158,13 @@ function checkOperationalApprovalBlock(
* Post-execution projection. Today only filesystem artifacts flow
* through this hook; as further projections (browser actions, social
* posts) migrate off the event-observer path they plug in here.
*
* Projection is treated as a primary persistence action: failures are
* logged at ERROR so they stay visible in the desktop log tail, and the
* `run-finished` reconciliation sweep (`RuntimeBridge`) revisits the
* workspace to register anything the hook missed. Silent swallow was
* the failure mode that left `work_products` empty while the workspace
* accumulated files the UI never surfaced.
*/
export function handleAfterToolCall(
deps: HookHandlerDeps,
@@ -172,7 +179,7 @@ export function handleAfterToolCall(
workspacePath: ctx.workspacePath,
};
try {
projectToolExecutionToWorkProduct(
const outcomes = projectToolExecutionToWorkProduct(
deps.db,
runCtx,
{
@@ -182,9 +189,15 @@ export function handleAfterToolCall(
isError: payload.isError,
},
);
const registered = outcomes.filter((o) => o.kind === "inserted" || o.kind === "updated").length;
if (registered > 0) {
deps.logger.info(
`[hook-handlers] projection registered ${registered} artifact(s) for run ${ctx.runId} via ${payload.toolName}`,
);
}
} catch (error) {
deps.logger.warn(
`[hook-handlers] artifact projection failed for run ${ctx.runId} tool ${payload.toolName}: ${error instanceof Error ? error.message : String(error)}`,
deps.logger.error(
`[hook-handlers] artifact projection threw for run ${ctx.runId} tool ${payload.toolName}: ${error instanceof Error ? error.message : String(error)}`,
);
}
return NO_OP_AFTER;