Skip to content

fix(run): --base creates the worktree from the branch but opens the PR against the repo default branch #1386

Closed

Description

@admarble

Epic: graph-2026-10-freeze Tier: mechanical Execution: sequant_run

Problem

sequant run <N> --base <branch> creates the worktree from <branch> and rebases onto origin/<branch> before the PR, but opens the PR against the repository's default branch. The PR's diff then includes everything that differs between <branch> and the default branch, not just the issue's change.

Seen: stranger smoke test, 2026-10-09, sequant 2.19.0 (npm), Claude Code 2.1.295. sequant run 21 --base smoke/stranger-2026-10-09 on a private fixture repo: the log says "Preparing worktrees from smoke/stranger-2026-10-09" and "Branch merged origin/smoke/stranger-2026-10-09", but the PR was created with base=main. Against its real base the change is 2 files, +161 lines. Against main the PR shows 37 files, +6,354/−440, because the base branch held a fresh sequant init that main did not.

Cause: createPR sets fields.base only from stackOptions.prBase (src/lib/workflow/worktree-manager.ts:2342). stackOptions is built only under --stacked / chain mode (src/lib/workflow/batch-executor.ts:1213, #605). A plain --base (or settings.run.defaultBase) never reaches gh pr create, which then uses the repo default. #605 and #748 fixed the chain and stacked variants of this class; the non-chain path was not covered.

Acceptance Criteria

  • AC-1: With --base <branch> and no --stacked, the PR is opened with base: <branch>, and worktree creation, rebaseBeforePR and createPR all receive the same ResolvedRun.baseBranch value. Evidence: a test that runs the issue path with a non-default base and asserts the three consumers got one identical value, mutation-verified by dropping the base from the createPR call.
  • AC-2: settings.run.defaultBase set to a non-default branch has the same effect as --base. Evidence: a test with the setting set and no CLI option.
  • AC-3: With neither --base nor defaultBase, the PR base is unchanged (the repo default). Evidence: an existing or added test.
  • AC-4: --stacked still targets the predecessor branch and takes precedence over --base for non-last links. Evidence: the existing feat(cli): --stacked flag — set chain-mode PR base to predecessor branch #605 tests pass.

Prior fixes / producers

May touch

src/lib/workflow/batch-executor.ts, src/lib/workflow/worktree-manager.ts (createPR only), their tests. Serialize with #1380 (same file, disjoint functions, graph doc D-5).

Non-Goals

  • Changing how the base is resolved (flag → setting → detected default stays as is).
  • --stacked behaviour beyond AC-4.
  • Any edit under plugin/, .claude/skills/ or templates/skills/ (plugin freeze, I-1 of the graph doc).

Activity

  1. added
    bug
    on Oct 9, 2026
  2. admarble commented on Oct 9, 2026

    @admarble
    ContributorAuthor

    Constraint for the fix: resolve the base once. The 2026-09-30 re-patch retrospective named "base ref / two worktree producers" as a cluster patched site by site, and this issue and #1380 arrived the same week. Today the base is resolved separately for worktree creation, for rebaseBeforePR(…, baseBranch) and for createPR (which only sees stackOptions.prBase).

    Resolve it in one place (--base → settings.run.defaultBase → repo default, with --stacked overriding for non-last links) and pass that one value to all three. The fix isn't done if createPR learns about --base while the other two keep their own resolution. Add a test that asserts the three consumers receive the same value. That's the parity gate the constitution's "one producer per artifact" row asks for (#1250).

    Related: #1380 (worktree re-creation rebuilds from base and drops commits), which touches the same resolution.

  3. added
    graph-2026-10-freeze
    on Oct 9, 2026
  4. added a commit that references this issue on Oct 10, 2026
  5. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    Runner context for the phase agents (graph-2026-10-freeze, wave 1). This applies to the exec phase and the qa phase by name.

    • No full npm test in the worktree, in exec or in qa. Three phases run in parallel in this wave, and a full-suite run (10–13 min) under that load crosses the 30-minute phase wall and kills the phase. Run only the test files you touch or add (npx vitest run <file>…), in the foreground, with a timeout, after a WIP commit. The runner session runs the full suite on the PR branch after the PR opens.
    • Plugin freeze (graph doc I-1): the diff must not touch plugin/, .claude/skills/ or templates/skills/. The runner checks this before any merge.
    • CHANGELOG.md [Unreleased]: add your line; conflicts with sibling PRs are expected and the runner resolves them.
    • Gate-test ACs need the mutation record in the PR body (see CLAUDE.md, Testing). The failedTest field starts with the test file path.
  6. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (4 ACs, 2 directories)

    AC Quality Check

    • AC-1 Evidence is a test with a mutation requirement. It fails today (createPR never receives the base), so it is not vacuous. "One identical value" must be pinned to a concrete assertion: the --base string reaches worktree creation, rebaseBeforePR, and the createPR / gh pr create --base argument.
    • AC-2 and AC-4 are fine. AC-3 ("unchanged") passes on today's code, so it is a regression guard, not a gate. Mutation-verify AC-1 only.
    • Non-Goals present.

    Scope Assessment

    Non-Goals: present (no change to resolution order, no --stacked work beyond AC-4, no plugin/skills edits).

    Metric Value Status
    Feature count 1 ✅
    AC items 4 ✅
    Directory spread 1 (src/lib/workflow) ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: --base <branch> without --stacked opens the PR against <branch>; all three consumers get one value

    Verification: Unit/Integration Test
    Scenario: Given --base feat/x (detected default main) → When the issue path runs through worktree creation, rebaseBeforePR, createPR → Then all three receive feat/x and gh pr create gets --base feat/x.
    Assumptions: The base reaching executeBatch/runIssueWithLogging is ResolvedRun.baseBranch, not the separate cfg.baseBranch (see Design Review Q5).

    AC-2: settings.run.defaultBase behaves like --base

    Verification: Unit Test (resolveRunOptions / orchestrator resolve with setting, no CLI option, then the same createPR assertion)

    AC-3: Neither set → PR base unchanged

    Verification: Unit Test (createPR called with base equal to the detected default passes no --base)

    AC-4: --stacked precedence unchanged

    Verification: Existing #605 tests (worktree-manager.test.ts, batch-executor.test.ts) plus one added case: non-last link with --base set still gets predecessorBranch.

    Implementation Plan

    Phase 1: One resolver for the PR base

    1. src/lib/workflow/worktree-manager.ts: add an exported resolvePrBase(stackPrBase, baseBranch, detectedDefault) next to computeWorktreeBaseRef (~line 827), same semantics: stackPrBase wins; else baseBranch with any origin/ prefix stripped when it differs from the detected default; else undefined (gh uses the repo default).
    2. createPR (line 2266): add the resolved base to its inputs and use resolvePrBase(...) for both createPRCliSync(..., base) (line ~2342) and updateExisting's fields.base. Prefer extending the existing stackOptions shape or the trailing opts object over a 13th positional parameter.

    Phase 2: Thread the value

    1. src/lib/workflow/batch-executor.ts (~line 1213): pass baseBranch (already destructured from ctx at line 1117) into the createPR call at ~line 1272. Do not build a second resolution here.
    2. Verify the baseBranch in BatchExecutionContext is the resolved ResolvedRun.baseBranch on every entry path: run-orchestrator.ts:1627 passes this.cfg.baseBranch, which is a separate field from the ResolvedRun.baseBranch computed at line 721. If it can be unset when only settings.run.defaultBase is given, populate it from the resolved value (this is the AC-2 failure mode).

    Phase 3: Tests (mutation-verified for AC-1)

    1. Parity test: one run with --base feat/x, spy on ensureWorktrees, rebaseBeforePR, createPR; assert one identical value. AC-2, AC-3, AC-4 cases alongside.
    2. Mutation: drop the base from the createPR call; confirm the AC-1 test fails; restore. Record with the Mutation-verified: marker, failedTest starting with the test file path.

    Design Review

    1. Where does this logic belong? worktree-manager.ts, beside computeWorktreeBaseRef; both turn "base option + detected default" into a ref/branch.
    2. Simplest correct approach? Pass the existing resolved value through and resolve the PR base with a helper that mirrors the worktree one. Rejected: calling detectDefaultBranch in batch-executor (extra git call, disturbs ordered mocks); always passing --base <detected default> (if detection falls back to "main" on a repo whose default is something else, gh pr create would break where it works today).
    3. Pattern / re-patch count? "PR base" was fixed in feat(cli): --stacked flag — set chain-mode PR base to predecessor branch #605 (--stacked) and fix(run): sequant run has two PR producers — exec opens the PR itself and createPR returns it untouched, dropping the QA note, ready-gate report and summary #1247 (one PR producer); fix(chain): --chain successors branch from main, not predecessor's committed work (up-front worktree provisioning) #748 covered chain. This is the third site-by-site patch, so the fix is the single helper plus the three-consumer parity test, per the issue's constraint, not another local patch.
    4. Reviewer challenge: "Why not always pass --base?" See Q2. "Why retarget an existing PR in updateExisting?" It already does so for prBase; same value, same rule.
    5. Producers/consumers (whole-repo grep): Producer of the base: run-orchestrator.ts:721 (ResolvedRun.baseBranch). Possible second producer: OrchestratorConfig.baseBranch (run-orchestrator.ts:207/238, used at 448 and 1627 with a ?? "main" fallback). Consumers: ensureWorktrees/ensureWorktreesChain, rebaseBeforePR, createCheckpointCommit, resolveDiffBase (batch-executor 2036/2059), createPR. No divergence from the prescribed lever, so no halt.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • origin/<x> bases: gh --base needs the bare name; strip the prefix.
    • A local-only base branch: gh pr create --base fails if it is not pushed. Today's behavior with --base is already to rebase onto the local branch (worktree-manager ~1668), so surface a clear error, not a silent fallback. Decide in Open Questions.
    • Plugin freeze: no edits under plugin/, .claude/skills/, templates/skills/. CHANGELOG.md [Unreleased] line required.

    Open Questions

    1. Retarget an existing PR on update? Recommendation: yes, same value as create (matches the prBase behavior). Impact: a hand-retargeted PR gets moved back.
    2. Local-only base branch at PR time — Recommendation: let gh fail and surface its error (already a failed PR step per 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). Impact: run marked failed instead of opening a PR against the wrong base.
    3. Serialize with ensureWorktree "recreating fresh" rebuilds a PR branch from base and drops its commits; qa re-run reviews the wrong tree #1380 (same file, disjoint functions, D-5) — Recommendation: land one then merge main into the other.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Small, mechanical fix with a parity test. Tests are written alongside exec (unit-test ACs, but a bug-fix with targeted tests, so no testgen). No UI. Runner context: no full npm test in exec or qa (per the wave comment).

    Label Review

    Current: bug, graph-2026-10-freeze
    Recommended: bug, graph-2026-10-freeze, planned
    Quality Loop: Won't auto-enable (SCOPE_OK, no complex labels)

  7. added
    planned
    on Oct 10, 2026
  8. admarble commented on Oct 10, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 4/4 met

    Gaps:

    • AC-1 mutation-verification record missing; add the marker to exec's final ## Summary
    • Stale comment: under --base the last stacked PR now targets the run's base, not main
    • Stale comment: batch-executor.ts:1211 still says "Last PR keeps main". With --base X and --stacked, the last PR now targets X. That is consistent, because the last link is rebased onto X, but the comment no longer matches.

    Suggestions:

    • A base on another remote (e.g. upstream/foo) is not prefix-stripped. This is an edge case and not required by any AC.
  9. added a commit that references this issue on Oct 10, 2026
  10. added 2 commits that reference this issue on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggraph-2026-10-freezeplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions