Skip to content

fix(#592): reconcile in_progress state when PR is merged on GitHub - #602

Merged
admarble merged 3 commits into
mainfrom
feature/592-fix-run-preflight-merged-inprogress
May 8, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/592-fix-run-preflight-merged-inprogress

Conversation

@admarble

@admarble admarble commented May 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Extend reconcileStateAtStartup (src/lib/workflow/state-cleanup.ts) to also escalate in_progress entries to merged when their PR is MERGED on GitHub or their branch is already in main.
  • Closes the gap where sequant run <N> would re-execute issues that were merged outside the current sequant session (separate process, gh pr merge, web UI, force-push) — exec would spawn for ~3 minutes producing no diff, and the generic MCP fallback retry would burn another spawn.
  • Existing pre-flight skip guard at run-orchestrator.ts:472-498 (and its message at :484) is unchanged — it sees merged after reconcile and skips with the existing voice. --force continues to bypass.

Closes #592.

Why this approach

Per the issue body's explicit recommendation: extend reconcileStateAtStartup (one OR clause added to the loop guard) rather than add a second pre-flight check. Existing PR-status check + git fallback + resolvedAt stamp need no changes.

Test plan

  • New src/lib/workflow/state-cleanup.test.ts (5 tests) — covers AC-1/AC-3/AC-7 (in_progress→merged escalation with mocked GitHubProvider), AC-6 (offline fallthrough), regression for ready_for_merge, unrelated-status no-op, and missing-state-file
  • Updated src/lib/workflow/state-utils.test.ts (should not advance issues in non-actionable statuses) — old assertion documented pre-fix(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423) #592 behavior; added spawnSync mock to handle a latent collision (test issue feat(#39): Add MCP browser testing patterns reference #44 with the real (#44) merge commit in this repo)
  • npm run build clean
  • npm run lint clean
  • Full workflow test suite: 810/810 passing
  • CHANGELOG entry added under ## [Unreleased] → ### Fixed

AC verification

AC Status
AC-1: Skips merged-on-GitHub in_progress issues ✅ MET (test 1 + AC trace)
AC-2: Skip message matches existing voice at run-orchestrator.ts:484 ✅ MET (line unchanged)
AC-3: state.json advances to merged, resolvedAt stamped ✅ MET (test 1)
AC-4: --force continues to bypass ✅ MET (existing gate at line 472 unchanged)
AC-5: One round-trip per in_progress issue, cached for run ✅ MET (reconcile invoked once)
AC-6: GitHub-unreachable falls through ✅ MET (test 2)
AC-7: Unit test with mocked PlatformProvider ✅ MET (test 1)

admarble added 2 commits May 7, 2026 21:45
reconcileStateAtStartup previously only escalated `ready_for_merge`
entries to `merged`. When a PR was merged outside the current sequant
session (separate process, `gh pr merge`, web UI, --force push), the
local state.json could keep `status: "in_progress"` indefinitely. The
pre-flight guard at run-orchestrator.ts:472-498 then let the issue
through, exec spawned for ~3 minutes producing no diff, and the
generic MCP fallback retry burned another spawn.

Relax the loop guard to also process `in_progress`. Existing PR-status
+ git-fallback logic and the `resolvedAt` stamp need no other changes.
The pre-flight skip message at run-orchestrator.ts:484 then handles the
skip with its current voice — `--force` continues to bypass.

Add state-cleanup.test.ts covering the in_progress → merged escalation
with mocked GitHubProvider, plus the offline (PR status null) fallthrough.
Update one state-utils.test.ts case whose old assertion documented the
pre-#592 behavior, and add a spawnSync mock to it (real git was
collapsing #44 onto an actual `(#44)` merge commit in this repo).
Two gap-fix follow-ups from adversarial QA second look:

1. Add test exercising the in_progress → merged escalation via the
   git-fallback branch (no pr.number recorded, isIssueMergedIntoMain
   matches a merge commit). Required adding vi.mock("child_process")
   so spawnSync is controllable per-test; default mock returns status:1
   so existing tests (which expected real git to fail in tempDir)
   continue to work without per-test wiring.

2. Update docs/internal/what-weve-built.md so the auto-reconciliation
   bullet under the #305 entry forward-references the #592 extension
   (still escalates ready_for_merge AND now in_progress).
@admarble
admarble merged commit c6f673d into main May 8, 2026
5 checks passed
@admarble
admarble deleted the feature/592-fix-run-preflight-merged-inprogress branch May 8, 2026 07:31
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(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423)

1 participant