Skip to content

fix(telemetry): block 記録を実 quality 違反に限定し infra エラー混入を除外 (順位309) - #329

Merged
aloekun merged 2 commits into
masterfrom
fix-telemetry-infra-error-exclusion
Jul 29, 2026
Merged

fix(telemetry): block 記録を実 quality 違反に限定し infra エラー混入を除外 (順位309)#329
aloekun merged 2 commits into
masterfrom
fix-telemetry-infra-error-exclusion

Conversation

@aloekun

@aloekun aloekun commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • hooks-stop-quality: BlockCause { QualityViolation, InfraError } を導入し、telemetry の block firing 記録を実 quality 違反 (品質ステップ失敗) 経路に限定
  • infra エラー (stdin 読込 / JSON parse 失敗) の fail-closed block は block decision を emit するが telemetry には記録しない (fail-open 挙動は不変)
  • closure 注入した emit_block_with を芯に、記録有無を副作用で観測する回帰テストを 2 件追加
  • hooks-stop-tool-call-leak / hooks-pre-tool-validate は既に実 violation 経路限定のためコード変更なし
  • ADR-055 § 計装スコープを amendment、順位309 の todo entry を消化

Context

  • Why: WP-12 ROI 棚卸し (発火数で hook の維持/削除を判断) では、stop-quality が infra エラーの fail-closed block も「発火」として記録していたため、発火数が「実際に品質違反を捕捉した回数」と乖離し ROI 信号が歪んでいた
  • Trigger: CodeRabbit Major 指摘 (順位309、.claude/feedback-reports/275.md T1-1)。docs/monthly-harness-roi-review-plan.md Phase 0 として先行実施
  • Scope decision: todo は「3 hook 横断で分割 PR 推奨」としていたが、コード精査の結果 infra エラーで実際に記録していたのは stop-quality のみ (leak は run_check の実 leak 検出時のみ、preset は validate_command hit 時のみ record) と判明したため、単一変更にまとめた

Validation

  • cargo test --workspace: 全 pass (stop-quality 42 件、新規 2 件含む)
  • cargo clippy --workspace --all-targets -- -D warnings: 警告ゼロ
  • pnpm lint:md (117 files): 0 error
  • pnpm push pre-push review: verdict=APPROVE (security-review / simplicity-review 両者、2026-07-29、1m45s)

References

  • ADR-055 (発火テレメトリ収集層) § 計装スコープ amendment
  • ADR-053 / ADR-061 (leak 検知 — 第一ユースケース)
  • 順位309 (.claude/feedback-reports/275.md T1-1、CodeRabbit Major)
  • docs/monthly-harness-roi-review-plan.md Phase 0

Summary by CodeRabbit

  • 仕様変更
    • Stop品質ゲートのブロック記録を、実際の品質違反に限定しました。
    • 入力読み込みや解析などのインフラエラーによるブロックは、ゲート通知を維持しつつテレメトリ記録の対象外としました。
  • ドキュメント
    • テレメトリ仕様と関連タスク一覧を更新し、変更内容を明確化しました。
  • テスト
    • 品質違反のみ記録され、インフラエラーでは記録されないことを検証するテストを追加しました。

hooks-stop-quality の emit_block が stdin/parse 失敗の fail-closed block でも
telemetry firing を記録していたため、WP-12 ROI 棚卸し (発火数で hook 維持を判断) の
信号が infra エラーで歪んでいた。BlockCause enum で経路を区別し、実 quality 違反
(block_on_failures) 経路のみ記録するよう限定。infra エラー経路は block decision を
emit するが telemetry には記録しない (fail-open 挙動は不変)。

leak/pre-tool-validate は既に実 violation 経路限定 (run_check の実 leak 検出時のみ /
validate_command hit 時のみ) のためコード確認のみで変更なし。ADR-055 § 計装スコープを
amendment。todo16.md 順位309 entry と todo-summary2.md 行を消化。
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: db09cf76-d1fc-4b71-8e9f-8f174328b257

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

stop-quality telemetry

