Repository navigation
fix(hooks): bind each body flag to its own gh invocation in perf advisory - #1015
Conversation
…sory
perf-multiplier-evidence-advisory matched `gh (issue|pr) (create|comment)` as
a regex over the whole command string and then returned the FIRST `--body` in
the flat shlex argv. Both halves lose which invocation a body belongs to, which
produced three wrong answers on real code:
- a claim in a second chained gh call was never seen, because the first
call's body ended the walk. The issue's exact scenario — evidence posted by
invocation 1 silencing an unsupported "5x faster" in invocation 2 — was
completely silent, with both `&&` and `;` separators.
- a non-gh command's `--body` (e.g. `curl -X POST --body "harmless"`) was
donated to the gh scan, hiding the real claim behind it.
- a false POSITIVE in the same root cause: `gh issue create` appearing only
inside a quoted `echo` argument fired the advisory with no deliverable
write anywhere in the command.
Replace both with per-invocation binding, mirroring the sibling
n1-quantitative-claim-advisory (PR #969): tokenize once, split into segments
with the shared `iter_command_starts` / `strip_prefix`, test each segment with
a new `_is_gh_deliverable(argv)`, and read each body with `_body_of(argv)`.
`_extract_bodies()` returns one body per gh deliverable and main() evaluates
the multiplier/lever test and the timing-artifact pass condition per body, so
evidence cited in one body no longer silences a claim in another. No
hooks/_lib/ change — both primitives are already public and used by 11 sibling
hooks. Issue Task 1 enumeration returned N=1 (this hook was the last structural
outlier), so the lift-to-_lib branch does not apply.
Mirroring the sibling alone introduced a new under-fire regression, so this
also adds `_newlines_to_separators()`: a newline separates commands in Bash,
but `shlex.split` consumes it as generic whitespace, so
`git status\ngh pr comment --body "5x faster"` flattened into ONE segment whose
argv[0] is `git` and went silent (it fired before this change). The shared
`safe_tokenize` cannot be used instead — it pre-splits on every raw newline,
cutting quoted multi-line bodies, which are this hook's primary input;
measured, `gh pr comment 1 --body "### Verification\n3x speedup expected"`
tokenizes to `[';']` under it. The rewrite therefore converts newlines to `;`
only outside quotes. Note the sibling carries this same newline gap and an
inaccurate comment blaming `safe_tokenize`'s `#` handling (it sets
`commenters = ""`); the accurate rationale is recorded here.
Evidence: a probe feeding real PreToolUse(Bash) payloads to the hook went from
4 wrong verdicts to 0, with both positive controls unchanged across the fix
(`--body "5x faster"` fires; the same body plus a wall-clock artifact stays
silent). 11 regression cases added; run against the pre-fix impl, R1-R4 and R11
fail and R5-R10 hold, so the new cases pin the defect rather than restating
current behavior. The hook's suite goes 25/25 -> 36/36 with no pre-existing
case changing verdict; `scripts/check-plugin-manifests.py` reports OK.
Unverified: heredoc and command-substitution bodies (unchanged from before, but
untested either way); exotic quoting forms against the new newline scanner
(`$'…'`, backticks spanning lines); backgrounded `&` and subshell-grouped
invocations. The hook is advisory-only and @fail_open, so a mis-split costs a
missed or spurious nudge, never a block.
Refs #973
Closes #973
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014Q4o2BtBPpsrr19he6qVpc
|
Warning Review limit reached
Next review available in: 119 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Verification —
|
| # | Claim | Result |
|---|---|---|
| 1 | 체인된 두 번째 invocation 의 근거 없는 주장이 변경 전에는 보이지 않았고, 이제 보인다 | PASS(live) |
| 2 | 비-gh 명령의 --body 가 gh 스캔에 기부되던 것이 멈췄다 |
PASS(live) |
| 3 | 같은 뿌리의 오탐이 사라졌다 — 인용된 텍스트 안의 동사만으로는 발화하지 않는다 | PASS(live) |
| 4 | 대조군 두 개의 판정이 움직이지 않았다 | PASS(live) |
| 5 | 범위 판정의 근거가 맞다 — 이 형태를 쓰는 훅은 main 에 하나뿐이다 |
PASS(live) |
| 6 | 스위트와 CI 5개 잡이 통과한다 | PASS(live) |
Unverified — (a) 개행 경계 처리는 형제 훅과 다른 구조라 그 차이가 다른 케이스에서 무엇을 하는지 미측정, (b) 실사용 발생 건수 0건
(a) PR 본문이 적은 대로 형제 훅 n1-quantitative-claim-advisory 의 구조를 그대로 옮기면 개행으로 분리된 케이스(R7)가 회귀하므로, 이 훅은 개행 경계 처리를 추가로 갖습니다. 행 4 의 두 번째 대조군이 R7 방향을 고정하지만, 두 훅이 이제 구조적으로 갈렸다는 사실 자체는 남습니다 — 나중에 공유 헬퍼로 합칠 때 이 차이가 결정 지점이 됩니다.
(b) 이 세 오답이 실사용에서 몇 번 잘못된 판정을 냈는지는 관측하지 않았습니다. 여기서 확인한 것은 전부 코드 경로 재현입니다.
Evidence 1 — `impl.py` 한 파일만 되돌린 트리와 브랜치 트리를 대조
세 오답 모두 "변경 전에는 이랬다" 는 주장이므로, 오라클은 before/after 대조여야 합니다. 브랜치 트리를 통째로 복사한 뒤 이 훅의 impl.py 한 파일만 main 것으로 되돌렸습니다 — 나머지 트리가 같아야 답이 이 파일에 귀속됩니다.
$ bash "$P/probe_1015.sh"
== 1. a second chained invocation's unevidenced claim
chain: body1 has evidence, body2 is a bare "5x faster" before=silent after=fires
same chain, ; separator before=silent after=fires
이슈가 서술한 정확한 형태입니다 — invocation 1 이 타이밍 근거를 싣고, invocation 2 가 맨 5x faster 를 싣습니다. 변경 전에는 && 와 ; 양쪽에서 완전히 침묵했습니다. 첫 번째 --body 만 보고 "근거 있음" 으로 끝냈기 때문입니다.
이 프로브의 첫 판은 impl.py 사본을 /tmp 에 단독으로 두었고, 그러면 from _hook_runtime import fail_open 이 ModuleNotFoundError 로 죽습니다. 판정을 "stderr 가 비었는가" 로만 했더니 모든 traceback 이 fires 로 읽혀 before 쪽이 전부 발화한 것처럼 나왔습니다. 트리 통째 복사로 고쳤고, 판정 함수도 ERROR 를 별도 값으로 구분하게 바꿨습니다 — 위 출력에 ERROR 가 없다는 것이 그 자체로 하니스가 살아 있다는 표시입니다. $P 는 프로브를 워크트리 밖에 두려고 담아 둔 경로 변수입니다.
Evidence 2 — 비-gh 명령의 본문이 기부되던 경로
평평한 argv 에서 첫 --body 를 집으면, 그 앞에 선 아무 명령의 --body 나 gh 의 본문 행세를 합니다. 위 블록의 이어지는 부분입니다 — 별도 실행이 아닙니다.
== 2. a non-gh --body donated to the gh scan
curl -X POST --body "harmless" && gh issue create --body "5x faster" before=silent after=fires
curl 의 무해한 본문이 뒤따르는 진짜 주장을 가렸습니다. 이것이 행 1 과 같은 뿌리(본문이 어느 invocation 소속인지를 잃는 것)의 다른 얼굴입니다.
Evidence 3 — 같은 뿌리의 오탐 방향
같은 결함은 반대 방향의 오답도 냅니다 — 커맨드 문자열 전체에 정규식을 걸면 인용된 텍스트 안의 gh issue create 도 매치합니다.
== 3. false positive: the trigger words live inside a quoted echo
quoted echo names the verb; the --body belongs to printf before=fires after=silent
여기에는 딜리버러블 쓰기가 하나도 없습니다 — echo 가 파일에 메모를 쓰고, --body 는 printf 의 인자입니다. 변경 전에는 이것이 advisory 를 발화시켰습니다. 이 명령은 제가 만든 것이 아니라 이 PR 의 R4 픽스처에서 그대로 가져왔습니다.
Evidence 4 — 판정이 움직이면 안 되는 두 대조군
세그먼트 단위 검사는 "체인 안에 배수 표현이 있으면 발화" 로 잘못 고칠 수 있고, 개행 처리를 형제 훅 구조로 옮기면 개행 케이스가 회귀합니다. 두 방향을 각각 고정합니다.
== controls
both chained bodies carry their own timing evidence -> silent before=silent after=silent
newline-separated git status, then unevidenced gh claim -> fires before=fires after=fires
첫 줄이 "모든 본문이 각자 근거를 가지면 침묵" 이고, 둘째 줄이 개행 경계입니다. 둘 다 before=after 이므로 이 변경의 폭이 정확히 행 1~3 의 세 줄입니다.
Evidence 5 — 범위 판정("이 훅 하나뿐")의 근거
이슈는 "1개뿐이면 단일 훅 수정, 3개 이상일 때만 공유 헬퍼" 라는 기준을 정했으므로, 개수가 곧 설계 결정입니다. 부재/개수 주장이라 오라클이 무언가를 찾을 수 있는지부터 봅니다.
$ git grep -l '_extract_body_text' origin/main -- hooks/
origin/main:hooks/advisory-nudge/perf-multiplier-evidence-advisory/impl.py
$ echo "git grep exit=$?"
git grep exit=0
Positive control: 이 grep 이 죽어 있지 않다는 근거가 곧 그 한 줄입니다 — 빈 출력이 아니라 실제 경로를 냅니다. git grep 은 매치가 없으면 exit 1 을 내므로, exit 0 + 한 줄은 "정확히 이 파일 하나" 를 뜻합니다. 확인 범위: origin/main 의 hooks/ 전체, 토큰 _extract_body_text. 다른 이름으로 같은 형태를 구현한 훅이 있다면 이 범위 밖입니다.
형제 훅 n1-quantitative-claim-advisory 가 목록에 없는 것은 PR #969 에서 이미 닫혔기 때문이고, 그래서 남은 것이 하나입니다.
Evidence 6 — 스위트와 CI
행 1~4 는 제가 고른 6개 명령이므로 이 PR 이 고정한 기대값 전량과 CI 도 함께 봅니다.
$ bash tests/hooks/advisory-nudge/test_perf_multiplier_evidence_advisory.sh
== 36 passed, 0 failed ==
$ gh pr checks 1015
link-check pass 8s ...
markdownlint pass 42s ...
ruff pass 15s ...
shellcheck pass 34s ...
test pass 7m59s ...
test 잡은 이전 실행에서 한 번 실패했다가 재실행에서 통과했습니다 — 그 실패의 원인은 별도 이슈로 열려 있고(이 PR 의 변경과 무관한 상태 파일 비원자성), 이 브랜치의 코드와는 관련이 없습니다. 위 5개는 현재 HEAD a83af33 에 대한 결과입니다. 각 잡의 URL 은 조직 계정 경로라 인용에서 ... 로 줄였습니다.
History — rev 1, 최초 게시
이전 판본 없음. 대체된 근거도 없습니다.
요약
perf-multiplier-evidence-advisory는gh (issue|pr) (create|comment)를 커맨드 문자열 전체에 대한 정규식으로 찾고, 그 뒤 평평한 shlex argv 에서 첫 번째--body를 반환했다. 두 축 모두 본문이 어느 invocation 소속인지를 잃는다.실측된 세 가지 오답
5x faster를 싣는 형태)가&&와;양쪽에서 완전히 침묵했다.--body가 gh 스캔에 기부된다 —curl -X POST --body "harmless"가 뒤따르는 진짜 주장을 가린다.echo인자 안에만 등장하는gh issue create가 딜리버러블 쓰기가 전혀 없는데도 advisory 를 발화시켰다.이슈 작업 1 (범위 판정)
_extract_body_text형 헬퍼와 전체-커맨드 스캔을 조합한 훅을 전수 열거한 결과 이 훅 하나뿐이다. 형제 훅n1-quantitative-claim-advisory는 PR #969(5dbfa8a)에서 이미 닫혔다. 이슈가 정한 기준("1개뿐이면 단일 훅 수정, 3개 이상일 때만 공유 헬퍼")에 따라 단일 훅 수정으로 처리했다.hooks/_lib/는 건드리지 않았다.수정
한 번 토크나이즈한 뒤 공유
iter_command_starts/strip_prefix로 invocation 단위 세그먼트로 쪼개고, 각 세그먼트가 gh 딜리버러블 쓰기인지 판정한 다음 그 세그먼트의 본문만 검사한다. 형제 훅의 구조를 따르되 개행 경계 처리를 추가했다 — 형제 구조를 그대로 옮기면 R7(개행으로 분리된git status다음의 gh 주장)이 회귀한다.회귀 픽스처 11종 — 양·음 양방향
&&체인, 본문 1 에 타이밍 근거 / 본문 2 에 맨5x faster;구분자curl --body "harmless" && gh issue create --body "5x faster"echo안의 트리거 단어git status && gh pr comment --body "3x faster; real 0m12.400s"git status다음 gh 주장### Verification으로 시작하고 근거 없는 여러 줄 본문#가 주석으로 먹히지 않음)/usr/bin/ghgh --repo owner/name pr comment(전역 플래그 삽입)tests/hooks/advisory-nudge/test_perf_multiplier_evidence_advisory.sh: 36 passed, 0 failed (브랜치 격리 상태에서 실행).미확인
gh호출 자체가 흔한 형태가 아니다. 이 PR 은 잠재 표면을 닫는 것이지 사고를 수습하는 것이 아니다.n1-quantitative-claim-advisory의_extract_bodies독스트링에 사실 오류가 있다 —safe_tokenize를 피하는 이유로 "인용 상태 확정 전#를 줄 끝까지 제거한다" 를 든다.safe_tokenize는lex.commenters = ""를 설정하므로 사실이 아니다(fix(hooks): fold lines across an open quote in safe_tokenize #1014 에서 실측). 이 PR 범위 밖이라 수정하지 않았다.Closes #973
🤖 Generated with Claude Code
https://claude.ai/code/session_014Q4o2BtBPpsrr19he6qVpc
Generated by Claude Code