Skip to content

feat: add codex subagent launch guardrails - #767

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-764-codex-subagent-ledger
Jun 8, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-764-codex-subagent-ledger

Conversation

@squne121

@squne121 squne121 commented Jun 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

要約です。

  • Codex custom agent 4 種の runtime contract を固定する validator と parity check を追加
  • SUBAGENT_LAUNCH_LEDGER_V1 の valid / invalid fixture と strict fail-closed validator を追加
  • impl-review-loop / post-merge-cleanup / workflow docs に、Codex CLI の root thread は data-plane を直接実行しない契約を明文化

Checks

確認項目です。

  • python3 scripts/check_codex_agent_config.py --assert-required-fields を実行し、必須 field 検査が通過した。
  • python3 scripts/check_codex_agent_config.py --assert-runtime-contract を実行し、runtime contract 検査が通過した。
  • python3 scripts/check_impl_review_loop_codex_dispatch.py --assert-max-depth --assert-no-project-profile-routing を実行し、dispatch 設定検査が通過した。
  • python3 scripts/check_impl_review_loop_codex_dispatch.py --assert-explicit-spawn-notes を実行し、spawn 文言検査が通過した。
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/valid.json を実行し、valid fixture が pass した。
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/hook-untrusted.json を実行し、想定どおり fail-closed を確認した。
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/pr763-replay.json を実行し、PR test: hooks tests の CI 取りこぼしを防ぐ (#682) #763 replay が想定どおり reject された。
  • python3 .claude/skills/review-issue/scripts/check_issue_contract.py --file tmp/issue-764-body.md --json を実行し、Issue contract checker が approve を返した。

受け入れ条件の達成状況

  • AC1: .codex/agents/implementation-worker.toml / test-runner.toml / pr-reviewer.toml / post-merge-cleanup-worker.toml を scripts/check_codex_agent_config.py --assert-required-fields で必須 field と runtime limitation field まで検査できる
  • AC2: scripts/check_codex_agent_config.py --assert-runtime-contract が model / reasoning effort / default_permissions / runtime_dependency_status と hook wiring を fail-closed で検査できる
  • AC3: .codex/config.toml に [agents] max_depth = 1 を追加し、project-local config を profile routing の証拠として扱わない文言を scripts/check_impl_review_loop_codex_dispatch.py --assert-max-depth --assert-no-project-profile-routing で検査できる
  • AC4: Step 1 / 2 / 4 と post-merge handoff docs に、Codex CLI では対象 custom agent を明示 spawn し root thread が data-plane を直接実行しない文言を追加した
  • AC5: scripts/check_subagent_launch_ledger.py が strict top-level schema と launch/root-thread action schema を持ち、valid fixture を通しつつ self-report only・missing launch・root-thread data-plane 実行を reject する
  • AC6: hook trust failure / skipped / disabled、unsupported tool path、Codex binary unavailable の fixture を追加し、fail-closed error code を固定した
  • AC7: tests/fixtures/subagent-ledger/pr763-replay.json で subagent_launch_evidence_missing と root_thread_data_plane_execution_observed を同時に返す fail audit を固定した
  • AC8: Runtime Verification Applicability の deferred 境界を維持したまま、Issue 実装: Codex CLI で impl-review-loop の明示 SubAgent spawn 監査を repo-side deterministic guardrail として導入する #764 本文が check_issue_contract.py を通ることを確認した

検証コマンド結果

  • python3 scripts/check_codex_agent_config.py --assert-required-fields: ✅ 通過
  • python3 scripts/check_codex_agent_config.py --assert-runtime-contract: ✅ 通過
  • python3 scripts/check_impl_review_loop_codex_dispatch.py --assert-max-depth --assert-no-project-profile-routing: ✅ 通過
  • python3 scripts/check_impl_review_loop_codex_dispatch.py --assert-explicit-spawn-notes: ✅ 通過
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/valid.json: ✅ valid fixture を pass
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/hook-untrusted.json: ✅ expected fail (hook_evidence_untrusted_or_missing)
  • python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/pr763-replay.json: ✅ expected fail (subagent_launch_evidence_missing, root_thread_data_plane_execution_observed)
  • python3 .claude/skills/review-issue/scripts/check_issue_contract.py --file tmp/issue-764-body.md --json: ✅ verdict: approve

Allowed Paths 遵守

  • 変更は .codex/config.toml、scripts/check_*、tests/fixtures/subagent-ledger/、tests/fixtures/codex-agent-config/、docs/dev/workflow.md、docs/dev/agent-skill-boundaries.md、.claude/skills/impl-review-loop/steps/*、.claude/skills/post-merge-cleanup/SKILL.md に限定した
  • .codex/rules/default.rules、.claude/agents/*.md、assets/、LICENSES/ は変更していない

Schema Change Applicability

スキーマ変更判定です。

  • decision: schema_change
  • reason: SUBAGENT_LAUNCH_LEDGER_V1 と Codex custom-agent runtime contract という machine-readable guardrail contract を validator/fixture として導入したため

Schema Consumer Inventory

スキーマ利用箇所の棚卸しです。
変更対象 schema: SUBAGENT_LAUNCH_LEDGER_V1, codex_agent_runtime_contract/v1

before/after 差分:

# before
# schema not materialized in repo-side validator/fixture form

# after
SUBAGENT_LAUNCH_LEDGER_V1:
  top_level:
    - ledger_schema
    - generated_by
    - codex_binary_status
    - fixture_expectation
    - hook_state
    - tool_path_support
    - project_trust_state
    - launches[]
    - root_thread_actions[]
  fail_closed_error_codes:
    - subagent_launch_evidence_missing
    - root_thread_data_plane_execution_observed
    - hook_evidence_untrusted_or_missing
    - unsupported_tool_path_observed
    - codex_binary_unavailable

codex_agent_runtime_contract/v1:
  checks:
    - model
    - model_reasoning_effort
    - default_permissions
    - runtime_dependency_status
    - runtime_followup_route
    - hooks route through scripts/check-codex-agents.mjs

Consumer 列挙(rg コマンド例と結果):

rg -l 'SUBAGENT_LAUNCH_LEDGER_V1|check_subagent_launch_ledger|check_impl_review_loop_codex_dispatch|check_codex_agent_config' .
./docs/dev/agent-skill-boundaries.md
./docs/dev/workflow.md
./scripts/check_subagent_launch_ledger.py
./tests/fixtures/subagent-ledger/valid.json
./tests/fixtures/subagent-ledger/hook-untrusted.json
./tests/fixtures/subagent-ledger/hook-skipped.json
./tests/fixtures/subagent-ledger/hook-disabled.json
./tests/fixtures/subagent-ledger/unsupported-tool-path.json
./tests/fixtures/subagent-ledger/codex-binary-unavailable.json
./tests/fixtures/subagent-ledger/generated-by-worker-only.json
./tests/fixtures/subagent-ledger/root-thread-test-execution.json
./tests/fixtures/subagent-ledger/root-thread-file-edit.json
./tests/fixtures/subagent-ledger/root-thread-review-judgment.json
./tests/fixtures/subagent-ledger/pr763-replay.json

Consumer 更新状況:

Consumer ファイル 更新有無 備考
scripts/check_subagent_launch_ledger.py 更新済み schema validator 本体
tests/fixtures/subagent-ledger/*.json 更新済み valid / negative fixture
docs/dev/agent-skill-boundaries.md 更新済み canonical evidence と deferred boundary を記載
docs/dev/workflow.md 更新済み workflow 上の dispatch guardrail を記載
scripts/check_codex_agent_config.py 更新済み runtime contract consumer

Compatibility Decision

互換性の判断です。

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: #601
  • reason: 既存 runtime を置き換えず、repo-side deterministic guardrail と fail fixture を追加した

Safety Claim Matrix

安全性主張と未制御範囲の対応表です。

Claim Implemented? Not controlled Evidence Follow-up
root thread の data-plane 実行は launch ledger validator で reject される yes live spawn 自体の runtime 実証は未実施 python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/pr763-replay.json #601
project-local .codex/config.toml を profile routing の証拠として扱わない yes parent runtime override / untrusted project そのものの外部 runtime は制御しない python3 scripts/check_impl_review_loop_codex_dispatch.py --assert-max-depth --assert-no-project-profile-routing #601
hook trust failure / unsupported tool path / binary unavailable は fail-closed yes hooks は security boundary ではない python3 scripts/check_subagent_launch_ledger.py tests/fixtures/subagent-ledger/hook-untrusted.json #601

Notes

補足です。

@github-actions

github-actions Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #767 closed).

@squne121
squne121 marked this pull request as ready for review June 8, 2026 14:59

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

マージ前 review の結果、Issue #764 の contract・Allowed Paths・local verification・GitHub required checks を確認し、blocking issue は見当たりませんでした。

LOOP_VERDICT_V2

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: 36a7d1b90a4b862dd4fbee2f35029ee9f6c42c2a
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []

@squne121

squne121 commented Jun 8, 2026

Copy link
Copy Markdown
Owner Author

結論: REQUEST_CHANGES

PR #767 は方向性としては妥当です。Issue #764 が求めている「root thread が実作業を直接実行せず、Codex custom agent の spawn と event-derived ledger を repo-side で検証する」設計に沿っています。PR 本文も、4つの Codex custom agents、SUBAGENT_LAUNCH_LEDGER_V1 fixture、fail-closed validator、handoff docs を追加したと説明しています。([GitHub]1) ([GitHub]2)

ただし現状の実装は、**「実イベント由来の guardrail」ではなく「手書き fixture の整合性 validator」**に留まっています。特に fixture_expectation を ledger 側に持たせている点、runtime 値を検証していない点、hook から ledger を生成していない点は merge blocker です。


調査した関連文脈

PR #767 は Issue #764 を閉じる想定で、Issue #764 は custom agents、hooks、launch-ledger validator、handoff docs、fixtures、PR #763 replay を in-scope としています。一方で、Codex CLI 自体の変更、subscription/plan detection、live spawn verification は out-of-scope とされ、OpenAI API key 環境での real spawn evidence は Issue #601 に defer されています。([GitHub]1) ([GitHub]1)

PR #763 は CI hook test discovery を修正した既存PRで、PR #767 ではその replay fixture を root-thread data-plane 実行の負例として扱っています。これは回帰テスト観点では有用です。([GitHub]3)

OpenAI Codex の一次情報上、custom agents は .codex/agents/ などに TOML で定義でき、name、description、developer_instructions が必須、model、reasoning、sandbox、mcp、skills などは optional です。また [agents].max_depth は direct child を許可し、より深い nesting を防ぐ設定で、fan-out や token/latency/resource cost に影響します。([OpenAI Developers]4) ([OpenAI Developers]4)

Codex hooks は lifecycle event に対して deterministic command を実行する仕組みですが、公式ドキュメント上も PreToolUse は「guardrail, not a full boundary」であり、すべての shell/non-shell/MCP/WebSearch 経路を捕捉するものではありません。([OpenAI Developers]5) ([OpenAI Developers]5)


Blocking findings

1. SUBAGENT_LAUNCH_LEDGER_V1 validator が audit validator ではなく fixture validator になっている

check_subagent_launch_ledger.py は ledger payload 内の fixture_expectation を読み、その期待結果と validator の計算結果が一致すれば exit 0 になります。これは test fixture には便利ですが、実運用 audit artifact に対しては危険です。失敗している ledger が自分で expected_status: fail を宣言すれば、CI が「想定どおり失敗」と解釈して通過できます。([GitHub]6)

これは Issue #764 の「event-derived launch ledger を canonical evidence とし、worker self-report は advisory」という設計意図と衝突します。([GitHub]1)

要求変更:

  • --fixture-mode と --audit-mode を分離する。
  • audit-mode では fixture_expectation を禁止、または完全に無視する。
  • audit-mode では validator が error code を1つでも出したら non-zero exit にする。
  • fixture だけが「expected failure なら exit 0」を許される構造にする。
  • CI で production ledger を検証する command は必ず --audit-mode を使う。

この分離がない限り、この validator は「fail-closed guardrail」ではなく「自己申告テスト harness」です。


2. “event-derived ledger” の生成経路が実装されていない

Issue #764 は event-derived launch ledger を canonical evidence として扱うことを求めています。PR #767 も PR 本文で SUBAGENT_LAUNCH_LEDGER_V1 fixtures と fail-closed validator を追加したと主張しています。([GitHub]1) ([GitHub]2)

しかし、現在の hook 側実装は .codex/hooks.json から scripts/check-codex-agents.mjs を呼び、SubagentStart では additional context を返すだけです。PR #767 の Python validator は fixture JSON を読むだけで、Codex hook event stdin から ledger を生成していません。([GitHub]7) ([GitHub]8)

OpenAI Codex の SubagentStart hook は turn_id、agent_id、agent_type、permission_mode などを入力として受け取れます。つまり、ledger を生成するための event input は存在します。([OpenAI Developers]5)

要求変更:

  • scripts/check-codex-agents.mjs に ledger append 機能を追加する、または別スクリプト emit_subagent_launch_ledger.mjs を追加する。

  • SubagentStart hook stdin から最低限以下を記録する。

    • hook_event_name
    • turn_id
    • agent_id
    • agent_type
    • permission_mode
    • cwd
    • model
    • timestamp
    • hook command hash/version
  • PreToolUse hook stdin から root-thread data-plane action を記録する。

  • Python validator は fixture だけでなく、この generated ledger artifact を検証対象にする。

現状のままだと、PR 名の “launch guardrails” は過大です。より正確には “launch ledger fixture validator” です。


3. runtime contract の値を検証していない

Issue #764 の AC2/AC5 は、Codex agent の model/reasoning/permission/runtime limitation と、wrong runtime config invalid fixture の失敗を要求しています。([GitHub]1)

リポジトリ側には expected-runtime-contract.json があり、implementation-worker、test-runner、pr-reviewer、post-merge-cleanup-worker それぞれに expected model、model_reasoning_effort、default_permissions が定義されています。([GitHub]9)

しかし check_subagent_launch_ledger.py 側は、launch event の runtime に model、reasoning_effort、default_permissions というキーが存在することは見ていますが、値が expected contract と一致するかを検証していません。つまり、implementation-worker が model: totally-wrong でも、キーさえ存在すれば ledger validator を通過し得ます。([GitHub]6)

さらに Codex 公式ドキュメントでは、CLI から subagent を spawn する際、親ターンの live runtime override が引き継がれるとされています。静的 TOML の値だけを検証しても、実際の spawned agent runtime を証明したことにはなりません。([OpenAI Developers]4)

要求変更:

  • check_subagent_launch_ledger.py は expected-runtime-contract.json を読み込む。

  • 各 launch の agent_name ごとに、以下を expected 値と厳密一致させる。

    • model
    • reasoning_effort / model_reasoning_effort
    • default_permissions
  • mismatch 時は runtime_contract_mismatch などの明示 error code を出す。

  • invalid fixture として wrong-runtime-config.json を追加する。

  • ドキュメント上も「TOML default runtime contract」と「live effective runtime evidence」を分ける。

この修正がないと、Issue #764 の runtime guardrail は満たせません。


4. PreToolUse hook の coverage を超えて “root-thread execution rejected” と主張している

PR 本文は AC2/AC5 を満たしたとしていますが、PR 自身の safety notes でも hooks は security boundary ではないと認めています。([GitHub]2)

OpenAI の hook 仕様でも、PreToolUse は Bash、apply_patch、MCP tool calls などを対象にする guardrail であり、全 tool path を完全に遮断するものではありません。PostToolUse も副作用を undo できません。([OpenAI Developers]5) ([OpenAI Developers]5)

そのため、「root thread data-plane execution を fail-closed で拒否する」と言うなら、最低限 coverage 境界を ledger schema に含める必要があります。

要求変更:

  • ledger に coverage_scope を追加する。

    • 例: pretool_supported_only
    • 例: unsupported_tool_path_observed
    • 例: post_facto_git_diff_observed
  • PreToolUse で捕捉できない経路は明示的に unknown_coverage または unsupported_tool_path として fail させる。

  • git status --porcelain、git diff --name-only、test artifact の有無などの post-facto audit を追加し、hook bypass 後の副作用検出も入れる。

  • PR 文言は「prevent」ではなく「detect and fail known supported paths」に落とす。


5. hook trust / project trust を fixture で自己申告している

Codex 公式ドキュメントでは、project-local hooks は .codex/ layer が trusted な場合のみ読み込まれます。また non-managed command hook は exact hook definition/hash を trust する必要があり、hook が変更されると review されるまで skip されます。([OpenAI Developers]5)

PR #767 の validator は project_trust_state や hook_state を fixture field として見ていますが、実際の Codex trust review state から値を得ているわけではありません。つまり、hook が untrusted/skipped で ledger が生成されないケースを、実イベントから fail-closed にしているわけではありません。

要求変更:

  • 実 ledger 生成時に hook 側が trust/load 状態を記録できないなら、「trust state は直接観測不能」として schema に反映する。
  • 実 audit では「期待される session に ledger が存在しない」こと自体を hook_pipeline_absent として fail にする。
  • fixture の project_trust_state: trusted は canonical evidence ではなく test input に限定する。
  • README/PR safety claim から “hook trust state verified” と読める表現を削る。

High severity findings

6. Claude/Codex parity check が表層的すぎる

check_claude_codex_agent_parity.py は Codex TOML の name と Claude skill doc の frontmatter name、さらに agent_name.split("-")[0] の role token が Claude doc 内にあるかを見る程度です。権限、runtime、output contract、禁止事項、worker self-report の扱い、root-thread boundary までは比較していません。([GitHub]10)

これは adversarial に見ると簡単に bypass できます。たとえば Claude 側 doc に implementation という単語を残したまま、実際の permission や handoff semantics を壊しても parity check は通ります。

要求変更:

  • Claude skill docs 側にも machine-readable block を持たせる。

  • 少なくとも以下を比較する。

    • agent name
    • allowed role
    • default permission profile
    • allowed root-thread action
    • prohibited root-thread action
    • required evidence source
    • runtime dependency status
  • token presence check は削除、または補助チェックに降格する。


7. post-merge-cleanup-worker の実行パスが弱い

PR #767 は4つの Codex custom agents を対象にしています。([GitHub]2)

しかし valid ledger fixture は implementation-worker、test-runner、pr-reviewer の3 agent launch を含む一方、post-merge-cleanup-worker の valid launch を含んでいません。([GitHub]11)

post-merge cleanup は git mutation を伴いやすい領域なので、ここが最も危険です。PR #767 の docs は post-merge handoff にも root-thread は commit/push/cleanup mutation を直接実行しないと書いていますが、fixture coverage は実装/review loop 側に偏っています。([GitHub]10)

要求変更:

  • post-merge-cleanup-worker の valid ledger fixture を追加する。
  • root thread が cleanup git mutation を実行した負例 fixture を追加する。
  • post-merge path では git push、branch deletion、worktree cleanup、tag mutation を明示分類する。

8. hook command validation が per-event 厳密ではない

check_codex_agent_config.py は hook event の存在と command fragment を検証していますが、「各 required event が意図した command に接続されているか」を厳密に見ていません。([GitHub]10)

adversarial には、SubagentStart を benign command に向け、PreToolUse だけが expected fragment を含むようにしても、断片的な fragment check だけでは見逃す可能性があります。

要求変更:

  • SubagentStart matcher .* が ledger generator へ接続されていることを exact match で検証する。
  • PreToolUse の Bash / apply_patch / Edit / Write matcher が expected command に接続されていることを event ごとに検証する。
  • command は fragment ではなく normalized argv として比較する。
  • cwd / repo root resolution / shell quoting も検証する。

良い点

[agents].max_depth = 1 を repo policy として固定しているのは妥当です。Codex の公式仕様上も max_depth = 1 は direct child は許可し、deeper nesting は防ぐ設定で、深くすると token、latency、resource consumption が増えます。([OpenAI Developers]4)

「project-local config は profile routing evidence ではない」と明示している点も正しいです。Codex の project-scoped config は provider/auth/profile/telemetry など machine-local な設定を override できず、untrusted project では .codex/ layer 自体が読み込まれません。([OpenAI Developers]12) ([OpenAI Developers]12)

PR #763 replay を fixture にした点も良いです。過去の root-thread 的な実作業実行を負例として固定化するのは、regression guardrail として価値があります。([GitHub]13)

ただしこれらは、上記 blocker を解消した後に初めて guardrail として意味を持ちます。


推奨する修正セット

  1. check_subagent_launch_ledger.py を fixture-mode と audit-mode に分離する。
    audit-mode では fixture_expectation を禁止し、error code があれば必ず non-zero exit。

  2. SubagentStart / PreToolUse から SUBAGENT_LAUNCH_LEDGER_V1 を生成する実装を追加する。
    fixture ではなく、Codex hook stdin 由来の generated artifact を canonical evidence にする。

  3. ledger validator に runtime contract value check を追加する。
    expected-runtime-contract.json を読み、agent ごとに model/reasoning/permission を厳密一致させる。

  4. hook coverage を schema 化する。
    捕捉できた tool path と捕捉不能 path を分け、unsupported/unknown は fail にする。

  5. hook trust state を自己申告 field から外す。
    観測できないなら「ledger absent = fail」に寄せる。

  6. post-merge cleanup path の fixture coverage を追加する。
    特に git mutation / push / cleanup を root-thread prohibited action として別 fixture 化する。

  7. Claude/Codex parity check を構造化する。
    name token ではなく permission、runtime、prohibited actions、evidence source を比較する。


そのまま貼れる review comment 案

REQUEST_CHANGES

方向性は Issue #764 に沿っていますが、現状は “event-derived launch guardrail” ではなく “hand-written fixture validator” です。merge 前に少なくとも以下を修正してください。

Blocking:
1. check_subagent_launch_ledger.py が payload 内の fixture_expectation を信頼しており、実 audit artifact でも「期待された失敗」として exit 0 にできる構造です。fixture-mode と audit-mode を分離し、audit-mode では fixture_expectation を禁止/無視してください。
2. SubagentStart / PreToolUse hook から SUBAGENT_LAUNCH_LEDGER_V1 を生成する経路がありません。現状は static fixture を読むだけで、event-derived evidence ではありません。
3. ledger validator が runtime の key 存在だけを見ており、expected-runtime-contract.json の model/reasoning/default_permissions 値と照合していません。wrong runtime config を fail させる fixture と error code を追加してください。
4. PreToolUse hook は Codex 仕様上 full security boundary ではないため、root-thread execution “prevention” と読める claim は過大です。coverage_scope / unsupported_tool_path / post-facto audit を schema に入れてください。
5. hook trust / project trust は fixture 自己申告では canonical evidence になりません。実 ledger 不在を fail とするか、観測不能範囲として claim を落としてください。

High:
- Claude/Codex parity check が role token presence 程度で、permissions/runtime/output contract を比較していません。
- post-merge-cleanup-worker の valid launch fixture がなく、post-merge git mutation path の coverage が弱いです。

このPRは設計文書としては良いですが、guardrail 実装としてはまだ merge 不可です。

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