Skip to content

feat(cli-pr-monitor,hooks-session-start): config 拡張 + SessionStart catch-up + T2-2 follow-up (Bundle b PR-3, Bb-3 順位 55)#115

Merged
aloekun merged 2 commits intomasterfrom
feat/bb-3-config-and-catchup
May 6, 2026
Merged

feat(cli-pr-monitor,hooks-session-start): config 拡張 + SessionStart catch-up + T2-2 follow-up (Bundle b PR-3, Bb-3 順位 55)#115
aloekun merged 2 commits intomasterfrom
feat/bb-3-config-and-catchup

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented May 5, 2026

Summary

Bundle b の最終 PR (Bb-3 / 順位 55)。Bb-1 (PR #113) / Bb-2 (PR #114) で導入した CronCreate park モデルの後始末として、固定値の config 化 + SessionStart catch-up + T2-2 follow-up を 1 PR で集約 land する。これで Bundle b 全体が完結。

ADR-030 の責務分離パターン (Rust 状態管理 + Claude Code 側の周期確認) の 3 つ目の適用例 として、Bundle b 全体が「Rust が状態を持ち、Claude Code が CronCreate / SessionStart 経由で再開する」モデルに統一される。

変更内容

1. config 拡張 — 旧 hard-coded const → [review_recheck] セクション

  • pr-monitor-config.toml に新セクション [review_recheck] 追加 (initial_review_wait_secs / review_recheck_wait_secs / max_review_rechecks、デフォルト 300/300/3)
  • 旧 const (INITIAL_REVIEW_WAIT_SECS / REVIEW_RECHECK_WAIT_SECS / MAX_REVIEW_RECHECKS) を PollContext 経由の scalar threading で置換
  • MonitorConfig::poll_interval_secs (Bb-2 で #[allow(dead_code)] 化済) を完全削除
  • 後方互換: 既存 toml の poll_interval_secs 行は serde が silently ignore (config_ignores_legacy_poll_interval_secs テストで machine-enforce)

2. SessionStart catch-up nudge — additionalContext 経由 (advisor 推奨 option b)

  • hooks-session-start が起動時に pr-monitor-state.json を partial deserialize
  • state.action.starts_with("parked_") かつ next_wakeup_at_unix <= now のとき additionalContext[PR_MONITOR_CATCHUP] メッセージを注入
  • nudge の手動再開コマンド hint は RESUME_MONITORING_COMMAND const に切り出し (rename 時の drift 検知をテストで machine-enforce)
  • 設計判断: 別プロセス spawn (cli-pr-monitor.exe --monitor-only) ではなく Claude に nudge する設計を採用。Windows 環境での handle 継承 / stdout 可視性問題を回避し、PARK signal flow を session 内に保つ
  • false-positive 抑制: terminal action (action_required / passed_clean / continue_monitoring) では古い park 由来の next_wakeup_at_unix 残存に対して nudge を出さない (action prefix parked_ を gate に使用)

3. T2-2 follow-up — sibling parity invariant の 3 sibling 化

PR #114 post-merge-feedback Tier 2 #2 採用分。finalize_park_siblings_have_symmetric_write_state_handling テストのカバレッジに finalize_initial_review_park を追加し、Bb-2 同時追加の sibling が parity invariant test の対象外になる self-violation を解消。

invoke_finalize_initial_review_park_with_bad_path test helper を追加し、既存 invoke_finalize_parked_with_bad_path / invoke_review_park_with_bad_path と並べて 3 sibling all-pass を assert。

4. 補助テスト

  • format_review_park_signal_uses_configured_max_rechecks — config 値 (例: 7) が PARK signal 出力に到達することを machine-enforce (default 3 が hard-coded で残っていないことを assert)
  • compute_catchup_nudge の decision matrix (wakeup なし / 未来 / 過去 / terminal action 4 種 + parked 2 種) を 8 unit test でカバー

設計参照

pre-push-review 結果

all("approved") (1 iteration、6m 54s)。レビュアーから RESUME_MONITORING_COMMAND const 抽出を有効なリグレッション保護として positive 言及あり (OBS-2)。

Test Plan

  • cargo test -p cli-pr-monitor (137 件 全 pass、parity test 3 sibling 化、PARK signal config 反映 test を含む)
  • cargo test -p hooks-session-start (22 件 全 pass、catch-up nudge 8 軸テスト + RESUME_MONITORING_COMMAND assertion)
  • cargo clippy -p cli-pr-monitor -p hooks-session-start --all-targets -- -D warnings (warning ゼロ)
  • cargo fmt --all (workspace 全体)
  • pnpm build:all 成功
  • pre-push-review all("approved")
  • (post-merge) dogfood: 実際に Claude Code を一度閉じて再起動した時に pending wakeup の catch-up nudge が表示されること
  • (post-merge) 派生プロジェクト (techbook-ledger / auto-review-fix-vc) の pr-monitor-config.toml から legacy poll_interval_secs 行を削除 (silently ignore で実害なしだが clean up)

Summary by CodeRabbit

  • 新機能

    • PR監視の「再確認」間隔と最大再試行回数を設定でカスタマイズ可能にしました。
    • SessionStart時にモニタリングの追いつき通知(catch-up nudge)を追加し、parked_プレフィックス以外のケースでは抑制します。
  • ドキュメント

    • 進捗・TODOを実績ベースで更新し、設定例と挙動説明を反映しました。
    • 設定ファイルに新しい再確認設定例をコメントで追記しました。
  • Chores

    • 既存の不要設定を整理・削除しました。
  • Tests

    • 再確認設定やcatch-up挙動をカバーするテストを追加・更新しました。

…tch-up + T2-2 follow-up (Bundle b PR-3, Bb-3 順位 55) (#115)

* `[review_recheck]` config セクションを `pr-monitor-config.toml` に追加し旧 hard-coded const (INITIAL_REVIEW_WAIT_SECS / REVIEW_RECHECK_WAIT_SECS / MAX_REVIEW_RECHECKS) を `PollContext` scalar 経由で thread。

* `MonitorConfig::poll_interval_secs` (Bb-2 で未使用化) を削除し、既存 toml は legacy フィールドを silently ignore で後方互換。

* `hooks-session-start` に PR monitor catch-up nudge を追加。state.action が `parked_*` かつ `next_wakeup_at_unix <= now` のとき additionalContext に `[PR_MONITOR_CATCHUP]` メッセージを注入し、CronCreate 失効時の silent loss を解消。

* terminal action (`action_required` / `passed_clean` / `continue_monitoring`) では古い park 由来の `next_wakeup_at_unix` 残存に対して false-positive nudge を action prefix gate で抑制。

* T2-2 follow-up (PR #114 post-merge-feedback): `finalize_park_siblings_have_symmetric_write_state_handling` を 3 sibling (rate_limit / review_recheck / initial_review) 化し、Bb-2 で追加した `finalize_initial_review_park` を parity invariant test の対象に含める (self-violation 解消)。

* 設計判断: SessionStart catch-up は別プロセス spawn せず additionalContext で nudge する設計 (advisor 推奨)。Windows 環境での handle 継承 / stdout 可視性問題を回避し、PARK signal flow を session 内に保つ。


ADR-030 の責務分離パターン (Rust 状態管理 + Claude periodic check) の 3 つ目の適用例として Bundle b 全体を完成させる。


由来: docs/coderabbit-monitoring-efficiency.md Bb-3 / 順位 55 / PR #114 post-merge-feedback T2-2 採用
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc9d4b18-78ac-472f-bbb0-e68e93c8dfe1

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc0164 and 9e6bf1d.

📒 Files selected for processing (1)
  • src/cli-pr-monitor/src/config.rs

📝 Walkthrough

Walkthrough

ハードコードされたレビュー再確認タイミング定数を新しい ReviewRecheckConfig に移行し、MonitorConfig.poll_interval_secs を削除。設定を PollContext 経由で注入し、SessionStart フックで pr-monitor-state.json を部分読みして予定ウェイクアップを過ぎた parked_ アクションに対してキャッチアップ・ナッジを生成する機能を追加。関連ドキュメントとテストを更新。

Changes

設定リファクタリングとセッションスタート・キャッチアップ・ナッジ

Layer / File(s) Summary
設定データ形状
src/cli-pr-monitor/src/config.rs, pr-monitor-config.toml
ReviewRecheckConfiginitial_review_wait_secsreview_recheck_wait_secsmax_review_rechecks)を追加。MonitorConfig.poll_interval_secs とその既定値関数を削除。load_config()review_recheck.sanitize() を呼ぶよう変更。TOML は poll_interval_secs を削除し、コメント化された [review_recheck] ブロックを追加。
設定使用(実行時伝播)
src/cli-pr-monitor/src/stages/poll.rs
PollContext に新設定フィールドを追加し、run_poll_loopfull_config.review_recheck から注入。finalize_initial_review_parkschedule_next_review_recheck_parkfinalize_review_recheck_park がこれらの値を使ってスケジューリング、上限判定、信号フォーマットを行うように変更。モジュール定数を削除。テストで PollContext の新フィールドを包含するよう更新。
セッションスタート・キャッチアップロジック
src/hooks-session-start/src/main.rs
emit_session_start_output を追加して stdout JSON 組立を分離。ParkedStatePartial による部分デシリアライズと pr-monitor-state.json 読取ヘルパを追加し、actionparked_ で始まり next_wakeup_at_unix <= now の場合のみ RESUME_MONITORING_COMMAND を含むキャッチアップ・ナッジを additionalContext に追記するロジックを実装。関連ユニットテストを追加。
状態コメント更新
src/cli-pr-monitor/src/state.rs
コメント表現を MAX_REVIEW_RECHECKS 参照から設定値 max_review_rechecks 参照へ更新(実行ロジック不変)。
ドキュメントとタスク管理
docs/coderabbit-monitoring-efficiency.md, docs/todo.md, docs/todo5.md
Bb-3 完了表記やタスク削除/追加を反映。finalize_parked の write_state 失敗時回帰テストエントリを削除。pr-monitor-config.toml[review_recheck] の説明をコメント追加。
テスト
src/cli-pr-monitor/src/config.rs tests, src/cli-pr-monitor/src/stages/poll.rs tests, src/hooks-session-start/src/main.rs tests
ReviewRecheckConfig のデフォルト/カスタム/sanitize 境界テスト、poll.rs の PollContext 注入と信号フォーマット・最大再確認値テスト、SessionStart のキャッチアップ抑制/生成/部分パースの単体テストを追加・更新。

Sequence Diagram

sequenceDiagram
    participant User as ユーザー
    participant Hook as SessionStart Hook
    participant FS as ファイルシステム
    participant State as pr-monitor-state.json
    participant Claude as Claude

    User->>Hook: セッション開始イベント
    Hook->>FS: セッションIDを書き込み(.session-id/.claude)
    Hook->>FS: pr-monitor-state.json を読み取り
    FS-->>Hook: 部分的な parked state
    Hook->>Hook: action が "parked_*" か判定、next_wakeup_at_unix と現在時刻を比較
    alt action が parked_* かつ next_wakeup_at_unix ≤ now
        Hook->>Claude: additionalContext(CLAUDE_CODE_SESSION_ID) + キャッチアップナッジ(RESUME_MONITORING_COMMAND)
        Claude-->>User: 再開ガイダンスを提示
    else
        Hook->>Claude: additionalContext のみを出力
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

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 タイトルは config 拡張、SessionStart catch-up、T2-2 follow-up という3つの主要な変更を簡潔に要約しており、PR の目的(Bundle b の最終 PR として複数の統合的な改善を実施)を明確に反映している。
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/cli-pr-monitor/src/config.rs`:
- Around line 129-159: ReviewRecheckConfig fields need range validation to avoid
zero or overflow: after deserializing the config in load_config, check
ReviewRecheckConfig.initial_review_wait_secs and review_recheck_wait_secs are >=
1 and <= i64::MAX (if out of range set them to
default_initial_review_wait_secs()/default_review_recheck_wait_secs()), and
ensure ReviewRecheckConfig.max_review_rechecks >= 1 (else set to
default_max_review_rechecks()); update load_config to perform these fallbacks so
later casts/Unix-timestamp math and the recheck-count logic don't break (refer
to ReviewRecheckConfig, initial_review_wait_secs, review_recheck_wait_secs,
max_review_rechecks, default_* functions).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b3f37bfa-bc46-4f49-a161-4ac3f4808adc

📥 Commits

Reviewing files that changed from the base of the PR and between 2775c80 and f6fa720.

📒 Files selected for processing (8)
  • docs/coderabbit-monitoring-efficiency.md
  • docs/todo.md
  • docs/todo5.md
  • pr-monitor-config.toml
  • src/cli-pr-monitor/src/config.rs
  • src/cli-pr-monitor/src/stages/poll.rs
  • src/cli-pr-monitor/src/state.rs
  • src/hooks-session-start/src/main.rs
💤 Files with no reviewable changes (1)
  • docs/todo5.md

Comment thread src/cli-pr-monitor/src/config.rs
aloekun added a commit that referenced this pull request May 5, 2026
…ク (PR #115 CR Major #1 採用)

* `max_review_rechecks=0` / `initial_review_wait_secs=0` / `review_recheck_wait_secs=0` / `wait_secs > i64::MAX` を defensive にデフォルト値 (3 / 300 / 300) にフォールバック。

* `load_config` 経路で `config.review_recheck = config.review_recheck.sanitize()` を適用。config は user 編集可能な system boundary のため、CLAUDE.md "ALWAYS validate at system boundaries" 原則に従う。

* sanitize 単体テスト 5 件追加 (zero max / zero waits / overflow / valid passthrough / i64::MAX boundary)。


由来: PR #115 CodeRabbit Major #1 採用 (id 3191214005)。
@aloekun
Copy link
Copy Markdown
Owner Author

aloekun commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@src/cli-pr-monitor/src/config.rs`:
- Around line 161-178: The addition now_unix + ctx.review_recheck_wait_secs as
i64 can overflow when review_recheck_wait_secs equals i64::MAX; update the logic
that sets state.next_wakeup_at_unix (in poll.rs where now_unix and
ctx.review_recheck_wait_secs are used) to perform a checked_add (e.g.,
now_unix.checked_add(wait as i64)) and handle the None case by capping to a safe
maximum (i64::MAX) or setting next_wakeup_at_unix to that max/None as
appropriate; alternatively enforce in ReviewRecheckConfig::sanitize that wait
values are <= (i64::MAX - now_unix) before casting, but the simplest fix is
replacing the direct + with checked_add and a clear fallback for overflow.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ade7ed65-7d14-4aa4-86b2-a6a2e606d5c7

📥 Commits

Reviewing files that changed from the base of the PR and between f6fa720 and 1cc0164.

📒 Files selected for processing (1)
  • src/cli-pr-monitor/src/config.rs

Comment thread src/cli-pr-monitor/src/config.rs
…ク (PR #115 CR Major #1 + #2 採用)

* `max_review_rechecks=0` / `wait_secs=0` / `wait_secs > MAX_SAFE_WAIT_SECS (1 年)` を defensive にデフォルト値 (3 / 300 / 300) にフォールバック。

* `load_config` 経路で `config.review_recheck = config.review_recheck.sanitize()` を適用。config は user 編集可能な system boundary のため、CLAUDE.md "ALWAYS validate at system boundaries" 原則に従う。

* CR Major #2 (review id 3192783887) 採用: 上限を `i64::MAX` から `MAX_SAFE_WAIT_SECS = 365 * 24 * 60 * 60 = 31_536_000 (1 年)` に変更。`now_unix (~1.78e9 in 2026) + wait_secs as i64` の加算で確実に overflow しない範囲に制限。CronCreate auto-expire (7 日) より十分余裕。

* sanitize 単体テスト 5 件: zero max / zero waits / unrealistic (`u64::MAX` / `i64::MAX as u64`) / valid passthrough / `MAX_SAFE_WAIT_SECS` 境界値 + overflow invariant (`now_unix + sanitize 後の値` が `checked_add` で Some を返すこと) を machine-enforce。


由来: PR #115 CodeRabbit Major #1 (id 3191214005、resolved) + CodeRabbit Major #2 (id 3192783887)。
@aloekun aloekun force-pushed the feat/bb-3-config-and-catchup branch from 1cc0164 to 9e6bf1d Compare May 6, 2026 03:40
@aloekun
Copy link
Copy Markdown
Owner Author

aloekun commented May 6, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aloekun aloekun merged commit d582f70 into master May 6, 2026
1 check passed
@aloekun aloekun deleted the feat/bb-3-config-and-catchup branch May 6, 2026 04:19
aloekun added a commit that referenced this pull request May 6, 2026
…(PR #115 follow-up) (#116)

* `coderabbit-monitoring-efficiency.md` Bb-3 エントリを「マージ済 (PR #115)」に更新、CR Major #1+#2 fold-in 修正の経緯と dogfood 実証 (Bundle b 全機能の連携) を記録。Bundle b 完結 (Bb-1 + Bb-2 + Bb-3 + 順位 75 + 76-78) を明記。

* `todo.md` priority table から完了済の順位 55 を削除し、PR #115 post-merge-feedback 採用 3 件を追加: 順位 76 (cross-module overflow 統合テスト) / 順位 77 (Unix timestamp baseline 境界値テスト) / 順位 78 (ADR-038 + CLAUDE.md security 拡充)。

* `todo5.md` に順位 76/77/78 の詳細セクション追加 (動機 / 設計決定 / 作業計画 / 完了基準 / 詰まっている箇所)。順位 76 と 77 は同一 PR で land 推奨 (両方 boundary を扱う test 層)、順位 78 は test 層 land 後の codification PR として位置づけ。


由来: PR #115 マージ + post-merge-feedback (`.claude/feedback-reports/115.md`、採用 3 / 様子見 4 / 却下 3)。
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