Skip to content

fix(ci): verify a queue-guard overlap hit actually cites the issue (#610) - #612

Merged
sv merged 1 commit into
mainfrom
fix/queue-guard-overlap-false-positive
Aug 31, 2026
Merged

sv merged 1 commit into
mainfrom
fix/queue-guard-overlap-false-positive

Conversation

@sv

@sv sv commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #610. Verified against 9da8f42.

queue-guard's overlap job reported any open PR whose text merely contained the digits of a
cited issue number. It fired for real today, on the PR before this one.

The bug

#608 cites #607. queue-guard commented that #271 "also cites #607". #271 is
fix(store): fsync room directory entries, opened five days before #607 existed. Its only
occurrence of those digits:

paired benchmark on WSL2 …: 6,607 appends/s file-only versus 6,292 with two directory syncs

Root cause — it is the query, not the extraction

/#\d+/g extracts #607 correctly. The defect is the line after it:

const q = 'repo:' + … + ' is:pr is:open "' + ref + '" in:title,body';

GitHub's search tokenizer does not treat # as part of a word, so "#607" is searched as the
bare token 607. Confirmed against the live API — the two queries are indistinguishable:

$ gh api -X GET search/issues -f q='… is:pr is:open "#607" in:title,body'
  #271  fix(store): fsync room directory entries
$ gh api -X GET search/issues -f q='… is:pr is:open "607"  in:title,body'
  #271  fix(store): fsync room directory entries

6,607 tokenizes on the comma, so 607 matches exactly. And nothing downstream re-checked the
hit — the search was serving as both prefilter and verdict.

The fix

The search stays the prefilter; the API offers nothing more precise. What changes is that every
hit is now confirmed against the title and body the search response already returns — so
no extra request, no added rate-limit cost:

const cites = (item, ref) => {
  const n = ref.slice(1);
  const rx = new RegExp('(#|(?:issues|pull)\\/)' + n + '(?!\\d)');
  return rx.test((item.title || '') + ' ' + (item.body || ''));
};

A literal #N, or an issues/N / pull/N URL tail, and not the prefix of a longer number so
#607 cannot answer for #6071. That puts the split in the right place: the API decides what is
cheap to fetch, this workflow decides what is true.

Why it is worth fixing rather than tolerating

PR bodies in this repo routinely carry measurements — appends/s, byte counts, millisecond
timings, module counts. Every one is a chance to name an unrelated PR as overlapping work, so the
false positive is the common case, not a corner. A guard that fires on arithmetic teaches
reviewers to skip it, and it then fails quietly on the real collision it exists to catch. It also
publicly mislabels the innocent PR: #271 currently carries a comment implying it duplicates work
it has nothing to do with.

This PR demonstrates the bug on itself

queue-guard ran against this PR using the code on main, and reported four overlaps:

- #611 (also cites #608)
- #393 (also cites #608)
- #108 (also cites #608)
- #271 (also cites #607)

Three are spurious. Running the new cites() filter over the real bodies:

claimed where the digits actually are new filter
#611 cites #608 "they picked up #608's mcp.technocore…" — a real reference ✅ kept
#393 cites #608 66,608 lines held, 7.8 M… 🚫 suppressed
#108 cites #608 66,608 lines 🚫 suppressed
#271 cites #607 6,607 appends/s 🚫 suppressed

The #611 row is the important one: it is a genuine citation and the filter keeps it. This is a
precision fix, not a blanket mute.

End-to-end, against the live API

Replaying the whole job — real search calls for #608 and #607, then the new filter — on this
PR's own refs:

BEFORE (current main): #611 (#608), #393 (#608), #108 (#608), #271 (#607)
AFTER  (this PR)     : #611 (#608)

One genuine overlap survives; the three arithmetic matches are gone.

On the "no extra request" claim

Worth stating because the fix depends on it: the filter reads item.body from the search
response
, so it would be a false-negative machine if that field were truncated — a real
citation late in a long body would be dropped, which is the one failure this guard cannot afford.
Checked rather than assumed. Search-API bodies are byte-identical to the pulls API:

PR body length via search via pulls
#611 3,255 3,255
#393 5,304 5,304
#108 12,788 12,788

No truncation, including the 12.7 KB body — so the check is complete and genuinely free.

A contributor already diagnosed this by hand

The bug is not new, and it is already costing people time. #108 — fix(http): validate a name before consulting its class — carries an "Overlapping work" section written to defend against
exactly this:

I checked the queue for #109 … gh api search/issues for open PRs citing #109 returns only
#393 … It cites this issue nowhere in its text: the search matches on the bare digits
appearing inside a larger figure it quotes (66,608 lines)
. No overlap with this change.

An independent contributor reached the same root cause unaided, then spent a paragraph proving a
negative to a reviewer. That is the cost this guard is currently imposing — and it lands on the
people doing the most careful queue triage, since they are the ones who check.

Verification

The workflow is not reachable from pytest, so it was checked directly. The cites function was
extracted verbatim from the committed YAML and run against the real bodies of #271 and #608
plus twelve synthetic cases — all 14 pass:

case expected got
real #271 body (6,607 appends/s) no match ✅ no match
real #608 body (Closes #607) match ✅ match
607 bare / 6,607 / 18,607 KiB / v1.607 no match ✅ no match
#607 / see #607 / Closes #607. / title-only match ✅ match
#6071 (longer number) no match ✅ no match
issues/607, pull/607 match ✅ match
null title and body no match ✅ no match

Also confirmed: the file still parses as YAML with both jobs intact, and both embedded scripts
pass node --check. The protected-files job is untouched.

Repo gates, all clean:

uv sync --frozen                          Checked 62 packages
uv run ruff check .                       All checks passed!
uv run ruff format --check .              74 files already formatted
uv run ty check                           All checks passed!
uv run coverage run -m pytest tests -q    609 passed
uv run sz.py --check                      core code-lines <= baseline (2247)

Note

I did not add a regression test. There is no harness in tests/ for workflow YAML, and building
one for a single embedded function looked like more surface than the fix. If you would rather have
one — say a tests/unit/test_queue_guard.py that extracts the script from the YAML and exercises
the regex through node — I am happy to add it.

Not addressed here

Post-filtering can only remove hits, so a genuine overlap that the fuzzy search pushed past
per_page: 10 is still missed. That is pre-existing and unchanged by this PR; precision improves,
recall does not. Worth a separate look if it ever bites.

Suggested release note

queue-guard no longer reports a PR as citing an issue when its text merely contains those
digits — a benchmark figure like 6,607 is no longer read as a reference to #607.

)

