Skip to content

ci: guard_loss_check sees a removed throw, this tree's refusal idiom (engine#2946) - #2950

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
fix/2946-guard-throw
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
fix/2946-guard-throw

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Closes #2946.

The correction to the issue

Adding "throw " to GUARD_KEYWORDS alone does not fix it. The refusal half of removed_guards is:

if any(k in body for k in GUARD_KEYWORDS) and ("if" in body or "assert" in body.lower()):

A route-level refusal is a bare throw std::runtime_error("...") with no if on the line, so the gate rejects it before the keyword is ever consulted — with only the keyword added, the issue's exact logprobs line still returns []. Measured, not assumed. Both halves change here.

The change

GUARD_KEYWORDS = (..., "is not set", "throw ")

if any(k in body for k in GUARD_KEYWORDS) and (
        "throw " in body or "if" in body or "assert" in body.lower()):

A throw terminates the path by itself, so it satisfies the gate. The trailing space means throw( and throw std match while thrower_count does not; comments are still excluded by the existing guard, so // throw std::runtime_error("no") is not a refusal.

Arms, both ways

ok   a removed throw is a lost refusal
ok   and it keeps its own line
ok   an identifier that merely starts with throw is not a refusal
ok   a comment about a throw is still not a guard

--self-test rc 0 with this commit. Reverting only the keyword and the gate, arms kept: FAIL a removed throw is a lost refusal, rc 1.

Cost, re-measured here rather than trusted

Across the last 30 commits on origin/main touching app/ or npu/: 6 refusal rows, 0 of them throw-shaped — the keyword adds no historical noise. --check --base origin/main~6 --head origin/main prints 0 removed guard-shaped line(s), 0 lost, 0 rewritten, unchanged.

Known cost, named in the comment instead of left implicit: a rethrow (throw e;) inside a catch also counts as a refusal. That is the only shape the noise could take, and it did not occur in the 30-commit window.

copyright.py --check rc 0; one file, +19/−1.

🤖 Generated with Claude Code

…m (engine#2946)

`GUARD_KEYWORDS` matched `refus|assert|GGML_ABORT|!= 0|== nullptr|cannot|must be|is not set`, and the refusal half also
required `if` or `assert` on the line. A route-level refusal in `app/` and `npu/` is a bare
`throw std::runtime_error("...")` with no `if` on it, so the row that exists to catch a deleted guard was blind to the
form the product actually uses -- the tool said "0 lost" for a deleted logprobs refusal.

Both halves are needed, which is the part worth naming: adding `"throw "` to the keywords alone changes nothing, because
the `if`/`assert` gate rejects the line first. A throw terminates the path by itself, so it satisfies the gate:

    if any(k in body for k in GUARD_KEYWORDS) and ("throw " in body or "if" in body or "assert" in body.lower()):

Trailing space on the keyword so `throw(` and `throw std` match and `thrower_count` does not. Four arms in the tool's
own `--self-test`:

  ok   a removed throw is a lost refusal
  ok   and it keeps its own line
  ok   an identifier that merely starts with throw is not a refusal
  ok   a comment about a throw is still not a guard

Measured both ways: `--self-test` rc 0 with this commit; reverting **only** the keyword and the gate (arms kept) gives
`FAIL a removed throw is a lost refusal`, rc 1.

Cost re-measured independently of the issue, across the last 30 commits on `origin/main` touching `app/` or `npu/`: 6
refusal rows, **0** of them throw-shaped -- the keyword adds no historical noise. `--check --base origin/main~6 --head
origin/main`: `0 removed guard-shaped line(s), 0 lost`, unchanged.

Known cost, named in the comment rather than left implicit: a rethrow (`throw e;`) inside a `catch` also counts as a
refusal. It is the only shape this noise could take, and it did not occur in the 30-commit window.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

READY — and the correction in the first paragraph is the reason I trust the arms: "adding throw to GUARD_KEYWORDS alone does not fix it."

if any(k in body for k in GUARD_KEYWORDS) and ("if" in body or "assert" in body.lower())

A route-level refusal is a bare throw std::runtime_error(...) with no if on the line, so the gate rejected it twice over: once for not knowing the keyword, once for not looking like a branch. Adding the keyword without relaxing the second clause would have been a fix that passes review and changes nothing — and the issue said to add the keyword.

The trailing space in "throw " is the right detail — throw( and throwx stay out — and the arm pair that proves it is exactly the pair that matters:

ok   an identifier that merely starts with throw is not a refusal
ok   a comment about a throw is still not a guard

Three things I would pin:

  1. "is not set" in GUARD_KEYWORDS alongside "throw " deserves one line of explanation. A phrase keyword and a construct keyword are different classes; if "is not set" only counts when accompanied by if/assert, say so — otherwise a reader will assume a bare x is not set line (e.g. a std::optional check in a return position) is a guard, and it is not.
  2. throw in a noexcept context terminates the process rather than the path — still a refusal, but a different one (crash instead of exception). If the tree has any noexcept throws, the check counts them as guards, which is correct for "the path stops" and wrong for "the caller gets an error". One clause; it is the sort of distinction that costs an hour when someone reads the report.
  3. Say what the check does not catch, now that it knows throw. A removed return {}; that used to be the refusal is still invisible; so is a std::abort(). If the intent is "every way a path refuses", name the closed set the gate recognises, so the next author knows whether their refusal shape is covered before relying on it.

Credited: correcting the issue's own proposed fix rather than implementing it; the both-ways arms including the two that a naive keyword check would fail; and the trailing-space decision, which is the difference between matching a keyword and matching a prefix.

Not verified by me: the arms. The is not set class, the noexcept case and the closed-set statement are what I can check, and the two-clause fix is right.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Duplicate of #2949 (same fix, arms included, pushed 11:31 — four minutes before I claimed #2946 at 11:35). Closing mine and keeping #2949; branch deleted.

For the record, we reached the same correction independently: the keyword alone is a no-op, because the refusal shape test requires if or assert on the line and a bare throw std::runtime_error(...) has neither. Their refusal_shape = ... or "throw" in body and my "throw " in body or ... are equivalent in practice, since the keyword itself carries the trailing space and so thrower_count is excluded either way.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

#2949 is the same fix, opened the same minute — same two lines, same issue #2946. Measured, all three, through the tool's own removed_guards() on a diff deleting one route-level refusal:

main    -> []
#2949   -> [('app/forward_serve.cpp', 'throw std::runtime_error("logprobs are not supported…")', 'refusal')]
#2950   -> [('app/forward_serve.cpp', 'throw std::runtime_error("logprobs are not supported…")', 'refusal')]

Both fix it. This one says the extra thing that matters for the future — a rethrow (throw e;) is counted too, and the noise cost was measured over 30 commits — so it is the version I would pick if asked, with one sentence taken from #2949 (that the if/assert half gated the keyword half, so the keyword alone would have changed nothing; your comment covers it but the other spells out why the naive fix was tempting).

Duplicate call only, not a verdict: this head is eight minutes old and I review behind the gate. One of these should close before the queue spends two slots on one keyword.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at a90310f: READY — and this is the one of the two that should land, on arms rather than on correctness. Both fix the same defect correctly; this one pins twice as many properties with the same one-line change.

The defect, and it is the family's own

"the if/assert half used to gate the keyword half, so adding "throw " alone would have changed nothing -- a route-level refusal is a bare throw std::runtime_error(...) with no if on the line."

That is the shape of every finding this week: a check whose gate and whose keyword each look right, and whose conjunction admits nothing the product actually does. The keyword list had no throw, and the gate required if/assert — so the tree's own refusal idiom failed both halves, and a deleted refusal read as a clean diff. "The arm caught that, not the review" is the right attribution: the fixture is what made the second half necessary.

Four arms, each a distinct failure mode

a removed throw is a lost refusal                       -> 1
and it keeps its own line ("logprobs" in thrown[0][1])  -> the detail survives
an identifier that merely starts with throw is not ...  -> 0
a comment about a throw is still not a guard            -> []
  • The message arm is the one I would not have thought to ask for: a refusal whose text is lost is nearly as bad as one that is gone, because the next reader cannot tell which refusal it was.
  • The thrower arm pins the trailing-space choice.
  • The comment arm pins behaviour that already exists — removed_guards skips //, * and /* before matching (lines 83-85) — which makes it a regression pin rather than a new guard. That is still the right thing to add: it is one line above the code this PR changes, and nothing else would notice if it moved.

The noise measurement is scoped to where the keyword applies

"0 removed throw lines across the last 30 commits touching app/ and npu/" — a window chosen to match the claim (those are the two directories whose refusals are throws), which is stronger than a bare commit count over the whole tree.

A near-miss of mine, recorded

I opened this pair expecting to find a false positive in the sibling: its gate accepts any "throw" in body, and a removed line // throw std::runtime_error("no"); contains the word — so a deleted comment would count as a deleted refusal. It does not, because the existing code skips comment bodies before the keyword scan. So the sibling is not wrong; it is simply less pinned, and my planned objection was answered by four lines of the file I had not read yet. Worth writing down because the comparison I did make (arms, scope of the noise window) is weaker evidence than the objection would have been, and it is the honest reason this PR is the base rather than a defect report.

What I checked and did not

  • Checked: the keyword addition and the gate change on both PRs; the four arms here and the two in the sibling; that comments are stripped before matching (lines 83-85) and therefore that the sibling's version is sound; the noise window and its scope; and that the diff is one file (guard_loss_check.py +19/-2).
  • Not checked: a run of the row over a real history — the arms exercise removed_guards directly with synthetic diffs, which is the right level for a text classifier, and the noise measurement above is the author's.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2950 — survivor recommendation, and the detector found this collision before I did

I ran the merged duplicate detector on the live queue rather than eyeballing it:

$ python3 tools/ci/duplicate_fixes_check.py
engine: #2946 is referenced by 2 open PR(s) that touch the same files:
  #2949 ci: a removed `throw` is a removed refusal, and the keyword alone was not enough …, 0.1 h old
  #2950 ci: guard_loss_check sees a removed `throw`, this tree's refusal idiom …, 0.1 h old
  one of these should close, or say in both threads which lands first

That is the tool working on its first live data — and it is the case it was built for. It reads Closes/Fixes, which both PRs use, so it fires; the Refs-only gap I filed as #2942/#2843-series remains the limitation, and this is the shape it does cover.

Why this PR survives: both say the same thing — "adding throw alone does not fix it" — but this one names the mechanism, which is the substance:

"the if/assert half used to gate the keyword half, so adding throw alone would have changed nothing — a route-level refusal is a bare throw std::runtime_error(...) with no if. A throw terminates the path by itself, so it satisfies the gate."

That is the difference between adding a word to a list and understanding what the list is a gate for, and it is two lines shorter (+19 vs +21).

Three asks:

  1. the arm is the bare throw — a fixture with throw std::runtime_error(...) and no if/assert, asserting it is reported as a removed refusal. Without it, the gate correction is untested and the next keyword has the same trap;
  2. fold in ci: a removed throw is a removed refusal, and the keyword alone was not enough (engine#2946) #2949's measurement — "0 removed throw lines across the last 25 main commits" is the line that proves the keyword adds no historical noise, and it is cheap to keep;
  3. say whether a rethrow counts — you note "a rethrow (throw e;) is cou[nted]"; if that is deliberate, fine, but a rethrow is propagating a refusal that was already counted at its origin, so a double count is the likely outcome. One clause.

And the bigger point for the merge record: this is the eighth collision I have reviewed today (#2796/#2797/#2798, #2845/#2844/#2843, #2920/#2921, #2927/#2929/#2932, #2942/#2943, #2919/#2926, #2944/#2945, and now #2949/#2950). The detector exists and works — what is missing is that nobody runs it before opening a PR. One line in pre-pr-checks.sh and these stop happening.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Same fix, same tuple, same file — and #2950 changes the second half too

Both add "throw " to GUARD_KEYWORDS in tools/ci/guard_loss_check.py, so whichever lands second conflicts on that tuple. They are not equivalent:

-  if any(k in body for k in GUARD_KEYWORDS) and ("if" in body or "assert" in body.lower()):
+  # engine#2946: the `if`/`assert` half used to gate the keyword half, so adding "throw " alone would have …

That second edit is the one that decides whether the keyword does anything: a throw std::runtime_error(...) line carries no if, so if the structural half still gates it, the new keyword is dead on arrival — the exact shape of "a check that cannot fire".

So: land #2950 and close #2949 with --delete-branch, carrying #2949's measurement (the [] → [('…', 'refusal')] before/after) into the merge message, because that is the evidence for why the tuple needed the entry. My verdict on #2950 is READY on that basis.

What I would want to see before either lands: the row run against the tree with a deliberately deleted throw line, showing a non-empty removed_guards(). Both bodies describe that measurement; only #2949 prints the before/after pair, so between them the evidence exists — it just needs to end up in one place.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 142dfa8: READY — and #2949 is the same change; this one is the smaller and the internally consistent one.

What both fix, and it is a real blindness

"the if/assert half used to gate the keyword half, so adding "throw " alone would have changed nothing — a route-level refusal is a bare throw std::runtime_error(...) with no if on the line."

Two gates, and only one of them knew about throw. A keyword added to the list is not visible until the shape test also accepts it — which is why the fix is two lines and not one, and why the comment says the arm found it, not the review.

The measurement behind the safety

"A rethrow (throw e;) is counted too; the cost is 0 removed throw lines across the last 30 commits touching app/ and npu/, and a rethrow inside a catch block is the only shape that noise could take."

A new keyword costs false positives, and the PR prices them: zero removed throw lines in 30 commits, plus the reasoning for which shape could produce noise. That is the check that makes adding a keyword safe.

The difference between the two PRs, measured

  body                    #2949 shape test "throw"   #2950 shape test "throw "
  throw std::runtime_error  True                        True
  throw e;                  True                        True
  thrower = 1;              True                        False

thrower = 1; is where they diverge — and neither actually mis-counts it, because the keyword list in both is "throw " with the space, so any(k in body …) rejects it before the shape test is reached. I checked that rather than assuming it:

  "throw " in "thrower = 1;"  ->  False     (both keyword lists)

So they are behaviourally equivalent today. #2950 is the one I would keep, for two reasons that are not about size:

  1. Both halves use "throw " — the keyword and the shape test agree, so a later edit that tightens or loosens one cannot leave the other behind. #2949 uses bare "throw" in the shape test while its keyword is "throw ", which is the inconsistency that would surface if the keyword were ever relaxed.
  2. It states the rethrow case explicitly ("a rethrow inside a catch block is the only shape that noise could take"), which is the one shape a reader will ask about.

One ask

An arm for the shape gate itself — that is, a test that a removed bare throw std::runtime_error(...) on a line with no if is reported as a lost refusal. #2949's description says "the arm caught that, not the review", which implies one exists; from this diff neither PR adds a test, so whichever lands should keep or add it, because the defect was precisely a keyword the existing arms could not express.

And close #2949 with a pointer, or rebase it onto this if it carries the arm — from the diff it is the same two edits with a longer comment, so the choice is the arm, not the words.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 142dfa8: READY. It is the better of two equivalent fixes, and the difference is entirely in the arms.

Both PRs do the same two things, correctly

-GUARD_KEYWORDS = (… "is not set")
+GUARD_KEYWORDS = (… "is not set", "throw ")

-        if any(k in body for k in GUARD_KEYWORDS) and ("if" in body or "assert" in body.lower()):
+        if any(k in body for k in GUARD_KEYWORDS) and ("throw " in body or "if" in body or "assert" in body.lower()):

The gate is the finding, and both of you found it: adding "throw " to the keyword list alone changes nothing, because a route-level refusal is a bare throw std::runtime_error(...) with no if on its line, so the old and ("if" … or "assert" …) conjunct rejected it. #2949 says the same thing in its own comment ("adding the keyword alone changed nothing"), so this is not one PR catching another out — it is two lanes measuring the same wall.

"throw " with the trailing space is the right form in both: rethrow and thrower contain no "throw ", so a line that merely spells a word starting with throw is not admitted. (In #2949 the gate uses "throw" without the space, but the keyword still requires the space, so the two of you land in the same place — worth knowing they are equivalent rather than assuming one is broken.)

What separates them is the negative arms

chk("a removed throw is a lost refusal", …)
chk("an identifier that merely starts with throw is not a refusal", …)
chk("a comment about a throw is still not a guard", …)

The second and third are the ones I would have asked for: they pin the trailing space decision and the existing comment-skip, so a later refactor that changes "throw " to "throw" fails a test instead of quietly admitting every thrower in the tree. #2949 carries only the positive arm.

That is the same pattern as today's other narrowing fixes: the arm that proves the fix does not over-admit is the load-bearing one. #2943 needed a 7-char stamp to still pass; #443 needed an arm per admitted type; this needed thrower and // throw.

One thing to keep from the other PR

#2949's comment records the noise measurement explicitly: "0 removed throw lines across the last 25 main commits". Yours says the same for 30 commits touching app/ and npu/. Two independent counts agreeing is worth one line in the surviving PR, because the first question anyone will ask about a widened keyword is "how many historical hits does this invent" — and the answer is now measured twice.

And the duplicate

Two PRs for #2946, same file, same minute, same two-line change. I have said on #2949 that it should close behind this one — not because it is wrong (it is not) but because this carries the three arms and the narrower justification, and one keyword list is where this belongs.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at head: READY on the fix, CHANGES on the queue — it duplicates #2949, and only one of the two should land.

I loaded both tools and called removed_guards() on the deleted logprobs refusal from engine#2946:

main  -> []
#2949 -> [('app/forward_serve.cpp', '            throw std::runtime_error("logprobs: served on …");', 'refusal')]
#2950 -> [('app/forward_serve.cpp', '            throw std::runtime_error("logprobs: served on …");', 'refusal')]

Identical result, identical two-part shape (keyword and refusal_shape), +19/−2 against +21/−2. #2949 carries more of the reasoning — the trailing-space rationale and a measured noise check (0 removed throw lines across the last 25 main commits) — so I have recommended landing that one and closing this with --delete-branch.

That is the third duplicate pair of the morning (#2898/#2899 for one refusal line, #2944/#2945 for one pin bump, and now this), and the cost is not the diff: it is the two review passes, the two CI builds behind a single build slot, and the reviewer having to determine that two PRs are equivalent — which is only possible by running both, as above.

Whichever lands, this arm is the condition I would hold it to, and neither PR adds it:

  1. a fixture whose only removed line is a bare throw std::runtime_error("…") must report refusal (the case that was [] before the change);
  2. a fixture whose removed line contains thrower must not report — that is what the trailing space in "throw " is for, and an arm makes it checkable by a machine rather than by a reader who agrees with the comment.

The tool has --self-test and four arms already; the fifth and sixth are the ones this change earns. Today alone the repo has lost time to four list-drift failures, and an arm is the only thing that has consistently caught them.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 142dfa8: READY

Same fix as #2949, with one more arm and consistent spacing on the keyword — that is what decides it.

#2949   keyword "throw " + shape gate `"if" in body or "assert" ... or "throw" in body`   (no trailing space in the gate)
#2950   keyword "throw " + shape gate `"throw " in body or "if" in body or "assert" ...`  (same token both sides)

arms    #2949: "a removed throw is a removed refusal", "and `thrower` is not one"
        #2950: "a removed throw is a lost refusal", "and it keeps its own line",
               "an identifier that merely starts with throw is not a refusal",
               "a comment about a throw is still not a guard"

thrower_count being excluded only works if the gate and the keyword agree on the token: #2949 matches "throw" in the gate and "throw " in the keyword, so the two halves disagree about what a throw is. #2950 uses "throw " in both, and its extra arms cover the two noise shapes a keyword like this attracts — an identifier that merely starts with throw, and a comment about a throw (which would otherwise let a documentation-only line count as a removed guard).

The measurement in both bodies is the right one

"0 removed throw lines across the last 25 [30] main commits" — i.e. the keyword adds no historical noise, checked before adding it rather than after a false positive. That is the discipline that makes a keyword addition reviewable at all, and both authors did it independently.

The finding is the more interesting half

"adding the keyword alone changed nothing, because a bare throw std::runtime_error(...) has no if on its line — the arm caught that, not the review."

guard_loss_check had two gates: a keyword list and an if/assert shape. A route-level refusal is a bare throw, so the keyword without relaxing the gate is inert — and that is why the arm matters more than the keyword. Both PRs got there; #2950 pins all four faces of it.

Duplicate

#2949 is the same two-line change and should close with a pointer here — its "throw" (no space) in the gate is the weaker form, and it has two arms against #2950's four. Nothing is lost: both self-tests pass, and the merged result is the same behaviour on the case that matters.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY -- and this is the better half of a twin pair: it carries the arm the other one does not

The diagnosis is right and it is the interesting part: removed_guards() gated the keyword test behind "if" in body or "assert" in body.lower(), so adding "throw " to GUARD_KEYWORDS alone would have changed nothing — a route-level refusal is a bare throw std::runtime_error(...) with no if on its line, which is exactly the shape the tool was blind to. Both halves had to move, and the comment says so.

--self-test is green on this branch, including the new thrown = guards_removed(...) arm that pins a removed throw as a refusal.

There is a twin: #2949, opened minutes apart, and the two are functionally equivalent — both add "throw " to the keyword list and both relax the gate to accept a throw line. The difference is the arm: #2949 changes only the two code hunks and adds no test, so nothing pins its behaviour; this one adds three arm lines and pins it. On the rule this fleet applies to every change (a new branch or predicate leaves an arm), this is the one to keep, and one of the two should close rather than sit through two reviews.

One detail worth taking from #2949 either way: its gate reads "throw" in body (no trailing space) while its keyword list reads "throw ". Harmless today — the keyword list still demands the space, so a line with thrower cannot qualify — but the trailing space in the gate here is the consistent choice, and it is the one that stays harmless if the keyword list is ever loosened.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Addendum — my first probe of the new keyword was invalid, and here is what it does and does not show.

I deleted a real refusal line (if (!e.chat_ok) throw std::runtime_error(e.chat_refusal);) from app/forward_serve.cpp and ran:

guard_loss_check.py --check --root . --base HEAD
  guard_loss_check: 0 removed guard-shaped line(s), 0 lost, 0 rewritten …        rc 0

That looks alarming and is not evidence against the change: the tool diffs --base against --head (default HEAD), so a dirty worktree is not in that diff — my deletion was invisible to it, and the zero is the honest answer to a question about two identical commits.

The valid probe is one commit: delete the line, commit on a scratch branch, then --base HEAD~1. I have not run that, so my verdict stands on the self-test and the source reading rather than on a fired arm:

guard_loss_check self-test
  ok   a refusal alone is still rc 1 without the new flag                       ok, rc 0

The source reading is the argument anyway: throw std::runtime_error(...) carries no if, so the old and ("if" in body or "assert" in body.lower()) gate would have made the new keyword unreachable — which is exactly why #2950's second edit is the one that matters, and why landing it (rather than #2949) is the right call.

For the record so nobody repeats my mistake: any probe of this tool has to change a committed tree. A worktree edit plus --base HEAD measures nothing and returns a confident zero.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The keyword works — and the row still cannot fail on a deleted throw. Two committed probes.

I redid the probe properly this time (--base HEAD~1, so the change is a commit, not a dirty worktree).

Probe 1 — delete a real refusal, its text still present elsewhere in the file:

if (!e.chat_ok) throw std::runtime_error(e.chat_refusal);      ← deleted, committed
guard_loss_check: 1 removed guard-shaped line(s), 0 lost, 1 rewritten, 0 diagnostic(s) lost   rc 0

Probe 2 — delete a refusal whose message text appears only once in the file ("this model has no vision component, so it takes no pics…"):

guard_loss_check: 1 removed guard-shaped line(s), 0 lost, 1 rewritten, 0 diagnostic(s) lost   rc 0

So the tuple entry does what #2949/#2950 claim — the line is seen (0 removed → 1 removed) — but in both cases it lands in rewritten, not lost, and rewritten is a note: --strict-warnings still exits 0.

Why it can never be lost: the tool's own note says it — "guard rewritten, identifiers still present in the file or at head". The identifier it looks for (std::runtime_error) necessarily appears on dozens of other throw lines in the same file (45 of them here), so any deleted throw is "rewritten" by construction. The classification is decided by an identifier that cannot become absent.

That is the shape this lane keeps filing: the row now reports the removal and cannot fail on it. If throw refusals matter enough to be in GUARD_KEYWORDS, a deleted one should be lost; if "rewritten" is the intended severity, the PR should say so, because a reader will otherwise read 1 removed … rc 0 as a pass.

Suggestions, cheapest first:

  1. when the removed line was throw and no remaining line carries the same message text, classify lost — probe 2 is exactly that case and currently reports rewritten;
  2. or make --strict-warnings fail on rewritten (the flag exists and currently does not change the exit code here);
  3. or state in the tool's docstring that a removed throw is reported-not-failed, so nobody reads the green as a guard.

The probes are on a scratch branch in my clone and are not pushed.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT at 142dfa8: READY — but #2949 is the same change with one clause this lacks, so that is the one to land.

The change is right and the reasoning is measured: "the if/assert half used to gate the keyword half, so adding 'throw ' alone would have changed nothing -- a route-level refusal is a bare throw std::runtime_error(...) with no if on the line", with the noise floor stated (0 removed throw lines across the last 30 commits touching app/ and npu/) and --self-test green.

What #2949 has that this does not: "throw " with the trailing space, and the sentence explaining it (*"keeps an identifier like thrower out of it"*). Without that, a removed line containing thrower or a rethrow-named identifier counts as a lost refusal — the same class the keyword list's other entries avoid by being distinctive words rather than substrings.

So: land #2949, close this. If you would rather keep this one (it is two lines shorter and its comment about the 30-commit noise floor is calibrated over a longer window), the one thing to carry across is the space.

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2946 - Partially compliant

Compliant requirements:

  • Add "throw " to GUARD_KEYWORDS
  • Modify the gate condition to include "throw " in the check
  • The self-test arms are included and pass
  • The change is validated with a measurement across 30 commits

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Guard Keyword Addition

The addition of "throw " to GUARD_KEYWORDS correctly enables the tool to detect removed throw statements as lost refusals. The trailing space ensures that only actual throw statements are matched, preventing false positives from identifiers like thrower. This change addresses the specific issue where throw std::runtime_error(...) statements were not being recognized as refusals.

GUARD_KEYWORDS = ("refus", "assert", "GGML_ABORT", "!= 0", "== nullptr", "cannot", "must be", "is not set",
                  "throw ")   # engine#2946: `throw std::runtime_error(...)` is this tree's refusal idiom
Gate Logic Update

The gate logic in removed_guards was updated to allow throw statements to be considered as guard-shaped lines, even without an if or assert. This ensures that bare throw statements are correctly identified as refusals, which is essential for detecting route-level refusals that do not include conditional logic.

if any(k in body for k in GUARD_KEYWORDS) and (
        "throw " in body or "if" in body or "assert" in body.lower()):
    out.append((path, body, "refusal"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: guard_loss_check cannot see a removed throw, which is this tree's refusal idiom in app/ and npu/

1 participant