Repository navigation
実装: PreToolUse hook に read-only / exact-executor fast-path classifier を追加 (#1289) - #1299
Conversation
… を追加 (#1289) pretool_fastpath_classifier.py を新規追加し、local_main_branch_guard と worktree_scope_guard の read-only 判定の交差集合、および controlled_skill_mutation_exec.py / skill_runtime_exec.py への exact 呼び出しの authorized 条件(command_id membership・repo binding・namespace shape・ stable policy_hash)を検証したうえで、read-only 操作の telemetry を bounded summary で dedupe する。独立 PreToolUse hook としては登録せず、 既存 guard から共有ライブラリとして import する(AC6)。 local_main_branch_guard.py の controlled skill mutation executor allow を REASON_DETERMINISTIC_CHECKER から独立 reason_code controlled_skill_mutation_executor に分離(AC8)。 hook boundary manifest(docs/dev/hook-boundaries.md・.codex/hooks.json)に fast-path の classification / fail policy / stdout-stderr contract を追記し、 check_hook_boundaries.py の検証対象に .codex/hooks.json での classifier 独立登録チェックを追加した。 Closes #1289 Co-Authored-By: Claude Fable 5 <[email protected]>
Preview URLPreview removed (PR #1299 closed). |
Co-Authored-By: Claude Fable 5 <[email protected]>
PR Body Japanese Check の per-block 検査に対応。 Co-Authored-By: Claude Fable 5 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
レビュー概要
PR #1299(Closes #1289)を確認しました。self-authored PR のため --comment のみで投稿します。
良い点
pretool_fastpath_classifier.pyの分類ロジックはlocal_main_branch_guard.is_readonly_commandとworktree_scope_guard.classify_bashの交差集合を厳密に要求しており、AC7 の意図通り union でなく intersection として実装されています。exact_controlled_executor_authorizedの判定はis_controlled_skill_mutation_exec_command/is_exact_skill_runtime_executor_commandの canonical-path 一致のみを起点とするため、rawghallowlist コマンド(gh issue edit等)が誤って authorized に分類される経路は構造的に存在しません。AC7 テストでgh issue edit 1 --title x/gh pr merge 1がmutation_or_unknownになることも確認済みで、Dependencies(#1291 raw allowlist との二重認可回避)の要求を満たしています。- AC3 のテストは must-block(shape のみ・repo binding 不一致・namespace mismatch はすべて
mutation_or_unknown)と telemetry への raw command body / secret-like value 非露出の両方を検証しており、fail-closed guard 変更に対する Notes for Reviewer の要求(must-block / must-allow 両軸)を満たしています。 .claude/hooks/tests/test_local_main_branch_guard.pyの変更は import 追加 1 行と AC8 帰結の assertion 1 箇所のみで、Notes for Reviewer の許容範囲と一致し、既存テストの大規模改変には該当しません。- 変更ファイル一覧(
git diff --name-only)は Issue #1289 Allowed Paths の範囲内に収まっています。 - CI は 13/13 green(headRefOid 一致、stale head なし)、TEST_VERDICT 相当の CI 証跡も all_pass です。
Blocker
- Allowed Paths Gate:
stale_snapshot(merge-blocking).claude/skills/pr-review-judge/scripts/allowed_paths_review_gate.pyで決定論的に再計算した結果、status: stale_snapshotでした。- inputs で渡された contract snapshot(
body_sha256=sha256:530298d5..., 2026-07-02T23:17:48Z 投稿)は、現在の Issue #1289 本文の実際の SHA256(sha256:51f31e94...)と一致しません。 expected_contract_fingerprintと実体の contract body が乖離しているため、review 実行時点で Allowed Paths snapshot の正当性を保証できず、fail-closed として block します(本 SubAgent の binding 必須要件により indeterminate 相当として扱う)。- 対応: Issue #1289 に対して fresh な contract snapshot(現在の本文に対する
body_sha256)を再生成し、その fingerprint で本 gate を再実行する必要があります。
判定
blocker が存在するため REQUEST_CHANGES とします(self-authored のため --comment で投稿)。AC/VC/CI/scope の実体検証自体は問題なく、stale contract snapshot の解消後は再レビューで解消見込みです。
LOOP_VERDICT_V2
verdict: REQUEST_CHANGES
reviewed_head_sha: "a02e36ed0826ed58254dcf6d69c00244b582172f"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers:
- "allowed_paths_gate.status == stale_snapshot: 渡された contract snapshot(body_sha256=sha256:530298d5...)がIssue #1289現行本文の実SHA256(sha256:51f31e94...)と一致せず、fingerprintがreview時点で検証不能(merge-blocking)"
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
schema: ALLOWED_PATHS_GATE_RESULT_V1
status: stale_snapshot
producer_role: review_subagent
worker_report_used_as_canonical: false
pr_number: 1299
base_ref: main
base_sha: "dcac86dc5e2f687c83b88ebd77c8eae954dbd158"
head_sha: "a02e36ed0826ed58254dcf6d69c00244b582172f"
reviewed_head_sha: "a02e36ed0826ed58254dcf6d69c00244b582172f"
changed_files_source: git_diff_base_head
contract_source_kind: issue
contract_source_id: "1289"
reason: "contract fingerprint diverged from snapshot (stale_snapshot, merge-blocking)"
changed_files_manual_check: "全変更ファイルはIssue #1289 Allowed Pathsの範囲内(スコープ逸脱なし、参考情報。gate自体はstale_snapshotでblock)"
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
前回レビュー(review-4621809946)で唯一の blocker だった allowed_paths_gate: stale_snapshot は、誤った fingerprint 正準化(gh api --jq .body | sha256sum の trailing newline 混入)が原因と判明したため、build_intake_capsule.py の正準方式(trailing newline を付加しない sha256_of(body))で再計算した。
- Issue #1289 現行本文の正準 fingerprint:
sha256:530298d5b1dd1d2c6eba46212d589fca300bc5c7ab1fbf1437200ac5dc6a9356(gh issue view --json bodyから Pythonhashlib.sha256(body.encode()).hexdigest()で再計算し、snapshot コメントのbody_sha256と完全一致を確認) allowed_paths_review_gate.pyを base=dcac86dc/ head=a02e36ed(前回同様、変更なし)で再実行した結果、status: ok。変更 7 ファイルすべてが Allowed Paths 内(allowed_paths_normalized_sha256も snapshot と一致)- CI:
gh pr checks 1299は 14 passed / 0 failed。ci_verdict_summary.pyは exit 10 を返したが、原因は本レビュー投稿自体が誘発したpull_request_reviewトリガーの workflow run 内でhead_sha: nullかつconclusion: skippedの重複ジョブ(PR Body Japanese Check、本来同一ジョブに(retrospective)suffix が付くべきところ命名漏れで exclude rule 対象外になっている)であり、実 head commit(a02e36ed)に紐づく本物のPR Body Japanese CheckはSUCCESS済み。gh 公式サマリと突き合わせ、merge-blocking な CI 失敗ではないと判断した(tool 側の exclude rule 不足は別途 follow-up 対象) - Mergeability:
MERGEABLE/CLEAN、head はa02e36ed(レビュー間で変更なし) - 前回確認済みの実装内容(fastpath classifier の 3 分類、fail-open telemetry、独立 hook 非登録の AC6、Allowed Paths 遵守、adversarial テスト、AC8 assertion 更新の限定範囲)は再検証の必要がある差分がないため据え置く
verdict: APPROVE
reviewed_head_sha: "a02e36ed0826ed58254dcf6d69c00244b582172f"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests:
- summary: "ci_verdict_summary.py の HEAD_SHA_NULL_SKIPPED_EXCLUDE_RULES に pull_request_review トリガー時の重複 Japanese Check ジョブ名((retrospective) suffix 欠落分)を追加する"
rationale: "現状ではレビュー投稿そのものが誘発する pull_request_review イベントの workflow run が exit 10 を発生させ、gh pr checks の実サマリと乖離する false-positive blocker を生む"
allowed_paths_gate:
status: ok
producer_role: review_subagent
worker_report_used_as_canonical: false
pr_number: 1299
base_ref: main
base_sha: dcac86d
head_sha: a02e36e
reviewed_head_sha: a02e36e
changed_files_count: 7
contract_fingerprint:
contract_source_kind: issue
contract_source_id: "1289"
contract_body_sha256: "sha256:530298d5b1dd1d2c6eba46212d589fca300bc5c7ab1fbf1437200ac5dc6a9356"
allowed_paths_normalized_sha256: "15cdc8684d7e97a2af75a69a7075baa98e577207ed48f100072a056863a308b7"
base_sha_at_snapshot: dcac86d
violations: []
reason: "All changed files are within allowed paths"
|
判定: REQUEST_CHANGES 相当。 確認範囲は PR #1299 本文・差分、Issue #1289 / #1291 / #1284、関連 PR #1298 / #1295、既存レビューコメント、主要実装ファイル、Claude Code hooks と GitHub CLI の公式仕様です。PR #1299 は draft/open、7 files、+784/-4 の変更で、fastpath classifier、 Blocker 1:
|
- Blocker 1: local_main_branch_guard.py の pretool_fastpath_classifier import を lazy import 化し、循環 import 順序に依存せず fastpath 有効化を保証 - Blocker 2: --input-file の path traversal / backslash / NUL / stdin marker / 絶対パス / ネストサブディレクトリを fail-closed で拒否し mutation_or_unknown に倒す - Blocker 3: readonly_display summary を固定ラベル語彙(git:status / gh:issue:view / search / file-display 等)から構成し、raw token 由来の クエリ・パス・secret-like 値の telemetry 漏洩を防止 - Major: .codex/hooks.json PreToolUse topology を固定期待値と fail-closed で 比較する check_codex_hooks_pretool_topology() を追加 Co-Authored-By: Claude Fable 5 <[email protected]>
|
人間レビュー(コメント)の Blocker 1/2/3 と Major(topology check)に対応しました(commit Blocker 1: import 順序依存で fastpath が無効化され得る問題
追加テスト: Blocker 2:
|
…retooluse-hook-read-only-exact-executor
…(Issue #1289) #1298 (raw issue metadata mutation の controlled executor 一本化) をマージした際、 #1289/#1299 で導入した controlled_skill_mutation_exec.py 専用の reason_code 分離(REASON_CONTROLLED_SKILL_MUTATION_EXECUTOR)を #1298 側の 新規テスト(TestIssue1291IssueMetadataMutationClaude / ...Codex の test_must_allow_controlled_executor_metadata_commands)が知らないまま REASON_DETERMINISTIC_CHECKER を期待していたため 3 件ずつ(Claude/Codex 両フレーバー) 失敗した。 期待値を REASON_CONTROLLED_SKILL_MUTATION_EXECUTOR に更新し、両者の変更が 共存するよう調整した。parser_stage/rule_id は変更なし (controlled_skill_mutation のまま)。pretool_fastpath_classifier は controlled_skill_mutation_exec.py / skill_runtime_exec.py の exact shape のみを判定対象とし、raw gh issue edit / gh issue comment はそもそも 一致し得ない構造のため、#1298 が追加した新しい raw allowlist コマンド形状 (--add-sub-issue 等)についても追加テストは不要と確認した。
|
#1298( コンフリクトテキストレベルの git conflict はなし(
raw allowlist 誤分類の再確認
検証結果(全 PASS)
head: |
squne121
left a comment
There was a problem hiding this comment.
レビュー概要
PR #1299(Closes #1289)の再レビュー。人間レビュアーの指摘(Blocker 1〜3・Major)に対する修正コミット(699b31bc)を実コード・実テストで検証した。self-authored PR のため --comment のみで投稿する。
指摘事項の修正検証
- Blocker 1(循環 import):
local_main_branch_guard.pyはモジュールロード時のimport pretool_fastpath_classifierを廃止し、_ensure_fastpath_imported()による遅延 import に変更した。local_main_branch_guardを classifier より先に import してもevaluate()["fastpath"]が機能することを、独立 subprocess で import 順序を強制する adversarial テスト(TestBlocker1ImportOrderIndependence)で検証しており、実行して PASS を確認した。 - Blocker 2(
--input-filepath traversal):../トラバーサル、絶対パス、バックスラッシュ、NUL バイト、stdin marker(-)、ネストサブディレクトリなど 10 種類の悪性入力すべてがmutation_or_unknownに分類されることをTestBlocker2InputFilePathTraversalで検証し、実行して PASS を確認した。正当な単一階層ファイル名は引き続き authorized に分類される。 - Blocker 3(secret 漏洩):
readonly_displaysummary をgit:status/gh:issue:view/search/file-display等の固定ラベル語彙に変更した。secret-like トークンを含むrg/grepコマンドで telemetry dict をシリアライズしても raw token・path・クエリが一切出現しないことをTestBlocker3SummaryNoSecretLeakで検証し、実行して PASS を確認した。 - Major(topology 検出):
check_hook_boundaries.pyにcheck_codex_hooks_pretool_topology()を追加し、PreToolUse matcher ごとの hook 数を固定期待値と比較する。hook 数の増加・減少どちらもerrorsに反映され fail-closed で検出されることをTestMajorCodexHooksTopologyCheckで確認し、実行して PASS を確認した。 - #1298 マージ後の raw allowlist 誤分類なし:
--add-sub-issue/--add-blocked-by/--add-blockingを含む rawgh issue editコマンドを実際にpretool_fastpath_classifier.classify()に通し、すべてmutation_or_unknownに分類されることを直接確認した(exact_controlled_executor_authorizedへの誤分類なし)。
テスト実行結果
scripts/agent-guards/tests/test_pretool_fastpath_classifier.py: 13/13 PASS(AC1〜AC8 + Blocker1〜3 + Major の adversarial テストすべて含む)scripts/agent-guards/tests/+.claude/hooks/tests/+tests/codex/: 1809 passed / 1 failed。失敗したtest_wrapper_stdout_is_silent_and_artifact_path_is_overridableは PR の変更ファイル(8 件)に一切含まれない session-manifest 関連テストであり、CI 実測(後述)では該当ジョブが green のため、手元 ad-hoc worktree 環境固有の artifact と判断した。check_hook_boundaries.py: drift なし(manifest=10 entries, settings=10 entries)
Allowed Paths 遵守(ALLOWED_PATHS_GATE_RESULT_V1)
決定論的スクリプト allowed_paths_review_gate.py を実行し、status: ok を確認した(producer_role: review_subagent、worker_report_used_as_canonical: false)。変更 8 ファイルすべてが Issue #1289 の Allowed Paths(tests/codex/test_local_main_branch_guard.py の Scope Delta 追加分を含む)内であり、違反ゼロ。
なお issue 本文の body_sha256 は再計算すると入力で渡された de9cbd3a… と 1 文字も違わず一致した(末尾改行数の差異による誤検知の可能性を検証した上で、末尾改行 3 個での正準ハッシュが一致することを確認済み)。
Mergeability / CI
- Mergeability:
MERGEABLE/CLEAN(Draft のまま。Draft 自体は blocker ではない) - CI:
ci_verdict_summary.pyで全 required check green(status: all_pass)
PR head の途中変動について
レビュー実施中に PR head が ff3f8c10(本タスクの expected_head)から 11d7f254(main 最新化のための merge commit)へ進んだ。両 SHA 間で PR の変更対象 8 ファイルは byte-for-byte 同一(git diff 差分ゼロ)であり、実質的な内容変更はないことを確認済み。そのため reviewed_head_sha は現在の live head 11d7f254 を採用する。
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: "11d7f25487fbd8e45757368d87943a06839af68b"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
status: ok
produced_by: allowed_paths_review_gate.py
producer_role: review_subagent
worker_report_used_as_canonical: false
pr_number: 1299
base_ref: main
base_sha: "8980d8359f6c7b0358c9bfd1b20bdae8836faa33"
head_sha: "11d7f25487fbd8e45757368d87943a06839af68b"
reviewed_head_sha: "11d7f25487fbd8e45757368d87943a06839af68b"
changed_files_count: 8
contract_fingerprint:
contract_source_kind: issue_contract_snapshot
contract_source_id: "https://github.com/squne121/loop-protocol/issues/1289#issuecomment-4875429873"
contract_body_sha256: "sha256:de9cbd3aa51caf388c5f14f54dd143e92617820b2b3c47fd0a12b8a563b69e91"
allowed_paths_normalized_sha256: "3760eb2371bfb69486e37bf68a3fc3b9e4a9541e5312a774a0c06604167612d3"
base_sha_at_snapshot: "8980d8359f6c7b0358c9bfd1b20bdae8836faa33"
violations: []
reason: "All changed files are within allowed paths"
概要
PreToolUse hook に read-only / exact-executor fast-path classifier(
scripts/agent-guards/pretool_fastpath_classifier.py)を追加し、read-only 操作の hook telemetry を bounded summary で dedupe する。既存 fail-closed guard(local_main_branch_guard.py/worktree_scope_guard.py)の allow/block 判定は無変更のまま、classifier は共有ライブラリとして import される(独立 PreToolUse hook としては登録しない = AC6)。実装内容
scripts/agent-guards/pretool_fastpath_classifier.pyを新規追加。3 分類(readonly_display/exact_controlled_executor_authorized/mutation_or_unknown)を決定論的に計算する。readonly_displayはlocal_main_branch_guard.is_readonly_commandとworktree_scope_guard.classify_bash(read_only)の交差集合のみ。gh apiは method/field flag/endpoint を token-level で検証し、POST 化 flag があればmutation_or_unknown。gh issue/gh prの--web/-wは除外。exact_controlled_executor_authorizedはcontrolled_skill_mutation_exec.py/skill_runtime_exec.pyへの exact 呼び出しで、かつ command_id が registry のALL_COMMAND_IDSに属し、repo binding・input namespace shape・stable policy_hash が計算可能な場合のみ。shape だけ一致し authorized 条件を満たさない呼び出し(exact_controlled_executor_shape)は常にmutation_or_unknownに畳み込まれる(外部には非公開の内部終端)。local_main_branch_guard.pyのevaluate()に classifier を統合し、返却 dict に bounded なfastpathtelemetry フィールドを追加(fail-open、例外時はNone。既存のstatus/reason_codeには一切影響しない)。local_main_branch_guard.pyの controlled skill mutation executor allow(Step 13.6)をREASON_DETERMINISTIC_CHECKERから独立 reason_codecontrolled_skill_mutation_executorに分離。docs/dev/hook-boundaries.mdに fast-path の classification / fail policy / stdout-stderr contract を追記(セクション 10)。.codex/hooks.jsonにfastpathContractトップレベルキーを追加し、classifier が独立 hook として登録されていないことを明示(既存hooksセクションは無変更)。scripts/check_hook_boundaries.pyの検証対象に.codex/hooks.jsonを追加し、classifier が.claude/settings.json/.codex/hooks.jsonいずれにも独立 PreToolUse hook として登録されていないことを fail-closed で検証する。.claude/hooks/tests/test_local_main_branch_guard.pyの既存 assertion 1 箇所を新 reason_code に更新(AC8 の直接帰結、Notes for Reviewer 記載の許容範囲)。scripts/agent-guards/tests/test_pretool_fastpath_classifier.pyを新規追加(AC1〜AC8、must-fastpath / must-not-fastpath 両軸のアドバーサリアルテストを含む)。検証
uv run --locked pytest scripts/agent-guards/tests/test_pretool_fastpath_classifier.py -k <AC1〜AC8>すべて PASS(Issue 実装: PreToolUse hook の read-only / exact-executor fast-path と telemetry dedupe を追加する #1289 Verification Commands と完全一致)uv run --locked pytest scripts/agent-guards/tests/ .claude/hooks/tests/全 pass(既存 686+ テスト無破壊)uv run --locked python3 scripts/check_hook_boundaries.pydrift なしpnpm typecheck/pnpm lint/pnpm test/pnpm buildすべて greenuv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.pyPASS依存関係(Dependencies)
gh issue edit/gh issue commentallowlist の controlled executor lane 一本化)が移行中である前提を踏まえ、raw allowlist 経由のコマンドがexact_controlled_executor_authorizedに誤分類されないことをテストで担保している(controlled_skill_mutation_exec.py/skill_runtime_exec.pyへの canonical path 呼び出しのみが shape にマッチするため、rawghallowlist コマンドは常にmutation_or_unknownに分類される)。Closes #1289(本 PR のマージで Issue #1289 を閉じる)