The overlap job reported any open PR whose text merely contained the digits of a
cited issue number. Today it told #608 that #271 "also cites #607"; #271 is an
fsync change opened five days before #607 existed, and its only occurrence of
those digits is a benchmark figure — 6,607 appends/s.

The extraction is not at fault: `/#\d+/g` yields `#607` correctly. The search
query is. GitHub's tokenizer does not treat `#` as part of a word, so
`"#607" in:title,body` is really a query for the token `607`. Confirmed against
the live API — searching `"#607"` and `"607"` return the identical single result.
`6,607` tokenizes on the comma, so the digits match exactly.

Nothing re-checked the hit, so the search was both the prefilter and the verdict.
It stays the prefilter — the API offers nothing more precise — and every hit is
now confirmed against the title and body the response already carries, which
costs no extra request. A literal `#N`, or an `issues/N` / `pull/N` URL tail, and
not the prefix of a longer number so `#607` cannot answer for `#6071`.

This matters more than one bad comment: PR bodies here routinely carry byte
counts, timings and throughput numbers, so the false positive is the common case.
A guard that fires on arithmetic trains reviewers to ignore it, and it then fails
quietly on the collision it exists to catch. It also publicly mislabels the PR it
names.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-31T15:49:01.864277Z df31a83 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sv
sv merged commit 01d7cbb into main Aug 31, 2026
10 checks passed
@sv
sv deleted the fix/queue-guard-overlap-false-positive branch August 31, 2026 15:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df31a835cb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const n = ref.slice(1);
// '#N' or an issues/N | pull/N URL tail, and not the prefix of a longer
// number: #607 must not answer for #6071.
const rx = new RegExp('(#|(?:issues|pull)\\/)' + n + '(?!\\d)');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recognize GH-N issue references

When a newly opened PR cites #607 but an existing open PR uses GitHub’s supported GH-607 shorthand for the same issue, the search prefilter returns the existing PR but this regex rejects it, silently hiding a genuine overlap that the previous implementation reported. Accept the GH- prefix as another literal reference form.

AGENTS.md reference: AGENTS.md:L30-L31

Useful? React with 👍 / 👎.

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.

queue-guard's overlap check matches bare digits, so a benchmark number reads as an issue citation

1 participant