Description
Problem
reconcileStateAtStartup (src/lib/workflow/state-cleanup.ts) was extended in #592 to escalate in_progress → merged when the PR was merged outside the current sequant session. The same drift class affects waiting_for_qa_gate: an issue whose exec phase finished and whose PR sits awaiting human gate approval can be merged externally (someone runs gh pr merge, or merges via the web UI, before sequant's QA gate runs in the next session). Local `state.json` keeps `status: "waiting_for_qa_gate"`, the pre-flight guard at `run-orchestrator.ts:472-498` (which only short-circuits `ready_for_merge` and `merged`) lets the issue through, and `sequant run ` re-executes the QA phase against already-merged work.
This was explicitly out of scope for #592 (which framed the fix narrowly to `in_progress` to match the live incident on 2026-05-06), but the symmetry is exact and the same fix pattern applies.
Why existing guards still miss it
Two reconciliation paths exist post-#592:
reconcileStateAtStartupin `state-cleanup.ts:295-304` — used by `sequant run`. Now relaxes to `ready_for_merge || in_progress`. `waiting_for_qa_gate` still falls through.- `reconcileState` in `reconcile.ts` (sequant status: reconcile-on-read with GitHub as source of truth #423) — used by `sequant status` and `sequant_status` MCP. Already classifies via `classifyDrift()` and handles `waiting_for_qa_gate` correctly via the "PR merged on GitHub" rule.
Just like #592 was the unaddressed sibling for `in_progress` after #423, this is the unaddressed sibling for `waiting_for_qa_gate`.
Acceptance Criteria
- `reconcileStateAtStartup` also escalates `waiting_for_qa_gate` → `merged` when `checkPRMergeStatus` reports `MERGED` or `isIssueMergedIntoMain` finds the branch in main.
- Pre-flight guard at `run-orchestrator.ts:472-498` then skips with the existing voice (`already merged — skipping (use --force to re-run)`).
- Local `state.json` is updated to `status: "merged"` for the skipped issue.
- `--force` continues to bypass.
- One GitHub round-trip per `waiting_for_qa_gate` issue at run start, not per phase.
- Failure to reach GitHub falls through to current behavior.
- Unit test in `src/lib/workflow/state-cleanup.test.ts` proves the `waiting_for_qa_gate` → `merged` escalation with mocked `GitHubProvider`.
Suggested implementation
Extend the loop guard in `reconcileStateAtStartup` (state-cleanup.ts:301-304) from a 2-status allowlist to a 3-status allowlist:
```diff
if (
issueState.status !== "ready_for_merge" &&
-
issueState.status !== \"in_progress\"
-
issueState.status !== \"in_progress\" && -
issueState.status !== \"waiting_for_qa_gate\" ) { continue; }
```
Existing PR-status check + git-fallback + state mutation + `resolvedAt` stamp need no changes. Mirror the test pattern from #592 (`state-cleanup.test.ts`).
Optional: at the same time, consider whether `reconcileStateAtStartup` should be merged into the newer batched `reconcileState` engine (#423) to eliminate the divergence between `sequant run` and `sequant status` reconciliation. Tracked as a separate refactor — keeping this issue scoped to the symmetric one-line fix.
Out of scope
- Reconciling `abandoned` / `blocked` / other drift cases — separate hygiene work.
- Merging the two reconcile paths (`reconcileStateAtStartup` vs `reconcileState`) — separate refactor.
Related
- fix(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423) #592 — sibling fix for `in_progress` (closed)
- 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; uses the newer `reconcileState` engine that already handles this case)
Activity
admarble commentedon May 9, 2026
→ PROCEED — Sibling bug to #592 with explicit one-line diff in body, 7 ACs including unit test pattern from #592. Code references verified (
state-cleanup.ts:295-304,run-orchestrator.ts:472-498).Workflow:
exec → qaadmarble commentedon May 10, 2026
Supersedes prior assess from 2026-05-09 (PROCEED)
→ PROCEED — Implementation commit
984f9e0already on local+remotefeature/606-…branch (+63/-4 across 3 files:state-cleanup.ts,state-cleanup.test.ts,CHANGELOG.md). No PR opened yet; resume at qa to push and create the PR.Workflow:
qa(resume — exec already done on branch)⚠ Branch is 5 commits behind main but no conflicts in
state-cleanup.ts; rebase in qa phase will be clean.admarble commentedon May 10, 2026
QA Review for Issue #606
AC Coverage
waiting_for_qa_gate→mergedviacheckPRMergeStatusMERGED orisIssueMergedIntoMainstate-cleanup.ts:303-308); existing PR-status check + git fallback unchanged.run-orchestrator.ts:472-498skips with existing voicemerged, the existingready_for_merge || mergedshort-circuit fires with the samealready merged — skipping (use --force to re-run)message.state.jsonupdated tostatus: "merged"for skipped issueAC-1/AC-3/AC-7 (#606)assertspersisted.issues["606"].status === "merged"andresolvedAtdefined.--forcecontinues to bypass!mergedOptions.force; this PR doesn't touch that branch.waiting_for_qa_gateissue at run start, not per phasereconcileStateAtStartupruns once at startup before per-phase work; loop callscheckPRMergeStatusexactly once per allowed-status issue.AC-6 (#606)mocksmockPRStatus = nulland assertspersisted.issues["606"].status === "waiting_for_qa_gate"andresolvedAtundefined.state-cleanup.test.tsproves escalation with mockedGitHubProvidervi.mock("./platforms/github.js")+mockGetPRMergeStatusSync.Coverage: 7/7 AC items fully met
Original ACs: 7/7 met
Derived ACs: None found
Quality Plan Verification
N/A — No quality plan found in issue comments (assess-only path).
CI Status
No PR exists yet for
feature/606-fix-run-pre-flight-guard-misses-waiting-for-qa-gat— CI status will be available after PR open.Quality Metrics
any)Local
npx tsc --noEmitclean;vitest run src/lib/workflow/→ 815/815 passed, including 8 instate-cleanup.test.ts(2 new for #606).Stale Branch Check
Branch is 5 commits behind main. Per the assess comment, no conflicts in
state-cleanup.ts— rebase will be clean. Recommended to rebase before opening PR.Cache Status
N/A —
--no-cachenot relevant; checks ran fresh.Build Verification
N/A —
tsc --noEmitclean on feature branch code.Test Coverage Analysis
src/lib/workflow/state-cleanup.tssrc/lib/workflow/state-cleanup.test.ts(2 new cases for #606)Coverage: 1/1 changed source files have corresponding tests.
Critical paths without tests: None.
Code Review
Strengths:
vi.mock("./platforms/github.js"), samemockPRStatusoverride, samemakeIssuehelper.reconcileStateAtStartupupdated to mention all three statuses with both fix(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423) #592 and fix(run): pre-flight guard misses waiting_for_qa_gate issues already merged on GitHub (sibling of #592) #606 references.Issues:
describeblock is still titled"reconcileStateAtStartup (#592 in_progress escalation)", but the new tests inside it are tagged(#606). Could be renamed to a broader title (e.g., "reconcileStateAtStartup escalation"). Not blocking — pattern matches fix(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423) #592 history exactly.Suggestions:
reconcileStateAtStartupinto the newerreconcileStateengine (sequant status: reconcile-on-read with GitHub as source of truth #423) sosequant runandsequant statusshare one reconciliation path. Tracked as scope-out.Test Quality Review
result.advanced/stillPendingoutputs, not internals.GitHubProviderandchild_process.spawnSyncmocked (external boundaries).tempDirfor isolation; no timing dependencies.Anti-Pattern Detection
Dependency Audit
N/A —
package.jsonnot modified.Code Patterns
No anti-patterns detected (no loops, catches, secrets, SQL, network binds in diff).
Call-Site Review
N/A — No new exported functions;
reconcileStateAtStartupsignature unchanged.Execution Evidence
N/A — No
scripts/or CLI changes; logic change is unit-test-covered library code.Skill Command Verification
N/A — No
.claude/skills/**/*.mdfiles modified.CLI Registration Verification
N/A —
RunOptionsandbin/cli.tsunchanged.Smoke Test
N/A — Pure library logic change, fully covered by unit tests using the same mocking infrastructure as the merged #592 fix.
Self-Evaluation
waiting_for_qa_gateissue has no PR record at all — the code falls through toisIssueMergedIntoMain(issueNum)(existing behavior), so handled. No new failure mode introduced.CHANGELOG Verification
[Unreleased]entry(#606)reference, action verb, details)Result: CHANGELOG requirements met.
Verdict: READY_FOR_MERGE
All 7 ACs are MET. The implementation is the exact symmetric one-line fix the issue prescribed, with test coverage that mirrors #592's pattern. Type-check clean, full workflow suite green, no regressions, CHANGELOG entry in place.
Documentation
(#606)under### Fixed)Next Steps
feature/606-…onorigin/main(5 commits behind, clean per assess)./docs 606if any user-facing CLI surface changes (none expected — purely internal reconciliation).chore(#606): tighten reconcile JSDoc, test names, and add waiting_for…
fix(#606): escalate waiting_for_qa_gate to merged when PR merged exte…
chore(#795): deprecate --qa-gate, an inert no-op flag (#807)
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…
fix(#606): escalate waiting_for_qa_gate to merged when PR merged exte…
chore(#606): tighten reconcile JSDoc, test names, and add waiting_for…