Repository navigation
fix(#1222): a watchdog-killed run writes no run log and half-deletes a clean worktree - #1238
Merged
admarble merged 7 commits intoSep 30, 2026
Conversation
Co-Authored-By: Claude Sonnet 5 <[email protected]> Entire-Checkpoint: 1a9a28ef19c6
Add a phase field to ShutdownManager cleanup tasks so log finalization always precedes worktree removal on SIGINT/SIGTERM, preserve worktrees with an in-progress phase or commits ahead of base, and raise the MCP run tool's SIGKILL grace above ShutdownManager's own force-exit timeout. Co-Authored-By: Claude Sonnet 5 <[email protected]> Entire-Checkpoint: ccbcae1d8a34
…rve log names its reason
QA test_gap: removing { phase: 'finalize' } from the orchestrator's run-log cleanup left every suite green. Extracts registerRunLogFinalizer and phaseInProgressPredicate so the wiring has tests; worktreePreserveReason makes the preserved line say why (was always 'uncommitted changes').
Entire-Checkpoint: 83db4e72cd7f
…along, tracker #1236) Entire-Checkpoint: f832e377ad60
Entire-Checkpoint: f13f6447a07a
3 tasks
…a-watchdog-killed-run-writes-no-run-log-an
admarble
deleted the
feature/1222-fix-run-a-watchdog-killed-run-writes-no-run-log-an
branch
September 30, 2026 17:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ShutdownManager.registerCleanupnow accepts{ phase: "finalize" | "resource" }(default"resource").gracefulShutdownruns every"finalize"task before any"resource"task, LIFO within each phase — so "Finalize run logs" (registered{ phase: "finalize" }) always runs before worktree-removal cleanups, regardless of registration order.shouldPreserveWorktree/cleanupWorktreeOnShutdown/registerWorktreeRemovalCleanupinworktree-manager.tsnow also preserve a clean worktree when its issue has a phase in progress (a lazily-evaluatedphaseInProgresscallback, plumbed fromRunOrchestrator.isPhaseInProgress) or when it has commits ahead of its base branch (hasCommitsAheadOfBase, base resolved viaresolveBaseReffromphase-executor.ts) — not just whengit statusis dirty.src/mcp/tools/run.ts'sSIGKILL_GRACE_MSis now derived fromShutdownManager's new exportedDEFAULT_FORCE_EXIT_TIMEOUT_MS(10000) plus a 1000ms buffer, instead of a standalone5000literal that was shorter than the manager's own force-exit timeout.docs/adr/0003-cleanup-phase-ordering.mddocumenting the rejected aggregate-registration alternative from the spec's Design Review.### Fixedentry under[Unreleased].AC Verification
src/lib/shutdown.ts(CleanupPhase, phase-sortedgracefulShutdown);src/lib/shutdown.test.tssrc/lib/workflow/worktree-manager.ts(shouldPreserveWorktree,hasCommitsAheadOfBase);src/lib/workflow/worktree-manager.test.ts,src/lib/workflow/run-orchestrator.shutdown.test.tssrc/mcp/tools/run.ts(SIGKILL_GRACE_MS);src/mcp/tools/run.test.tsMutation verification
Checks
npm run build: passnpm run lint: pass (0 errors, 0 warnings)npm test):npx vitest run src/lib/shutdown.test.ts src/lib/workflow/run-orchestrator.test.ts src/lib/workflow/worktree-manager.test.ts src/mcp/tools/run.test.ts src/lib/workflow/run-orchestrator.shutdown.test.ts— 161 passedRunner verification (tracker #1236)
QA verdict: NEEDS_VERIFICATION, 3/3. Its gaps were real, and the runner fixed them:
{ phase: "finalize" }from the run-log registration and every suite stayed green (40/40), so AC-1's actual fix had no guard. Infdc7c5fc, the runner extractedregisterRunLogFinalizer(shutdown, writer)andphaseInProgressPredicate(ref, issueNum)fromrun()and tested them inrun-orchestrator.shutdown.test.ts:{ phase: "finalize" }madesrc/lib/workflow/run-orchestrator.shutdown.test.ts > run-orchestrator shutdown wiring (#1222) > AC-1: the run-log finalizer runs, as aborted, before a worktree cleanup registered after itfail (1 failed / 4 passed); restored.phaseInProgressPredicatereturning() => falsemade… > AC-2: the phase predicate reads the orchestrator lazily, false until it existsfail (1 failed / 4 passed); restored.worktreePreserveReasonnow returns the rule that applied, so the log sayspreserved (uncommitted changes | phase in progress | commits ahead of base). A real-git test covers the feat(logs): run log records each phase's model and the sequant version #1198 shape (a clean tree with a committed WIP) and the phase-in-progress case.currentPhaseis cleared when a phase completes (run-orchestrator.ts, the phase-complete handler), so the predicate goes back to false between phases. The newworktree-manager → phase-executorimport adds no import cycle (madge: 18 cycles onmainand on the branch, the same set).shutdown,run-orchestrator,run-orchestrator.shutdown,worktree-managerandmcp/tools/runtests: 164 passed.tscand prettier are clean.4af86ba8:abort-logging.integration.test.ts(the Nested phase claude that hangs after its turn is killed at ~106s, taking down the parent sequant run #856 guard) scansrun-orchestrator.tsfor the finalizer block, and extracting the helper moved that block. The scan now targetsregisterRunLogFinalizer's block and checks thatrun()still calls it. Mutation: a barewriter.finalize()fails both that guard and the new wiring test (2 failed / 6 passed); restored.### Fixedline for bug(metrics): resolvedModel records the Haiku helper, not the phase's model, since 2026-09-20 — first modelUsage key is no longer the main model #1227 (theresolvedModelfix, which shipped without one).Test plan
shutdown.test.ts: new test asserts a finalize-phase task registered early still runs before resource-phase tasks registered later; existing LIFO/failure/abort-context tests unchanged.worktree-manager.test.ts: new#1222 AC-2describe block covershasCommitsAheadOfBase,shouldPreserveWorktree(commits-ahead, phase-in-progress, and the still-removed base case),cleanupWorktreeOnShutdown, andregisterWorktreeRemovalCleanupwiring, using real git worktrees against a bare remote.run-orchestrator.shutdown.test.ts: existing fix(run): abort-path paper cuts — "work is preserved in <worktree>" is false under SIGTERM, andabort's doc comment cites the wrong issue #935 regression tests still pass against the extendedshouldPreserveWorktree(fixture now adds a self-referentialoriginremote soorigin/mainresolves).run.test.ts: new test pinsSIGKILL_GRACE_MS >= DEFAULT_FORCE_EXIT_TIMEOUT_MS.Closes #1222
Refs #1236, #1203
🤖 Generated with Claude Code