Skip to content

feat(lib-telemetry): 発火テレメトリ収集層 — 全 hook の block/warn を JSONL 記録 (WP-12 step1) - #275

Merged
aloekun merged 1 commit into
masterfrom
feat/firing-telemetry
Jul 16, 2026
Merged

feat(lib-telemetry): 発火テレメトリ収集層 — 全 hook の block/warn を JSONL 記録 (WP-12 step1)#275
aloekun merged 1 commit into
masterfrom
feat/firing-telemetry

Conversation

@aloekun

@aloekun aloekun commented Jul 16, 2026

Copy link
Copy Markdown
Owner

概要

WP-12「発火テレメトリ + ハーネス ROI 棚卸し」の step 1(収集層) を実装します(ADR-055)。ハーネス複雑度(custom rule 12 本・pre-tool preset 群・hook)の維持判断を発火実績で機械化する ROI 棚卸しの土台です。

3 ステップ構成のうち、telemetry はマージ後に初めてデータが溜まるため、収集層のみ先行 PR とし、集計 pre-step(step 2)と卒業判定機械化(step 3)は 28 日 warm-up 後に着手します(todo 順位 307/308 へ移管済み)。

変更内容

新規 crate lib-telemetry

各 hook の block/warn 発火を .claude/telemetry/firings-<YYYY-MM-DD>-<pid>.jsonl に append する共通層。

  • record()(prod 入口)+ 副作用注入版 record_to / record_gated_to / telemetry_enabledlib-jj-helpers::pipeline_lock_at パターンに準拠、テスト確定性のため)
  • Windows 並行競合を per-process(pid) + 日次 partition + プロセス内 Mutex + 単一 write_all の 3 重で排除
  • opt-in default OFF(config 内部集約 + OnceLock キャッシュ)+ kill-switch CLAUDE_TELEMETRY_DISABLE + fail-open
  • 記録はメタデータのみ(hook / kind / id / decision / timestamp、任意 session_id)。ファイルパス・編集内容・コマンド本文は非記録(custom rule ② no-personal-paths の思想)

6 hook の計装(裁量発火に限定)

hook kind id decision
hooks-pre-tool-validate preset preset 名 block
hooks-post-tool-linter rule rule id error→block / warning→warn
hooks-post-tool-jj-op-verify hook jj-op-verify warn
hooks-stop-quality hook hooks-stop-quality block
hooks-stop-tool-call-leak hook hooks-stop-tool-call-leak block
hooks-post-tool-comment-lint-rust hook file-length block

除外: 常時 ON の構造チェック(非 doc コメント / 関数長 / file_size / utf8)と nudge-only hook。削除候補にならず ROI 信号を希釈するノイズのため。

設計方針

  • fail-open(ADR-043 の fail-closed はゲート関数限定、telemetry は observation 層)
  • ADR-039 3 点セット(opt-in / kill-switch / bounded lifetime)
  • UTC ヘルパーは lib-pending-file から最小複製(ADR-044 の責務結合回避、抽出トリガ到達を ADR に記録)

テスト

  • lib-telemetry ユニットテスト(opt-in gating / kill-switch / JSON エスケープ / 50 スレッド並行 / partition 命名)
  • 既存 hook テスト無退行、workspace 全体の build/test/clippy(-D warnings)/ignored 直列すべて緑
  • 手動 dogfood: preset block → 発火記録、kill-switch env で記録抑止を確認

pre-push review の自動修正

simplicity review が is_truthy の 3 重複(lib-telemetry / comment-lint-rust / stop-tool-call-leak、後 2 者は本 PR で lib-telemetry 依存を追加済み)を検出し、fix ループが lib_telemetry::is_truthy を pub 化して共通化しました(ローカルコピー + テスト削除)。security review は APPROVE。

follow-up(本 PR では対応せず)

  • step 2 / step 3: 28 日 warm-up 後に集計 pre-step + 卒業判定機械化(todo 順位 307/308)
  • 非ブロッキング: custom-regex な blocked_patterns エントリは生の regex 文字列が telemetry の id に載る(現行 config は named preset のみで非発火)。派生プロジェクト向けに fallback branch へ合成 id を使う対策を検討(PR フィードバック時に todo 化予定)

