Skip to content

fix(#1469): a failed git worktree add must fail the issue, not run its phases in the main checkout (two CLIs race on .git/config) - #1493

Merged
admarble merged 6 commits into
mainfrom
feature/1469-fix-run-a-failed-git-worktree-add-must-fail-the-is
Oct 17, 2026
Merged

admarble merged 6 commits into
mainfrom
feature/1469-fix-run-a-failed-git-worktree-add-must-fail-the-is

Conversation

@admarble

@admarble admarble commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1469

Under worktree isolation, an issue whose git worktree add failed used to drop out of the worktree map and run spec, exec and QA in the main checkout (the executor's process.cwd() fallback), on whatever branch was checked out there. Seen 2026-10-15 when two sequant run CLIs raced on .git/config.lock; reproduced 11/40.

  • IssueExecutionContext carries worktreeRequired and worktreeError; BatchExecutionContext/OrchestratorConfig carry worktreeRequired and a worktreeFailures map that provisioning fills with git's stderr. Both producers (executeOneIssue, executeBatch) set them; the one consumer, runIssueWithLogging, fails the issue before state init and before any phase (abortReason: worktree provisioning failed: …, empty phaseResults). The executor's fallback is unchanged: undefined there is also the legitimate isolation-off and spec-phase case (ADR-0017, option B rejected).
  • git-config-lock.ts: retryOnConfigLock (5 attempts, 100→800 ms, injectable sleep) wraps worktree add and recordWorktreeBaseRef. A retry re-checks whether the failed -b attempt already created the branch and adds it as existing; git worktree prune runs before each retry.
  • recordWorktreeBaseRef returns { ok } | { ok: false, error } instead of swallowing; both callers warn that the default base is in effect.
  • Provisioning summary: N created, M reused, K failed; chain mode fails every successor of a broken link with chain broken: #<pred> has no worktree.
  • Skills pre-flight no longer falls back to the main checkout when isolation is on and every worktree failed.

Acceptance criteria

AC Status Evidence (runner re-ran, worktree, head 6f6f22a + this PR's last commit)
AC-1 met npx vitest run src/lib/workflow/run-orchestrator.worktree-failure.test.ts → 3 passed, 0 failed
AC-2 met npx vitest run src/lib/workflow/worktree-manager.integration.test.ts -t "config.lock" → 2 passed, 0 failed
AC-3 met npx vitest run src/lib/workflow/phase-executor.test.ts -t "recordWorktreeBaseRef" → 3 passed, 0 failed
AC-4 met npx vitest run src/lib/workflow/worktree-manager.integration.test.ts -t "concurrent" → 1 passed, 0 failed (two npx tsx child processes released by a barrier file)

Mutation-verified: AC-1 — replaced the worktreeRequired && !worktree guard in runIssueWithLogging with a never-true condition; src/lib/workflow/run-orchestrator.worktree-failure.test.ts > worktree provisioning > a missing worktree fails the issue before any phase failed (the other two cases in the file skipped by -t); restored, 3 passed.

QA findings and their resolution

QA verdict AC_MET_BUT_NOT_A_PLUS, 4/4. The three findings:

  1. AC-1 mutation record missing → run by the runner (above) and recorded here.
  2. Concurrency test asserted the [branch "…"] header and called it "kept the upstream" → the header is also written by recordWorktreeBaseRef, and after a lost lock the retry adds the branch without -b, so no upstream is guaranteed (the PR push sets it with push -u). The test now asserts branch.<name>.sequantBaseRef = origin/main, the thing provisioning guarantees, and the comment says why. Fixed in this PR.
  3. Spec-recommended ADR not added → docs/adr/0017-worktree-required-contract.md plus its index row. Fixed in this PR.

Checks


🤖 Generated by sequant run; verified and amended by the runner session.

Entire-Checkpoint: 3fcd41291415
Entire-Checkpoint: 4f88caa4562c
…the [branch] header; ADR-0017 records the worktreeRequired contract

QA: the '[branch "…"]' section is also written by recordWorktreeBaseRef, so the old assertion passed with no upstream; after a lost lock the retry adds the branch without -b and the upstream is set later by push -u. Assert branch.<name>.sequantBaseRef, the thing provisioning guarantees. ADR-0017 (spec Design Review) with options B–E rejected.
Entire-Checkpoint: 502d4326c9eb
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): a failed git worktree add must fail the issue, not run its phases in the main checkout (two CLIs race on .git/config)

1 participant