Skip to content

bug(qa): the qa phase rebases an already-pushed branch onto main, forcing a force-push to land it #1069

Closed

Description

@admarble

What happens

The qa phase rebases the feature branch onto origin/main mid-review. Its own output says so:

✔ Branch rebased onto origin/main

When main has advanced since the branch was pushed, this rewrites already-pushed commits. The local branch and its remote diverge (ahead 8, behind 7), and the only way to land the rewritten history is a force-push — which this repo's hooks block and CLAUDE.md forbids.

Observed

On #1059 (2026-09-15, sequant 2.15.1, sequant_run over MCP, phases: qa). main advanced to 32118b71 (#1065) during the review. Seven pushed commits were rewritten with new SHAs; the run otherwise succeeded with verdict AC_MET_BUT_NOT_A_PLUS.

Recovery, since the rebased commits were content-identical:

git reset --hard origin/<branch>
git merge origin/main

Why it matters

A phase should not rewrite history that exists on the remote. The failure is silent — nothing in the verdict mentions it — and the next git push is what surfaces it, by which point a careless --force looks like the obvious fix. An orchestrator that does not check git status -sb after every qa run will either force-push or get stuck.

Suggested fix

Merge origin/main instead of rebasing whenever the branch has an upstream (@{u} exists), which is the rule the repo already applies everywhere else. Rebase is only safe on a branch that was never pushed.

Acceptance criteria

  • AC-1: when the feature branch has an upstream (@{u} resolves), the pre-PR step merges origin/main instead of rebasing, and no pushed commit SHA changes — Verify: npx vitest run src/lib/workflow/worktree-manager.test.ts -t "1069" → a temp repo with a pushed branch and an advanced main ends with the same SHAs for the pushed commits plus one merge commit. Mutation-verified per CLAUDE.md §Testing: restore the unconditional rebase → the case fails; restore.
  • AC-2: a branch with no upstream still rebases as before — Verify: same command, case no upstream rebases.
  • AC-3: the phase's printed line says which happened (merged origin/main or rebased onto origin/main) — Verify: same command, case reports merge vs rebase.
  • AC-4: npm run build && npm test green.

Release-graph plan — guard-2026-09 (2026-09-20)

Graph: guard-2026-09 Tier: mechanical Wave: 2
May touch: src/lib/workflow/worktree-manager.ts (rebaseBeforePR), src/lib/workflow/batch-executor.ts (the pre-PR call site at the rebase step only), their tests, CHANGELOG.md

The npm run build && npm test AC is verified by the runner from a clean shell after the PR opens (PLAN I-1); the agent runs only the test files its ACs name. Mutation markers use failedTest starting with the test file path (I-4). Wave 2 because #1070 edits batch-executor.ts in wave 1; no hard edge.

Activity

  1. added
    bug
    on Sep 16, 2026
  2. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Runner context — guard-2026-09 wave 2 launch, 2026-09-20. Base: origin/main at bef0ac98 (all seven wave-1 PRs merged: #1086 scrub, #1104 marker docs, #1053, #1106 ownership gate, #1095 parsers, #1096 conformance suite, #1070 failing verdicts post). These rules override the exec AND qa skills' defaults for this run:

    • No full npm test in the worktree — this applies to the qa phase too. Under concurrent phase agents that one call exceeds the 30-minute no-progress wall and the phase is killed (three wave-1 phases died this way). Verify each AC by its own command; run only the test files the ACs name. The runner runs the full suite once per PR from a clean shell and records it on the PR.
    • A named test file red before your change: the suite is now hermetic (bug(test): suite isn't hermetic against the SEQUANT_* env phases inject — exec sees red tests it didn't cause and opens no PR #1086), so a red file is real. Name the issue number and the base-vs-head result in the PR body.
    • Mutation marker (gate-test ACs): <!-- SEQUANT_MUTATION: {"ac":"AC-N","mutation":"<what you deleted>","failedTest":"<test file path> > <describe> > <case>"} --> in the PR body. failedTest MUST start with the test file path. Run parseMutationMarkers on your body before opening the PR. Commit before mutating.
    • 30-minute no-progress wall per phase. Commit a WIP checkpoint before any long command; every command foreground, with timeout.
    • Commits: single-line git commit -m "...", no Co-Authored-By. Push the branch and open the PR yourself (one wave-1 exec forgot). Never rebase or force-push after pushing. One AC per line in the PR body, ids AC-N only.
    • Stop at the PR. Do not merge.

    Issue-specific: src/lib/workflow/batch-executor.test.ts is shared with #1087 this wave: add your cases in ONE new describe("#1069 …") block appended at the end of the file and touch nothing else there (#1087 appends its own block). batch-executor.ts: the pre-PR rebase call site only. Note the qa phase itself currently rebases pushed branches (this is the bug); expect the ✔ Branch rebased onto origin/main line in your own run.

  3. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (4 ACs, 1 directory)

    AC Quality Check

    AC-1..3 are measurable and carry a Verify: command. Two notes:

    • AC-1/AC-2/AC-3 name src/lib/workflow/worktree-manager.test.ts, which does not exist (only worktree-manager.build-pr-body.test.ts and .frozen-install.test.ts). It is created new. -t "1069" requires 1069 in the describe/case name.
    • AC-4 (npm run build && npm test) is runner-verified from a clean shell per the graph plan; the agent runs only the named test files.

    Scope Assessment

    Non-Goals: not stated in the issue. Inferred from "May touch": the chain-mode successor rebase (ensureWorktree, rebaseOntoLocalBranch, ~L905/L1373) is out of scope — those rebase onto a local predecessor branch, not origin/main.

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

    Verdict: ✅ SCOPE_OK


    Acceptance Criteria

    AC-1: pushed branch → merge origin/main, no pushed SHA changes

    Verification: Integration Test (real temp repos: bare remote + clone + worktree, no mocks)
    Scenario: Given a branch pushed to origin/<branch> with N commits and origin/main advanced → When rebaseBeforePR runs → Then the N original SHAs are all still ancestors of HEAD (and HEAD~ chain unchanged) plus exactly one merge commit; git status -sb shows ahead 1, not ahead N, behind M.
    Assumptions: hermetic git identity from vitest.global-setup.ts covers the merge commit. Mutation: restore the unconditional git rebase → this case must fail.

    AC-2: no upstream → still rebases

    Verification: Integration Test (no upstream rebases)
    Scenario: Given a never-pushed branch, main advanced → When run → Then history is linear (no merge commit), branch sits on origin/main.
    Assumptions: see Open Question 1 — the fixture must also cover the fresh-worktree shape (below).

    AC-3: printed line says which happened

    Verification: Integration Test (reports merge vs rebase)
    Scenario: Given each of the two setups → Then stdout contains merged origin/main / rebased onto origin/main respectively (spy console.log; chalk color stripped).

    AC-4: npm run build && npm test green

    Verification: runner, clean shell. Existing rebaseBeforePR unit tests in src/commands/run.test.ts:1382+ mock spawnSync positionally (fetch → rebase → …); they will break when a new upstream-probe call is added and must be updated (see plan step 4).


    Implementation Plan

    Phase 1: rebaseBeforePR (worktree-manager.ts:1418)

    1. Add a small helper branchIsPushed(worktreePath, baseRef): true iff the branch has an upstream (rev-parse --abbrev-ref --symbolic-full-name @{u} succeeds) and that upstream is not baseRef (see Open Question 1 — this is the key correctness point).
    2. After the fetch, if pushed: git merge --no-edit <baseRef>; else existing git rebase <baseRef>. Conflict path: merge --abort (vs rebase --abort), same RebaseResult shape (success:false, "conflict - manual resolution required"). Keep messaging parallel.
    3. Print ✔ Merged origin/main into branch (…) → exactly merged origin/main / rebased onto origin/main per AC-3; also handle "Already up to date" (print it truthfully rather than claiming a merge). Consider adding strategy: "merge" | "rebase" to RebaseResult so callers/tests don't parse stdout.
    4. Capture HEAD before the operation and pass it as preRebaseRef to reinstallIfLockfileChanged (it defaults to ORIG_HEAD, which a merge that is "already up to date" or fast-forward does not reliably set). Update the positional spawnSync mocks in src/commands/run.test.ts for the extra probe call.

    Phase 2: call site + tests

    1. batch-executor.ts:2253 — no logic change expected (it already just calls rebaseBeforePR); touch only if RebaseResult.strategy should be surfaced in the log. Add the #1069 describe once, appended at the end of batch-executor.test.ts, only if a call-site assertion is needed (shared with bug(codex): usage-limit turn failures classified 'unknown' — quality loop re-runs into the same quota, --auto-wait can't engage #1087 — touch nothing else).
    2. New src/lib/workflow/worktree-manager.test.ts with cases: #1069 pushed branch merges and keeps SHAs, no upstream rebases, reports merge vs rebase, plus (added) fresh worktree branch tracking origin/main still rebases and merge conflict aborts and leaves branch intact. Real git, and name it so the 5s default timeout isn't an issue (or set explicit timeouts — no .integration. in the name ⇒ 5s limit).
    3. CHANGELOG.md entry. Record mutation-verified marker in the PR body (failedTest beginning with src/lib/workflow/worktree-manager.test.ts > …).

    Rule Touchpoints

    Rule-shaped AC ("instead of … whenever … no pushed commit") — touchpoints: worktree-manager.ts:1418 (rebaseBeforePR, the fix site) and batch-executor.ts:2253 (call site). Skill prose also describes rebasing: .claude/skills/qa/SKILL.md:327,332 tells users to git rebase origin/main — advice to a human, and it contradicts the repo's merge-not-rebase rule; not in "May touch", so raised as a follow-up, not silently widened (Open Question 2).

    Design Review

    1. Where does the logic belong? worktree-manager.ts::rebaseBeforePR — the only place the origin/main sync happens; the call site stays dumb.
    2. Simplest correct approach? One helper + a branch on it. Rejected: always merge (changes the never-pushed lockfile-drift/linear-history behavior AC-2 preserves); rejected: skip the sync when pushed (leaves the PR stale).
    3. Existing pattern? Same shape as rebaseOntoLocalBranch (fetch → op → abort on conflict → result struct); the "merge pushed branches" rule from repo practice.
    4. Senior challenge: "why not just @{u} as the issue says?" → because of the finding below.

    Feature Quality Planning

    Notable items:

    • ⚠️ The issue's suggested test — "@{u} resolves" — is wrong for fresh worktrees. Verified empirically: git worktree add -b feat <path> origin/main (what ensureWorktree does at L893) auto-sets upstream to origin/main, so @{u} resolves to origin/main for a never-pushed branch. A bare @{u} check would merge on every first run — silently regressing AC-2 in production while a "no upstream" fixture (branch created without tracking) still passes. Same trap the unpushed-commits probe at L300 sits next to. The check must be "upstream exists and is not the base ref" (equivalently, origin/<branch> exists). Derived AC below.
    • Merge commit needs a git identity in the worktree; real runs have it (checkpoint commits already require it).
    • Conflict on merge must merge --abort; otherwise the worktree is left mid-merge and createPR operates on a dirty tree.

    Derived ACs

    Source Derived AC Priority
    Correctness (empirical) AC-5: a never-pushed branch whose upstream is origin/<base> (fresh worktree add -b … origin/main) still rebases — case fresh worktree branch tracking origin/main still rebases High
    Error handling AC-6: merge conflict aborts the merge, leaves HEAD/SHAs unchanged, returns success:false Medium

    Open Questions

    1. Upstream test — Recommendation: "upstream resolves and ≠ origin/<baseBranch>" (adopt AC-5). Impact if the issue's literal @{u} is used: every fresh branch merges instead of rebasing; AC-2's literal fixture still passes, so QA could miss it.
    2. qa/SKILL.md:327,332 recommends git rebase origin/main to users — Recommendation: file a follow-up (not in "May touch"; skill edits need all three mirror dirs). Impact if left: prose contradicts the fix.
    3. Title says "qa phase" but the rebase runs in the pre-PR step after all phases — Recommendation: fix at rebaseBeforePR as planned; it fires on any run, so title is loosely worded, not a scope difference.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: Single-function bug fix with bug label; ACs are unit/integration verified by the tests the issue names, so testgen is skipped (targeted tests are written in exec). No UI, no security surface. Runner rules from the launch comment apply (no full npm test in the worktree; commit before mutating; stop at the PR).

    Label Review

    Current: bug
    Recommended: bug, planned
    Quality Loop: Won't auto-enable (SCOPE_OK, simple fix)

  4. added
    planned
    on Sep 20, 2026
  5. added 2 commits that reference this issue on Sep 20, 2026
  6. admarble commented on Sep 20, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 0/6 met

    Gaps:

    • New real-git test file sits in the 5s unit vitest project, the documented fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings #842 flake class, against the spec's explicit instruction
    • The non-conflict merge-failure abort branch, added specifically so createPR never sees MERGE_HEAD, has zero test coverage
    • merge --abort on the non-conflict failure path could discard uncommitted unrelated changes; the clean-tree assumption is undocumented
    • Three un-updated positional-mock cases still pass but their comments misdescribe the call order, a trap for the next editor
    • AC-1's parenthetical mechanism no longer describes the shipped contract; the spec superseded it with AC-5 but the issue AC text was never edited
    • An already-up-to-date merge still reports 'Branch merged origin/main', a spec item left unimplemented
    • The new strategy field is a test-only affordance with no production consumer, so the merge-vs-rebase choice stays invisible in the run log
    • A sibling intra-file rebase site shares the root cause but is out of the declared May-touch scope; follow-up rather than scope widening
    • Skill prose still advises users to rebase onto origin/main, contradicting this fix and the repo merge-not-rebase rule
    • F1 — new test file lands in the 5s unit vitest project. vitest.config.ts:19-30 puts **/*.test.ts without .integration. into unit, which keeps vitest's 5s default testTimeout. Each of the 5 cases spawns 10+ real git subprocesses. The spec explicitly said "name it so the 5s default timeout isn't an issue (or set explicit timeouts — no .integration. in the name ⇒ 5s limit)" — neither was done. Measured 2.53s for 5 cases on an idle machine; fix(test): tsx-spawning integration tests blow vitest's 5s default — phase-registry should use the prebuilt dist like its five siblings #842 measured 7.5–17.8s for subprocess tests under full-suite load. beforeEach is safe (60s hookTimeout), but the it() bodies commit, push and advance main inside the 5s budget.
    • F2 — the merge --abort on non-conflict failure has zero test coverage. That branch (if (pushed) { merge --abort }) was added by fb95d910 specifically so createPR never runs against a MERGE_HEAD tree. No case exercises it: worktree-manager.test.ts covers only the conflict abort, and both updated run.test.ts cases mock the upstream probe as status 128 → rebase path, so they never reach it.
    • F3 — merge --abort can discard uncommitted work on that same path. git merge --abort resets hard; unrelated dirty files would be lost. Mitigated in practice (a checkpoint commit runs at batch-executor.ts:2216-2240 before the rebase step, and git refuses to start a merge that would overwrite tracked local changes), but there's no guard or comment recording that assumption.
    • F4 — stale comments in src/commands/run.test.ts. Three cases were not updated (should successfully rebase…, should continue when fetch fails, should use custom base branch…). They still pass — the un-updated mockReturnValueOnce now feeds the upstream probe, whose empty stdout makes branchIsPushed return false, so the rebase path is still taken and should use custom base branch still meaningfully asserts ["rebase", "origin/master"]. But the // Mock rebase (success) comments now describe the wrong call, which will mislead the next editor of these positional mocks.
    • F6 — spec item not implemented. Implementation Plan step 3 asked to "also handle 'Already up to date' (print it truthfully rather than claiming a merge)". The success path prints ✔ Branch merged origin/main unconditionally. Cosmetic; AC-3 is still satisfied.

    Suggestions:

    • F7 — RebaseResult.strategy has no production consumer; batch-executor.ts:2253 discards the return value entirely. It's a test-only affordance today (the spec did suggest it). Surfacing it in the run log would make the merge-vs-rebase choice visible to the operator, which is closer to the issue's "the failure is silent" complaint.
    • F8 — Spec Open Question 2 is still open: qa/SKILL.md tells users git rebase origin/main (stale-branch remediation) and git pull origin main (pre-flight sync). That prose now contradicts this fix and the repo's merge-not-rebase rule. Correctly excluded from "May touch"; worth filing.
  7. added a commit that references this issue on Sep 20, 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

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions