Skip to content

fix(#837): --ready-gate resume no longer re-executes already-gated issues (chain and non-chain) - #839

Merged
admarble merged 5 commits into
mainfrom
feature/837-fix-chain-chain-ready-gate-resume-re-executes-
Jul 28, 2026
Merged

admarble merged 5 commits into
mainfrom
feature/837-fix-chain-chain-ready-gate-resume-re-executes-

Conversation

@admarble

@admarble admarble commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #837.

Problem

#817's --ready-gate terminates a gated issue in waiting_for_human_merge (threshold reached) or blocked (guard halt) rather than ready_for_merge — deliberately, since ready_for_merge would read as auto-merge-ready and defeat the human merge gate the feature exists to preserve.

chain-resume.ts was never updated for those statuses:

const COMPLETED_STATUSES = new Set(["ready_for_merge", "merged"]);

computeChainResumePlan peels the contiguous completed prefix using that set. A gated link is not in it, so resuming a halted --chain --ready-gate run re-executed every already-gated link from phase 0 — a full spec/exec/qa pipeline plus another full-weight ready gate, silently, on exactly the runs a user opted into for extra rigor.

Change

waiting_for_human_merge is added. blocked is deliberately not.

Rationale, recorded at the constant:

  1. blocked is a generic member of IssueStatusSchema ("waiting on external input or dependency"), not a ready-gate-exclusive terminal. Admitting it would silently apply to every other writer of that status, present and future.
  2. A guard halt is the human-attention signal. Skipping it as a completed prefix would report the link as passed when it demonstrably did not.

So a blocked link stays in active and is re-executed — the same conservative rule already applied to links whose state lookup fails. Re-running wastes tokens; silently dropping an issue the user must look at is the worse failure. Once the user clears the blocker, the re-run is what lets the chain make progress.

COMPLETED_STATUSES becomes a const array deriving both the runtime set and a new CompletedStatus type, so ChainResumeSkip.status widens structurally instead of drifting from the set it mirrors.

The dirty-worktree fail-fast needed no control-flow change — it already sits in the non-merged branch that gated links reach. But its three messages hardcoded "is ready_for_merge", which is factually wrong for a gated link; they now interpolate the actual status.

AC coverage

AC Status Evidence
AC-1 gated statuses treated as completed MET chain-resume.ts:50-55; 3 tests
AC-2 blocked distinguished + documented MET Excluded; rationale at chain-resume.ts:24-49; 2 tests
AC-3 dirty check still fires; type widened MET status: CompletedStatus; 3 fail-fast tests assert the gated status is named
AC-4 test fails if a gated link is re-executed MET waiting_for_human_merge ... skipped, NOT re-executed
AC-5 :175-181 comment corrected MET Plus module header and else-branch lead-in
AC-6 mutation-verified MET Both directions, below

AC-6 mutation verification

Mutation A — revert to ["ready_for_merge", "merged"]:

Tests  8 failed | 17 passed (25)

All 8 failures are the new #837 tests. All 17 pre-existing tests pass.

Mutation B — add "blocked" to the array:

Tests  3 failed | 22 passed (25)

Exactly the 3 tests asserting blocked is excluded.

Every new test is sensitive to at least one direction — no tautologies. Restored: 25/25 pass.

Scope beyond the literal ACs

batch-executor.ts carried the same stale premise in two places. AC-5 names only the chain-resume.ts comment; these are flagged for explicit review:

  1. A comment (:1506) asserting "the status above is already ready_for_merge".
  2. A user-facing warning (:1525) telling users the issue "stays ready_for_merge" when a gated run had persisted waiting_for_human_merge. This one is visible output, not just a comment — it would have misdirected a user debugging a failed checkpoint. finalStatus is hoisted so the warning names the status actually written.

Verification

  • chain-resume.test.ts: 25/25 (17 pre-existing + 8 new)
  • npm run build: clean
  • Full src/lib/workflow + src/commands: 82 files, 1616 passed, 2 skipped (main baseline: 1607 + 9 new)
  • No consumers of ChainResumeSkip / CompletedStatus outside chain-resume.ts

An earlier run in the fresh worktree showed 6 failures in subprocess-spawning integration tests; all were cold-tsx-cache spawn timeouts against a 5s limit. Confirmed by re-running warm (all green) and by the same 82-file run on unmodified main (all green).

Out of scope

Per the issue: #817's terminal-status choice, auto-merging gated links, and non-chain --ready-gate behavior. The non-chain skip guard at run-orchestrator.ts:844 still filters only ready_for_merge/merged; in chain mode that branch is mutually exclusive with the chain-resume path, so it does not affect this fix.

🤖 Generated with Claude Code


Follow-up: scope widened to all gated-status gaps

The maintainer asked to fix all gaps, which lifts this issue's Non-Goal on non-chain behavior. A sweep of every consumer of the completed-status concept found two more instances of the same omission, so the predicate is now a single source of truth (completed-status.ts) rather than three inline copies with three different lists.

Site Was Impact
run-orchestrator.ts:842 (non-chain guard) inline ready_for_merge || merged sequant run <gated-issue> without --chain re-ran an issue the gate had cleared
state-cleanup.ts:303 (merge sweep) missing waiting_for_human_merge a gated issue whose PR merged never advanced to merged; state rotted

The cleanup sweep has now been patched three times for this same omission (#592, #606, #837), so its list carries an explicit note that it is deliberately wider than isCompletedIssueStatus — "might this have a merged PR?" vs "is this done?" — to stop a future reader unifying them.

Also corrected the comments this invalidated: types.ts's --force doc, the chain-resume.ts header, and state-cleanup.test.ts's header.

Investigated and cleared: isTerminalStatus correctly excludes gated statuses (including it would make --cleanup delete gated state); getReadyForMergeIssues() is dead surface with zero callers, left alone.

Mutation C — the finding worth flagging

Reverting the non-chain guard to its inline pair compiled clean and failed nothing. completed-status.test.ts proved the predicate correct but not that the orchestrator calls it — the inert-surface class this repo has hit twice (#795, #810).

Closed with non-chain-skip-guard.test.ts, following the existing run-options-dead-surface.test.ts source-text pattern (the guard is an inline branch in RunOrchestrator.run(), unreachable without standing up state/worktrees/GitHub/locks), scoped to the guard region rather than the 1,700-line file. @tautology-skip claimed with mutation justification; re-running Mutation C fails exactly its 2 assertions.

Suite: 84 files, 1627 passed, 2 skipped (was 82/1616; main baseline 1607).

admarble added 2 commits July 28, 2026 01:21
#817's `--ready-gate` terminates a gated issue in `waiting_for_human_merge`
(threshold reached) or `blocked` (guard halt) rather than `ready_for_merge`,
which would read as auto-merge-ready and defeat the human merge gate. Chain
resume was never updated for those statuses, so `computeChainResumePlan`'s
prefix-peel did not recognise an already-gated link as complete: resuming a
halted `--chain --ready-gate` run silently re-ran each gated link from phase 0
— a full spec/exec/qa pipeline plus another full-weight gate.

Add `waiting_for_human_merge` to COMPLETED_STATUSES. Deliberately do NOT add
`blocked`: it is a generic member of IssueStatusSchema rather than a
gate-exclusive terminal, and a guard halt is precisely the human-attention
signal, so skipping it would report a link as passed when it did not. A
`blocked` link therefore stays in `active` and is re-executed — the same
conservative rule already applied to failed state lookups. The reasoning is
recorded at the constant.

COMPLETED_STATUSES becomes a `const` array that derives both the runtime set
and the new `CompletedStatus` type, so `ChainResumeSkip.status` widens
structurally instead of drifting from the set it mirrors.

The dirty-worktree fail-fast needed no control-flow change (it already sits in
the non-`merged` branch that gated links reach), but its three messages
hardcoded "is ready_for_merge" — factually wrong for a gated link. They now
interpolate the actual status.

Comment corrections: the `chain-resume.ts` dirty-worktree explanation whose
"already written as ready_for_merge" premise no longer holds for gated runs,
plus the module header and the else-branch lead-in.

Beyond the literal ACs: `batch-executor.ts` carried the same stale premise in
a comment AND in the user-facing checkpoint-failure warning, which told users
the issue "stays ready_for_merge" when a gated run had persisted
`waiting_for_human_merge`. `finalStatus` is hoisted so the warning names the
status actually written.

Fixes #837
admarble added 3 commits July 28, 2026 10:37
…anup sweep

The chain resume fix covered `--chain`, but the same "status vocabulary was
extended and consumers did not follow" bug existed at two more sites. Rather
than patch each inline, the predicate becomes a single source of truth.

New `completed-status.ts` owns `isCompletedIssueStatus`, with the
`waiting_for_human_merge` inclusion and the `blocked` exclusion rationale
recorded once instead of per call site.

1. `run-orchestrator.ts` non-chain pre-flight guard tested
   `status === "ready_for_merge" || status === "merged"` inline, so
   `sequant run <gated-issue>` without `--chain` still re-ran an issue the
   ready gate had already cleared — the same waste the chain fix removed, and
   asymmetric with chain mode once that landed.

2. `state-cleanup.ts`'s merge-detection sweep skipped
   `waiting_for_human_merge`, so a gated issue whose PR a human then merged
   never advanced to `merged` and rotted in state. That sweep has now been
   patched three times for exactly this omission (#592 in_progress, #606
   waiting_for_qa_gate, #837 waiting_for_human_merge), so its list carries an
   explicit note that it is deliberately WIDER than `isCompletedIssueStatus` —
   it asks "might this have a merged PR?", not "is this done?" — to stop a
   future reader unifying the two.

`chain-resume.ts` now consumes the shared predicate; the type guard narrows
`link.status` directly, so the `as CompletedStatus` cast is gone.

Comments invalidated by the guard change are corrected in the same pass:
`types.ts`'s `--force` doc, the `chain-resume.ts` module header, and
`state-cleanup.test.ts`'s header, which asserted the old inline pair.

Tests: new `completed-status.test.ts` pins both directions of the predicate
plus a schema cross-check that every entry is a real `IssueStatusSchema`
member; `state-cleanup.test.ts` gains the gated-advance case and a `blocked`
exclusion case.
Mutation-testing the previous commit found the non-chain guard fix was
unpinned: reverting `isCompletedIssueStatus(...)` back to the pre-#837 inline
`ready_for_merge || merged` pair compiled clean and failed nothing in the
suite. `completed-status.test.ts` proves the predicate is correct but not that
the orchestrator calls it — a correct predicate nobody consults is the inert
surface this repo has already been bitten by twice (#795 `--qa-gate`, #810
`reuseWorktrees`).

The guard is an inline branch inside `RunOrchestrator.run()` and cannot be
reached without standing up a state manager, worktrees, GitHub and locks, so
this follows the existing source-text guard pattern
(`run-options-dead-surface.test.ts`) rather than adding an orchestrator
harness. Scoped to the guard region between its marker comment and the
state-lookup catch, per the repo rule that file-reading gate tests assert on a
region rather than a whole file — run-orchestrator.ts is ~1,700 lines and a
whole-file assertion would pass or fail for unrelated reasons.

`@tautology-skip` is claimed with its justification: the file calls no
production function by design, and the exemption is earned by the mutation
above failing exactly these assertions and nothing else.
@admarble admarble changed the title fix(#837): --chain --ready-gate resume no longer re-executes already-gated links fix(#837): --ready-gate resume no longer re-executes already-gated issues (chain and non-chain) Jul 28, 2026
@admarble
admarble merged commit f6aa25c into main Jul 28, 2026
5 checks passed
@admarble
admarble deleted the feature/837-fix-chain-chain-ready-gate-resume-re-executes- branch July 28, 2026 16:12
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 --ready-gate resume re-executes already-gated links (COMPLETED_STATUSES misses waiting_for_human_merge/blocked)

1 participant