Skip to content

fix(#1234): sequant run worktrees record their exact base ref; the exec guard and pre-PR rebase read it - #1242

Merged
admarble merged 7 commits into
mainfrom
fix/1234-sequant-base-ref
Sep 30, 2026
Merged

admarble merged 7 commits into
mainfrom
fix/1234-sequant-base-ref

Conversation

@admarble

@admarble admarble commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1234

#1241 (#1232) has merged, and main has been merged into this branch. The diff is now the #1234 change only. The worktree-manager.test.ts conflict with #1240 was resolved by keeping both describe blocks.

What

resolveBaseRef read branch.<b>.sequantBase, which only the legacy new-feature.sh writes. So for every sequant run worktree, the exec guard compared against origin/main. When --base was ahead of main, the base's own commits counted as "commits ahead", and the none and uncommitted branches (#534 / #879 / #1032) never fired. That's why 3 of 18 stranded exec phases in the #1138 bench "passed" with their work uncommitted.

  • phase-executor.ts:
    • recordWorktreeBaseRef writes branch.<b>.sequantBaseRef.
    • readRecordedBaseRef reads it back, but only a single-line value that resolves to a commit (git rev-parse --verify).
    • resolveBaseRef tries that key first, verbatim. It then falls back to the legacy sequantBase with origin/ prepended, which is unchanged, so a bare name is never read as a stale local branch. Last comes the origin/main fallback, also unchanged.
  • worktree-manager.ts:
    • computeWorktreeBaseRef is extracted from ensureWorktree, with identical logic.
    • The creation path records the ref it cut from. The reuse path records it only if absent, so pre-fix worktrees get it and existing values are kept.
    • rebaseBeforePR fetches origin/<base> as before. If the fetch fails and origin/<base> doesn't resolve but a local <base> branch does, it rebases onto the local branch without the Could not fetch / invalid upstream warnings. The decision depends on the remote, not on the recorded ref, so a pushed --base is always fetched fresh, and a chain's final link (which recorded its predecessor) behaves the same.
  • fix(run): a watchdog-killed run writes no run log and half-deletes a clean worktree — worktree removal outruns the 5 s SIGKILL grace #1222's hasCommitsAheadOfBase goes through resolveBaseRef, so it picks up the recorded ref too.

AC-1/AC-2 were revised in the issue body before implementation. The original "local branch unchanged when one exists" would have compared against a stale local main.

Acceptance criteria

  • AC-1: worktree-manager.test.ts > #1234 ensureWorktree records sequantBaseRef uses real git in a child process (the feat(worktree): configurable worktree root #1199 pattern). No --base records origin/main, --base origin/remote-base records origin/remote-base, and a local --base local-base records local-base.
  • AC-2: phase-executor.integration.test.ts > exec guard with a local base ahead of main (integration, #1234):
    • a recorded ref is used verbatim;
    • an unresolvable recorded ref falls back to origin/main;
    • a legacy bare sequantBase=main still resolves to origin/main.
  • AC-3: same describe block. With a recorded local base one commit ahead of main:
  • AC-4: worktree-manager.test.ts:
    • a local-only base prints no fetch failure and rebases onto local-base;
    • the same holds for a chain final link whose recorded ref is its predecessor;
    • a pushed --base remote-base is still fetched and picks up a teammate's newer commit;
    • a chain final link with caller base main still targets origin/main.

Verification

  • QA follow-up (493f7e4): the first version keyed the rebase on the recorded ref. That skipped the fetch for a pushed --base (QA reproduced a teammate's commit going missing) and still warned for a chain run with a local base. Both are fixed and covered by the two new AC-4 tests. readRecordedBaseRefAtHead was removed; the rebase path no longer reads the recorded ref.
  • Ran every test file that names a changed symbol or literal (resolveBaseRef, rebaseBeforePR, sequantBase, Could not fetch, hasCommitsAheadOfBase, classifyExecChanges, hasExecChanges, ensureWorktree, plus every workflow, command and root test mocking child_process), one file at a time. All pass.
  • phase-executor.test.ts queues execFileSync results in call order. Its mock factory now answers *.sequantBaseRef lookups as unset, so the existing queued sequences stay valid, and the recorded case is covered with real git in the integration file. rebaseBeforePR's ref checks use execFileSync and run only when the fetch fails, so run.test.ts's ordered spawnSync queue is unchanged.
  • Mutation-verified: AC-1 — removed the creation-path recordWorktreeBaseRef call; 1234 records origin/main when no --base is given failed (plus the other two record tests and the local-base rebase test); restored.
  • Mutation-verified: AC-2 — resolveBaseRef ignores the recorded exact ref; 1234 resolveBaseRef uses a recorded sequantBaseRef verbatim failed; restored.
  • Mutation-verified: AC-3 — the same mutation; 1234 uncommitted-only exec on a recorded local base fails and is WIP-committed failed; restored.
  • Mutation-verified: AC-4 — removed the local-only fallback; 1234 pre-PR rebase onto a local-only base prints no fetch failure failed (plus the chain-final-link local case); restored.
  • Mutation-verified: AC-4 — reintroduced the QA-found regression (prefer a local base whenever one exists); 1234 pre-PR rebase still fetches a pushed --base and picks up a teammate's commit failed; restored.

Overlap note

#1240 (#1223, in flight in another session) also edits worktree-manager.ts, in a different area: PR title/body building. Whichever lands second merges main.

🤖 Generated with Claude Code

…per's checkout

phase-executor.model-ladder/model-roles/phase-agent tests called executePhaseWithRetry with no worktreePath, so the exec change guard ran against process.cwd() and the #1032 rescue auto-committed a dirty checkout as a wip checkpoint. They now pass a throwaway repo (HEAD one commit ahead of origin/main) and assert the dispatched cwd.

Entire-Checkpoint: 8c34f86c09f8
QA follow-up: a git error after mkdtempSync leaked the dir, and afterAll's cleanup on an undefined repo masked the real error.

Entire-Checkpoint: 1e9886dc23d5
…ec guard and pre-PR rebase read it

ensureWorktree now writes branch.<b>.sequantBaseRef (the ref it cut from); resolveBaseRef uses it verbatim when it resolves, keeping legacy sequantBase and the origin/main fallback. Before, every sequant run worktree compared against origin/main, so a --base ahead of main disabled the no-change/uncommitted guard. rebaseBeforePR rebases onto a recorded local base that matches the run's base without fetching origin/<base>.

Entire-Checkpoint: adf7c75e638f
…o a recorded local base

Real-git child-process tests for the three --base shapes and both rebaseBeforePR branches (matching local base, chain final link). The branch lookup moves into readRecordedBaseRefAtHead (execFileSync) so rebaseBeforePR's spawnSync sequence is unchanged; phase-executor.test.ts's ordered execFileSync mock answers the new key as unset.

Entire-Checkpoint: 8eb42a637185
…/<base> doesn't exist

QA follow-up: keying on the recorded ref skipped the fetch for a pushed --base (rebasing onto a stale local copy, dropping a teammate's commit) and missed a chain final link with a local run base. The rule is now decided by the remote: fetch as before; on failure, if origin/<base> doesn't resolve but refs/heads/<base> does, rebase onto the local branch without the warning.

Entire-Checkpoint: e573183c7fab
…-ref

# Conflicts:
#	src/lib/workflow/worktree-manager.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant