Skip to content

fix(#748): --chain successors branch from predecessor's committed work, not main - #752

Merged
admarble merged 5 commits into
mainfrom
feature/748-fix-chain-chain-successors-branch-from-main-not-pr
Jun 28, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/748-fix-chain-chain-successors-branch-from-main-not-pr

Conversation

@admarble

@admarble admarble commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On a fresh sequant run <a> <b> --chain run, successors were branching from main instead of their predecessor's committed work. ensureWorktreesChain provisions all worktrees up-front, branching each successor from the predecessor's branch name — but at that point the predecessor branch still points at the base (it hasn't executed yet), so every successor effectively branched from main.
  • Fix (issue's Option 2): executeSequential now re-rebases each chain successor's worktree onto its predecessor's local committed tip just before the successor runs — independent of --stacked, targeting feature/<predecessor> (not origin/main). Extracted a rebaseOntoLocalBranch helper from the existing chain-rebase block; the re-run path now reuses it too.
  • On rebase conflict/failure: abort (restore branch), warn loudly, and break the chain — record the failed link (abortReason) and stop before the conflicted successor (and any later issues) run, rather than silently producing a successor on the wrong base whose break would propagate downstream. A missing worktree-map entry is surfaced with a warning instead of being silently skipped.

Acceptance Criteria

AC Description Status Evidence
AC-1 Fresh --chain run: successor branch contains predecessor's committed work ✅ executeSequential rebase step (run-orchestrator.ts); integration test
AC-2 Real-git test asserts git merge-base --is-ancestor <pred-exec-commit> <succ-HEAD> on a fresh run, no mock of the rebase step ✅ chain-rebase.integration.test.ts (3 real-git tests, incl. pre-fix BUG-state assertion + conflict-abort)
AC-3 bin/cli.ts --chain help text accurate ✅ Updated to "each successor is rebased onto the previous issue's committed work before it runs"

Key files changed

  • src/lib/workflow/worktree-manager.ts — new rebaseOntoLocalBranch helper (+ LocalRebaseResult); existing chain-rebase block refactored to reuse it.
  • src/lib/workflow/run-orchestrator.ts — rebase each chain successor (i>0) onto predecessor's local branch before execution.
  • bin/cli.ts — --chain help text.
  • src/lib/workflow/chain-rebase.integration.test.ts — real-git integration coverage (new).
  • __tests__/run-orchestrator.test.ts — wiring tests + mock export.

Test plan

  • npm run build — passes
  • npm run lint — passes
  • npx vitest run src/lib/workflow/chain-rebase.integration.test.ts — 3/3 pass
  • npx vitest run __tests__/run-orchestrator.test.ts — 22/22 pass
  • Full workflow + run suites green (one unrelated phase-registry.integration.test.ts tsx-spawn timeout flake; passes in isolation)

⚠️ Overlaps #749 on batch-executor.ts / run-orchestrator.ts — merge sequentially, not in parallel.

Closes #748


Follow-up: second-look hardening

A QA second-look surfaced that the orchestrator's conflict branch was untested (the wiring mock always returned success) and that continuing on conflict left a contract-violating successor. Addressed in the follow-up commit:

  • Conflict/failure now breaks the chain (was: warn + continue) — consistent with predecessor exec/qa-failure semantics; honors AC-1 by never producing a successor built on the wrong base. The break is recorded as an IssueResult with abortReason, which renders as the failure reason in the run summary and CI output.
  • Missing worktree-map entry is now surfaced with a warning instead of silently skipped.
  • Tests: wiring tests for the conflict-break and missing-predecessor paths (previously-unexercised orchestrator branch); integration test for the zero-commit-predecessor no-op case. 28/28 in the two suites; full CI green.

… run (#748)

On a fresh `--chain` run, `ensureWorktreesChain` provisions every worktree
up-front, branching each successor from its predecessor's branch name. At
provisioning time that branch still points at the base (the predecessor hasn't
executed yet), so every successor effectively branched from `main` and missed
its predecessor's committed work — contradicting the `--chain` help text and the
code's own AC comment. No execution-time rebase corrected it: the existing
chain-rebase only fired on the re-run path, and `rebaseBeforePR` targets
`origin/main`, not the predecessor.

`executeSequential` now re-rebases each successor's worktree onto its
predecessor's local committed tip just before the successor runs (independent of
`--stacked`), via an extracted `rebaseOntoLocalBranch` helper that the re-run
path now also reuses. On conflict it aborts + warns rather than silently
greening a broken link.

- Add real-git integration test asserting
  `git merge-base --is-ancestor <predecessor-exec-commit> <successor-HEAD>` on a
  fresh chain run (no mock of the rebase step), plus conflict-abort coverage.
- Add orchestrator wiring tests proving each successor is rebased onto its
  predecessor's local branch (and not rebased when chain mode is off).
- Update `--chain` help text to describe actual behavior.

Entire-Checkpoint: 301696cea7c0
admarble added 4 commits June 28, 2026 11:28
The #748 helper was inserted between rebaseBeforePR's JSDoc and its
declaration, orphaning the doc block. Move rebaseOntoLocalBranch above
rebaseBeforePR's JSDoc so each function's doc comment is adjacent again.
No behavior change.

Entire-Checkpoint: a9f3fce71038
…ccessor on wrong base (#748)

QA second-look gaps:
- On a chain rebase conflict/failure, executeSequential now warns loudly,
  records the failed link (abortReason), and breaks — stopping the conflicted
  successor and all later issues, rather than silently producing a successor
  built on the wrong base (the original #748 bug) whose break would propagate
  downstream. Consistent with predecessor exec/qa failure semantics.
- A missing worktree-map entry is surfaced with a warning instead of being
  silently skipped.
- Tests: wiring tests for the conflict-break and missing-predecessor paths
  (the orchestrator's failure branch was previously unexercised — the mock
  always returned success); integration test for the zero-commit predecessor
  no-op case.

Entire-Checkpoint: 296109918a44
…-chain-successors-branch-from-main-not-pr

# Conflicts:
#	CHANGELOG.md
…cument broken-link behavior (#748)

- A missing worktree-map entry now breaks the chain identically to a rebase
  conflict (was: warn + continue) — both mean the successor cannot be chained,
  so the asymmetry is removed. Recorded with an abortReason and stops before
  the successor and later issues run.
- Document the chain rebase mechanism and the broken-link stop behavior in
  docs/reference/run-command.md (Chain Mode), and update the CHANGELOG entry.
- Tests: the missing-predecessor wiring test now asserts the chain breaks;
  pre-existing chain-mode tests gained realistic worktree maps (they relied on
  the now-removed non-fatal missing-entry path) via a makeChainWorktreeMap
  helper.
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(chain): --chain successors branch from main, not predecessor's committed work (up-front worktree provisioning)

1 participant