Skip to content

fix(hooks): take the model-rule cached count from the dry-run plan - #167

Merged
furedea merged 5 commits into
mainfrom
fix/74-model-rules-cached-count
Nov 11, 2026
Merged

furedea merged 5 commits into
mainfrom
fix/74-model-rules-cached-count

Conversation

@furedea-agent

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

Copy link
Copy Markdown
Contributor

概要

Stop の表示が,すべての対象が判定キャッシュから来た場合でも「0 cached」になる問題を直します.

  • 原因:jev-lint review --json の報告(jev-lint 0.7.0)には cachedCount がありません._judgement はそのキーを読んでいたため,常に 0 でした.
  • 修正:キャッシュ件数は --dry-run --json の cached から取ります.件数の出どころは dry run の 1 か所だけです.
  • 取るタイミング:判定のキャッシュロックの中,モデルに問い合わせる直前に,判定するファイルだけで dry run をもう一度行います(レビュー指摘への対応).理由は 2 つあります.
    • 全体の計画の cached は,上限で残したファイルの件数とは限りません.
    • 計画の後に別セッションがキャッシュを更新すると,判定が使う状態と件数がずれます.
  • 計画(上限の判定)の dry run は 1 回のままで,Plan は件数を持ちません.
  • ロック内の処理は _judge_locked に分けました.ネストの上限に当たったため,責務で分けています.
  • テストの偽 jev-lint が,実物にはない cachedCount を出していたので外しました.
  • Stop hook の指摘(command-query-naming)に合わせ,偽ツールの書き込み用メソッドを write_report と write_plan_of_files に改名しました.

Refs #74(計画コメント:Issue #74 の「計画:モデル判定の改善」)

検証

  • 先に失敗するテストを追加(dry run が cached=4 のとき表示が「4 cached」).修正前は「0 cached」で失敗しました.
  • 上限適用時のテストを追加(全体の cached が 5,残すファイルでは 3 のとき「3 cached」).
  • dry run が 2 回になったので,test_model_rules_process.py の 2 つのテストを「計画用と判定直前用の 2 回」に合わせました.
  • uv run --offline pytest tests/hooks -q:3698 passed, 1 skipped

計画からの変更

なし

レビュー指摘の扱い

指摘 扱い
上限適用時に min(...) で件数を推測している(claude P3,codex P2) 推測をやめ,実際に判定するファイルの dry run から取る
キャッシュ更新との競合で件数がずれる(codex P2) 取得をキャッシュロックの中,判定の直前に移した
2 回目の dry run の失敗で表示のためだけにレビューが止まる(claude P3→P2) 反論:失敗するならレビュー本体も失敗する.0 に戻すと今回直した誤表示が復活する

jev-lint review --json has no cachedCount key, so the Stop footer always showed 0 cached.

The dry-run plan carries the count; Plan now holds it and Judgement reads it from there.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T15:58:36.568072Z 432907f 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_run.py Resolved
@github-actions

Copy link
Copy Markdown

Review summary: no blocking findings.

The fix is correct. _judgement now reads plan.cached, which _capped_plan fills from the dry run's cached. That replaces the cachedCount key, which the real report never contains. On the uncapped path the count is exact. The new tests cover it and show the bug is fixed.

  • P3: no test covers the min(...) clamp on the capped path, and that count is only an upper bound (inline comment).

@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: 9d4f1d70ed

ℹ️ 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_run.py Resolved
The whole-diff dry run gives one cached total, not one per file.

Plan the kept files again so the footer shows their exact cached count.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

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

Copy link
Copy Markdown

Review summary

No blocking findings (0 × P0, 0 × P1).

The fix looks correct. cached now comes from the dry-run plan instead of cachedCount, which jev-lint does not output.

  • Without the cap: the count is the whole-diff cached.
  • With the cap: a second dry run over only the kept files gives their exact count, so nothing is guessed.
  • Empty plans: a plan with no kept paths still returns before the extra run.
  • Tests: they cover all three cases (some cached, cap applied, none cached). The fake no longer outputs the made-up cachedCount key.

One optional point (P3, inline): when the cap applies, a failure in the second dry run now cancels the whole review, even though it only feeds a number in the message. Consider falling back to cached=0 in that case.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 149b019bff

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

Rename report and plan_of_files to write_report and write_plan_of_files.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

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

Copy link
Copy Markdown

Review summary (read-only)

The fix itself is correct. The cached count now comes from the dry-run plan's cached instead of the cachedCount key, which jev-lint does not emit. When the cap applies, a second dry run over the kept files gives the right count. The fake jev-lint no longer emits the made-up key, and the new tests cover three cases: no cap, cap applied, and zero cached.

Findings:

  • P2 agents/hooks/lib/model_rules_run.py:85: if the second dry run fails or times out, the whole Stop review returns Prevented. That second run only feeds the cached-count display. It also takes up to another 20s of the shared deadline. No test covers that failure path.

Blocking findings (P0/P1): 0

@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: 5b0fd52806

ℹ️ 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_run.py Resolved
A count taken at plan time can differ from the judgement when another session writes the cache.

Plan the files to judge again under the lock; plan() is one dry run and Plan has no cached field.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

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

Copy link
Copy Markdown

Review summary (read-only)

No P0/P1/P2 findings.

  • The fix reads the cached count from the dry run's cached key instead of the missing cachedCount. That matches what _capped_plan already reads.
  • The counting dry run now happens under the verdict-cache lock and is limited to the paths actually judged (plan.paths or self.paths). This fixes both the cap mismatch and the cross-session race.
  • The token is still passed only to the op child. Both dry runs use the allowlisted environment, and the tests now check every dry run.
  • New tests cover the uncapped count, the capped count (from the files kept), and the zero-cached case.

One P3 inline: the new failure path where the second dry run makes the review stop has no test.

Blocking findings: 0

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 52529b43ab

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

A counting dry run that prints a non-integer cached stops the review before op is run.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@furedea

furedea commented Nov 11, 2026

Copy link
Copy Markdown
Owner

@codex review

@github-actions

Copy link
Copy Markdown

レビュー結果(自動)

指摘なし(P0: 0,P1: 0,P2: 0,P3: 0).

確認した点:

  • cached を判定ロック内の dry run(実際に判定するファイルのみ)から取るため,上限適用時の件数ずれと他セッションのキャッシュ更新との競合が解消されている.
  • 上限なし(plan.paths が空)の場合は self.paths で dry run するので,計画時と同じ対象を数える.
  • 2 回目の dry run はトークンなしの環境で起動され,その点もテストで全 dry run について確認されている.
  • cached が整数でない場合はモデル呼び出し前に止まり,テストもある.
  • 偽 jev-lint から実物にない cachedCount を外し,「4 cached」「3 cached(上限適用時)」「0 cached」の回帰テストが追加されている.

補足(指摘未満):dry run がロック内に入ったため,ロック保持時間と判定に使える残り時間が最大 PLAN_TIMEOUT_SECONDS 分減る.既存の deadline で上限が掛かっているので問題とはしていない.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 432907f5b3

ℹ️ 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
furedea merged commit c87fdfd into main Nov 11, 2026
24 checks passed
@furedea
furedea deleted the fix/74-model-rules-cached-count branch November 11, 2026 16:10
furedea pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.1.2](v0.1.1...v0.1.2)
(2026-11-12)


### Features

* **hooks:** add Go and Rust model rules with eval fixtures
([#158](#158))
([9731488](9731488))
* **hooks:** show model-rule timing and skip rule fixtures
([#157](#157))
([d0c32ae](d0c32ae))
* **hooks:** show the model rules as one result line with cost
([#170](#170))
([41b9033](41b9033))


### Bug Fixes

* **hooks:** allow a jq filter after read-only GraphQL queries
([#180](#180))
([cfb80d8](cfb80d8))
* **hooks:** keep model-rule eval fixtures out of Stop test verification
([#160](#160))
([a4f1c6c](a4f1c6c))
* **hooks:** read paths literally in every jev-lint child process
([#173](#173))
([0d2c683](0d2c683))
* **hooks:** remove model-rule false positives with principles and eval
fixtures ([#163](#163))
([b07fc4e](b07fc4e))
* **hooks:** report one count per runner in the Stop test lines
([#177](#177))
([0f36b82](0f36b82))
* **hooks:** take the model-rule cached count from the dry-run plan
([#167](#167))
([c87fdfd](c87fdfd))

---
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.

1 participant