feat(hooks): polling-anti-pattern preset で polling loop をブロック (Phase 1)#93
Merged
Conversation
- hooks-pre-tool-validate に preset_polling_anti_pattern を追加 - 検出パターン: `until COND; do BODY; sl<>p N; done` 形式 および `while !` 版 (regex は \bdo\b 制約で loop syntax のみマッチ) echo 文字列や --until=DATE フラグの誤検出は \bdo\b 制約で排除 - .claude/hooks-config.toml で本プロジェクト用に opt-in (デフォルトフォールバックには非追加、後方互換維持) - 14 件のテスト追加 (block 6 / allow 7 / 後方互換 1) 後追加 negative test 3 件: echo string / git --until flag / for loop は誤検出しない 動機: PR #86 で実証された rate-limit 40% 浪費 (1 セッション) の再発防止。 背景タスクは task-notification 経由で自走するため polling 不要。 ブロック時は Monitor tool / run_in_background / 単発取得への誘導メッセージを表示する。 Note: 当初設計案にあった "run_in_background -> polling" の cross-tool-call 検出は YAGNI 適用で見送り (transcript 読み取りが必要、複雑度に対する効果が 低い)。in-command 検出で PR #86 の canonical case を捕捉できる。 todo.md 推奨実行順序 Phase 1 (順位 3) 完了。
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughポーリング・アンチパターン( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
4 tasks
aloekun
added a commit
that referenced
this pull request
Apr 29, 2026
PR #93 post-merge-feedback finding #1 (Cross-File Reference Lifecycle ルール) の retroactive 適用。永続成果物 (hook block messages / config / コード) から ephemeral な docs/todo*.md セクション名への参照を排除する。 修正箇所 (3 件): 1. src/hooks-pre-tool-validate/src/main.rs (preset_polling_anti_pattern block message) `docs/todo.md の「Polling anti-pattern 検出ルール」を参照` を削除。 当該 todo.md エントリは PR #93 自身で削除済みの dead pointer。 ADR-018 への参照のみ残す (こちらは permanent reference)。 2. .claude/custom-lint-rules.toml (no-mutable-anchor 由来コメント) `[docs/todo.md](todo.md#推奨実行順序サマリー)` 形式の引用を、 日本語 heading 自体を anchor 形式で書かない記述に書き換え。 日付付き heading のスラッグは時間で変化するため、引用例自体が stale になる構造的問題があった (まさに本ルールが検出する pattern)。 3. .markdownlint-cli2.jsonc (config 由来コメント) `per docs/todo.md "Markdown linter hook 統合" task` を `introduced in PR #88 (markdownlint-cli2 PostToolUse hook integration)` に置換。PR 番号は permanent reference。 背景: ~/.claude/rules/common/coding-style.md に追加した "Cross-File Reference Lifecycle" ルール (永続→ephemeral 参照禁止) の retroactive sweep。grep で非 docs ファイルを洗い出し全件対応。 検証: - cargo test -p hooks-pre-tool-validate: 122/122 pass - grep "docs/todo" --glob '!docs/**': matches 0 (clean) - ./.claude/hooks-pre-tool-validate.exe を rebuild
6 tasks
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.
Summary
PreToolUse hook に
polling-anti-patternpreset を追加し、until COND; do BODY; sleep N; done/while ! COND; do ... sleep N形式の polling loop をブロックします。Claude Code が反射的に書きがちな polling pattern を決定論的に検出することで、PR #86 で実証された rate-limit 大量浪費 (1 セッションで 40%) の再発を防止します。Why
PR #86 のセッション中、
run_in_background: trueで起動した背景タスクの完了確認用にuntil grep -q done; do sleep N; done形式の polling が反射的に書かれ、Claude Code Max (5x) のレートリミットを 1 時間で 40% 消費する事故が発生しました。背景タスクは task-notification 経由で自動的に完了通知される設計のため、polling は本来不要です。ガイドライン (順位 26) と組み合わせ、決定論的検出 + ドキュメント補完の二層防御を構築する第一段階。Changes
src/hooks-pre-tool-validate/src/main.rspreset_polling_anti_pattern()を追加 (既存 preset 関数群と同一パターン)(?is)\buntil\b.*?\bdo\b.*?\bsleep\s+\d/(?is)\bwhile\s+!\s.*?\bdo\b.*?\bsleep\s+\d\bdo\b制約により bash loop syntax のみマッチ (echo 文字列・--until=DATEフラグ等の false positive を排除)run_in_background+ 通知 / 単発取得) を提示.claude/hooks-config.toml"polling-anti-pattern"をblocked_patternsに追加[ ]/while !/ state file polling / chainwhile true/ echo string /--until=flagdocs/todo.md順位 3 とdocs/todo2.md該当エントリを削除し、参照を整合化Design notes
Test plan
Phase
todo.md 推奨実行順序 Phase 1 (順位 3, Tier 1) 完了。次は Bundle T (順位 9 + 14) を計画。
Summary by CodeRabbit
リリースノート
新機能
ドキュメント