You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(state): reconcile marks an open issue merged when any squash commit title mentions (#N) — isIssueMergedIntoMain's commit-mention fallback confuses PR and issue numbers #1044
Tier: mechanical Found: 2026-09-11 during the wave-2 graph run (#1030, PR #1042 open)
What happened
sequant run 1030 --phases qa printed State reconciled: #1030 → merged and sequant_status then reported status: "merged" with nextAction: "sequant status --cleanup" — while PR #1042 was open and the branch feature/1030-… was not an ancestor of main. The run only continued because force was set; a cleanup at that point would have removed a live worktree.
The third pattern was meant for squash-merge subjects, where the parenthesised number is the PR number, not the issue. Applied to an issue number it matches any of the last 20 commits whose title mentions the issue — here the merged docs PR #1031, docs(graph): wave-2 plan — node 09 (#1030), …. Reproduced: git log main --oneline -E --grep='\(#1030\)' → 2 hits, both other PRs; git merge-base --is-ancestor feature/1030-… main → no.
Method 1 (feature branch merged) was correct; the fallback overrode it. The state guard (#592) and status --cleanup both trust this answer.
Proposed fix
Drop the (#N) pattern from Method 2 (keep Merge #N / Merge pull request #<pr> forms only), or better: when the issue has a linked PR, trust checkPRMergeStatus alone; when it has none, require Method 1 (branch ancestry) and never infer "merged" from a commit mentioning the number.
Regression test: a repo whose main has a squash commit titled docs: … (#N) for an unrelated PR and an open, unmerged feature/N-… branch → isIssueMergedIntoMain(N) is false.
Never emit nextAction: status --cleanup for an issue whose branch is not an ancestor of the base.
Acceptance criteria
AC-1: isIssueMergedIntoMain(N) returns false when main contains a commit whose subject mentions (#N) but no branch feature/N-* is merged and no linked PR is merged — Verify: npx vitest run src/lib/workflow/pr-status.test.ts -t "mention" → passes on a temp repo built for the case. Mutation: restore the (#N) grep → fails; restore.
AC-2: the existing true-positive cases (Merge #N merge commit; merged feature branch; merged linked PR) still return true — Verify: npx vitest run src/lib/workflow/pr-status.test.ts → green.
AC-3: reconcileStateAtStartup leaves an in_progress issue with an open PR untouched in the scenario above — Verify: npx vitest run src/lib/workflow/state-cleanup.test.ts -t "open PR".
AC-4: suite green — Verify: npm run build && npm test.
Related: #616 (a different reconcile false positive — empty orphan branches), #592 (the pre-flight guard that consumes this answer).
Runner context — launch (2026-09-11). Base: main at ac9afc3 (wave 1 + wave 2 merged). Stop-at-PR: open the PR, do not merge. Gate tests need Mutation-verified: records in the PR body with failedTest as <test file path> > <test name>. Foreground only: run every check in the foreground with a timeout (timeout 600 npm test 2>&1 | tail -80), once — the pre-tool hook blocks Monitor and run_in_background under the orchestrator and nothing will wake you; the phase ends when your turn ends. Commit a WIP within 5 minutes and every ~10 minutes; every phase has a hard 30-minute wall. CHANGELOG.md[Unreleased]: one bullet under the matching existing ### heading.
All 4 ACs pass lint (lintAcceptanceCriteria) — each has a concrete verify command and, for AC-1, an explicit mutation-verification instruction. No vague/unmeasurable/incomplete/open-ended flags.
Scope Assessment
Non-Goals: Not present in the issue body — heuristic warns "Non-Goals section not found."
Metric
Value
Status
Feature count
2 (keyword clusters: "ui", "test")
⚠️
AC items
4
✅
Directory spread
2 (src, test files)
✅
Verdict:⚠️ SCOPE_WARNING (raw heuristic) → overriding to SCOPE_OK. The "ui"/"test" 2-feature split is a keyword-clustering false positive — every AC is one root-cause fix (isIssueMergedIntoMain's Method 2 grep) plus its regression coverage, not two features. Not auto-enabling the quality loop on this basis.
Acceptance Criteria
AC-1: isIssueMergedIntoMain(N) returns false on a commit that merely mentions (#N)
Verification: Integration Test (real git, temp repo) Scenario: Given a temp repo where main has a squash commit titled docs: ... (#1030) (an unrelated PR that mentions issue 1030 in prose) and an unmergedfeature/1030-* branch → When isIssueMergedIntoMain(1030) is called → Then it returns false. Assumptions: Real git temp repo required, not mocked spawnSync — the bug is in what real git log --grep matches (per runner's launch comment).
AC-2: Existing true-positive detection paths still return true
Verification: Integration Test (real git, temp repo) Scenario: Three sub-cases, each in its own temp-repo fixture: (a) a merge commit titled Merge #N ... → true; (b) an actually-merged feature/N-* branch (tip is a non-first parent of a merge commit on main) → true via isBranchMergedIntoMain; (c) a linked PR reported MERGED by checkPRMergeStatus (mocked GitHubProvider) → true. Assumptions: (c) exercises checkPRMergeStatus, not isIssueMergedIntoMain — both belong in the new pr-status.test.ts.
AC-3: reconcileStateAtStartup leaves an in_progress issue with an open PR untouched
Verification: Integration Test Scenario: Given state {status: "in_progress", pr: {number: 1042}}, GitHubProvider.getPRMergeStatusSync mocked to return "OPEN", and a real temp git repo reproducing the AC-1 false-positive commit shape for issue 1030 → When reconcileStateAtStartup() runs → Then issue stays in stillPending, status remains in_progress, resolvedAt stays unset. Assumptions:state-cleanup.test.ts mocks spawnSync globally in beforeEach for isolation. This test needs to opt out and delegate to real spawnSync scoped to itself, on a real temp repo it seeds — see Open Questions.
AC-4: Full suite green
Verification: Integration Test / CI gate Scenario: Given the AC-1–3 changes → When npm run build && npm test runs → Then it exits 0. Assumptions: None beyond the new tests themselves passing.
Remove the `(#${issueNumber})`--grep pattern from Method 2's git log call (pr-status.ts:155). Keep `Merge #${issueNumber}` and `Merge.*#${issueNumber}` — both anchor on the word "Merge", so they don't match a squash-commit title that merely references the issue number in prose.
Update the function's JSDoc (pr-status.ts:102-112) to state Method 2 only matches actual merge-commit subjects, not any commit mentioning #N.
Phase 2: New pr-status.test.ts (AC-1, AC-2)
Create src/lib/workflow/pr-status.test.ts (does not exist today — this file currently has zero test coverage).
Use a real temp git repo per test (fs.mkdtempSync + git init + git -C <dir> commit --allow-empty -m "..." via execSync/spawnSync, chdir into it for the duration of the call since both functions default baseBranch: "main" and use spawnSync with the process cwd).
AC-1 case: build the exact repro shape (squash commit docs: ... (#1030) unrelated to issue 1030 as an ordinary commit — no real merge needed since it just needs to appear in git log --grep results; unmerged feature/1030-x branch created but never merged).
AC-2 cases: (a) real Merge #N commit subject, (b) real merge commit recording an actually-merged branch tip as a non-first parent (matches isBranchMergedIntoMain's docstring definition), (c) mock GitHubProvider per the existing state-cleanup.test.ts pattern (lines 39-47) to test checkPRMergeStatus returns true-equivalent ("MERGED").
Phase 3: state-cleanup.test.ts — add AC-3 case
Add one test literally named to satisfy -t "open PR" (e.g. "AC-3 (#1044): leaves in_progress untouched when linked PR is open and main has an unrelated squash commit mentioning the issue number").
Within that test only, restore real spawnSync (see AC-3 Assumptions) and seed the temp repo with the AC-1 repro shape; set mockPRStatus = "OPEN".
Assert result.stillPending includes the issue, result.advanced does not, and persisted status/resolvedAt are unchanged.
Where does this logic belong?pr-status.ts — it already owns both merge-detection strategies; the fix is localized to Method 2's grep patterns, no new module needed.
What's the simplest correct approach? Drop the one over-broad grep pattern. The issue's own "better" alternative (always trust checkPRMergeStatus alone when a linked PR exists, never fall back to Method 2) is a larger behavioral change to reconcileStateAtStartup's fallback semantics — not required by any AC, and risks regressing the #606/#837/#972 escalation paths that intentionally use Method 2 as a fallback when checkPRMergeStatus is unreachable (null). Recommend the minimal fix; see Open Questions.
What existing pattern does this follow? Same shape as the two surviving Method 2 patterns and Method 1 — anchor matches to actual merge semantics (Merge #N, a real non-first-parent merge relationship), never to "any commit that mentions N."
What would a senior reviewer challenge? "Why not require Method 1 or a merged linked PR, full stop, and drop Method 2 entirely?" — because Method 2's two remaining patterns still catch real merge commits made outside this repo's own branch-naming convention (e.g. a manually-authored Merge #1030 commit with no feature/1030-* branch ever pushed). Dropping only the provably-wrong pattern is the narrower, AC-justified change.
Feature Quality Planning
pr-status.ts has zero existing test coverage — this PR introduces pr-status.test.ts, so AC-1/AC-2 tests double as first regression guard for isBranchMergedIntoMain/checkPRMergeStatus; worth thoroughness over minimum repro.
Real-git vs mocked-spawnSync split. Keep the real-git override local to the one AC-3 test (scoped mockImplementation, restored after) so it doesn't weaken isolation for the file's other ~15 tests.
Shared real-git test helper? Recommendation: write inline in pr-status.test.ts first; extract only if state-cleanup.test.ts's AC-3 version turns out identical enough to dedupe.
Recommended Workflow
Phases: exec → qa Quality Loop: disabled Reasoning: Single-root-cause bug fix, bug label only, SCOPE_OK after override, no UI surface (testgen skipped per bug-only label rule).
Label Review
Current:bug Recommended:bug, planned Reason: Standard bug-fix flow, no complexity/UI/security signals warranting additional labels. Quality Loop: Won't auto-enable — SCOPE_WARNING overridden to OK (keyword-clustering false positive, see Scope Assessment).
The retained Merge.*#N pattern still confuses PR numbers with issue numbers via numeric-prefix matching, so an open issue whose number is a prefix of a merge commit's PR number is still reported merged and can still be advanced to merged by state-cleanup.ts:343-347 despite an explicitly OPEN PR.
No regression test covers the numeric-prefix collision in the surviving Merge.*#N pattern.
checkPRMergeStatus OPEN and null branches lack direct coverage in the new test file.
Three tests fail locally on darwin at both HEAD and the base commit while passing in CI — pre-existing and unrelated to this diff, but AC-4's literal 'suite green' does not hold in the local environment.
The new real-git tests run under the unit project's 5s timeout with file parallelism enabled, a documented flake profile for subprocess-heavy tests.
The surviving Merge.*#${issueNumber} pattern is unanchored and still produces the same class of false positive, reproducible on today's main.pr-status.ts:157-159 keeps --grep "Merge.*#${issueNumber}" with no trailing word boundary, so an issue number that is a numeric prefix of a #N in a merge-commit subject matches. Verified against the real repository:
Suggestions:
Follow-up (or a maintainer's call to fold in — it is a one-line change to the same three lines): switch Method 2 to -E with an end-anchored number, e.g. --grep "Merge.*#${issueNumber}([^0-9]|$)", and add a regression case for Merge pull request #1043 vs isIssueMergedIntoMain(104).
pr-status.test.ts AC-2c covers only checkPRMergeStatus → "MERGED"; the "OPEN" and null (gh-unreachable) branches — the ones that actually gate the Method 2 fallback — remain untested in that file.
Activity
admarble commentedon Sep 11, 2026
Runner context — launch (2026-09-11). Base:
mainat ac9afc3 (wave 1 + wave 2 merged). Stop-at-PR: open the PR, do not merge. Gate tests needMutation-verified:records in the PR body withfailedTestas<test file path> > <test name>. Foreground only: run every check in the foreground with a timeout (timeout 600 npm test 2>&1 | tail -80), once — the pre-tool hook blocksMonitorandrun_in_backgroundunder the orchestrator and nothing will wake you; the phase ends when your turn ends. Commit a WIP within 5 minutes and every ~10 minutes; every phase has a hard 30-minute wall.CHANGELOG.md[Unreleased]: one bullet under the matching existing###heading.feature/N-*branch), not mocked spawnSync — the false positive lives in what git returns. refactor(sync): fold computeDriftFingerprint's templates→.claude mapping into templateDestination; document the retired-file limitation #1045 runs in parallel; it touchessrc/commands/sync.ts/src/lib/templates.tsonly, no overlap withpr-status.ts/state-cleanup.ts.admarble commentedon Sep 11, 2026
Complexity: Standard (4 ACs, 2 directories)
AC Quality Check
All 4 ACs pass lint (
lintAcceptanceCriteria) — each has a concrete verify command and, for AC-1, an explicit mutation-verification instruction. No vague/unmeasurable/incomplete/open-ended flags.Scope Assessment
Non-Goals: Not present in the issue body — heuristic warns "Non-Goals section not found."
src, test files)Verdict:⚠️ SCOPE_WARNING (raw heuristic) → overriding to SCOPE_OK. The "ui"/"test" 2-feature split is a keyword-clustering false positive — every AC is one root-cause fix (
isIssueMergedIntoMain's Method 2 grep) plus its regression coverage, not two features. Not auto-enabling the quality loop on this basis.Acceptance Criteria
AC-1:
isIssueMergedIntoMain(N)returnsfalseon a commit that merely mentions(#N)Verification: Integration Test (real git, temp repo)
Scenario: Given a temp repo where
mainhas a squash commit titleddocs: ... (#1030)(an unrelated PR that mentions issue 1030 in prose) and an unmergedfeature/1030-*branch → WhenisIssueMergedIntoMain(1030)is called → Then it returnsfalse.Assumptions: Real git temp repo required, not mocked
spawnSync— the bug is in what realgit log --grepmatches (per runner's launch comment).AC-2: Existing true-positive detection paths still return
trueVerification: Integration Test (real git, temp repo)
Scenario: Three sub-cases, each in its own temp-repo fixture: (a) a merge commit titled
Merge #N ...→true; (b) an actually-mergedfeature/N-*branch (tip is a non-first parent of a merge commit on main) →trueviaisBranchMergedIntoMain; (c) a linked PR reportedMERGEDbycheckPRMergeStatus(mockedGitHubProvider) →true.Assumptions: (c) exercises
checkPRMergeStatus, notisIssueMergedIntoMain— both belong in the newpr-status.test.ts.AC-3:
reconcileStateAtStartupleaves anin_progressissue with an open PR untouchedVerification: Integration Test
Scenario: Given state
{status: "in_progress", pr: {number: 1042}},GitHubProvider.getPRMergeStatusSyncmocked to return"OPEN", and a real temp git repo reproducing the AC-1 false-positive commit shape for issue 1030 → WhenreconcileStateAtStartup()runs → Then issue stays instillPending, status remainsin_progress,resolvedAtstays unset.Assumptions:
state-cleanup.test.tsmocksspawnSyncglobally inbeforeEachfor isolation. This test needs to opt out and delegate to realspawnSyncscoped to itself, on a real temp repo it seeds — see Open Questions.AC-4: Full suite green
Verification: Integration Test / CI gate
Scenario: Given the AC-1–3 changes → When
npm run build && npm testruns → Then it exits 0.Assumptions: None beyond the new tests themselves passing.
Implementation Plan
Phase 1: Fix
isIssueMergedIntoMain(src/lib/workflow/pr-status.ts:140-168)`(#${issueNumber})`--greppattern from Method 2'sgit logcall (pr-status.ts:155). Keep`Merge #${issueNumber}`and`Merge.*#${issueNumber}`— both anchor on the word "Merge", so they don't match a squash-commit title that merely references the issue number in prose.#N.Phase 2: New
pr-status.test.ts(AC-1, AC-2)src/lib/workflow/pr-status.test.ts(does not exist today — this file currently has zero test coverage).fs.mkdtempSync+git init+git -C <dir> commit --allow-empty -m "..."viaexecSync/spawnSync,chdirinto it for the duration of the call since both functions defaultbaseBranch: "main"and usespawnSyncwith the process cwd).docs: ... (#1030)unrelated to issue 1030 as an ordinary commit — no real merge needed since it just needs to appear ingit log --grepresults; unmergedfeature/1030-xbranch created but never merged).Merge #Ncommit subject, (b) real merge commit recording an actually-merged branch tip as a non-first parent (matchesisBranchMergedIntoMain's docstring definition), (c) mockGitHubProviderper the existingstate-cleanup.test.tspattern (lines 39-47) to testcheckPRMergeStatusreturnstrue-equivalent ("MERGED").Phase 3:
state-cleanup.test.ts— add AC-3 case-t "open PR"(e.g."AC-3 (#1044): leaves in_progress untouched when linked PR is open and main has an unrelated squash commit mentioning the issue number").spawnSync(see AC-3 Assumptions) and seed the temp repo with the AC-1 repro shape; setmockPRStatus = "OPEN".result.stillPendingincludes the issue,result.advanceddoes not, and persisted status/resolvedAtare unchanged.Phase 4: Docs + changelog
CHANGELOG.md[Unreleased]→ one bullet under the existing### Fixedheading (line 9) describing the fix and citing fix(state): reconcile marks an open issue merged when any squash commit title mentions (#N) — isIssueMergedIntoMain's commit-mention fallback confuses PR and issue numbers #1044.Design Review
pr-status.ts— it already owns both merge-detection strategies; the fix is localized to Method 2's grep patterns, no new module needed.checkPRMergeStatusalone when a linked PR exists, never fall back to Method 2) is a larger behavioral change toreconcileStateAtStartup's fallback semantics — not required by any AC, and risks regressing the#606/#837/#972escalation paths that intentionally use Method 2 as a fallback whencheckPRMergeStatusis unreachable (null). Recommend the minimal fix; see Open Questions.Merge #N, a real non-first-parent merge relationship), never to "any commit that mentions N."Merge #1030commit with nofeature/1030-*branch ever pushed). Dropping only the provably-wrong pattern is the narrower, AC-justified change.Feature Quality Planning
pr-status.tshas zero existing test coverage — this PR introducespr-status.test.ts, so AC-1/AC-2 tests double as first regression guard forisBranchMergedIntoMain/checkPRMergeStatus; worth thoroughness over minimum repro.spawnSyncsplit. Keep the real-git override local to the one AC-3 test (scopedmockImplementation, restored after) so it doesn't weaken isolation for the file's other ~15 tests.Open Questions
reconcileStateAtStartupalso stop falling back to Method 2 whenevercheckPRMergeStatusgives a definitive non-merged answer, not just when it'snull? Recommendation: no — none of the 4 ACs require it, and today's fallback-on-anything-but-"MERGED"is intentional for the gh-unreachable case (fix(run): pre-flight guard misses in_progress issues already merged on GitHub (gap in #305/#423) #592/fix(run): pre-flight guard misses waiting_for_qa_gate issues already merged on GitHub (sibling of #592) #606/fix(chain): --chain --ready-gate resume re-executes already-gated links (COMPLETED_STATUSES misses waiting_for_human_merge/blocked) #837,state-cleanup.ts:329-348). Impact if wrong: a future naming convention could reintroduce a similar false positive via the two surviving patterns — a new bug report, not a regression of this fix.pr-status.test.tsfirst; extract only ifstate-cleanup.test.ts's AC-3 version turns out identical enough to dedupe.Recommended Workflow
Phases: exec → qa
Quality Loop: disabled
Reasoning: Single-root-cause bug fix,
buglabel only, SCOPE_OK after override, no UI surface (testgen skipped perbug-only label rule).Label Review
Current:
bugRecommended:
bug,plannedReason: Standard bug-fix flow, no complexity/UI/security signals warranting additional labels.
Quality Loop: Won't auto-enable — SCOPE_WARNING overridden to OK (keyword-clustering false positive, see Scope Assessment).
→
gh issue edit 1044 --add-label plannedadmarble commentedon Sep 11, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 0/4 met
Gaps:
Merge.*#${issueNumber}pattern is unanchored and still produces the same class of false positive, reproducible on today'smain.pr-status.ts:157-159keeps--grep "Merge.*#${issueNumber}"with no trailing word boundary, so an issue number that is a numeric prefix of a#Nin a merge-commit subject matches. Verified against the real repository:Suggestions:
-Ewith an end-anchored number, e.g.--grep "Merge.*#${issueNumber}([^0-9]|$)", and add a regression case forMerge pull request #1043vsisIssueMergedIntoMain(104).pr-status.test.tsAC-2c covers onlycheckPRMergeStatus → "MERGED"; the"OPEN"andnull(gh-unreachable) branches — the ones that actually gate the Method 2 fallback — remain untested in that file.fix(#1044): end-anchor the surviving Merge #N patterns; regression te…
fix(state): stop reconcile from matching (#N) commit-mention as issue…