Skip to content

fix(exec): phase agent that backgrounds the test suite and waits for a notification strands uncommitted work — block Monitor/run_in_background under the orchestrator, WIP-commit on the no-commit guard #1032

Closed

Description

@admarble

Blocked by: — Tier: mechanical Doc: W2 field finding 2026-09-10 (graph-run wave 1)

Why

A recurring exec-phase failure class across three projects: the phase agent starts the full test suite as a background job (Monitor, or Bash with run_in_background: true plus a polling loop), then ends its turn with "I'll wait for the notification". Under sequant run the driver treats the end of the turn as the end of the phase (claude-code.ts returns on the first result message), and in every stranded transcript zero task notifications were ever delivered. The #879 guard then fires — exec left N file(s) uncommitted and made no commits — and the work sits in the worktree until a human rescues it.

Instances found in the retained run logs and their exec transcripts (last assistant text quoted):

Date Project Issue Outcome Agent's last words
2026-08-24 ad-motion #226 exec 574s, 21 files stranded "While the suite runs, let me re-read…" (Monitor on the suite)
2026-08-30 vid-gen bench #5, #6 phase ended, re-dispatched "The Monitor task is still running and will notify me… I'll wait for that."
2026-09-07 sequant #933 ×2 exec 557s/680s, 5 files stranded (backgrounded npm test)
2026-09-10 ad-motion #233 exec 474s, 18 files stranded "I'll stop issuing commands now and wait for the Monitor/background task notification to arrive."
2026-09-10 sequant #990 exec 708s, 12 files stranded "I'll now wait for the original npm test background task to notify me when it completes."

A second sub-pattern: when the agent keeps polling instead of ending its turn (#980, 2026-09-10), the phase idles until the MCP server's 30-minute no-progress kill, which landed mid-suite and left 35 tracked root files deleted in the worktree (a test moves them aside and never got to restore them).

Nothing prevents it today: the /exec skill has no foreground rule for test runs (it models backgrounding for worktree creation and parallel implementers), and pre-tool.sh has no guard for Monitor or run_in_background inside a phase.

Proposed change (three parts)

  1. Deterministic guard (hook). When SEQUANT_ORCHESTRATOR is set, pre-tool.sh blocks a Monitor tool call and a Bash call with run_in_background: true with HOOK_BLOCKED: background tasks never notify a phase agent — run it in the foreground with \timeout``. Interactive sessions are untouched.
  2. Skill rule. /exec §3 Checks-first: run the suite once, in the foreground, with a timeout, after a WIP commit; never wait on a background task or Monitor for it.
  3. WIP-commit on the guard. When mapAgentSuccessToPhaseResult classifies the exec tree as uncommitted, commit the dirty paths as chore(#N): wip checkpoint — exec ended with uncommitted work (auto-committed by sequant) (a conventional type: the pre-tool hook rejects wip as a type) before failing the phase, and name the commit in the error. The phase still fails; the work now survives git checkout, stale-worktree cleanup and a re-dispatch's rebase.

Scope

  • may touch: templates/hooks/pre-tool.sh (+ synced copies via npm run sync:hooks), templates/skills/exec/SKILL.md (+ synced copies via npm run sync:skills), src/lib/workflow/phase-executor.ts (mapAgentSuccessToPhaseResult, one helper), CHANGELOG.md (one bullet); tests: new src/lib/__tests__/pre-tool-background-guard.integration.test.ts, new src\/lib\/workflow\/phase-executor.wip-commit.test.ts (real temp git repo; the existing phase-executor.test.ts mocks child_process), new src\/lib\/__tests__\/exec-skill-foreground-rule.test.ts.
  • not in scope: the MCP 30-minute PHASE_TIMEOUT; the driver's phase-end semantics; the root-file-moving test (separate finding).

Acceptance criteria

  • AC-1: with SEQUANT_ORCHESTRATOR set, pre-tool.sh exits 2 with a HOOK_BLOCKED: line for a Monitor tool call and for a Bash call whose tool_input.run_in_background is true; a foreground Bash call with the same command is allowed — Verify: npx vitest run src/lib/__tests__/pre-tool-background-guard.integration.test.ts -t "AC-1" → three cases. Mutation: delete the guard block → the two blocked cases fail; restore.
  • AC-2: without SEQUANT_ORCHESTRATOR, the same Monitor and background Bash calls exit 0 — Verify: npx vitest run src/lib/__tests__/pre-tool-background-guard.integration.test.ts -t "AC-2" → both allowed.
  • AC-3: /exec §3 (Checks-first Mindset) states the foreground rule and names timeout, and the three skill copies are identical — Verify: npx vitest run src/lib/__tests__/exec-skill-foreground-rule.test.ts → the §3 region (between the ### 3. Checks-first Mindset heading and the next ###) matches /foreground/ and /timeout/; npm run lint:skill-sync → clean. Mutation: delete the rule line → fails; restore.
  • AC-4: an exec phase whose worktree has uncommitted changes and no commits ends with the files committed as a chore(#N): wip checkpoint … commit on the branch, the phase still reports success: false, and the error names the commit SHA — Verify: npx vitest run src\/lib\/workflow\/phase-executor.wip-commit.test.ts -t "AC-4" → real temp git repo, git rev-list --count base..HEAD → 1, git status --porcelain empty, error matches /auto-committed as [0-9a-f]{7}/. Mutation: drop the commit call → fails; restore.
  • AC-5: the WIP commit never runs when the tree has commits or is clean — Verify: npx vitest run src\/lib\/workflow\/phase-executor.wip-commit.test.ts -t "AC-5" → commits and none cases leave the log untouched.
  • AC-6: CHANGELOG.md [Unreleased] names the guard and the WIP commit — Verify: grep -c "run_in_background" CHANGELOG.md ≥ 1.
  • AC-7: suite green — Verify: npm run build && npm test → pass.

Done when

A phase agent cannot park itself on a background task, and when an exec phase still ends with uncommitted work, that work is on the branch before the failure is reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions