Skip to content

fix(hooks): show each Stop model-rule finding once per session - #252

Merged
furedea merged 3 commits into
mainfrom
fix/stop-findings-once
Nov 19, 2026
Merged

furedea merged 3 commits into
mainfrom
fix/stop-findings-once

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

概要

Stop の model rules(Jev,advisory)が,同じセッションで一度出した指摘を,別のファイルを編集するたびに出し直していた.一度出した指摘は後の Stop で出さず,件数だけを 1 行で示す.

Closes #245
Refs #169

変更

  • 指摘の識別:(ruleKey または rule, file, 作業ツリーの line..endLine の内容のハッシュ).subject の本体が変われば新しい指摘として出し,行番号だけが動いた subject は同じ指摘として隠す.jev-lint 0.7.0 の Finding 型(ruleKey,endLine,任意の text)に基づく.text は実出力にあるとは限らないので使っていない.
  • 記録先:既存のセッション記録 results.json に model_rules_shown(出した指摘のハッシュの一覧)を足した.新しい保存機構は作っていない.
  • 記録先の選択理由:jev-lint の verdict cache は全セッション共有なので,セッションごとの「出した」には使えない.検証のレシート(model_rules)は入力の指紋ごとに置き換わるので,編集で消える.セッション記録は新しいセッションで空になるため,「新しいセッションでは改めて出す」がそのまま成り立つ.
  • 表示:jev-lint: 3 findings · 17 already shown · ....
  • 同じ指摘のハッシュが 1 回の実行で重なる場合(同一内容の subject,読めない subject)は,連番を付けて 1 件ずつ区別する.出した指摘の記録とレシートは 1 回の save_results で保存する.
  • 従来の「出した件数」(shown)は,指摘のハッシュに置き換えた.再試行(resume)でも二重に数えない.
  • 変更していないもの:規則,cutoff,advisory の扱い,ファイルの選択.

テスト

  • tests/hooks/test_model_rules_shown.py(新規):無関係な編集後に隠れる,行だけ動いても隠れる,本体が変わると再び出る,新しい指摘だけ列挙し既出は件数にする,新しいセッションでは出る.
  • 既存の 2 件を新しい仕様に合わせた:changed_inputs は別の規則の指摘で再び block することを確かめる.bounded は 1 行ファイルに 30 件の指摘が重なっていたので,30 行のファイルにした.
  • uv run pytest tests/hooks:全件通過.ruff,ty,lefthook も通過.

レビュー

3 件の P2(同一ハッシュの衝突を 2 件,保存の原子性を 1 件)は,この変更を誤らせるので修正し,テストを足した.スレッドは解決済み.

4 件目の P2(同一内容の subject が既存のものより前に追加されると,序数が入れ替わって最大 1 件を見逃す)は,内容で識別する以上,同一内容の subject は区別できないという限界なので,修正しない.見逃しは advisory 1 件分で,ブリーフの脅威モデルが許す範囲.対処するなら,識別子に行位置を足す必要があり,行が動いても隠すという要件と両立しない.スレッドは範囲外として回答し,解決した.

範囲外(ブリーフに基づく)

