Repository navigation
ci: block closing keywords that would auto-close a pull request - #484
Merged
Merged
Conversation
GitHub scans a PR's description and its commit messages for a bare KEYWORD-then-
reference adjacency (close/closes/closed, fix/fixes/fixed, resolve/resolves/
resolved, immediately followed by #N) and closes item N on merge into the default
branch. Two properties make this a trap:
1. The parser has NO notion of negation. The phrase "does not retroactively
fix", immediately followed by "#N", links and closes item N exactly as if it
had read "fixes #N".
2. Pull requests and issues share one numbering space, so an N that happens to
be a PR closes that PR.
Both fired together: the body of PR #483 contained that negated phrasing followed
by a bare reference to the then-open PR #482, silently closing that unrelated
in-flight PR on merge. GitHub attributes such closes to whoever merged, so the
audit trail blamed a human who never clicked anything.
There is no repo/org/enterprise setting to disable closing keywords, so a check is
the only systemic defense. New `closing-keywords` job scans the same two surfaces
GitHub does and fails only when a keyword-linked number resolves to a pull request.
The everyday intended use -- a closing keyword naming a real issue -- stays green.
Surface handling mirrors GitHub's own parser:
- PR description is Markdown: fenced blocks and inline code spans are stripped
first, since GitHub does not parse references inside them. Without this the
guard flags any doc that merely quotes a keyword -- including the backticked
form the guard's own error message recommends.
- Commit messages are plain text: backticks do NOT defuse a keyword there, so
they are scanned raw. This matters because squash-merge concatenates every
commit message into the squash body.
Regex notes: the leading (^|[^[:alnum:]_]) is a word boundary -- without it
"postfix #N" trips on the trailing "fix". Spelled out rather than \b so it does
not rely on GNU-grep extensions. An intervening word (as in "fix PR #N") breaks
GitHub's adjacency rule and is correctly not matched here either.
Wired into the aggregate `gate` verdict; skipped on push/workflow_dispatch, where
there is no PR body to scan.
Verified: replays the incident (PR #483 -> RED, PR #482 -> GREEN), plus 15
positive/negative regex cases including the defusing forms the error suggests.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The step's shell is `bash -e` and the script adds pipefail, so the keyword grep exiting 1 on NO match -- the healthy, common case -- propagated and killed the script before it printed anything. Every clean PR went red; caught when this branch's own PR failed its own check with zero output. Guard the assignment with `|| true` and note why it must stay. Verified under `bash -e` + pipefail: no-keyword -> exit 0, keyword-present -> detected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The incident this prevents
While merging #483, GitHub silently closed the unrelated, in-flight PR #482. Nobody clicked anything — but the audit trail said
actor=nockawa, because GitHub attributes keyword-closes to whoever merged.The cause was one sentence in #483's description, in a Notes section explaining what the PR doesn't do:
Two GitHub behaviours combined:
KEYWORD #Nadjacency and nothing else.does not retroactively fix #Nlinks and closes identically tofixes #N.#Nthat happens to be a PR closes that PR.There is no repository, org, or enterprise setting to disable closing keywords. A CI check is the only systemic defense — hence this PR.
What the check does
New
closing-keywordsjob, wired into the aggregategateverdict. It scans the same two surfaces GitHub's own parser reads and fails only when a keyword-linked number resolves to a pull request. The everyday intended use — a closing keyword naming a real issue — stays green.Surface handling deliberately mirrors GitHub:
Word boundary is spelled
(^|[^[:alnum:]_])rather than\bso it doesn't depend on GNU-grep extensions — without it,postfix #1trips on the trailingfix.Verification
Replayed against the real incident:
argument-hint#481, a genuine issue → GREEN (no false positive on legitimate use)Plus 15 positive/negative regex cases, including every defusing form the error message suggests (
`#N`backticked,PR #Nintervening word, rephrased) and near-miss words (postfix,hotfix,suffix,prefix-fixture).And the markdown-stripping test: a synthetic PR body documenting closing keywords drops from 4 false positives → 0, keeping only the one genuinely live reference.
When it fires, contributors see
🤖 Generated with Claude Code