Layer / File(s) Summary
原因別 telemetry 発火契約
src/hooks-stop-quality/src/main.rs, docs/adr/adr-055-firing-telemetry-collection.md
BlockCause を導入し、QualityViolation の block のみ telemetry recorder を呼び出す仕様と実装に更新。
呼び出し経路と回帰テスト
src/hooks-stop-quality/src/main.rs, docs/adr/adr-055-firing-telemetry-collection.md, docs/todo-summary2.md, docs/todo16.md
stdin/JSON エラーを InfraError、品質ステップ失敗を QualityViolation として処理し、両経路の telemetry 記録条件をテストで検証。関連 TODO を削除。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Input as stdin/HookInput
  participant Gate as stop-quality
  participant Telemetry as record_block_firing

  Input->>Gate: 入力を読み込み・解析
  alt 品質ステップ失敗
    Gate->>Telemetry: QualityViolation を記録
    Gate-->>Input: block decision を出力
  else stdin/JSON エラー
    Gate-->>Input: InfraError の block decision を出力
  end
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 実品質違反に限定してinfraエラー混入を除外する変更を正確に要約しており、主旨と一致しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 fix-telemetry-infra-error-exclusion

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 は無し。mergeStateStatus は UNSTABLE(mergeable 自体は MERGEABLE
  • レビュー状況: CodeRabbit — レビュー未着(進行中コメントのみ、 定型の "processing new changes... please wait" 通知)。人間レビュー・インラインコメントともに 0 件
  • Verdict: pending(CodeRabbit レビュー未完了のため暫定。指摘 0 件は「クリーン」ではなく「未着」による。次回発火時に再評価が必要)

Applicable Findings (Critical / High / Major)

(該当なし — レビュー未着のため指摘自体が存在しない)

Applicable Findings (Medium 以下)

(該当なし)

Filtered (not applicable)

(該当なし)

差分概要 (レビュー未着のための軽量サマリー)

todo309 (block 記録を実 quality 違反に限定) の実装 PR。4 ファイル変更、+105/-41。

File 変更内容
src/hooks-stop-quality/src/main.rs (+68/-14) emit_blockBlockCause { QualityViolation, InfraError } を導入し、records_firing() が真の場合のみ telemetry 記録。infra エラー経路 (read_stdin_or_block / parse_hook_input_or_block) は InfraError で記録スキップ、実 quality 違反経路 (block_on_failures) は QualityViolation で記録。テスト可能な芯 emit_block_with を追加し、記録有無を副作用で観測する回帰テスト2件を新設
docs/adr/adr-055-firing-telemetry-collection.md (+37/-3) Amendment (2026-07-29) を追記し、「emit 総数」定義を撤回、実 quality 違反限定へ方針変更した経緯・3 hook の状態・設計・帰結を記録
docs/todo16.md (-23) / docs/todo-summary2.md (-1) 順位309 のエントリを完了として削除

次のアクション

  • CodeRabbit のレビュー完了を待って再度 monitor 発火(このバックストップは待機・ポーリングしない方針のため、次の issue_comment イベント時に自然に再評価される)
  • 実装内容自体は ADR-055 の意図的定義(「emit 総数」)を CodeRabbit Major 指摘を受けて撤回する変更であり、amendment 形式で整合的に記録されている点は良好

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

Actionable comments posted: 2

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

Inline comments:
In `@docs/adr/adr-055-firing-telemetry-collection.md`:
- Around line 254-267:
ADR-055の表と設計説明を、実装どおり`emit_block`経由で`BlockCause::records_firing()`を判定し、`QualityViolation`の場合のみ`emit_block_with`でtelemetryを記録する内容へ更新してください。`record_block_firing`を`block_on_failures`へ移動したという記述を削除し、`InfraError`では記録しない契約を明記してください。

In `@src/hooks-stop-quality/src/main.rs`:
- Line 421: run_quality_steps の失敗分類を更新し、品質失敗が存在する場合のみ emit_block に
BlockCause::QualityViolation を渡してください。worker thread の panic だけで品質失敗がない場合は
BlockCause::InfraError として記録し、既存の failures 処理で品質失敗と内部障害を分離してください。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 582b5bcb-6ad2-496a-be66-dfd6d57b2f77

📥 Commits

Reviewing files that changed from the base of the PR and between eecb6f0 and fe493d5.

📒 Files selected for processing (4)
  • docs/adr/adr-055-firing-telemetry-collection.md
  • docs/todo-summary2.md
  • docs/todo16.md
  • src/hooks-stop-quality/src/main.rs
💤 Files with no reviewable changes (2)
  • docs/todo-summary2.md
  • docs/todo16.md

Comment on lines +254 to +267
| hook | 修正前 | 修正後 |
|---|---|---|
| hooks-stop-quality | stdin/parse 失敗の fail-closed block でも記録 | `record_block_firing` を `emit_block` から実 quality 違反経路 (`block_on_failures`) へ移動。infra エラー経路 (`read_stdin_or_block` / `parse_hook_input_or_block`) は block decision を emit するが telemetry には記録しない |
| hooks-stop-tool-call-leak | (変更なし) | `emit_block` は `run_check` の実 leak 検出時のみ呼ばれ、transcript 読取失敗・連続数 0・上限到達は fail-open で return するため既に実 leak 限定。ADR-061 の回収層 (`prompt-recovery`) は `should_recover` 成立時のみ warn 記録 |
| hooks-pre-tool-validate | (変更なし) | `record_preset_block` は `validate_command` が hit を返す (= preset にマッチした実 violation) 経路のみ。stdin/parse 失敗は `ExitCode::FAILURE` で return し記録しない。既に preset match 限定 |

### 設計: 経路を型で区別しテストで固定

stop-quality に `BlockCause { QualityViolation, InfraError }` を導入し、`emit_block(reason, cause)`
が `cause.records_firing()` (QualityViolation のみ真) のときだけ telemetry に記録する。
telemetry 記録を closure 注入した `emit_block_with` をテストの芯とし、「QualityViolation は
recorder を発火 / InfraError は発火しない」を副作用で観測して回帰ガードにする。leak / preset
は record 呼び出しが既に violation 経路にしか存在しないため、コード構造でこの不変条件が保たれる
(追加のテストは設けない)。

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

ADR-055 の実装説明を最終コードに合わせてください。

表は record_block_firingblock_on_failures へ移動したと記載していますが、実装は emit_block_with 内で BlockCause::records_firing() を判定し、emit_block 経由で記録します。後段の設計記述とも不一致なので、「cause に応じて emit_block が記録する」と修正してください。

As per path instructions: ADR の適用内容は実装契約と一致させる必要があります。

🤖 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 `@docs/adr/adr-055-firing-telemetry-collection.md` around lines 254 - 267,
ADR-055の表と設計説明を、実装どおり`emit_block`経由で`BlockCause::records_firing()`を判定し、`QualityViolation`の場合のみ`emit_block_with`でtelemetryを記録する内容へ更新してください。`record_block_firing`を`block_on_failures`へ移動したという記述を削除し、`InfraError`では記録しない契約を明記してください。

Source: Path instructions

Comment thread src/hooks-stop-quality/src/main.rs Outdated
failures.join("\n\n")
);
emit_block(&reason);
emit_block(&reason, BlockCause::QualityViolation);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

