feat(cloud-setup): cache-phase 反映確認の決定論化 — stamp 観測機構 + setup script 登録 snippet の fail-open 化 (ADR-060) - #321
Conversation
… 冒頭報告 (ADR-060 C-3) E2E 検証 1 回目 (2026-07-25) で cache-phase の成果 (pnpm store / cargo target) が snapshot に未反映と判明したが、「走っていない」のか「走ったが残らない」のかを 判別する材料が無かった。cache-phase 完了時に stamp を HOME と CARGO_TARGET_DIR の 2 箇所へ書き、session-phase 冒頭で反映状況を SessionStart ログへ決定論的に報告する (ADR-042: 繰り返す手動確認は仕組みへ)。ADR-060 に検証記録を追記。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XWoGTBZ2ShrpVeDaCxVZ8
…本原因記録 E2E 検証 2 回目 (ユーザー報告) で、セットアップスクリプト欄の相対パス起動が exit 127 (repo clone 前/外の cwd) となり cache-phase が一度も完走していなかった ことが確定。公式ドキュメントも setup script 実行時の cwd / repo 存在を保証して いない。登録 snippet を「repo 探索 + fallback shallow clone + 常に exit 0 (fail-open、検出は C-3 stamp 報告)」に更新し、検証記録と学びを追記。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XWoGTBZ2ShrpVeDaCxVZ8
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughcache-phase の実行結果をスタンプとして保存し、次回の session-phase でキャッシュ反映状態をログ判定できるようにした。セットアップスクリプトはリポジトリ探索と一時 clone に対応し、失敗時も Changesキャッシュフェーズ観測とセットアップ運用
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SetupScript as cloud-setup.sh
participant CacheStamp as Cache stamp locations
participant SessionPhase as session-phase
SetupScript->>CacheStamp: cache-phase 完了時に write_cache_stamp()
SessionPhase->>CacheStamp: stamp の有無を確認
CacheStamp-->>SessionPhase: HOME/CARGO_TARGET_DIR の反映状態
SessionPhase-->>SetupScript: 判定結果を SessionStart ログへ出力
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🤖 PR Monitor 分析 (GitHub Actions バックストップ)
差分概要 (軽量サマリー)
Applicable Findings (Critical / High / Major)(該当なし — レビュー指摘 0 件) Applicable Findings (Medium 以下)(該当なし) Filtered (not applicable)(該当なし) 次のアクション
|
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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-060-cloud-harness-sessionstart-dispatcher.md`:
- Around line 182-185: CLONED の一時ディレクトリ作成に成功した場合だけ git clone を実行するよう、CLONED
の代入と既存の git clone 処理を同じ条件分岐にまとめてください。mktemp -d が失敗した場合は clone を行わず、/repo が clone
先にならないようにします。
In `@scripts/cloud-setup.sh`:
- Around line 459-472: Update the cache-status reporting around the HOME and
CARGO_TARGET_DIR stamp checks so stamp presence is reported only as “あり,” not as
evidence of a warm cache. Read the recorded cargo_warmup value from the stamp
and report warmup completion only when it is done; preserve distinct messaging
for failed, skipped, missing, or unreadable stamp states without claiming
lint:rust starts with a warm cache.
- Around line 407-409: Update the warmup command setup around warmup_cmd so
cargo warmup is never run without a timeout. Require the timeout utility and
fail through the Web UI, or skip warmup while setting CARGO_WARMUP_RESULT to
“skipped-no-timeout”; do not execute the unrestricted warmup command when
timeout is unavailable.
🪄 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: be94ebfb-9347-4972-ba76-84d37ab88c18
📒 Files selected for processing (2)
docs/adr/adr-060-cloud-harness-sessionstart-dispatcher.mdscripts/cloud-setup.sh
| CLONED="$(mktemp -d)" | ||
| if git clone --depth 1 https://github.com/aloekun/claude-code-hook-test "${CLONED}/repo"; then | ||
| REPO_DIR="${CLONED}/repo" | ||
| fi |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
mktemp 失敗時に /repo へ clone しないでください。
set -e がないため、mktemp -d 失敗後も CLONED="" のまま進み、clone 先が /repo になります。作成成功を条件に clone を実行してください。
修正例
if [ -z "${REPO_DIR}" ]; then
- CLONED="$(mktemp -d)"
- if git clone --depth 1 https://github.com/aloekun/claude-code-hook-test "${CLONED}/repo"; then
- REPO_DIR="${CLONED}/repo"
+ if CLONED="$(mktemp -d)"; then
+ if git clone --depth 1 https://github.com/aloekun/claude-code-hook-test "${CLONED}/repo"; then
+ REPO_DIR="${CLONED}/repo"
+ fi
+ else
+ echo "[setup-script] 一時ディレクトリを作成できず cache-phase を skip (fail-open)"
fi
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| CLONED="$(mktemp -d)" | |
| if git clone --depth 1 https://github.com/aloekun/claude-code-hook-test "${CLONED}/repo"; then | |
| REPO_DIR="${CLONED}/repo" | |
| fi | |
| if CLONED="$(mktemp -d)"; then | |
| if git clone --depth 1 https://github.com/aloekun/claude-code-hook-test "${CLONED}/repo"; then | |
| REPO_DIR="${CLONED}/repo" | |
| fi | |
| else | |
| echo "[setup-script] 一時ディレクトリを作成できず cache-phase を skip (fail-open)" | |
| fi |
🤖 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-060-cloud-harness-sessionstart-dispatcher.md` around lines 182 -
185, CLONED の一時ディレクトリ作成に成功した場合だけ git clone を実行するよう、CLONED の代入と既存の git clone
処理を同じ条件分岐にまとめてください。mktemp -d が失敗した場合は clone を行わず、/repo が clone 先にならないようにします。
| if command -v timeout >/dev/null 2>&1; then | ||
| ( cd "${REPO_ROOT}" && timeout "${timeout_secs}" cargo clippy --workspace --all-targets --all-features ) \ | ||
| || warn "cargo warmup 未完了 (timeout/失敗)。初回 Stop の lint:rust は cold compile になります。" | ||
| warmup_cmd=(timeout "${timeout_secs}" "${warmup_cmd[@]}") | ||
| fi |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -eu
command -v timeout
timeout 1 trueRepository: aloekun/claude-code-hook-test
Length of output: 167
🏁 Script executed:
#!/bin/bash
set -eu
printf 'tracked script exists: '
git ls-files 'scripts/cloud-setup.sh' || true
printf '\nRelevant sections:\n'
sed -n '360,495p' scripts/cloud-setup.sh | cat -n
printf '\nReferences to CARGO_WARMUP_RESULT and timeout_secs:\n'
rg -n 'CARGO_WARMUP_RESULT|timeout_secs|warmup_cmd|cargo (clippy|check)|cargo-warmup|webui|Web UI' scripts/cloud-setup.shRepository: aloekun/claude-code-hook-test
Length of output: 8240
timeout 非搭載時にも cargo warmup を未制限実行させないでください。
timeout がない場合、ログは「最大 ${timeout_secs}s」となりますが実際は制限されず、重い crate/cache で warmup が長時間実行するかセットアップが止まります。timeout を必須にして未搭載時は Web UI で失敗するか CARGO_WARMUP_RESULT="skipped-no-timeout" としてスキップしてください。
🤖 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 `@scripts/cloud-setup.sh` around lines 407 - 409, Update the warmup command
setup around warmup_cmd so cargo warmup is never run without a timeout. Require
the timeout utility and fail through the Web UI, or skip warmup while setting
CARGO_WARMUP_RESULT to “skipped-no-timeout”; do not execute the unrestricted
warmup command when timeout is unavailable.
| if [ -f "${CACHE_STAMP_HOME}" ]; then | ||
| log "cache-phase 反映 (HOME): あり — pnpm store 暖機が snapshot に残存" | ||
| # set -e 下でも読み出し失敗 (権限/race) で setup を止めない (上記コメントの fail-open を実装で担保) | ||
| sed 's/^/ /' "${CACHE_STAMP_HOME}" 2>/dev/null \ | ||
| || warn "stamp の内容を読み出せませんでした (表示のみ skip)" | ||
| else | ||
| log "cache-phase 反映 (HOME): なし — pnpm install はフルダウンロードになります (セットアップスクリプト欄の --cache-phase 登録とキャッシュ再構築を確認)" | ||
| fi | ||
| if [ -z "${CARGO_TARGET_DIR:-}" ]; then | ||
| log "CARGO_TARGET_DIR: 未設定 — cargo 暖機はセッションに反映されません (Web UI の環境変数欄で /opt/cargo-target 等を設定)" | ||
| elif [ -f "${CARGO_TARGET_DIR}/.cache-phase-stamp" ]; then | ||
| log "cache-phase 反映 (CARGO_TARGET_DIR=${CARGO_TARGET_DIR}): あり — lint:rust は warm cache で開始" | ||
| else | ||
| ( cd "${REPO_ROOT}" && cargo clippy --workspace --all-targets --all-features ) \ | ||
| || warn "cargo warmup 未完了。初回 Stop の lint:rust は cold compile になります。" | ||
| log "cache-phase 反映 (CARGO_TARGET_DIR=${CARGO_TARGET_DIR}): なし — 初回 Stop の lint:rust は cold compile" |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
stamp の存在を warm cache の証拠として表示しないでください。
write_cache_stamp() は cargo_warmup=failed、skipped-env、skipped-no-cargo でも target 側 stamp を書きます。そのため次セッションで「lint:rust は warm cache」と表示されます。HOME 側も stamp の残存しか示せません。表示を「stamp あり」に留め、cargo_warmup を読み取って done の場合だけ warmup 完了を報告してください。
🤖 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 `@scripts/cloud-setup.sh` around lines 459 - 472, Update the cache-status
reporting around the HOME and CARGO_TARGET_DIR stamp checks so stamp presence is
reported only as “あり,” not as evidence of a warm cache. Read the recorded
cargo_warmup value from the stamp and report warmup completion only when it is
done; preserve distinct messaging for failed, skipped, missing, or unreadable
stamp states without claiming lint:rust starts with a warm cache.
🤖 PR Monitor 分析 (GitHub Actions バックストップ)
Applicable Findings (Critical / High / Major)
Applicable Findings (Medium 以下)(該当なし) Filtered (not applicable)
次のアクション
|
…告の正確化 / snippet の mktemp ガード - warmup_cargo: timeout 未検出時は無制限実行せず skipped-no-timeout として skip (ログの「最大 Ns」と実挙動の乖離を解消) - report_cache_phase_status: stamp の存在だけで warm cache と断定せず、記録された cargo_warmup=done の場合のみ warm 開始を報告。HOME 側の文言も stamp 残存の 事実に限定 - ADR-060 snippet: mktemp -d 失敗時に clone 先が /repo になる経路を成功条件付き 分岐で排除 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014XWoGTBZ2ShrpVeDaCxVZ8
概要
ADR-060 の E2E 検証で cache-phase 暖機が未反映 (セッション開始時に
/opt/cargo-target不存在、pnpm install がreused 0のフルダウンロード) と判明。調査の結果、根本原因は Web UI セットアップスクリプトの相対パス起動が exit 127 (repo clone 前/外の cwd でscripts/cloud-setup.shを解決できない) となり、cache-phase が一度も完走していなかったことと確定した。本 PR は再発防止の観測機構と登録手順の修正を行う。変更内容
1. cache-phase 反映の観測機構 (C-3 stamp)
run_cache_phase完了時に stamp (~/.cache/cloud-setup/cache-phase-stampと$CARGO_TARGET_DIR/.cache-phase-stampの 2 箇所、completed_at / commit / cargo_warmup 結果を記録) を書き込むrun_session_phase冒頭で stamp の有無とCARGO_TARGET_DIRの設定状況を SessionStart ログに決定論的に報告する (ADR-042: 繰り返す手動確認は仕組みへ)warmup_cargoは結果 (done/failed/skipped-*) を stamp に記録するよう変更し、timeout有無で重複していた 2 分岐をコマンド配列 + 単一if/elseに集約2. ADR-060 の更新
exit 0(fail-open)」版へ更新。公式ドキュメントは setup script 実行時の cwd / repo 存在を保証せず、非ゼロ exit はセッション開始をブロックするため検証
bash -n構文チェックcargo_warmup=doneを含む) を実機確認CARGO_TARGET_DIR未設定) を実機確認マージ後のユーザー側手順
🤖 Generated with Claude Code
https://claude.ai/code/session_014XWoGTBZ2ShrpVeDaCxVZ8
Generated by Claude Code
Summary by CodeRabbit
改善
ドキュメント