Summary by CodeRabbit

  • 新機能

    • hook の block/warn 発火を、メタデータ בלבדの JSONL テレメトリとして記録できるようになりました。
    • 設定によるオプトインと無効化スイッチに対応し、記録失敗時も通常の判定を妨げません。
    • 発火元の hook、ルール、プリセットを識別できるようになりました。
  • ドキュメント

    • テレメトリの運用方針、プライバシー要件、28日間のウォームアップ計画を追加しました。

…12 step1)

ADR-055。ハーネス複雑度 (rule/preset/hook) の維持判断を発火実績で機械化する ROI 棚卸しの収集層。lib-telemetry を新設し 6 hook を計装 (pre-tool-validate preset / post-tool-linter custom rule / jj-op-verify warn / stop-quality / stop-tool-call-leak / comment-lint-rust file-length gate)。記録は .claude/telemetry/firings-<date>-<pid>.jsonl にメタデータのみ (パス・内容は非記録)。opt-in default OFF + kill-switch + fail-open (ADR-039/043)。

集計 pre-step (step2) / 卒業判定機械化 (step3) は 28 日 warm-up 後に着手 (順位 307/308)。
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

共有の lib-telemetry を追加し、6つのhookがblock/warn発火をメタデータ בלבדのJSONLとして記録するよう変更した。設定、ADR、workspace統合、28日後の集計・運用計画も追加した。

Changes

発火テレメトリ収集

