Skip to content

fix(#616): isBranchMergedIntoMain returns false for empty orphan branches - #617

Merged
admarble merged 2 commits into
mainfrom
fix/616-empty-orphan-branch-false-positive
May 10, 2026
Merged

admarble merged 2 commits into
mainfrom
fix/616-empty-orphan-branch-false-positive

Conversation

@admarble

@admarble admarble commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • npm test — full suite (2996 tests) passes
  • npm run lint — clean
  • npm run build — clean
  • Manual verification against live repo state (orphaned feature/608-... and feature/604-... branches): isBranchMergedIntoMain('feature/608-...') returns false (was true); isIssueMergedIntoMain(613) and isIssueMergedIntoMain(601) (real recently-merged issues) still return true via Method 2.
  • Reviewer: confirm Method 2 (git log --grep "(#N)") correctly catches squash-merged issues without Method 1 — see test case "should detect merge via merge commit pattern (fix: pre-flight state guard and worktree lifecycle management #305)" at state-utils.test.ts:1049+.

Closes #616.

…ches

Replace `git branch --merged <base>` reachability check with a
merge-evidence check: resolve the branch tip with `git rev-parse` and
only return true if the tip is recorded as a non-first parent of a merge
commit on the base branch (`git rev-list --merges --parents -200 <base>`).

This eliminates the false positive where an empty branch — created from
main but never advanced past the fork point — was misclassified as
"merged" because its tip happened to be reachable from main. The
production trigger was a SIGINT-interrupted `npx sequant run`: worktree
removal does not delete the branch, so the orphan branches lingered with
their tips equal to an old main commit; the next run's
`reconcileStateAtStartup` advanced the issues to `merged` and the
pre-flight guard then skipped them as "already merged" even though the
issues were still OPEN on GitHub.

Squash-merged branches continue to be detected via Method 2's `(#N)` /
`Merge #N` commit-message grep, which is unchanged. Existing #305 tests
in state-utils.test.ts migrated from `git branch --merged` mocks to
`git rev-parse` + `git rev-list --merges --parents` mocks; new
regression test covers the empty-orphan case mirroring the live repro.

Entire-Checkpoint: ad5f2c8c363c
After ac2be37 rewrote isBranchMergedIntoMain to use `git rev-parse` +
`git rev-list --merges --parents`, the JSDoc on isIssueMergedIntoMain
still described Method 1 as `git branch --merged <baseBranch>`. Update
the bullet to reference the actual `git branch -a` + isBranchMergedIntoMain
flow, linking via {@link} so the "merged" definition stays in one place.

Caught by /qa 616 as the AC_MET_BUT_NOT_A_PLUS blocker.

Entire-Checkpoint: 4a267c526c78
@admarble
admarble merged commit 5296e2b into main May 10, 2026
5 checks passed
@admarble
admarble deleted the fix/616-empty-orphan-branch-false-positive branch May 10, 2026 01:45
admarble added a commit that referenced this pull request May 11, 2026
Gap 1 — §6c precondition greps diff hunks, not file content.

The first cut of this section's precondition shelled out to
`xargs grep -lE ...` against the *current* skill-md file content. All
19 sequant SKILL.md files mention `grep|awk|jq|sed` in unrelated
example code, so the gate triggered on 100% of skill-md PRs and the
cost-saving intent of #608 / #609 evaporated. The fix iterates the
diffed skill-md files and only triggers §6c when the **added lines**
contain the patterns. On 6 historical merged PRs (#623 #620 #621 #617
#622 #547) the new gate skips §6c on 4/6 (67%) — vs 0/6 under the old
content-grep gate. Mirrored across `.claude/skills/`,
`templates/skills/`, `skills/`.

Gap 2 — `extractIdentifiersFromDiff` skips indented locals.

`content = line.slice(1).trimStart()` defeated the comment's claim of
"no nested-block decls" by stripping the indent that distinguishes
top-level from function-body declarations. The dogfood run on #609
surfaced 24 identifiers (17 of them local `const lines = …` /
`let inFence = …` style variables). Dropping `.trimStart()` brings
the surface to top-level decls only. New test asserts indented
`+  const local = …` is skipped while `+const topLevel = …` matches.

Gap 3 — Empirical 5-PR replay for AC-5 / AC-6.

New `--base-sha` / `--head-sha` CLI flags let `precheck.ts` replay
against historical merged PRs. SHAs validated with `/^[0-9a-f]{4,40}$/`
to avoid shell injection. Ran replay against 6 PRs (5 recent +
#547 for AC-6 demo): aggregate ≈ −1,002 tok/PR under the new gate;
PR #620's replay surfaced `acLiteralDiff.missingInPR.length = 8` —
a real catch the inline §1 prose was supposed to make but #608's
data shows §1 surfaced silently for years. Investigation doc
appended with per-PR table + correction to the prior
"true on 0 PRs" calibration claim.

Test count: 27 → 30 (indented-skip + 2 parseArgs flag tests).
`scripts/check-skill-sync.ts` reports qa/SKILL.md synced 3/3.
admarble added a commit that referenced this pull request May 11, 2026
…628)

* feat(#609): extract deterministic QA gap-checks into precheck script

New `scripts/qa/precheck.ts` runs three deterministic gap-checks before
the QA agent and emits `.sequant/gap-precheck.json`:

  - fixtures      — verbatim motivating-example extraction from issue body
                    (feeds §6d Q1 / §6c Step 4)
  - siblingGrep   — changed-identifier scan for cross-file sibling sites
                    (feeds §5)
  - acLiteralDiff — AC checkbox IDs in issue body vs PR body (feeds §1)

`qa/SKILL.md` gains Phase 0c that runs the precheck inline and consumes
its findings. §6c becomes a file-glob hard precondition (no skill-md
diff → emit nothing). §6c Step 4 prefers precheck `fixtures` over the
inline `awk` extractor when available. §6d trims to a single
adversarial paragraph (per #608's 9/14 / 0-actioned signal).

Inline fallback preserved on missing/error/`not_applicable` output.
Mirrored across all three `qa/SKILL.md` copies. Exit code always 0.

Investigation doc at `docs/investigations/qa-precheck-extraction.md`
covers AC-1 (22-row gate classification), AC-2 (per-PR run frequency),
AC-5 (section-size delta calibration via #608's 50-PR window:
~−1,585 tok/invoke window-typical), and AC-6 (regression-coverage
methodology against PR #547 / PR #533 shapes).

Builds on #608's signal-to-noise data which informed Phase A scope.

* fix(#609): close three gaps surfaced in post-commit QA

Gap 1 — §6c precondition greps diff hunks, not file content.

The first cut of this section's precondition shelled out to
`xargs grep -lE ...` against the *current* skill-md file content. All
19 sequant SKILL.md files mention `grep|awk|jq|sed` in unrelated
example code, so the gate triggered on 100% of skill-md PRs and the
cost-saving intent of #608 / #609 evaporated. The fix iterates the
diffed skill-md files and only triggers §6c when the **added lines**
contain the patterns. On 6 historical merged PRs (#623 #620 #621 #617
#622 #547) the new gate skips §6c on 4/6 (67%) — vs 0/6 under the old
content-grep gate. Mirrored across `.claude/skills/`,
`templates/skills/`, `skills/`.

Gap 2 — `extractIdentifiersFromDiff` skips indented locals.

`content = line.slice(1).trimStart()` defeated the comment's claim of
"no nested-block decls" by stripping the indent that distinguishes
top-level from function-body declarations. The dogfood run on #609
surfaced 24 identifiers (17 of them local `const lines = …` /
`let inFence = …` style variables). Dropping `.trimStart()` brings
the surface to top-level decls only. New test asserts indented
`+  const local = …` is skipped while `+const topLevel = …` matches.

Gap 3 — Empirical 5-PR replay for AC-5 / AC-6.

New `--base-sha` / `--head-sha` CLI flags let `precheck.ts` replay
against historical merged PRs. SHAs validated with `/^[0-9a-f]{4,40}$/`
to avoid shell injection. Ran replay against 6 PRs (5 recent +
#547 for AC-6 demo): aggregate ≈ −1,002 tok/PR under the new gate;
PR #620's replay surfaced `acLiteralDiff.missingInPR.length = 8` —
a real catch the inline §1 prose was supposed to make but #608's
data shows §1 surfaced silently for years. Investigation doc
appended with per-PR table + correction to the prior
"true on 0 PRs" calibration claim.

Test count: 27 → 30 (indented-skip + 2 parseArgs flag tests).
`scripts/check-skill-sync.ts` reports qa/SKILL.md synced 3/3.
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(state): reconcile false-positive — empty orphan branches mistakenly flagged as merged

1 participant