promoted・blocking の規則(#249),ファイル選択(#234),suppression コメント,規則や cutoff.

🤖 Generated with Claude Code

@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T03:52:01.014007Z 2005d64 Manual request
ℹ️ 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.

Comment thread agents/hooks/lib/model_rules_gate.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary

I found one minor problem and no blockers. Review was by reading the diff and the surrounding code. I did not run the tests.

P2 (inline, model_rules_gate.py:107)

  • Findings with the same (rule, file, subject text) are merged into one dict entry.
  • The merged findings are then counted as "N already shown", even though the agent never saw them.
  • This applies to identical subjects in one file, and to any file whose subject can't be read (the fingerprint falls back to rule and file only).
  • Counting only the keys found in known fixes it. A test for the case is missing.

Behaviour I traced and found sound

  • Cases traced: the stop_hook_active path (fresh findings are not remembered, the receipt becomes findings-unshown, and they block once at the next Stop), the resume retry, and the new-session reset.
  • The path guard in model_rules_seen._subject_text (resolve, then relative_to) correctly rejects paths outside the root.

Gaps, not blocking

  • If jev-lint doesn't emit endLine, it defaults to 0 and only the first line of the subject is hashed. That is weaker than the "line..endLine" identity the PR describes. A test with a finding that has no endLine would pin this down.
  • _answer_from reports only receipt["findings"], so the "already shown" count is lost when the same inputs are re-answered from the receipt.
  • No test covers stop_hook_active combined with the new remembered set, or resume combined with it.

🤖 Generated with Claude Code

@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: 66160370c2

ℹ️ 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".

Comment thread agents/hooks/lib/model_rules_gate.py Resolved
Comment thread agents/hooks/lib/model_rules_gate.py Resolved
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary: no blocking findings.

I read the full diff and checked these paths:

  • Save ordering: the receipt and model_rules_shown are written in one _save, and shown keys are recorded only when the Stop actually blocks. On a stop_hook_active Stop the keys go into the receipt and move to the shown set when the next Stop blocks on them. The failed-save test covers this.
  • Resume: asdict already serializes the new rule_key and end_line fields. The loader defaults them for older receipts, so a resume doesn't re-show findings.
  • Path handling: _subject_text resolves the path and checks it against the root, so symlinks and .. can't read outside the repo. Unreadable or undecodable files fall back to rule+file, and the #n numbering keeps duplicates apart.
  • jev-lint output: endLine and ruleKey are optional with safe defaults, so a missing endLine can't raise. A subject is then fingerprinted by its first line only.

Minor, not worth blocking (P3):

  • model_rules_shown only grows within a session. This is fine in practice.
  • A session already running with an old-format findings-unshown receipt has no keys, so those findings aren't recorded as shown after the one-time block. This only matters during the upgrade.
  • There's no direct round-trip test of rule_key and end_line through the resume dump and load.

I didn't run the tests. The PR reports pytest tests/hooks, ruff, ty and lefthook as passing.

@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: edbeec8ac0

ℹ️ 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".

Comment thread agents/hooks/lib/model_rules_seen.py Resolved
@furedea

furedea commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

Review summary

No findings at P0–P2. I read the full diff and traced these paths:

  • the blocking, stop_hook_active and resume paths through _Stop.judged
  • the receipt-reuse path in _advise
  • the single-write _save
  • the fingerprint and numbering in model_rules_seen

Checked and found sound

  • Findings are only recorded as shown when they actually block. A Stop with stop_hook_active leaves them UNSHOWN in the receipt, and they are recorded when the next Stop on the same inputs blocks on them.
  • Resumed runs re-carry earlier findings, and the known filter keeps them from blocking twice.
  • Old receipts without keys, and old shown ints, degrade safely to "nothing remembered".
  • The path in _subject_text is confined to the repo root. Decode errors are ValueErrors and are caught.
  • except OSError, ValueError: is valid on the pinned Python 3.15.

P3 (optional, no inline comment)

  • fingerprint reads the working tree, but select(..., ReviewedSpan(base, "HEAD")) can review committed content. If the working tree differs from HEAD for such a file, the line range could point at different text. Neither case blocks the merge: the worst outcome is a finding shown once more, or one hidden whose key has the same rule, file and text.
  • Findings whose subject cannot be read, or that have line == 0, are keyed by rule and file alone. One of them blocking would hide later such findings from the same rule in the same file for the rest of the session. The PR documents this as intended.
  • When the receipt is reused on unchanged inputs, describe_unchanged(receipt["findings"]) no longer includes the "N already shown" count. This is cosmetic.

Tests cover the new behaviour well: move, edit, new session, duplicates, and the failed save.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 2005d6451b

ℹ️ 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".

furedea added a commit that referenced this pull request Nov 19, 2026
…s under it (#246)

Stop 時の model rules の subject 上限 `SUBJECT_CAP` を,実測に基づいて 250 → 2000
に上げます.
あわせて,cap が効くときにキャッシュ済みファイルの finding が落ちる不具合と,1 ファイルも cap
に入らないと差分全体を送ってしまう不具合を直します.
当初含めていた「promote 済み rule(`severity: error`)で毎 Stop ブロックする
gate」は,ADR-0027(#250)の決定に従って取り除きました.

Refs #220

| 項目 | 変更前 | 変更後 |
| ---------------------------------------------------------------------
| ----------------------------------------------- |
-------------------------------------------------------------------------------------------
|
| `SUBJECT_CAP` | 250 | 2000 |
| cap で他のファイルが外れるとき,全 subject がキャッシュ済みのファイル | judge から外れ,キャッシュ済み finding
が消える | 費用 0 として必ず渡し,finding を報告する |
| 1 ファイルも cap に入らず,一部がキャッシュ済み | 選択が空になり差分全体を送る(cap 超過) | 何も送らない(`0/N
subjects` と報告) |
| ADR-0021 の実行時間の記述 | 「A run has 60 seconds」 | Stop 内で最大 90
s(検証の使用分を差し引く),子プロセスごとに最大 60 s(planning は 20 s) |

## 検証

- [x] `uv run pytest`(全体): 6134 passed, 2 skipped(origin/main にリベース後)
- [x] ruff check / ty: pass.lefthook pre-commit / commitlint: pass
- [x] Red → Green: 全件キャッシュ済みファイルのテストは,実装前に「差分全体を送る」理由で失敗
- [x] Red → Green: 1 ファイルも cap に入らない場合のテストは,実装前に `op` が呼ばれて失敗
- [x] Red → Green:
`test_the_subject_cap_holds_the_largest_measured_session_whole` を 988
subjects に更新すると,250 で失敗
- [x] CI: push 後の結果は下のチェック欄を参照

## 計測(`SUBJECT_CAP` の根拠)

- 条件:2026-11-18,`jev-lint` 0.7.0,model `jev-1.14.0`.#201 のマージコミット
`db7226d0` を `--base 746cd48` で review.`-R
agents/hooks/lint/model-rules`(#240–#244 後の全ルール,ADR
ルールを含む),新規キャッシュ,concurrency は既定の 32,`op run` 経由
- 計画(dry-run): 988 subjects,60 requests,cached 0,約 $0.028
- 実測(**1 回のみ**のためばらつきは不明): real 3.41 s(user 2.70 s,sys 0.18 s),exit 0
- 記録ファイル(`--record`)との照合:送信は 60 requests で計画どおり.988 subjects
すべてに回答があり(欠落 0),retried・rateLimited・splits はいずれも 0.問い合わせ区間の `wallMs` は
969 ms(リクエスト時間の合計は 20.2 s),入力 583,810 tokens,$0.0245
- 参考:同じ差分を全件キャッシュ済みで実行すると(ネットワークなし),3 回とも 0.17–0.18 s
- 判断:2000 は #201 の 2 倍超を丸ごと収める.1 subject ≈ 590 tokens なので,cap いっぱいでは
jev-lint の token burst(1.2M)の約 98% になり,超過分のペーシングは最大でも約 6 s.実測の 10 倍でも 90
s 予算の 70%(63 s)を大きく下回る.計測が 1 回だけなので,数値そのものではなく余裕幅で判断した

<details>
<summary>範囲・除外・経緯</summary>

-
範囲:`agents/hooks/lib/model_rules_run.py`(`SUBJECT_CAP`,`_capped_plan`),ADR-0021
の amendment(cap と実行時間の記述),`docs/DESIGN.md` と `docs/DESIGN_ja.md`(cap
の値と根拠),テスト(`test_model_rules.py`,`test_model_rules_report.py`,`test_model_rules_tiers.py`)
- 取り除いたもの(ADR-0027): exit 1 を error finding の結果として読む処理,gating finding
による毎 Stop ブロック,その文言・receipt・resume
項目,`test_model_rules_gate_findings.py`,ADR-0021 への gate の追記.revert コミット
676f15e で取り除き,squash 後の差分には残らない
- 除外(ブリーフに従う): model rule の promote やブロック(ADR-0027),セッションごと 1
回の報告(#245/#252),ルールファイルと cutoff,他リポジトリ
- キャッシュと cap: dry-run の batches は未キャッシュの subject だけを含むため,キャッシュ済み subject
はもともと cap に数えられていなかった(変更不要)
- batch の `file` と渡したパスの一致:実際の dry-run(#201 の差分,34
ファイル)で,全件完全一致することを確認した
- #252 との関係:#252 は `model_rules_gate.py` を変更する.本 PR は同ファイルを変更しないため,競合はない
- レビュー対応(rework 後の 1 回目):
- P1(Claude)「gate 機能が差分にない」: 説明を差し替える前のレビューだった.gate は ADR-0027
に従って意図的に除いたもので,タイトルと本文は絞り込み済みと返信して resolve
  - P2(Codex)「設計書が 250 のまま」: 5891a33 で両方の設計書を 2000 と新しい根拠に更新
- P3(Claude summary,スレッドなし)「`paths` が空のレビューでは全件キャッシュ済みファイルが残らない」:
`_Changes.reviews` は `sendable` が空でないときだけ `Review`
を作り,常に明示的なパスを渡すため,現状では起きない(潜在のみ).修正はせず,ここに記録する
- レビュー対応(rework 後の 2 回目,修正なし): P2「対象のないパスがあると `if not chosen`
を通らず,対象のないファイルだけで `op run` が起動する.`judged` にもスキップ分のキャッシュが混ざる」.dry-run
だけでは対象のないファイルと全件キャッシュ済みのファイルを区別できず,後者のキャッシュ済み finding
を報告するにはその起動が必要.新たな問い合わせは 0 で,誤った finding も出ない.件数表示のずれは以前からのもので advisory
に限られるため,ブリーフの基準に従い返信・resolve・記録にとどめた(Limits)
- 前回レビューの P3「never paced に余裕がない」は,コメントと ADR の表現を「最大約 6 s のペーシング」に直して解消した

</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: furedea <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@furedea
furedea merged commit 49cd6f9 into main Nov 19, 2026
29 checks passed
@furedea
furedea deleted the fix/stop-findings-once branch November 19, 2026 05:02
furedea pushed a commit that referenced this pull request Nov 19, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.3.0](v0.2.0...v0.3.0)
(2026-11-19)


### Features

* **lint:** fit the bash and yaml model rule cutoffs
([#243](#243))
([d5eab6b](d5eab6b))
* **lint:** fit the Go model rules on eval fixtures
([#244](#244))
([cf87c36](cf87c36))
* **lint:** fit the Rust model rules to eval fixtures
([#241](#241))
([3275ce2](3275ce2))
* **lint:** fit the TypeScript model rules on eval fixtures
([#242](#242))
([bb41bb7](bb41bb7))
* **lint:** make bash_local_underscore_prefix an error
([#251](#251))
([cd8c5b8](cd8c5b8))


### Bug Fixes

* **hooks:** let cleanup_worktrees remove worktrees left with only
regenerable outputs
([#235](#235))
([a25ce5b](a25ce5b))
* **hooks:** raise the model rules subject cap and keep cached findings
under it ([#246](#246))
([a451e93](a451e93))
* **hooks:** show each Stop model-rule finding once per session
([#252](#252))
([49cd6f9](49cd6f9))
* **hooks:** skip commits already on the default branch in model rules
([#247](#247))
([3df49a2](3df49a2))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: furedea-release[bot] <353651101+furedea-release[bot]@users.noreply.github.com>
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(hooks): show each Stop model-rule finding once per session

1 participant