Layer / File(s) Summary
共有テレメトリライブラリ
src/lib-telemetry/*, Cargo.toml
Firing、opt-in、kill-switch、fail-open、日次・PID別JSONL追記、セッションID補完、並行書き込み制御、テストを追加。
プリセット発火元の保持
src/hooks-pre-tool-validate/*
パターンにpreset名を付与し、Bash・PowerShell・secret scanのblock発火を発火元付きで記録。
各hookへの発火記録配線
src/hooks-post-tool-comment-lint-rust/*, src/hooks-post-tool-jj-op-verify/*, src/hooks-post-tool-linter/*, src/hooks-stop-quality/*, src/hooks-stop-tool-call-leak/*
file-length、jj-op-verify、custom rule、quality、tool-call-leakの判定経路にlib_telemetry::recordを追加。
設定・ADR・運用計画
.claude/*, .gitignore, CLAUDE.md, docs/adr/*, docs/harness-improvement-plan.md, docs/todo-summary.md, docs/todo13.md
テレメトリ設定、ADR-055、保存先除外、WP-12のstep 2/3計画を追加。

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Hook
  participant lib_telemetry
  participant Config as hooks-config.toml
  participant Storage as JSONLファイル
  Hook->>lib_telemetry: 発火イベントをrecord
  lib_telemetry->>Config: enabledとkill-switchを確認
  lib_telemetry->>Storage: メタデータを1行追記
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 新規 lib-telemetry による block/warn の JSONL 発火テレメトリ収集という主変更を的確に要約しています。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/firing-telemetry

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Monitor 分析 (GitHub Actions バックストップ)

  • トリガー: issue_comment (created) / 実行 run
  • CI: CodeRabbit のみ登録 (pending, "Review in progress")。他の CI check は未登録
  • レビュー状況: CodeRabbit — レビュー未着 (処理中コメントのみ、指摘 0 件)。人間レビュー・他 bot レビューなし (reviews API 応答は空配列)
  • Verdict: user_decision (レビュー未着のため fix/approve いずれの判断もまだ下せない)

Applicable Findings (Critical / High / Major)

該当なし (レビュー指摘が 1 件も存在しない)

Applicable Findings (Medium 以下)

該当なし

Filtered (not applicable)

該当なし

次のアクション

  • CodeRabbit のレビュー完了を待ち、指摘が投稿されてから再度本 workflow (または次回トリガー) で分析する
  • 変更概要: 30 ファイル (+982/−84)、src/lib-telemetry 新規クレート追加 + 各 hook (pre-tool-validate, post-tool-linter, post-tool-comment-lint-rust, post-tool-jj-op-verify, stop-quality, stop-tool-call-leak) への計装組み込み、docs/adr/adr-055-firing-telemetry-collection.md 新設、.claude/hooks-config.toml[telemetry] セクション追加 (WP-12 step1、ADR-055、試験運用)
  • mergeStateStatusUNSTABLE (CodeRabbit pending 起因の可能性) — マージ判断はレビュー確定後に行う

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks-stop-quality/src/main.rs (1)

154-175: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

telemetry を品質違反に限定してください
emit_block()record_block_firing() を呼ぶと、stdin/JSON 失敗などの fail-closed 経路も同じ Block カウントに混ざります。ADR-055 の ROI 判定を歪めないよう、block_on_failures 側だけで記録するか、infra 用カウンタを分けてください。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks-stop-quality/src/main.rs` around lines 154 - 175, 品質違反以外の
fail-closed 経路まで Block telemetry に含めないよう、emit_block と record_block_firing
の連携を見直してください。record_block_firing は品質違反を処理する block_on_failures
側からのみ呼び出し、stdin/JSON 失敗などのインフラエラー経路では呼ばないようにしてください。
🧹 Nitpick comments (1)
src/lib-telemetry/src/lib.rs (1)

136-169: 🧹 Nitpick | 🔵 Trivial

per-pid×日次partitionによるファイル数増加への配慮。

各hook実行が短命プロセスであるため、firings-<date>-<pid>.jsonl は実行ごとに新規ファイルを生成しやすく、28日間のwarm-up期間中に .claude/telemetry/ 配下へ小さなファイルが多数蓄積される可能性があります。集計 (WP-12 step 2) 実行までの保持・クリーンアップ方針(例: 古いファイルの定期削除、上限件数)を検討することを推奨します。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib-telemetry/src/lib.rs` around lines 136 - 169, Add a retention and
cleanup policy to the record_to telemetry writer for stale firings-*.jsonl
files, such as removing files older than the configured warm-up period or
enforcing a file-count limit. Keep cleanup scoped to the telemetry directory and
preserve the existing append behavior and per-process daily filename
partitioning.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/hooks-stop-quality/src/main.rs`:
- Around line 154-175: 品質違反以外の fail-closed 経路まで Block telemetry
に含めないよう、emit_block と record_block_firing の連携を見直してください。record_block_firing
は品質違反を処理する block_on_failures 側からのみ呼び出し、stdin/JSON 失敗などのインフラエラー経路では呼ばないようにしてください。

---

Nitpick comments:
In `@src/lib-telemetry/src/lib.rs`:
- Around line 136-169: Add a retention and cleanup policy to the record_to
telemetry writer for stale firings-*.jsonl files, such as removing files older
than the configured warm-up period or enforcing a file-count limit. Keep cleanup
scoped to the telemetry directory and preserve the existing append behavior and
per-process daily filename partitioning.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd50ab53-fbfd-4ed3-a23a-a18f9bc3b26a

📥 Commits

Reviewing files that changed from the base of the PR and between dea9cb2 and f3b3a9b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (29)
  • .claude/hooks-config.toml
  • .gitignore
  • CLAUDE.md
  • Cargo.toml
  • docs/adr/adr-055-firing-telemetry-collection.md
  • docs/harness-improvement-plan.md
  • docs/todo-summary.md
  • docs/todo13.md
  • src/hooks-post-tool-comment-lint-rust/Cargo.toml
  • src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs
  • src/hooks-post-tool-jj-op-verify/Cargo.toml
  • src/hooks-post-tool-jj-op-verify/src/main.rs
  • src/hooks-post-tool-linter/Cargo.toml
  • src/hooks-post-tool-linter/src/custom_rules/engine.rs
  • src/hooks-pre-tool-validate/Cargo.toml
  • src/hooks-pre-tool-validate/src/blocked_patterns.rs
  • src/hooks-pre-tool-validate/src/handlers.rs
  • src/hooks-pre-tool-validate/src/presets/basic.rs
  • src/hooks-pre-tool-validate/src/presets/gh.rs
  • src/hooks-pre-tool-validate/src/presets/jj.rs
  • src/hooks-pre-tool-validate/src/presets/safety/polling_exe.rs
  • src/hooks-pre-tool-validate/src/presets/safety/powershell.rs
  • src/hooks-pre-tool-validate/src/presets/safety/secret.rs
  • src/hooks-stop-quality/Cargo.toml
  • src/hooks-stop-quality/src/main.rs
  • src/hooks-stop-tool-call-leak/Cargo.toml
  • src/hooks-stop-tool-call-leak/src/main.rs
  • src/lib-telemetry/Cargo.toml
  • src/lib-telemetry/src/lib.rs

@github-actions

Copy link
Copy Markdown
Contributor

🤖 PR Monitor 分析 (GitHub Actions バックストップ)

  • トリガー: pull_request_review (submitted) / 実行 run
  • CI: analyze (本 workflow 自身) が in_progress、CodeRabbit は pass (Review completed)。他の CI check 登録なし。mergeStateStatus は UNSTABLE (analyze 進行中起因の可能性)
  • レビュー状況: CodeRabbit — レビュー完了、指摘 2 件 (Major 1 / Trivial 1)。人間レビュー・他 bot レビューなし
  • Verdict: user_decision (Critical/High/Major の applicable 指摘なし。Trivial の applicable 指摘 1 件のみ)

Applicable Findings (Critical / High / Major)

該当なし

Applicable Findings (Medium 以下)

# File (Line) Reviewer Issue Recommended Action
1 src/lib-telemetry/src/lib.rs (136-169) CodeRabbit firings-<date>-<pid>.jsonl の保持・クリーンアップ方針が未定義。28日 warm-up 期間中に .claude/telemetry/ 配下に小ファイルが多数蓄積し得る ADR-055 は step 2/3 (集計・棚卸し、後続 PR) を明示的に別スコープとしており対応済み計画内。今回のPRで対応必須ではないが、必要なら人間判断で軽量な保持上限を先行追加

Filtered (not applicable)

# File (Line) Issue Filter Reason
1 src/hooks-stop-quality/src/main.rs (154-175) record_block_firing() が品質違反と fail-closed infra エラー (stdin/JSON 失敗) を区別せず同一 Block カウントに記録している Intentional design: ADR-055 「計装スコープ」節に明記済み — 「stop-quality は infra エラー (stdin/parse 失敗) の fail-closed 経路でも block を emit するため、『hook が block を emit した総数』として記録する」。コード側コメント (main.rs:166-167) も同旨を明記しており、CodeRabbit の指摘は既存の設計判断と矛盾する

次のアクション

  • Trivial 指摘 (telemetry JSONL 保持方針) は ADR-055 で WP-12 step 2 に計画済みのため、今回の PR では追加対応不要と判断できる。人間が先行対応するかは任意判断
  • analyze check が in_progress のため mergeStateStatus: UNSTABLE — 本 workflow 完了後に CI 状態が確定するか確認
  • 上記以外に blocking な issue はなし。マージ可否は人間の最終判断に委ねる

@aloekun
aloekun merged commit 470cd6e into master Jul 16, 2026
2 checks passed
@aloekun
aloekun deleted the feat/firing-telemetry branch July 16, 2026 04:59
aloekun added a commit that referenced this pull request Jul 16, 2026
PR #275 (feat(lib-telemetry) WP-12 step1) の post-merge feedback (ADR-030) から採用候補9件を採用し順位309-317に登録。Tier1: telemetry の block 記録を実 quality 違反に限定 (CodeRabbit Major、ADR-055 amendment 併記) / custom-regex の生 regex が telemetry id に流れる privacy 是正 (非ブロッキング follow-up 統合) / 逐語的関数複製の pre-push DRY lint rule。Tier2: telemetry retention/cleanup / is_truthy 三重複製の ADR-049 fixture 化 / bookmark 未作成 push のエラーメッセージ改善。Tier3: ADR-055 warm-up 期限の config コメント明記 / ADR-044 2nd-consumer 原則の明確化 / utility 追加前チェックリスト。様子見4件は report のみ。根拠は .claude/feedback-reports/275.md。
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