Skip in_review for autonomous top-level completions

In `ai_ceo` mode the operator opted out of human review, but
`processRunCompletion` still advanced every successful run through
`in_review`. The top-level CEO has no manager to walk up to and no
human gate, so the task became a dead letter: the heartbeat candidate
filter only picks `todo / in_progress / blocked`, so the CEO never
saw its own stuck rows and looped on taskless heartbeats every two
minutes producing nothing.

The previous workaround was even uglier: `advanceToInReview`
unconditionally force-flagged `requires_user_review = true` on every
top-level completion just to bypass `guardInReviewHasReviewer`. The
guard's own comment said "the right root fix is to reject at source";
the workaround did the opposite.

`decideTerminalStatus` is the new single source of truth: it returns
`done` only when the assignee is top-level AND the company is in
`ai_ceo` mode AND `reviewDeliverables` is off. Every other shape —
non-top-level, ai_cofounder, or operator-opted-in deliverable review
— still routes to `in_review` so existing manager-review and
human-review flows are unchanged. `advanceSuccessfulRun` is the
single entry point both successful branches call so the deliverable
and non-deliverable paths cannot diverge again.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-19 18:19:59 -04:00
1 parent 69a72b12a3
commit ba66a6bdc3
2 files changed
+94 -9

No files matched your search

@@ -169,8 +169,11 @@ describe("document run provenance", () => {
errorMessage: null,
}, () => false);
// ai_ceo + top-level CEO without `reviewDeliverables` advances
// straight to `done` — there is no reviewer in that configuration
// so the prior `in_review` state was a dead letter.
const task = harness.db.getTask(harness.taskId);
expect(task.status).toBe("in_review");
expect(task.status).toBe("done");
} finally {
harness.server.stop();
harness.db.close();