Skip to content

fix(run): pre-flight guard misses waiting_for_qa_gate issues already merged on GitHub (sibling of #592) #606

Closed

Description

@admarble

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:

  1. reconcileStateAtStartup in `state-cleanup.ts:295-304` — used by `sequant run`. Now relaxes to `ready_for_merge || in_progress`. `waiting_for_qa_gate` still falls through.
  2. `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

Activity

  1. added
    bug
    on May 8, 2026
  2. admarble commented on May 9, 2026

    @admarble
    ContributorAuthor

    → 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 → qa

    npx sequant run 606 --phases exec,qa
    
  3. admarble commented on May 10, 2026

    @admarble
    ContributorAuthor

    Supersedes prior assess from 2026-05-09 (PROCEED)

    → PROCEED — Implementation commit 984f9e0 already on local+remote feature/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)

    npx sequant run 606 --phases qa
    

    ⚠ Branch is 5 commits behind main but no conflicts in state-cleanup.ts; rebase in qa phase will be clean.

  4. admarble commented on May 10, 2026

    @admarble
    ContributorAuthor

    QA Review for Issue #606

    AC Coverage

    AC Source Description Status Notes
    AC-1 Original Escalate waiting_for_qa_gate → merged via checkPRMergeStatus MERGED or isIssueMergedIntoMain MET Loop guard relaxed from 2 to 3-status allowlist (state-cleanup.ts:303-308); existing PR-status check + git fallback unchanged.
    AC-2 Original Pre-flight guard at run-orchestrator.ts:472-498 skips with existing voice MET Pre-flight code untouched; once status is escalated to merged, the existing ready_for_merge || merged short-circuit fires with the same already merged — skipping (use --force to re-run) message.
    AC-3 Original Local state.json updated to status: "merged" for skipped issue MET Test AC-1/AC-3/AC-7 (#606) asserts persisted.issues["606"].status === "merged" and resolvedAt defined.
    AC-4 Original --force continues to bypass MET Pre-flight guard wraps !mergedOptions.force; this PR doesn't touch that branch.
    AC-5 Original One GitHub round-trip per waiting_for_qa_gate issue at run start, not per phase MET reconcileStateAtStartup runs once at startup before per-phase work; loop calls checkPRMergeStatus exactly once per allowed-status issue.
    AC-6 Original Failure to reach GitHub falls through to current behavior MET Test AC-6 (#606) mocks mockPRStatus = null and asserts persisted.issues["606"].status === "waiting_for_qa_gate" and resolvedAt undefined.
    AC-7 Original Unit test in state-cleanup.test.ts proves escalation with mocked GitHubProvider MET Two new test cases mirror the #592 pattern using the file-level vi.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

    Metric Value Status
    Type issues (any) 0 OK
    Deleted tests 0 OK
    Files changed 3 OK
    Lines added +63 OK
    Lines deleted -4 OK

    Local npx tsc --noEmit clean; vitest run src/lib/workflow/ → 815/815 passed, including 8 in state-cleanup.test.ts (2 new for #606).


    Stale Branch Check

    Check Value
    Commits behind main 5
    Threshold 5
    Status ⚠️ Warning (at threshold, not exceeded)

    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-cache not relevant; checks ran fresh.


    Build Verification

    N/A — tsc --noEmit clean on feature branch code.


    Test Coverage Analysis

    Changed File Tier Has Tests? Test File
    src/lib/workflow/state-cleanup.ts Standard ✅ Yes src/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:

    Issues:

    Suggestions:


    Test Quality Review

    Category Status Notes
    Behavior vs Implementation ✅ OK Asserts on persisted state + result.advanced/stillPending outputs, not internals.
    Coverage Depth ✅ OK Happy path (PR=MERGED) + offline fallthrough (PR=null).
    Mock Hygiene ✅ OK Only GitHubProvider and child_process.spawnSync mocked (external boundaries).
    Test Reliability ✅ OK Deterministic; uses tempDir for isolation; no timing dependencies.

    Anti-Pattern Detection

    Dependency Audit

    N/A — package.json not 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; reconcileStateAtStartup signature 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/**/*.md files modified.


    CLI Registration Verification

    N/A — RunOptions and bin/cli.ts unchanged.


    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

    • Verified working: Yes — checked out feature branch files, ran the new tests (8 passed including the 2 new cases) and the full workflow suite (815 passed). Verified the loop guard relaxation matches the issue's suggested diff literally.
    • Test efficacy: High — happy path locks in the escalation; offline test locks in the fallthrough; together they would catch any future regression of the loop-guard allowlist.
    • Likely failure mode: Edge case where a waiting_for_qa_gate issue has no PR record at all — the code falls through to isIssueMergedIntoMain(issueNum) (existing behavior), so handled. No new failure mode introduced.
    • Verdict confidence: High — symmetric one-line fix to a well-understood pattern, with mirrored test coverage.

    CHANGELOG Verification

    Check Status
    CHANGELOG.md exists ✅ Found
    User-facing changes ✅ Yes (fix: behavior change)
    [Unreleased] entry ✅ Present
    Entry format ✅ Valid (includes (#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

    Next Steps

    1. Rebase feature/606-… on origin/main (5 commits behind, clean per assess).
    2. Push and open PR linking to fix(run): pre-flight guard misses waiting_for_qa_gate issues already merged on GitHub (sibling of #592) #606.
    3. Wait for CI to pass.
    4. Run /docs 606 if any user-facing CLI surface changes (none expected — purely internal reconciliation).
  5. added
    ready-for-review
    on May 10, 2026
  6. added a commit that references this issue on May 10, 2026
  7. added a commit that references this issue on May 10, 2026
  8. added 3 commits that reference this issue on Jul 26, 2026
  9. added 2 commits that reference this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugready-for-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions