Exclude archived work_products from the deliverable signal

`collectRunDeliverableSignals` queried the full `work_products`
table by run provenance. When a run's only filesystem action was a
deletion, the retirement stamped `last_touched_by_run_id` onto the
archived row — and the deliverable gate read that stamp as
"produced an artifact", letting `determinePostRunStatus` advance
the task to `in_review` for content the agent had just removed.

Pin `status <> 'archived'` onto the query so retirement tombstones
never count as deliverable evidence. A run that actually edits a
file still flips the row back to `active` via `upsertFilesystemArtifact`
before the signal is read, so real edits remain visible; only
deletions — which leave the row archived — stop masquerading as
produced output.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-19 17:30:50 -04:00
1 parent 78e406c20a
commit 8be61f141e
1 file changed
+7 -1
+7 -1
View File
@@ -221,8 +221,14 @@ export function buildKnowledgeMethods(
// refreshes `last_touched_by_run_id`. Querying by either side keeps
// the deliverable signal correct for a run that edited a pre-existing
// work product as well as a run that created a new one.
//
// `status <> 'archived'` excludes retirement tombstones: a run
// whose only filesystem action was deleting the file stamps
// `last_touched_by_run_id` onto the archived row, and without
// this filter the deliverable gate would count the removal as a
// produced artifact and let the task advance to review.
const workProducts = readAll<{ id: string }>(
"select id from work_products where company_id = ? and (last_touched_by_run_id = ? or created_by_run_id = ?) limit 1",
"select id from work_products where company_id = ? and status <> 'archived' and (last_touched_by_run_id = ? or created_by_run_id = ?) limit 1",
companyId, runId, runId,
);