Repository navigation
Description
Problem
sequant run <N> does not detect when <N> is already merged on GitHub if the local state.json still records it as in_progress. The exec skill spawns, runs for ~3 minutes, produces no changes, and the orchestrator marks the phase failed and triggers the generic MCP fallback retry — burning another spawn.
Evidence (live incident, 2026-05-06)
Command: npx sequant run 583 580 568
| Source | #568 state |
|---|---|
| GitHub | CLOSED at 2026-05-07T00:23:45Z, PR #590 merged (commit 9aa2b4a) |
.sequant/state.json |
status: "in_progress", currentPhase: "exec" (residue from a partial run on 2026-05-04) |
| Result | phases.exec.error = "exec produced no changes (no commits, no uncommitted work)" after 197s, then ! Phase failed with MCP enabled, retrying without MCP... |
The user-facing surface ("retrying without MCP") is misleading — MCP wasn't the cause. The cause was that the work was already on main.
Why existing guards missed it
Two guards exist from prior work; both rely on local-state status fields:
- Pre-flight guard (
src/lib/workflow/run-orchestrator.ts:472-498, from fix: pre-flight state guard and worktree lifecycle management #305) skips onlystatus === "ready_for_merge" | "merged".in_progresspasses through. reconcileStateAtStartup(src/lib/workflow/state-cleanup.ts:295-299, from fix: pre-flight state guard and worktree lifecycle management #305) only advancesready_for_merge → merged. It never escalatesin_progress → merged, even thoughisIssueMergedIntoMain/checkPRMergeStatusalready exist inpr-status.tsand would answer correctly.
#423 introduced reconcile-on-read for sequant status and explicitly listed this drift class ("Issues closed on GitHub still show as in_progress"), but the fix did not extend to the run command path.
State drifts to this configuration whenever a PR lands via a path that doesn't write back to state.json: a separate sequant session, gh pr merge, the web UI, or a --force push.
Acceptance Criteria
-
sequant run <N>skips<N>when GitHub reports the issue closed AND the corresponding branch/PR is merged into the base branch — even if localstate.jsonsaysin_progress. - Skip message clearly identifies the cause (issue merged on GitHub) and mentions
--forceas the bypass, matching the existing pre-flight guard's voice atrun-orchestrator.ts:484. - Local
state.jsonis updated tostatus: "merged"for the skipped issue (so subsequent runs hit the cheaper local-status check). -
--forcecontinues to bypass the new check, same as the existing guard. - One GitHub round-trip per
in_progressissue at run start — not per phase. Cached for the duration of the run. - Failure to reach GitHub falls through to current behavior (do not block offline runs).
- Unit test using a mocked
PlatformProviderproves anin_progressentry whose remote shows merged is skipped.
Out of scope
- Reconciling all other state drift cases (abandoned, renamed, etc.) — covered by separate hygiene work.
- Changing the MCP-fallback message itself. The fallback is correct; the upstream cause is what this issue removes.
Suggested implementation
Prefer extending reconcileStateAtStartup (option (a) from the diagnosis) over adding a second check in the pre-flight loop:
- Loop over
in_progressentries in addition toready_for_merge. - Reuse
isIssueMergedIntoMain(issueNum)and (if PR number is recorded)checkPRMergeStatus. - On match, advance
status → "merged"and stampresolvedAt.
The existing pre-flight guard at run-orchestrator.ts:472 then handles the skip with its current message, no new code path needed.
Related
- fix: pre-flight state guard and worktree lifecycle management #305 — original pre-flight guard (closed)
- sequant status: reconcile-on-read with GitHub as source of truth #423 — reconcile-on-read for
sequant status(closed; this is the unaddressed sibling forrun) - fix(orchestrator): treat null QA verdict and zero-diff exec as failure, not success #534 — zero-diff exec as failure (closed; surfaces the symptom)
Activity
admarble commentedon May 8, 2026
/spec — Plan
Acceptance Criteria
sequant run <N>skips<N>when GitHub reports merged, even if localstate.jsonsaysin_progress(Verification: unit test + manual smoke)already merged — skipping (use --force to re-run)) atrun-orchestrator.ts:484(Verification: code review)state.jsonadvancesin_progress → merged,resolvedAtstamped (Verification: unit test)--forcecontinues to bypass (no change required, existing flag) (Verification: code review)in_progressissue at run start, cached for run (Verification: code review — reconcile runs once pre-loop)GitHubProviderproves the escalation (Verification: new test file)Implementation
File: `src/lib/workflow/state-cleanup.ts`
Change: Relax the loop guard at line 297 in `reconcileStateAtStartup` to include `in_progress` alongside `ready_for_merge`. Existing logic (PR check → git fallback → state mutation → `resolvedAt` stamp) requires no changes.
New test: `src/lib/workflow/state-cleanup.test.ts` (mirrors mock pattern from `reconcile.test.ts`).
Why this approach
Issue body recommends extending `reconcileStateAtStartup` over adding a second pre-flight check. This is the smallest correct change:
Out of Scope (per issue body)
Conflict Check
Only in-flight worktree is #568 (skill namespace fix) — no file overlap.
Recommended Workflow
`spec → exec → qa` (no `/test` — backend only)
admarble commentedon May 8, 2026
/exec — Implementation complete
Branch:
feature/592-fix-run-preflight-merged-inprogressCommit:
aacbf13Diff summary
src/lib/workflow/state-cleanup.tsreconcileStateAtStartupto includein_progress; updated JSDocsrc/lib/workflow/state-cleanup.test.tsready_for_mergesrc/lib/workflow/state-utils.test.tsshould not affect issues with other statuses) — old assertion documented pre-#592 behavior; addedspawnSyncmock to avoid colliding with real(#44)merge commit in this repoVerification
state-cleanup.test.ts)state-utils.test.ts(31),reconcile.test.ts(32),state-manager.test.ts(65) — all greennpm run build— cleannpm run lint— cleanadmarble commentedon May 8, 2026
/fullsolve Complete
Issue: #592
Status: READY_FOR_MERGE
PR: #602
Summary
state-cleanup.test.ts)Iterations
Implementation
Single guard relaxation in
src/lib/workflow/state-cleanup.ts:reconcileStateAtStartup:Existing PR-status check + git fallback +
resolvedAtstamp + state persistence all reused unchanged. The pre-flight skip guard atrun-orchestrator.ts:472-498(and its message at:484) is unchanged — it seesmergedafter reconcile and skips with the existing voice.--forcecontinues to bypass.Risk Assessment
in_progressissue's number happens to appear as(#N)in an unrelated commit on main,isIssueMergedIntoMainwould return true. Pre-existing risk (same code path is used forready_for_merge); explicitly out of scope per the issue body.isIssueMergedIntoMainpath for anin_progressissue without a PR number — covered indirectly by existingpr-status.tsintegration tests; mockingspawnSyncin unit tests would be brittle. Manual smoke against the originatingstate.jsonpost-merge is the appropriate complement.Ready for human review and merge.
test(#592): cover git-fallback escalation + cross-ref in what-weve-built
admarble commentedon May 8, 2026
Adversarial second-look follow-ups
After the user asked "any gaps?", an adversarial walk-through surfaced 3 minor gaps + 1 noted (non-actionable) latency point. All 3 actionable items addressed:
vi.mock("child_process")+ new test 6 instate-cleanup.test.tsexercisingin_progress+ nopr.number+ mocked merge commit → escalation0292123docs/internal/what-weve-built.md:855didn't reference the in_progress extension0292123waiting_for_qa_gatehas the same drift potentialLatency note (non-actionable): every
sequant runnow incurs Ngh pr viewcalls where N = count ofin_progress(and post-#606, alsowaiting_for_qa_gate) entries instate.json. AC-5 of #592 explicitly accepts this behavior. Failure mode is graceful (gh-unreachable falls through, AC-6).Updated test count: 6/6 in
state-cleanup.test.ts(was 5). Full workflow suite still green.fix(#592): reconcile in_progress state when PR is merged on GitHub (#602
admarble commentedon May 8, 2026
/docs — No separate doc needed
This fix is an internal reconciliation behavior change with no new user-facing surface:
bin/cli.ts— unchanged (no new flags)src/commands/,src/mcp/,app/admin/— unchanged (no new commands, MCP tools, or UI)Documentation already in place at the correct level:
A standalone `docs/features/*.md` page would have empty Prerequisites / Setup / Reference sections — not appropriate for an internal fix with no new commands or workflows.
fix(#610): broaden /qa §10a user_facing regex to scoped conventional …
chore(#606): tighten reconcile JSDoc, test names, and add waiting_for…
fix(#606): escalate waiting_for_qa_gate to merged when PR merged exte…
admarble commentedon May 11, 2026
Cross-ref: #625 (cross-session issue lock) covers a related but distinct staleness mode — local concurrent sessions targeting the same issue, rather than GitHub-side PR merges.
Both implementations need a "is this state still fresh?" check. If #592 and #625 land close together, worth extracting a shared helper (e.g., a
StalenessProbethat takes a state record and returnsfresh | stale | unknown) so the two failure modes share a vocabulary.feat(driver): surface structured rate-limit/credits errors from SDK m…
feat(#762): lightweight content pre-flight for --chain (#764)
fix(#837): extend the gated-status fix to the non-chain guard and cle…
fix(#837): --ready-gate resume no longer re-executes already-gated is…
feat(driver): surface structured rate-limit/credits errors from SDK s…
fix(#606): escalate waiting_for_qa_gate to merged when PR merged exte…
chore(#606): tighten reconcile JSDoc, test names, and add waiting_for…
feat(#762): lightweight content pre-flight for --chain