From 8be61f141e348dd57d01bbfcf9ea49eddf2bcce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Sun, 19 Apr 2026 17:30:50 -0400 Subject: [PATCH] Exclude archived work_products from the deliverable signal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. --- src/main/database/knowledge.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/database/knowledge.ts b/src/main/database/knowledge.ts index abb2e014..151ca1ba 100644 --- a/src/main/database/knowledge.ts +++ b/src/main/database/knowledge.ts @@ -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, );