Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#433"
goal_ref: "blocked Stop/SubagentStop attempt では標準 agent_session_manifest を生成せず、guard と producer を単一 coordinator hook で直列化する(session manifest hook は best-effort telemetry であり AI agent 作業をブロックしない)"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: blocked Stop/SubagentStop attempt の manifest policy を設計文書に記録し、coordinator hook 実装の implementation Issue を起票する
- Desired Destination: Stop / SubagentStop で guard verdict を producer より先に確定し、blocked attempt では標準 manifest を生成しない deterministic wiring へ移行する。ただし session manifest hook は best-effort telemetry であり、manifest 生成失敗で AI agent 作業をブロックしない。
Current Validated Scope
.claude/settings.jsonの Stop / SubagentStop wiring を sibling hooks から coordinator hook に置き換える.claude/hooks/session_manifest_coordinator.shを追加し、guard → producer の直列実行と exit code contract を実装する(coordinator は原則 exit 0 で fail-open).claude/hooks/tests/に blocked attempt suppress / pass-through / stop_hook_active まわりの unit test を追加するdocs/dev/session-recording-policy.mdを coordinator 実装 reality(best-effort telemetry, single coordinator only)に同期する
Remaining Parent Gaps
- blocked attempt を監査記録として残す場合の
agent_session_block/v1スキーマ設計と producer 実装は別 Issue で扱う - Secret 境界の upstream 統制と scanner 強化は
#412側で扱う
Outcome
Stop / SubagentStop で coordinator hook が guard verdict を直列確定する。guard failure 時は標準 agent_session_manifest を生成せず coordinator は exit 0 で終了し(AI agent 作業を阻止しない)、対応テストと policy 文書が coordinator の best-effort テレメトリとしての位置付けに一致している状態。
In Scope
- Stop / SubagentStop 用 coordinator hook の追加
.claude/settings.jsonの wiring 置換と sibling hook 解消- blocked attempt 時の標準 manifest 非生成テスト
- guard pass 時の producer 実行継続テスト
stop_hook_active: true時の short-circuit テスト(producer を呼ばず exit 0)- policy SSOT の実装 reality 同期(best-effort telemetry, single coordinator only)
Out of Scope
agent_session_block/v1の schema / artifact 実装- PostToolUse hook の matcher 仕様変更
- GitHub Actions artifact workflow の権限や retention 設計変更
- Secret scan / token revoke / rotate-on-leak の upstream 制御変更
- exit 2 による AI agent 停止を必要とする enforcement(別 Issue で扱う)
Acceptance Criteria
- AC1:
.claude/settings.jsonの Stop / SubagentStop はsession_manifest_coordinator.sh単一 hook のみを参照し、guard と producer を sibling hooks として並べない - AC2: coordinator は
session_recording_policy_guard.shを producer より先に実行する - AC3: guard が
exit 0(success)の場合のみgenerate_session_manifest_from_hook.mjsを実行する - AC4: guard が非0 exit(failure)の場合、標準
agent_session_manifestは生成しない。coordinator は Stop/SubagentStop をブロックせずexit 0で終了し、stderr に skip 理由だけを出す - AC5: producer が失敗した場合も Stop/SubagentStop をブロックせず
exit 0で終了し、stderr に保存失敗だけを出す - AC6:
stop_hook_active: trueの場合、coordinator は producer を呼ばずexit 0で終了する(short-circuit を維持する) - AC7: coordinator は stdin を一度保存し、guard と producer の両方に同一 payload を渡す
- AC8: Stop/SubagentStop 配下に
session_recording_policy_guard.shやgenerate_session_manifest_from_hook.mjsへの直接参照が残っていないことをテストで確認する - AC9:
docs/dev/session-recording-policy.mdに「session manifest hook は best-effort telemetry であり、AI agent 作業をブロックしない」を明記し、「guard → producer の順に固定」という説明を「single coordinator only」に置換する - AC10: 実際の Claude Code agent / subagent 動作で、guard failure・producer failure・artifact write failure の各ケースでも Stop/SubagentStop が完了することを smoke test 証跡として残す
Runtime Verification Applicability
decision: immediate
- AC1: not_applicable(rg による決定論的ファイル構造検証)
- AC2: deferred(実装後 PR review 時に pytest で確認)
- AC3: deferred(実装後 PR review 時に pytest で確認)
- AC4: deferred(実装後 PR review 時に pytest で確認)
- AC5: deferred(実装後 PR review 時に pytest で確認)
- AC6: deferred(実装後 PR review 時に pytest で確認)
- AC7: deferred(実装後 PR review 時に pytest で確認)
- AC8: deferred(実装後 PR review 時に pytest で確認)
- AC9: not_applicable(rg による決定論的テキスト検索)
- AC10: immediate(実 Claude Code agent / subagent 動作による smoke test、PR 本文に証跡添付。
_*_fallback: trueを含む結果は PASS と見なさない)
Verification Commands
# AC1
$ rg -n 'session_manifest_coordinator' .claude/settings.json
# AC2
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and guard_order'
# AC3
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and guard_exit_0'
# AC4
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and guard_failure'
# AC5
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and producer_failure'
# AC6
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and stop_hook_active'
# AC7
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and stdin'
# AC8
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and sibling_absent'
# AC9
$ rg -n 'best-effort telemetry|AI agent 作業をブロックしない|single coordinator' docs/dev/session-recording-policy.md
# AC10
# preflight-scope: pr_review_only
$ uv run pytest .claude/hooks/tests/ -q -k 'coordinator and smoke'
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
.claude/settings.json.claude/hooks/session_manifest_coordinator.sh.claude/hooks/generate_session_manifest_from_hook.mjs.claude/hooks/session_recording_policy_guard.sh.claude/hooks/tests/docs/dev/session-recording-policy.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- 動作検証 AC の VC が SKIP(exit 77)を返した場合(実行環境不可のためエスカレーション)
- fallback 経由でのみ「成功」する場合(FAIL として扱い、実行環境を確認)
Required Skills
- Bash / shell hook scripting
- Node.js CLI / JSON stdin contract
- pytest
ランタイム Smoke 検証手順
以下を実 Claude Code セッションで確認し、証跡を PR に添付する。
- normal path: Stop hook が coordinator を起動 → guard pass → producer 実行 → manifest 生成成功 → Claude Code の停止が阻害されない
- guard failure path: watched policy file を意図的に不整合にする → guard failure → producer 未実行 → stderr に skip 理由 → Stop/SubagentStop がブロックされない
- producer failure path: node 実行失敗または artifacts 書き込み不可を再現 → stderr に保存失敗 → Stop/SubagentStop がブロックされない
- subagent path: Task/Subagent を実行し SubagentStop を発火 → failure path でも subagent が終了できる
- output safety: stdout に manifest 本文を出さない、stderr に raw transcript / local absolute path / secret-like value を出さない
Scope Delta(任意)
N/A
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 6, 2026
人間からのコメントです。
いぜん日本語制約hookの導入において、大量の厳しいフック制約によるAIエージェント作業の阻止を発生させてしまったので、AIエージェント作業をブロックするようなフックの導入は気をつけて行いたい。特にこのフックは、作業履歴をGitHubに保存するようなもののため、AIエージェントの作業を妨げず、セッション情報の保存失敗だけを出力するような内容にしたいです。
また、フックの動作を検証して、想定外の動作がないことを実際のAIエージェントの動作から確認したいです。
squne121 commentedon Jun 6, 2026
判定
REQUEST_CHANGES 相当。#651 の方向性は正しいが、Issue契約がまだ甘いです。
#651 は「blocked Stop/SubagentStop attempt では標準
agent_session_manifestを生成しない」「guard と producer を単一 coordinator hook で直列化する」という実装Issueです。現時点で関連ブランチ/PRはなく、レビュー対象は実装前のIssue契約・設計レビューになります。([GitHub]1)関連経緯の整理
#402 / PR #426 で、Stop/SubagentStop/PostToolUse から
agent_session_manifestを生成する配線が入っています。ただし当時は「session_recording_policy_guard.shを producer より前に書く」構造で、Stop/SubagentStop の manifest 生成を安全に制御できる前提でした。([GitHub]2)その後 #433 で、この前提が崩れています。
.claude/settings.jsonに guard と producer を sibling hook として登録すると、Claude Code は同一eventに一致する複数hookを並列実行し、guard が exit 2 しても sibling producer の副作用は止められない、というP0欠陥が明文化されています。つまり「設定順序で guard first」は安全性の根拠になりません。([GitHub]3)#651 はその修正として、Stop/SubagentStop を単一 coordinator hook に置き換え、guard exit 2 のとき標準manifestを生成しない、guard exit 0 のときだけ producer を呼ぶ、という狙いです。これは妥当です。([GitHub]1)
ただし、Claude Code の hook 仕様上、exit 2 は Stop/SubagentStop をブロックする特別な終了コードで、exit 1 は多くの文脈で非ブロッキングです。また PostToolUse は実行後hookなので、exit 2 でも「ツール実行そのもの」は止められません。ここを曖昧にすると、#651 はまた policy illusion になります。([Claude Code]4)
Blockers
1.
.claude/settings.jsonの不変条件が弱い#651 のACは「Stop/SubagentStop は coordinator のみ」としているものの、実装者が producer 直呼びを残してもテストが甘いとすり抜けます。現在の main では Stop/SubagentStop に
session_recording_policy_guard.shとgenerate_session_manifest_from_hook.mjsが sibling 登録されており、まさに #433 の欠陥構造です。([GitHub]5)要求すべき不変条件:
session_manifest_coordinator.shのみ。session_manifest_coordinator.shのみ。session_recording_policy_guard.shやgenerate_session_manifest_from_hook.mjsへの直接参照が残っていたらテスト失敗。これは「順序テスト」ではなく「sibling producer 不在テスト」に変えるべきです。
2. coordinator は stdin を一度捕捉して guard / producer に再注入しないと壊れる
現行の
session_recording_policy_guard.shは stdin を読み切って一時ファイルに保存します。producer も stdin から hook payload を読む実装です。したがって coordinator が単純にguard | producerや順次実行だけをすると、producer 側に元payloadが渡らず、Stop/SubagentStop の session情報・subagent情報が欠落します。([GitHub]6) ([GitHub]7)要求仕様:
重要なのは、guard と producer の両方に同一stdinを渡すことです。
3. guard の非0終了を fail-closed にしていない
#651 のACは guard exit 2 の扱いは書いていますが、guard が exit 1 や不明な非0で落ちた場合の扱いが弱いです。Claude Code 仕様では、Stop/SubagentStop を確実に止めるには exit 2 が必要です。(Claude Code)
推奨: coordinator は guard の
0以外を原則 fail-closed とし、2以外の非0も sanitized stderr を出してexit 2に正規化するべきです。guard のクラッシュ時に producer が走るのは最悪です。4.
stop_hook_activeの扱いが未定義Claude Code の Stop/SubagentStop input には
stop_hook_activeがあり、stop hook による無限ループを避けるために確認すべき値です。SubagentStop にも同様の制御情報が入ります。([Claude Code]4)現行guardは
stop_hook_active == trueのとき exit 0 で抜けます。([GitHub]6)#651 のACは「既存の short-circuit semantics を壊さない」と言っていますが、その後 producer を呼ぶのか呼ばないのかが未定義です。
敵対的には、ここは duplicate manifest / stop-loop 副作用の温床です。
推奨は、coordinator 側で
stop_hook_active: trueを検出したら producerを呼ばず exit 0。少なくとも、このケースの期待挙動をACとテストに明記すべきです。5. docs が現在の危険な説明を残している
現行docsは Stop/SubagentStop について「policy guard → producer の順に固定」と説明しています。([GitHub]8)
しかし #433 で、その説明は安全性の根拠として否定されています。([GitHub]3)
修正文言はこうするべきです。
「設定順序で守る」という表現は削除対象です。
6. #412 / PR #495 の secret boundary と混同してはいけない
#651 は blocked Stop/SubagentStop の標準manifest抑止であり、secret boundary そのものではありません。#412 / PR #495 は PreToolUse の
secret_boundary_guard.sh、permissions deny/ask、secret-safe workflow を扱う別境界です。([GitHub]9) ([GitHub]10)#651 のdocsで「coordinator により秘密情報漏洩を防ぐ」と書くのは過大主張です。正しくは、blocked Stop/SubagentStop attempt に対する標準manifest生成を抑止するだけです。secret流入防止は #412 系の責務です。
7. GitHub Actions artifact を「private」と誤記してはいけない
GitHub Actions artifact は public repo では read access があれば取得可能で、REST API 経由で artifact metadata / download endpoint が提供されています。public resource なら認証不要で使えるendpointもあります。([GitHub Docs]11)
したがって #651 のdocs更新では、PR #426 のレビューで指摘された通り、artifact を confidentiality boundary と扱ってはいけません。artifact retention や digest validation は有用ですが、秘密保持ではありません。([GitHub]12) ([GitHub Docs]13)
強化すべき受け入れ条件
#651 のACは次のように補強すべきです。
.claude/settings.jsonentry は coordinator 1本のみ。direct guard / direct producer が残っていたら失敗。stop_hook_active: trueの期待挙動を明文化する。agent_id/agent_type/agent_transcript_pathを落とさないテストを入れる。agent_session_block/v1、GitHub Actions retention/security、secret rotation、PostToolUse matcher拡張には触れない。実装方針
.claude/settings.jsonは Claude Code 公式仕様に合わせ、exec form を維持すべきです。argsがある場合は shell tokenization されず、commandが直接 executable として spawn されます。Node script の場合もcommand: "node", args: ["..."]が推奨形です。([Claude Code]4)Stop/SubagentStop では例えば次の形が妥当です。
{ "matcher": "", "hooks": [ { "type": "command", "command": "${CLAUDE_PROJECT_DIR}/.claude/hooks/session_manifest_coordinator.sh", "args": [] } ] }producer を直接呼ぶ構造は PostToolUse に限定します。PostToolUse は「事後hook」であり、Stop/SubagentStop のような停止制御とは性質が違うためです。([Claude Code]4)
貼れるレビューコメント案
squne121 commentedon Jun 6, 2026
#651 (comment)
結論: この人間コメントは正しいです。#651 は現状のままだと危険です。
特に #651 の AC2 は「guard が
exit 2の場合、coordinator もexit 2を返す」としており、Claude Code の Stop/SubagentStop ではexit 2が「停止を阻止して会話・サブエージェントを継続させる」動作になります。これは、人間コメントの「AIエージェント作業をブロックしない」という要求と正面衝突します。([GitHub]1) ([Claude API Docs]2) ([Claude API Docs]2)敵対的レビュー
#651 の設計意図である「guard → producer の直列化」は妥当です。親 Issue #433 でも、Stop/SubagentStop に guard と producer を sibling hooks として並べると、Claude Code では一致した hook が並列実行されるため、guard の
exit 2では兄弟 hook の副作用を止められない、という問題が明記されています。Claude Code 公式 docs も「All matching hooks run in parallel」としているため、coordinator 化そのものは必要です。([GitHub]3) ([Claude API Docs]2)ただし、coordinator 化 = blocking policy にすること、ではありません。
#651 は「blocked attempt では標準 manifest を生成しない」ことと、「AI作業を止める」ことを混同しています。セッション履歴保存・manifest 生成は観測/証跡系の副作用なので、保存失敗で Stop/SubagentStop をブロックする設計は過剰です。現在の
generate_session_manifest_from_hook.mjsもコメント上は「producer failure exits 0」「best-effort telemetry — session is NOT blocked」としており、むしろ人間コメントの方向に寄っています。([GitHub]4)一番危ないのは、
session_recording_policy_guard.shのexit 2を coordinator がそのまま返す設計です。Stop/SubagentStop でexit 2を返すと、Claude は止まらず、サブエージェントも終了できません。過去に日本語制約 hook で作業阻止を起こした反省を踏まえるなら、#651 は 「保存・記録系 hook は fail-open」 を明示する必要があります。([GitHub]5) ([Claude API Docs]2)#651 の修正方針
#651 は次のように契約を変えるべきです。
Stop/SubagentStopの coordinator は 原則exit 0固定。stderrに「manifest skipped / policy guard failed」を出してexit 0。stderrに出すだけでexit 0。exit 2を返す挙動が必要なら、それは「session recording policy enforcement」という別 Issue に分離する。つまり、#651 の中核はこうです。
Acceptance Criteria の差し替え案
そのまま #651 に貼るなら、AC はこう直すのが安全です。
検証で必須にすべきこと
unit test だけでは不足です。今回の論点は「hook が本当に AI エージェントを止めないか」なので、実際の Claude Code 動作で確認すべきです。
Issue コメント案
判断
#651 は実装に進める前に契約修正が必要です。
coordinator 化は正しいですが、
exit 2伝播は削るべきです。履歴保存・manifest 生成の失敗で AI エージェントを止める設計にすると、また hook が開発作業の単一障害点になります。squne121 commentedon Jun 6, 2026
Contract Review: BLOCKED (2026-06-06T05:30:00Z)
VC preflight はすべて pass しましたが、Step 4.5(Runtime Verification Applicability: decision: immediate)で必須項目の欠如を検出しました。
不足項目
## Stop Conditionsに 2 エントリの追加が必要docs/dev/runtime-verification-policy.mdのセクション 6 に従い、以下を## Stop Conditionsの末尾に追加してください:## Runtime Verification Applicabilityにフォールバック FAIL 明示が必要AC10 の immediate エントリに、
_*_fallback: trueを PASS と見なさない旨を追記してください:- AC10: immediate(実 Claude Code agent / subagent 動作による smoke test、PR 本文に証跡添付。fallback 経由の成功は PASS としない)その他のチェック結果(すべて pass)
推奨アクション
上記 2 点は小さな追記です。
issue-refinement-loopを使わず、直接gh issue editで修正してからissue-contract-reviewを再実行してください。squne121 commentedon Jun 6, 2026
Contract Snapshot (2026-06-06T05:35:00Z)
全チェックが通過しました。
implement-issueへの handoff 準備ができています。agent_session_manifestを生成せず coordinator はexit 0で終了し(AI agent 作業を阻止しない)、対応テストと policy 文書が coordinator の best-effort テレメトリとしての位置付けに一致している状態。pr_review_only; AC1, AC9 は baseline fail 確認済み; AC10 smoke test は immediate / 証跡 PR 添付).claude/settings.json.claude/hooks/session_manifest_coordinator.sh.claude/hooks/generate_session_manifest_from_hook.mjs.claude/hooks/session_recording_policy_guard.sh.claude/hooks/tests/docs/dev/session-recording-policy.md.claude/worktrees/issue-651-blocked-stop-subagentstop-attempt-manifeworktree-issue-651-blocked-stop-subagentstop-attempt-manifesqune121 commentedon Jun 6, 2026
implement-issue: 実装完了
.claude/worktrees/issue-651-blocked-stop-subagentstop-attempt-manifeworktree-issue-651-blocked-stop-subagentstop-attempt-manifefix(#651): coordinator stdout/stderr 制御修正 + env override + buildStabl…
feat(#651): blocked Stop/SubagentStop attempt で標準 manifest を抑止する coor…