Repository navigation
Description
Epic: graph-2026-10-freeze-b Tier: judgment Execution: sequant_run
Problem
Phase agents get no base-branch information. The CLI resolves the base correctly: #343 added detectDefaultBranch() (worktree-manager.ts:180) and settings.run.defaultBase, and phase-executor.ts records the base per branch (branch.<b>.sequantBaseRef, read back by resolveBaseRef, :906). But the env built for the phase agent (phase-executor.ts:1683–1710) sets SEQUANT_WORKTREE, SEQUANT_ISSUE, SEQUANT_ORCHESTRATOR, SEQUANT_PHASE and SEQUANT_ISSUE_TYPE, and no base branch. The skills that do read one (BASE="${SEQUANT_BASE_BRANCH:-main}" in exec, qa, loop and testgen) therefore always fall back to main. grep -rn SEQUANT_BASE_BRANCH src finds nothing.
On a repo whose default branch is master, every origin/main in a phase's git commands fails. Measured in varius (default master): git diff origin/main...HEAD --name-only prints fatal: ambiguous argument 'origin/main...HEAD' and exits 128. The skill-side half of the fix is #1461.
Acceptance Criteria
- AC-1: The phase env sets
SEQUANT_BASE_BRANCHto the base branch name (noorigin/prefix) taken fromresolveBaseRef(cwd), for every phase, including spec, which runs in the main checkout with no recorded base. Evidence: phase-executor unit tests for a worktree phase with a recordedsequantBaseRefoforigin/masterand for a no-worktree spec phase on a repo whoseorigin/HEADismaster, both assertingenv.SEQUANT_BASE_BRANCH === "master", mutation-verified by deleting the assignment - AC-2:
resolveBaseRef(cwd)'s literal"origin/main"fallback (used when HEAD is detached, nothing is recorded, or git fails) is replaced byorigin/<default branch of cwd>, usingdetectDefaultBranchwith an optionalcwdargument (defaultprocess.cwd(), so existing callers are unchanged), so no hard-codedmainis left on the resolver path. Evidence: aresolveBaseRefunit test in a temp repo whose default branch ismaster, with no recorded base, passing the temp repo ascwdwith noprocess.cwdpatch, returningorigin/master, mutation-verified by restoring the literal - AC-3:
docs/reference/run-command.mdlistsSEQUANT_BASE_BRANCHwith the other phase env variables. Evidence:grep -n SEQUANT_BASE_BRANCH docs/reference/run-command.mdreturns the new row
Why AC-2 is in scope: resolveBaseRef (phase-executor.ts:906–937) returns the literal origin/main in four places whenever there is no recorded base. Worktree phases always have a recorded base (#1234), but spec runs in the main checkout on the default branch with nothing recorded. Without AC-2, spec on a master repo would get SEQUANT_BASE_BRANCH=main, which is the bug this issue fixes. AC-2 adds no new producer. It routes the fallback to the existing detectDefaultBranch(). Callers that benefit too: the exec guard (phase-executor.ts:1000) and hasCommitsAheadOfBase (worktree-manager.ts:421, not edited).
Graph note (graph-2026-10-freeze-b, 2026-10-16): detectDefaultBranch() runs its git commands in process.cwd(), not in a passed cwd (worktree-manager.ts:180). Called from resolveBaseRef(cwd) as-is, it would read the wrong repo whenever the two differ, and AC-2's temp-repo test could only pass by patching process.cwd, which this repo's forks pool leaks across test files. So AC-2 adds an optional cwd parameter to detectDefaultBranch. That edits worktree-manager.ts, so this issue is blocked by #1406 (same file as #1405 and #1406) and runs in wave 3. When origin/HEAD is unset, detectDefaultBranch falls back to git remote set-head origin --auto, a network call; that path is reached only when no base is recorded (the spec phase), at most once per phase.
Import note: worktree-manager.ts already imports from phase-executor.ts, so importing detectDefaultBranch back is an ESM cycle. That's safe here, because both are function declarations called at run time, not at module load, and the repo has no cycle lint. Moving detectDefaultBranch out of worktree-manager.ts to break the cycle is allowed but not required; either way the edit lands after #1406.
May touch
src/lib/workflow/phase-executor.ts (env block, resolveBaseRef fallback, and their tests), src/lib/workflow/worktree-manager.ts (detectDefaultBranch signature only: an optional cwd), docs/reference/run-command.md, CHANGELOG.md.
Prior fixes / producers
This is the base-ref design cluster from the 2026-09-30 re-patch retrospective (#1236: "base ref / two worktree producers", 5 fixes then, more since). Prior fixes: #748, #878 (diff stats against origin/<base>, which added resolveDiffBase), #890 (remaining bare main...HEAD consumers via resolveDiffBase), #1069, #1234 (worktrees record their exact base ref; the exec guard and pre-PR rebase read it), #343 (CLI default-branch detection), #1386 (--base PR target).
Root cause, from the trace: every TypeScript consumer now goes through one resolver (resolveDiffBase / resolveBaseRef), but shell and skill consumers have no channel to it, so each one hard-codes a guess. #890 itself changed quality-checks.sh from main...HEAD to a literal origin/main...HEAD, which fixed staleness but left the default branch hard-coded. This issue is that channel: it exports the resolver's answer and adds no third producer. #1136 added SEQUANT_BASE_BRANCH as a skill input for in-place mode, where the user sets it. Nothing in sequant run sets it.
Not a regression: no commit broke a working path, so nothing needs reverting.
Non-Goals
- No skill-text edits (plugin freeze). That's fix(skills): origin/main is hard-coded in exec/qa/spec commands, and quality-checks.sh turns the git failure into zeros on master-default repos #1461.
- Any other change to
worktree-manager.ts(fix(worktree): first creation on a fresh machine ignores origin/<branch>, and a recreated PR worktree is recreated again on every run (#1380 follow-up) #1405 and fix(worktree): a non-default bare --base is cut from local <base> but counted against origin/<base> (#1380 follow-up, #1234/#1386 class) #1406 own it in this graph). - Any edit under
plugin/,.claude/skills/ortemplates/skills/(plugin freeze).
Activity
docs(graph): add #1460 to graph-2026-10-freeze-b as a wave-3 node blo…
docs(graph): add #1456 and #1460 to graph-2026-10-freeze-b (#1462)
admarble commentedon Oct 16, 2026
Runner context (graph-2026-10-freeze-b, wave 3)
#1406 merged as 91fb052 and changed
computeWorktreeBaseRefand its fetch inworktree-manager.ts, so build onmainas it is now. These notes are for both the exec phase and the qa phase:npm test(the full suite) in exec or qa. Each phase stops after 30 minutes with no progress, and these phases run the published sequant 2.19.0, which has no affected-tests mode. Run the test files you change or name withnpx vitest run <file>. CI runs the full suite on the PR.mutationandfailedTesttext.plugin/,.claude/skills/ortemplates/skills/. The issue's skill half is fix(skills): origin/main is hard-coded in exec/qa/spec commands, and quality-checks.sh turns the git failure into zeros on master-default repos #1461, which is frozen.skills-commit-state.ts) and feat(#1454): open PRs on origin whose files overlap the work are merge-order members — add them to the existing overlap checks #1481 (merge-check/) don't touch this issue's files.admarble commentedon Oct 16, 2026
Complexity: Standard (3 ACs, 3 directories)
AC Quality Check
Evidence:clause, and the issue has## Non-Goals.grep -n SEQUANT_BASE_BRANCH docs/reference/run-command.mdreturns nothing onmain(91fb052). The AC-1/AC-2 tests don't exist yet. The existingresolveBaseRef falls back to origin/maintest (phase-executor.integration.test.ts:183) still passes with the literal restored, so it can't serve as AC-2's mutation target. Only the newmastertest can.run-command.mdhas no list of "the other phase env variables" today. Its only env table (~:636) covers input settings (SEQUANT_QUALITY_LOOP, …). Exec should add a short "Phase agent environment" table (SEQUANT_WORKTREE,SEQUANT_ISSUE,SEQUANT_ORCHESTRATOR,SEQUANT_PHASE,SEQUANT_ISSUE_TYPE,SEQUANT_BASE_BRANCH), not one orphan row.Scope Assessment
Non-Goals: present (no skill edits, #1461; no other
worktree-manager.tschange; nothing underplugin/,.claude/skills/,templates/skills/).src/lib/workflow,docs/reference, rootCHANGELOG.md)Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: phase env sets
SEQUANT_BASE_BRANCHfromresolveBaseRef(cwd), for every phaseVerification: Unit Test (driver boundary mocked, as in
full-qa.test.ts)Scenario: (a) Given a temp worktree with
branch.<b>.sequantBaseRef=origin/master, passed asworktreePath→ WhenexecutePhaseWithRetry(N, "exec", config)runs → ThenagentConfig.env.SEQUANT_BASE_BRANCH === "master". (b) Given no worktree and a repo whoseorigin/HEADismaster→ When thespecphase runs → Then the same holds.Assumptions: Strip only a leading
origin/. A local chain-mode ref (feature/x,base-arm) passes through unchanged, which matches how the skills use it ([[ "$CURRENT" == "$BASE" ]], a bare branch name). Case (b) has a test-harness problem, see OQ-1.AC-2:
resolveBaseReffallback becomesorigin/<detectDefaultBranch(cwd)>Verification: Integration Test (real temp git repo)
Scenario: Given a temp repo + bare origin whose HEAD is
master, and nosequantBaseReforsequantBase→ WhenresolveBaseRef(tmp)→ Then"origin/master". Noprocess.cwdpatch.Assumptions: All three
spawnSynccalls indetectDefaultBranchtake{ cwd }. The defaultprocess.cwd()keeps the 6 existing call sites (worktree-manager.ts:994,1032,1105,1190,1390,1437,2496) unchanged. The existing no-origin tests (:183,:307) still resolveorigin/main, because their bare origins are--initial-branch=mainandset-head --autoagainst a local path works without network access.AC-3:
run-command.mddocumentsSEQUANT_BASE_BRANCHVerification: Manual Test (
grep, plus reading the row)Scenario: Given the docs → When grep runs → Then a row says it's a bare branch name, set on every phase, taken from the worktree's recorded base or else the repo's default branch.
Implementation Plan
Phase 1: Resolver (
worktree-manager.ts, signature only;phase-executor.ts)detectDefaultBranch(verbose = false, cwd: string = process.cwd()): threadcwdinto its threespawnSynccalls. Add it as a second parameter so existingdetectDefaultBranch(verbose)callers don't change.resolveBaseRef(cwd): replaceconst fallback = "origin/main"with a lazyconst fallback = () => \origin/${detectDefaultBranch(false, cwd)}`. Lazy so the recorded-base path (every worktree phase) never spawns the extra git calls or theset-head --autonetwork call. Update the doc comment's step 3. ImportdetectDefaultBranchfrom./worktree-manager.js`. The cycle is safe because it only runs at call time (issue's import note). Don't move the function.Phase 2: Env channel (
phase-executor.ts~:1697)env.SEQUANT_PHASE = phase;, addenv.SEQUANT_BASE_BRANCH = resolveBaseRef(cwd).replace(/^origin\//, "");.cwdis the existing local at :1636 (worktree orprocess.cwd()). Set it unconditionally, so it covers spec too.Phase 3: Tests + docs
src/lib/workflow/phase-executor.base-branch.integration.test.ts(the.integration.suffix avoids the 5s cap on real git). It holds AC-2'sresolveBaseReftest plus AC-1 (a) and (b).docs/reference/run-command.md: add the phase-env table (AC-3). Add aCHANGELOG.mdUnreleased → Fixed entry.npx vitest runon the new file +phase-executor.integration.test.ts+worktree-manager.test.ts+full-qa.test.ts(runner note: no fullnpm test). Mutation-verify AC-1 (delete the assignment) and AC-2 (restore the literal). Record both asSEQUANT_MUTATIONmarkers with no braces in the text, andfailedTeststarting with the file path.Design Review
resolveBaseRef, the single TS resolver.RunOptions.base/BatchExecutionConfig.baseBranchintoExecutionConfig. That is a second producer racing the recorded ref, which is the tracker(graph): pre-release fixes before the next release after 2.18.0 (4 nodes) #1236 failure shape. (b) Detect the default branch inside each skill. That's fix(skills): origin/main is hard-coded in exec/qa/spec commands, and quality-checks.sh turns the git failure into zeros on master-default repos #1461's job, and it's frozen.mainon the TS resolver path. No new producer, so not a divergence.--basefor spec?" Spec doesn't read the variable (only exec/qa/loop/testgen do), and worktree phases already get--basethrough the recorded ref. "Why the extra git spawns per phase?" With the lazy fallback, a recorded base costs 2–3 localgitcalls. Only the spec phase can reachset-head --auto.docs/reference/checkout-modes.md:30, outsidesequant run). Consumers:{.claude,plugin,templates}/skills/{exec,qa,loop,testgen}/SKILL.md(BASE="${SEQUANT_BASE_BRANCH:-main}").resolveBaseRefconsumers that get the new fallback: exec guardphase-executor.ts:1000,hasCommitsAheadOfBaseworktree-manager.ts:421. That's one producer insidesequant run, so no parity test needed.Feature Quality Planning
All standard checks pass. Notable items:
SEQUANT_BASE_BRANCH.envspreadsprocess.envfirst. Undersequant runthe resolver is the authority, so overwriting is intended. Say so in the code comment and the docs row (OQ-2).checkout-modes.md:30says "Defaults tomain". That's true for in-place mode; leave it, since fix(skills): origin/main is hard-coded in exec/qa/spec commands, and quality-checks.sh turns the git failure into zeros on master-default repos #1461 owns skill-side wording.Open Questions
cwd = process.cwd()(the sequant checkout,origin/HEAD=main).process.cwdspies leak across the forks pool. Recommendation: in the new test file,vi.mock("child_process", …importActual…)and overrideexecFileSync/spawnSynconly for therev-parse --abbrev-ref HEAD,config --get branch.*, andsymbolic-ref refs/remotes/origin/HEADargv. Everything else passes through. Impact if wrong: aprocess.chdirversion flakes other files in the same fork.SEQUANT_BASE_BRANCHinprocess.envwin? Recommendation: no, the resolver wins (AC-1 literal). Impact: a user exporting it beforesequant runis silently overridden. That's documented, and it's the correct value anyway.--base feature/xgets the default branch. That's accepted, because no spec consumer exists. Recommendation: note it in the docs row and don't fix it here.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning:
bug, 3 ACs, one module plus docs. Skip testgen: the tests are specific git fixtures exec writes alongside the code. Not security-sensitive (execFileSyncargv is unchanged).Label Review
Current:
bug,graph-2026-10-freeze-b. Recommended: addplanned. Quality Loop: won't auto-enable (SCOPE_OK).admarble commentedon Oct 16, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 3/3 met
Gaps:
phase-executor.ts:993still says the base ref "defaults toorigin/main". It is now the default branch ofcwd.src/lib/merge-check/combined-branch-test.ts:57hasconst BASE_REF = "origin/main". This is the same hard-coded-default defect, but it is not on the resolver path, so it is outside this issue's scope.docs(#1460): the zero-diff guard's base comment names resolveBaseRef'…
fix(#1460): phase agents never get SEQUANT_BASE_BRANCH — skills fall …