Skip to content

fix(#935): preserve dirty worktrees on signal shutdown; fix abort citation - #1007

Merged
admarble merged 1 commit into
mainfrom
feature/935-fix-run-abort-path-paper-cuts-work-is-preserved-in
Sep 8, 2026
Merged

admarble merged 1 commit into
mainfrom
feature/935-fix-run-abort-path-paper-cuts-work-is-preserved-in

Conversation

@admarble

@admarble admarble commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On a signal-driven shutdown (SIGINT/SIGTERM), a worktree this run created is only force-removed if it's clean. A dirty worktree (uncommitted/untracked changes) is preserved instead — the fix(run): exec that leaves work uncommitted reports success and the run passes with no PR — #534's empty-branch escape, reopened via a new route #879 exec-failure message ("The work is preserved in <path>") would otherwise be false the moment an external SIGTERM fires the shutdown cleanup and deletes exactly that directory (D13, option A from docs/internal/graph-2026-09/PLAN.md).
  • Extracted the decision (shouldPreserveWorktree) and the cleanup task itself (cleanupWorktreeOnShutdown / registerWorktreeRemovalCleanup) into worktree-manager.ts so both are independently testable and reused by run-orchestrator.ts's cleanup registration block.
  • bin/cli.ts's abort command description and src/commands/abort.ts's header comment cited #645 (the relay bug, "relay messages silently lost") as the origin of the abort command. #645 never mentions abort. git log -S'Out-of-band abort' -- bin/cli.ts shows the citation should be #858, the PR that actually introduced the command.

Acceptance Criteria

AC Status Evidence
AC-1: signal-driven shutdown preserves a dirty worktree, removes a clean one ✅ src/lib/workflow/run-orchestrator.shutdown.test.ts — mutation-verified (see below)
AC-2: failure text matches the post-shutdown filesystem (path when preserved, branch when removed) ✅ Same test — preserved-case message names the still-existing path; removed-case (incl. non-signal/abort=null teardown) names the branch, never the (now-gone) path
AC-3: abort cites its origin ✅ (scoped) bin/cli.ts:507 and src/commands/abort.ts:3,7 (the only citations tied to the abort command) now cite #858; see note below on the AC's verify command

Note on AC-3's verify command: the literal grep (grep -n '#645' bin/cli.ts src/commands/abort.ts | wc -l → 0) also matches bin/cli.ts:470, an unrelated #645 citation on the prompt --wait command's --wait flag description ("Block until a reply arrives or the timeout elapses (#645, Gap 4)"). That citation is correct — #645's own "Gap 4" section is specifically about this behavior — and isn't one of the citations the issue names as wrong (bin/cli.ts:507 and abort.ts:3,7). I left it as-is rather than scrubbing a correct citation to satisfy a whole-file grep; happy to change if that's not the right call.

Mutation-verified: AC-1 — shouldPreserveWorktree hardcoded to return false; AC-1: a signal-driven shutdown preserves a dirty worktree and removes a clean one failed; restored.

Files changed

  • src/lib/workflow/worktree-manager.ts — isWorktreeDirty, shouldPreserveWorktree, cleanupWorktreeOnShutdown, registerWorktreeRemovalCleanup
  • src/lib/workflow/run-orchestrator.ts — cleanup registration block now delegates to registerWorktreeRemovalCleanup
  • bin/cli.ts, src/commands/abort.ts — citation fix
  • src/lib/workflow/run-orchestrator.shutdown.test.ts — new regression test (real git worktrees, no mocks)

Test plan

  • npx vitest run src/lib/workflow/run-orchestrator.shutdown.test.ts -t "935" → passes
  • npm run build / npm run lint → clean
  • Full suite (npx vitest run): 3 pre-existing failures unrelated to this diff (batch-executor.test.ts, prompt-wait.test.ts, relay-hook.integration.test.ts — none of these files, or files they depend on, were touched by this PR; reproduced failing on an unmodified checkout of the same base commit)

Closes #935

@admarble
admarble merged commit bdf32be into main Sep 8, 2026
6 checks passed
@admarble
admarble deleted the feature/935-fix-run-abort-path-paper-cuts-work-is-preserved-in branch September 8, 2026 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(run): abort-path paper cuts — "work is preserved in <worktree>" is false under SIGTERM, and abort's doc comment cites the wrong issue

1 participant