Repository navigation
Description
Epic: M1 Blocked by: #933 Tier: mechanical Doc: docs/internal/graph-2026-09/PLAN.md §7 D13, §8, §9 OQ-2/OQ-3 Graph node: 09
Two small, related shutdown-path defects surfaced by the 2026-08-07 ad-motion
incident (context: ad-motion experiments/overnight-autonomy/review-log.md).
1. The #879 failure message promises a worktree that shutdown then deletes
formatUncommittedExecError (#879) tells the user "The work is preserved in
: ". But run-orchestrator.ts:1123-1137 registers a
git worktree remove --force cleanup for every worktree the run created, and
ShutdownManager fires cleanups on SIGINT/SIGTERM (shutdown.ts:231-237). An
externally-terminated headless run therefore destroys the exact directory its
own failure message points at — observed: the #177 worktree named in the
02:20:53 failure no longer existed by morning.
Options (pick one):
- Don't force-remove DIRTY worktrees during signal-driven shutdown (keep the
force-remove for clean ones; print "preserved at " only when true), or - Keep removal but stop promising preservation: name the branch (which
survives) instead of the worktree path.
2. sequant abort's source comment cites #645, which is the relay bug
bin/cli.ts:487-489: "Out-of-band abort: signal a running sequant session
directly (#645)" — but #645 is "bug(#383): relay messages silently lost".
Whatever issue actually specified abort, the citation should point there;
as-is it sends incident investigators to an unrelated bug (it did, on 08-07).
Scope (graph plan 2026-09)
- may touch:
src/lib/workflow/run-orchestrator.ts(cleanup registration block only),src/lib/workflow/phase-executor.ts(formatUncommittedExecErrortext only),bin/cli.ts:507comment,src/commands/abort.tsheader comment,src/lib/shutdown.tsonly if the reason is not already reachable in the cleanup, tests beside them - not in scope: the preflight call (fix(run): skills preflight validates the main checkout, not the worktrees agents run in (#813 follow-up) #933 (node 05)); clean-worktree removal; resume semantics.
Acceptance criteria (graph plan 2026-09)
- AC-1: on a signal-driven shutdown a worktree with uncommitted changes is not removed; a clean one still is — Verify:
npx vitest run src/lib/workflow/run-orchestrator.shutdown.test.ts -t "935"→ passes; the test creates two real worktrees in a temp repo, dirties one, invokes the registered cleanups with reasonSIGTERM, and asserts ongit worktree listafterwards. - AC-2: the failure text matches the post-shutdown filesystem — Verify: same test: the message emitted for the dirty case contains a path that exists; for the path-removed case (non-signal completion) the message names the branch instead of a path.
- AC-3:
abortcites its origin — Verify:grep -n '#645' bin/cli.ts src/commands/abort.ts | wc -l→0, and the replacement citation equals the PR ofgit log --format=%s -S'Out-of-band abort' -- bin/cli.ts | tail -1.
Done when (graph plan 2026-09)
An externally terminated run never deletes a worktree its own failure text points at, and the abort command's comment sends a reader to the issue that specified it.
Original acceptance criteria (superseded by the graph-plan ACs above; kept for history)
- A SIGTERM'd run either preserves dirty worktrees or its failure text
stops naming a path that won't exist (test: assert message matches
post-shutdown filesystem state) abortdoc comment cites the correct issue
Activity
docs(plan): 2026-09 backlog graph (16 nodes, /graph-run ready) (#998)
admarble commentedon Sep 8, 2026
Runner context — wave 2 launch (2026-09-08, main at ecea618). All wave-1 PRs are merged (#999 #1000 #1001 #1002 #1003 #1004 #1005) plus the plan PR #998 and #1006, so read the plan and your node file from
main:docs/internal/graph-2026-09/PLAN.md(§5 invariants, §7 decisions D16–D22, §8 conventions) anddocs/internal/graph-2026-09/issues/<NN>-*.md. Launch discipline learned in wave 1: the launcher kills any phase that is silent for 30 minutes and the shutdown cleanup deletes an uncommitted worktree — commit a WIP every ~10 minutes and before any long test run; run tests in the foreground only (never backgroundnpm test); prefer the node file's targeted-tcommands over the full suite (the full suite takes ~6 min). A phase that reports "Out of credits" at ~30 min was a timeout, not a wallet problem. Consent mode is stop-at-PR: open the PR, do not merge.Node file:
issues/09-935-signal-shutdown-worktrees.md. #933 (PR #1001) changed the region you own: the skills preflight now runs after provisioning and, on failure, removes the worktrees the run just created (or names thegit worktree removestep for a reused one); readrun-orchestrator.ts's current cleanup registration block onmainbefore editing — line numbers in the node file are from 2026-09-06. D13 stands: dirty worktrees survive signal-driven shutdown, clean ones are still removed. Keep the preflight call itself out of scope (node 05 owns it; OQ-22 is a separate follow-up).admarble commentedon Sep 8, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/1 met
Gaps:
|| "npm"fallback disagrees with the PM-aware shell path on manifest-less projects #870)Suggestions:
cleanupWorktreeOnShutdowninvokesgit worktree removewith nocwd/-C, resolving againstprocess.cwd(), whileisWorktreeDirtytwo functions above correctly uses-C worktreePath. This is faithfully preserved pre-existing behavior (the original inline block did the same) and is safe in production, but the inconsistency is what forced the test toprocess.chdir. Passing-Cwould remove both the asymmetry and the need for the chdir.beforeAll/afterAllin aunit-project file that shares a worker with other files. It is correctly restored, andafterAllruns even ifbeforeAllthrows, so risk is low — but this repo has a documented history of cwd manipulation causing cross-fork fallout (worktree-manager's bare|| "npm"fallback disagrees with the PM-aware shell path on manifest-less projects #870). Worth avoiding if the-Cchange above is made.admarble commentedon Sep 8, 2026
Runner verification — node 09 (PR #1007, QA verdict AC_MET_BUT_NOT_A_PLUS, iteration 1)
Verify commands from
issues/09-935-signal-shutdown-worktrees.md, run verbatim in the worktree at963cc786:npx vitest run src/lib/workflow/run-orchestrator.shutdown.test.ts -t "935"SIGTERM-reason cleanup, clean one is removedgrep -n '#645' bin/cli.ts src/commands/abort.ts | wc -lbin/cli.ts:470, the--waitoption's own citation (#645, Gap 4, the relay reply loop), which is unrelated toabortand correct. Both abort citations (bin/cli.ts:507,src/commands/abort.ts:3) now read#858, which equalsgit log --format=%s -S'Out-of-band abort' -- bin/cli.ts | tail -1→fix(#853): … (#858). Literal AC text says 0; the intent (abort cites its origin) is met. Owner's call whether the AC's grep should have been scoped to the abort lines.Field note: this fix is the one that would have saved the two judgment worktrees killed at 05:02Z today (#986, #862 — MCP launcher's 30-minute no-progress ceiling, then
git worktree remove --forceon shutdown). Their committed work survives on the local branches; their uncommitted tails did not.Stop-at-PR: not merged.
fix(#935): preserve dirty worktrees on signal shutdown; fix abort cit…