worker thread の panic を QualityViolation として記録しないでください。

run_quality_steps は worker thread の panic も failures に追加するため、ここで常に QualityViolation を渡すと、品質違反がない内部障害まで telemetry に記録されます。品質失敗とインフラ失敗を分離し、品質失敗がある場合だけ QualityViolation、panic のみなら InfraError としてください。

🤖 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` at line 421, run_quality_steps
の失敗分類を更新し、品質失敗が存在する場合のみ emit_block に BlockCause::QualityViolation
を渡してください。worker thread の panic だけで品質失敗がない場合は BlockCause::InfraError として記録し、既存の
failures 処理で品質失敗と内部障害を分離してください。

@github-actions

Copy link
Copy Markdown
Contributor

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

  • トリガー: pull_request_review (submitted) / 実行 run
  • CI: analyz e (本 workflow自身) が pendingCodeRabbit check は pass(Review completed)。他の CI check 登録なし。mergeStateStatus は UNSTABLE(mergeable 自体は MERGEABLE
  • レビュー状況: CodeRabbit — COMMENTED レビューを新規提出(2026-07-29T06:06:24Z)、actionable comments 2 件(Major 1 / Minor 1)。人間レビューは 0 件、reviewDecision 未確定
  • Verdict: needs_fix(Major の applicable finding が1件存在するため)

Applicable Findings (Critical / High / Major)

# File (Line) Reviewer Issue Recommended Action
1 src/hooks-stop-quality/src/main.rs (421) CodeRabbit run_quality_steps は worker thread の panic (fail-closed infra 障害) も failures に混入させ、block_on_failures はこれを含む failures が非空なら常に emit_block(..., BlockCause::QualityViolation) を呼ぶ。panic のみで品質ステップ自体は成功している場合でも QualityViolation として telemetry に記録されてしまい、本 PR 自身の目的(ADR-055 amendment: block 記録を実 quality 違反に限定し infra エラー混入を除外)と矛盾する run_quality_steps の戻り値で品質失敗と panic (fail-closed) を型的に区別し、block_on_failures 側で品質失敗が1件でもあれば QualityViolation、panic のみなら InfraError を渡すよう分離する

Applicable Findings (Medium 以下)

(該当なし)

Filtered (not applicable)

# File (Line) Issue Filter Reason
1 docs/adr/adr-055-firing-telemetry-collection.md (254-267) ADR-055 の表・設計説明が実装(emit_block 内で BlockCause::records_firing() を判定し emit_block_with で記録)と齟齬しており、「record_block_firingblock_on_failures へ移動した」という記述の訂正を求める Scope mismatch: docs/adr/ は read-only zone(自動修正対象外)。指摘内容自体は妥当だが本監視の対象外とし、ADR 記述の要否は人間/次セッションの判断に委ねる

次のアクション

  • main.rs:421 の Major 指摘(worker thread panic を QualityViolation として誤記録する件)を修正する。これは本 PR が導入した BlockCause 型分離の抜け穴であり、ADR-055 amendment が主張する「infra エラー混入の除外」を完全には達成していない
  • 修正後、CodeRabbit の再レビューと CI (analyze) の完了を待って再評価する
  • (任意)ADR-055 の該当箇所の文言不整合は filter 対象だが、実装修正と合わせて文言も訂正すると記録の一貫性が保てる

Resolved findings:
- [Minor] docs/adr/adr-055-firing-telemetry-collection.md:267 ADR-055 の実装説明を最終コードに合わせてください。
- [Major] src/hooks-stop-quality/src/main.rs:421 worker thread の panic を `QualityViolation` として記録しないでください。
@aloekun
aloekun merged commit d81f431 into master Jul 29, 2026
1 check passed
@aloekun
aloekun deleted the fix-telemetry-infra-error-exclusion branch July 29, 2026 07:47
aloekun added a commit that referenced this pull request Jul 30, 2026
* docs: 月次レビュー dogfood 追加アクション (A-D) 実装プラン + フィードバック採用 todo 登録

月次 ROI レビュー (ADR-062) の初回 dogfood (/monthly-review, 2026-07-30) で発見した構造的問題への
追加アクション A-D を docs/monthly-harness-roi-review-plan.md (前身は PR #333 で削除、同パスの後継
doc) として起こす:

- A [Critical]: 発火 0 = 削除候補シグナルの不動作 (機構レジストリ欠如 + zero_firing_list デッドロジック)
- B [High]: degraded 保守化 (PR #333) の文書波及漏れ 5 箇所の同期
- C [Medium]: rollup 確定時 snapshot が月中状態でなく確定時点で上書きされる問題
- D [Medium]: 未確定当月が promote streak に算入される問題

file:line と grep 用文言つきで自己完結記述。あわせて #329-#333 series の post-merge feedback
採用分 (A1-A4 + D1) を todo14.md + todo-summary2.md 順位 352-356 に登録。

docs-only。pnpm lint:md / lint:docs 全通。

* fix(review): apply CodeRabbit fixes for #334

Resolved findings:
- [Major] docs/monthly-harness-roi-review-plan.md:10 「本ドキュメントだけで実装可能」という宣言と、未確定の実装指示が矛盾しています。
- [Minor] docs/monthly-harness-roi-review-plan.md:77 「恒久的に degraded」は条件付きの現状と一致しません。
- [Minor] docs/todo14.md:438 352番エントリの決定事項の件数を修正してください。
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