Skip to content

feat(#760): resume a partially-completed chain from its last good link - #765

Merged
admarble merged 3 commits into
mainfrom
feature/760-feat-resume-a-partially-completed-chain-from-its-l
Jul 15, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/760-feat-resume-a-partially-completed-chain-from-its-l

Conversation

@admarble

@admarble admarble commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Re-running sequant run … --chain after a mid-chain failure now skips the completed prefix and resumes at the first incomplete link, rebased onto the last completed link's committed tip — turning "chain dead, 1–3 hours wasted" into "re-run picks up where it broke" (the dominant chain failure class from the #604 forensics).

AC Verification

AC Description Status Evidence
AC-1 Re-run skips completed links; resumes at first incomplete, rebased onto last-completed tip ✅ chain-resume.ts + run-orchestrator.ts first-active-link rebase; chain-resume.integration.test.ts (merge-base --is-ancestor)
AC-2 Skipped links reported (issue #, reason, resume commit) ✅ run-orchestrator.ts skip + ↻ Resuming chain at #N from <sha> lines
AC-3 Destroyed completed link: merged→resume from base, ready_for_merge-but-gone→fail fast ✅ computeChainResumePlan merged/fail-fast branches; unit + integration tests
AC-4 createCheckpointCommit failure loud, reflected in result ✅ Always-on warning in worktree-manager.ts + call-site warning + run-summary notice + checkpointFailed on IssueResult
AC-5 Integration test: 3-link chain, force link 2 fail, re-run, assert link 1 skipped + link 2 branches from link 1's tip ✅ chain-resume.integration.test.ts (#752 real-git pattern)

QA follow-up (commit 2)

QA on this PR found the AC-4 warning stated the opposite of what happens, plus three smaller loose ends. All four are fixed in 33bd40e:

  1. Honest checkpoint warning + dirty-tip fail-fast. The status is written ready_for_merge before the checkpoint is attempted, so a re-run reads the link as a completed prefix, skips it, and takes its branch tip as the resume base — the warning's claims that "resume is unavailable" and "a re-run will redo #N" were both false. Since createCheckpointCommit only fails when it has in-scope dirty work it couldn't commit, that tip is missing exactly the work the checkpoint would have captured, and the user was told a re-run would handle it.

    The message now states the real outcome, and computeChainResumePlan no longer takes the tip on trust: a ready_for_merge resume base whose worktree is dirty fails fast, symmetric with the existing destroyed-branch fail-fast. Only the resume base is checked — an earlier prefix link's dirt is irrelevant (the chain rebases onto the last link's tip alone), and a merged prefix resumes from the base branch regardless.

  2. checkpointFailed is now consumed. It was set on IssueResult and read by nobody; it's restated in the run summary, where the user is actually looking once the per-issue warning has scrolled away.

  3. The state→plan seam is now tested. There were no orchestrator tests at all — which is why the layer the original fix(chain): --chain successors branch from main, not predecessor's committed work (up-front worktree provisioning) #748 bug lived in went uncovered. Extracted planChainResumeFromState so it's testable without standing up an orchestrator, including the previously untested rule that a failed state lookup treats a link as incomplete rather than skipping it.

  4. Documented the contiguous-prefix-only rule: a completed link sitting after an incomplete one is re-executed, not silently dropped.

Design notes

  • --force still bypasses resume entirely (redo the whole chain) — resume logic sits inside the !mergedOptions.force branch. Non-chain skip guard unchanged.
  • Only a contiguous completed prefix is skipped (conservative — never silently drop an issue the user meant to redo).
  • Merged prefix resumes from the base branch (never rebase a successor onto a squash-orphaned local tip).
  • Known trade-off: a completed link's worktree that is dirty for benign reasons (stray edits) will stop a resume until the changes are committed or --force is used. Deliberate — an incomplete resume base is the failure this issue exists to prevent, and the message names the file and the two ways out.

Test plan

  • npm run build — clean
  • npm run lint — clean (0 warnings)
  • npx vitest run — full suite: 185 files, 3777 passed, 1 expected fail, 2 skipped
  • chain-resume.test.ts (16), chain-resume.integration.test.ts (6, real git), checkpoint.integration.test.ts AC-4 case, run-display.test.ts (3, new)

Closes #760

🤖 Generated with Claude Code

Re-running `sequant run … --chain` after a mid-chain failure now skips the
contiguous prefix of links that are already ready_for_merge/merged and resumes
at the first incomplete link, rebased onto the last completed link's committed
tip (reusing the #748 rebaseOntoLocalBranch path).

The existing pre-flight state guard was chain-unaware: it dropped completed
links before worktree provisioning, leaving the first incomplete link at index
0 where the #748 successor-rebase never fires, so it silently rebuilt on main
(the #748 wrong-base bug). A new pure `computeChainResumePlan` (chain-resume.ts)
peels the completed prefix, provisions the incomplete tail from the resume base,
and executeSequential explicitly rebases the first active link onto that tip
with fail-fast (a provisioning-time rebase failure only warns, so this is the
authoritative correctness gate).

- AC-1/AC-5: resume rebases first active link onto last completed link's tip;
  real-git integration test (3-link chain, force link 2 fail, re-run, assert
  link 1 skipped + link 2 branches from link 1's checkpoint via
  merge-base --is-ancestor).
- AC-2: skipped links reported with issue number, reason, and resume commit.
- AC-3: merged prefix resumes from the base branch (work is in origin/main);
  ready_for_merge link whose branch/checkpoint is destroyed fails fast with a
  clear message instead of wrong-basing the successor. Unit-tested via injected
  branch resolver.
- AC-4: createCheckpointCommit failure is no longer verbose-gated — the commit
  step warns prominently and the call site records checkpointFailed on the
  IssueResult, since resume depends on the checkpoint.

--force still bypasses resume entirely. Non-chain skip guard unchanged.

Entire-Checkpoint: 815b3132b40c
admarble added 2 commits July 15, 2026 09:04
…-fast

QA on PR #765 found the AC-4 checkpoint warning states the opposite of what
happens, plus three smaller loose ends. All four addressed.

1. The warning claimed "chain resume from this link is unavailable" and
   "re-running the chain will redo #N". Neither was true: the status is
   written ready_for_merge *before* the checkpoint is attempted, so a re-run
   reads the link as a completed prefix, skips it, and takes its branch tip as
   the resume base. Since createCheckpointCommit only fails when it has
   in-scope dirty work it could not commit, that tip is missing exactly the
   work the checkpoint would have captured — and the user was told a re-run
   would handle it, so they'd do nothing.

   The message now states the real outcome (work is off-branch, the link stays
   ready_for_merge, resume will stop here until it is committed, or --force),
   and computeChainResumePlan no longer takes that on trust: a ready_for_merge
   resume base whose worktree is dirty now fails fast, symmetric with the
   existing destroyed-branch fail-fast, instead of rebasing the successor onto
   an incomplete tip. Only the resume base is checked — an earlier prefix
   link's dirt is irrelevant, since the chain rebases onto the last link's tip
   alone, and a merged prefix resumes from the base branch regardless.

2. checkpointFailed was set on IssueResult and read by nobody. It is now
   restated in the run summary, where the user is actually looking by the time
   a multi-hour chain ends and the per-issue warning has scrolled away.

3. The state→plan step had no coverage — there were no orchestrator tests at
   all, which is why the seam the original #748 bug lived in went untested.
   Extracted planChainResumeFromState so it is testable without standing up an
   orchestrator, and covered it, including the previously untested rule that a
   failed state lookup treats a link as incomplete rather than skipping it.

4. Documented the contiguous-prefix-only rule in the CHANGELOG: a completed
   link sitting after an incomplete one is re-executed, not silently dropped.

Tests: 30 in the touched files (was 17); full suite 3777 passing; build and
lint clean.

Entire-Checkpoint: 030e1c082ab8
…me-a-partially-completed-chain-from-its-l

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit db0cee4 into main Jul 15, 2026
5 checks passed
admarble added a commit that referenced this pull request Sep 9, 2026
…-fast

QA on PR #765 found the AC-4 checkpoint warning states the opposite of what
happens, plus three smaller loose ends. All four addressed.

1. The warning claimed "chain resume from this link is unavailable" and
   "re-running the chain will redo #N". Neither was true: the status is
   written ready_for_merge *before* the checkpoint is attempted, so a re-run
   reads the link as a completed prefix, skips it, and takes its branch tip as
   the resume base. Since createCheckpointCommit only fails when it has
   in-scope dirty work it could not commit, that tip is missing exactly the
   work the checkpoint would have captured — and the user was told a re-run
   would handle it, so they'd do nothing.

   The message now states the real outcome (work is off-branch, the link stays
   ready_for_merge, resume will stop here until it is committed, or --force),
   and computeChainResumePlan no longer takes that on trust: a ready_for_merge
   resume base whose worktree is dirty now fails fast, symmetric with the
   existing destroyed-branch fail-fast, instead of rebasing the successor onto
   an incomplete tip. Only the resume base is checked — an earlier prefix
   link's dirt is irrelevant, since the chain rebases onto the last link's tip
   alone, and a merged prefix resumes from the base branch regardless.

2. checkpointFailed was set on IssueResult and read by nobody. It is now
   restated in the run summary, where the user is actually looking by the time
   a multi-hour chain ends and the per-issue warning has scrolled away.

3. The state→plan step had no coverage — there were no orchestrator tests at
   all, which is why the seam the original #748 bug lived in went untested.
   Extracted planChainResumeFromState so it is testable without standing up an
   orchestrator, and covered it, including the previously untested rule that a
   failed state lookup treats a link as incomplete rather than skipping it.

4. Documented the contiguous-prefix-only rule in the CHANGELOG: a completed
   link sitting after an incomplete one is re-executed, not silently dropped.

Tests: 30 in the touched files (was 17); full suite 3777 passing; build and
lint clean.

Entire-Checkpoint: 030e1c082ab8
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.

feat: resume a partially-completed chain from its last good link

1 participant