Skip to content

実装: isolation worktree agent の Issue comment request を issue_comment.publish controlled mutation lane へ parent delegation で接続する #1633

Closed

Description

@squne121

Parent Issue

#1608

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "1608"
goal_ref: "isolation worktree agent が生成する bounded Issue comment request を parent-owned materializer/delegation を通して issue_comment.publish controlled mutation lane へ接続する"
change_kind: mixed
fixed_base_sha: "4ab8ec2d9495638695ef774fb8737b509585f492"

Parent Goal Ref

  • Goal: isolation worktree agent が生成した Issue comment mutation request を、raw gh issue comment や preflight 専用 skill_runtime_exec.py の汎用化に依存せず、既存 issue_comment.publish controlled mutation lane(controlled_skill_mutation_exec.py / controlled_skill_mutation_policy.py)へ安全に受け渡す canonical producer/parent delegation/execution contract を確定する(調査: skill runtime exec 経由の worktree mutation command-id 実行が block される根本原因を特定する #1608 research)。
  • Desired Destination: OWNER の敵対的レビュー(issuecomment-5013579411)で採用された「第一候補: controlled metadata executor を再利用する」案(isolation worktree agent が bounded comment request を生成し、parent/orchestrator が issue-scoped input namespace へ materialize し、controlled_skill_mutation_exec.py --command-id issue_comment.publish を起動して GitHub へ投稿し、marker/readback/idempotency を検証する)を実装する。

Current Validated Scope

  • isolation worktree agent 向けの bounded comment request schema(閉じたキーのみ)の新規定義
  • parent 側 materializer 関数(bounded request から issue-scoped input namespace への JSON 書き込み、controlled_skill_mutation_exec.py --command-id issue_comment.publish の exact argv 起動)の追加
  • .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py(_post_github_comment 関数、raw gh issue comment --body-file - を直接呼んでいる唯一の production 箇所として grep で特定済み)を、上記 bounded request 経路へ置き換える
  • fake gh を用いた no-live-mutation integration test(positive/negative)の追加
  • .codex/rules/default.rules への controlled_skill_mutation_exec.py allow エントリ追加(Codex 側は現状 exact allow を持たないことを docs/dev/hook-boundaries.md:730 で確認済み)
  • 対応する docs 更新(docs/dev/agent-skill-boundaries.md / docs/dev/hook-boundaries.md)

Remaining Parent Gaps

Outcome

isolation worktree agent が生成する bounded Issue comment request(issue_number / repo / comment_body / marker の閉じたフィールドのみ)が、canonical main root 上の parent orchestrator(issue-refinement-loop の comment 投稿箇所)が持つ materializer 関数によって issue-scoped input namespace(artifacts/{issue_number}/issue-metadata/issue_comment.publish/)へ書き込まれ、既存の controlled_skill_mutation_exec.py --command-id issue_comment.publish の exact argv で起動されて GitHub へ投稿される状態になっている。isolation worktree agent 側に残っていた raw gh issue comment production 呼び出し(publish_termination_report.py::_post_github_comment)が上記経路へ置き換わり、.codex/rules/default.rules に controlled_skill_mutation_exec.py の allow エントリが追加され、fake gh を用いた no-live-mutation integration test と関連 docs 更新を含む状態で PR が open されている。

In Scope

  • isolation worktree agent 向けの bounded comment request schema(JSON、閉じたキーのみ: schema / issue_number / repo / comment_body / marker)を新規定義する
  • parent 側の materializer 関数(bounded request を受け取り、artifacts/{issue_number}/issue-metadata/issue_comment.publish/ 配下へ ISSUE_COMMENT_PUBLISH_INPUT_V1 互換 JSON を書き込み、controlled_skill_mutation_exec.py --command-id issue_comment.publish --issue-number (対象issue番号) --input-file (materialize済みJSONパス) --repo squne121/loop-protocol の exact argv を起動する)を追加する
  • .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py の _post_github_comment(raw gh issue comment --body-file - 呼び出し)を、上記 bounded request 生成 + materializer 呼び出しへ置き換える
  • fake gh を用いた no-live-mutation integration test(positive: request 生成 → materialize → controlled executor 起動 → fake gh POST → marker readback 成功 → idempotent retry。negative: absolute path/../symlink/hardlink/schema mismatch/wrong repo/wrong issue number/duplicate marker/marker-body conflict)を追加する
  • .codex/rules/default.rules に controlled_skill_mutation_exec.py の allow エントリを追加し、Codex 側でも同じ controlled mutation lane が使えるようにする
  • 上記変更に対応する docs 更新(docs/dev/agent-skill-boundaries.md および/または docs/dev/hook-boundaries.md)

Out of Scope

Acceptance Criteria

  • AC1: isolation worktree agent 向けの bounded comment request schema が定義され、閉じたキーのみを許可する
  • AC2: parent 側 materializer 関数が、request を artifacts/{issue_number}/issue-metadata/issue_comment.publish/ へ書き込み、既存 controlled_skill_mutation_exec.py --command-id issue_comment.publish の exact argv を起動する
  • AC3: publish_termination_report.py の raw gh issue comment 呼び出し(_post_github_comment)が上記経路へ置き換わっている
  • AC4: fake gh による no-live-mutation 統合テスト(positive/negative 双方)が追加され、実際の GitHub へのネットワーク呼び出しが一切発生しないことが検証されている
  • AC5: .codex/rules/default.rules に controlled_skill_mutation_exec.py の allow エントリが追加され、Codex 側でも既存の Claude 側 hook parity が成立する
  • AC6: pnpm typecheck / pnpm lint / pnpm test / pnpm build が全て pass する
  • AC7: 関連 docs が更新されている

Verification Commands

# AC1
# baseline-expect: fail
$ rg -n "ISOLATION_ISSUE_COMMENT_REQUEST_V1" scripts/agent-guards/controlled_skill_mutation_policy.py
# AC2
# baseline-expect: fail
$ rg -n "def materialize_isolation_issue_comment_request" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# AC3
# baseline-expect: pass
$ rg -c "issue., .comment." .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# AC4
# baseline-expect: fail
$ test -f scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
# AC5
# baseline-expect: fail
$ rg -n "controlled_skill_mutation_exec.py" .codex/rules/default.rules
# AC6
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build
# AC7
# baseline-expect: fail
$ rg -n "isolation_issue_comment_request" docs/dev/agent-skill-boundaries.md

Allowed Paths

  • scripts/agent-guards/controlled_skill_mutation_exec.py
  • scripts/agent-guards/controlled_skill_mutation_policy.py
  • scripts/agent-guards/tests/
  • .codex/rules/default.rules
  • .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
  • .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py
  • docs/dev/agent-skill-boundaries.md
  • docs/dev/hook-boundaries.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • PR feat: live Issue scope snapshot materializer を追加 #1630 がマージ済みで origin/main の controlled_skill_mutation_exec.py / controlled_skill_mutation_policy.py が本 Issue 起票時点と実質的に異なる場合は、rebase 後に AC1/AC2 の実装方針を再確認する

Required Skills

  • Python(stdlib のみ、subprocess/argparse/pathlib)
  • GitHub CLI(gh api argv-list 呼び出しの安全設計)
  • pytest(fake subprocess ハーネスによる no-live-mutation テスト設計)

Required Design References

  • docs/dev/hook-boundaries.md 内 Parallel Agent Runtime Safety セクション
  • docs/dev/agent-skill-boundaries.md

Scope Delta(該当時のみ記載)

  • 2026-07-19: implementation-worker が AC3 実装着手前に、.claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py(元の Allowed Paths 外)が _post_github_comment の raw gh issue comment argv shape(["gh", "issue", "comment", ...])を前提に subprocess.run を mock する既存テスト約20件(TestGhBodyFile / TestIntegration positive path / TestRepoFlag / TestExecMarkerInjection 等)を持つことを検出した。AC3 実装(_post_github_comment を bounded request 生成 + materializer 呼び出しへ置き換え)はこれらのテストの前提(cmd[0] == "gh")を変えるため、追随修正が必須。
  • 対応: 既存テストを削除せず、.claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py を Allowed Paths へ追加し、新しい呼び出し経路(materializer 経由の controlled_skill_mutation_exec.py 起動)に合わせてテストを更新する(fake subprocess mock の対象コマンドを gh から controlled_skill_mutation_exec.py invocation へ変更)。既存テストが検証していた intent(body-file 経由の投稿・repo flag・exec marker injection・integration path)は維持し、経路のみ更新する。

Delivery Rule

  • 1 Issue = 1 PR
  • 実装は issue-worktree(.claude/worktrees/issue-番号-x 等)で行う
  • PR は Draft PR として作成する

Notes for Reviewer

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Jul 19, 2026
  2. squne121 commented on Jul 19, 2026

    @squne121
    OwnerAuthor

    敵対的レビュー結果

    判定: REQUEST_CHANGES — 現状のままではマージ不可

    対象は PR #1639 の current head 11758655ad8e49f65db977abcbc1c03c7ca60dc8。Draft/Open で、現在の CI は全成功しています。直前の CI failure は日本語見出し修正で解消済みです。したがって、以下は CI では検出されていない設計・認可・並行実行上の問題です。

    Blocker 1: parent delegation ではなく controlled executor の自己ネストになっている

    Issue #1633 の意図は、isolation agent が生成した bounded request を canonical main root の parent が materialize し、issue_comment.publish executor を一度だけ起動する構造です。

    実装は次の経路です。

    controlled_skill_mutation_exec.py
      --command-id termination_report.publish
        └─ publish_termination_report.py
             └─ controlled_skill_mutation_exec.py
                  --command-id issue_comment.publish
    

    外側 executor が publisher を subprocess 起動し、その publisher が同じ executor をもう一度 subprocess 起動しています。

    さらに、materializer は isolation agent 由来の request object を受け取らず、既に parent 内に存在する引数から request を自分で再構築しています。closed-key validator は、呼び出し元が作った dict に対して実行されるため、実際の agent→parent 境界を検査していません。

    必要な修正

    • termination_report.publish から issue_comment.publish への処理を executor 内部の関数呼び出しとして統合し、executor subprocess の再帰起動を廃止する。
    • または termination report の render と publish を分離し、parent が renderer 出力から bounded request artifact を生成して issue_comment.publish を一度だけ起動する。
    • isolation agent が返した実際の ISOLATION_ISSUE_COMMENT_REQUEST_V1 object/artifact を validator に渡す producer/consumer 経路を実装する。

    Blocker 2: Codex に Issue comment 以外の全 remote mutation を許可している

    追加された Codex rule は、controlled_skill_mutation_exec.py というスクリプト prefix 全体を allow にしています。コメントと justification も、issue_body.update、contract_snapshot.publish、pr_review.publish など全 remote mutation を許可する内容です。

    executor の allowlist には実際に五種類の command ID が登録されています。したがって #1633 の Issue comment bridge を理由に、Issue body 更新や PR review 投稿まで Codex の無承認経路へ追加されています。

    Codex rules は、sandbox 外のコマンドを無承認で許可するか、承認対象または block にするかを決定する認可レイヤーです。単なるコマンド補完設定ではありません。 ([OpenAI]1)

    必要な修正

    • issue_comment.publish 専用の小さい wrapper executable を設け、その固定 path だけを Codex rule で許可する。
    • wrapper は command ID を内部固定し、他の command ID、追加フラグ、render mode を受理しない。
    • 全 mutation executor の包括的 Codex allow は、別 Issue・別 threat-model review に分離する。

    Blocker 3: 固定ファイル名による TOCTOU と cross-run 上書きがある

    materializer は常に次の固定ファイルへ通常の write_text() で上書きします。

    artifacts/<issue>/issue-metadata/issue_comment.publish/
      issue_comment_publish_input.json
    

    その後に別 subprocess が同じファイルを読みます。

    同じ Issue に対する二つの publish が並行すると、以下が成立します。

    A: body A を書く
    B: body B で上書き
    A: child executor が body B を読む
    

    この場合、A の処理が B の本文を投稿できます。local marker や remote readback では、投稿前に入力が差し替わった事実を検出できません。

    必要な修正

    • canonical JSON bytes の SHA-256 をファイル名に含める。
    • O_CREAT | O_EXCL 相当で immutable に生成し、既存ファイルを上書きしない。
    • executor input に comment_body_sha256 と input_sha256 を含め、読込後に再検証する。
    • 同一 Issue の二並列 publisher を barrier で交差させる concurrency regression test を追加する。

    High 1: 「integration test」が process boundary を検証していない

    新規テストは、_find_gh_bin、remote 検証、POST、marker 検索、readback をすべて mock し、_exec.main() を同一 Python process 内で直接呼び出しています。

    このテストでは、実運用で重要な以下を検証できません。

    • publisher → child executor の実 subprocess argv
    • Python executable・cwd・PATH の解決
    • environment sanitization の継承
    • fake gh executable の実呼び出し
    • timeout 後の remote side-effect ambiguity
    • stderr・exit code・JSON output の process 間伝播

    必要な修正

    一時ディレクトリに実行可能な fake gh を作り、PATH の先頭に置いた状態で publish_termination_report.py または外側 executor を本当に subprocess 起動してください。fake gh は argv/stdin/env を記録し、指定シナリオに応じて GitHub API 互換 JSON と exit code を返す構成にします。

    GitHub の comment endpoint は 201 に加え、403、404、410、422 を返し得て、短時間の連続投稿は secondary rate limiting の対象です。少なくともこれらと 429、POST 成功後の readback timeout を matrix 化すべきです。 ([GitHub Docs]2)

    High 2: 新しく追加された trusted module が realpath trust chain に入っていない

    publisher は scripts/agent-guards を sys.path 先頭へ挿入し、controlled_skill_mutation_policy.py を importしています。また child executor path も同じ場所から組み立てています。

    一方、外側 executor の module realpath check は publisher、renderer、prose_boundary_policy しか検査していません。新しい policy module と child executor は対象外です。

    必要な修正

    • controlled_skill_mutation_policy.py
    • controlled_skill_mutation_exec.py

    を _check_module_realpaths() の trusted chain に追加し、単純な文字列 startswith ではなく Path.is_relative_to(project_root.resolve()) で ancestry を検証してください。import 後の module.__file__ も canonical path と一致させるべきです。

    High 3: request schema と marker identity が弱い

    bounded validator は marker が非空で、本文中に substring として存在することしか要求しません。executor の remote precheck/readback も同じ substring 検索です。

    また materialized executor input からは repo が落ち、body hash もありません。

    そのため、直接 executor を呼べる caller は、短い一般文字列や既存コメントに含まれ得る文字列を marker に指定できます。誤衝突時には無関係なコメントを idempotency authority として扱う可能性があります。

    必要な修正

    • executor 側でも exact-key schema を適用する。
    • repo、comment_body_sha256、producer_role、必要なら request ID を input に含める。
    • marker は parent/executor が生成し、caller 指定を禁止する。
    • canonical shape を <!-- CONTROLLED_EXEC_MARKER:<32-or-64 hex> --> に固定する。
    • 本文中で count == 1 かつ trailing position であることを要求する。

    High 4: direct Codex path では GitHub host/env binding が不足する

    Issue comment lane の gh issue view と gh api 呼び出しには、sanitized env も --hostname github.com も渡されていません。

    GitHub CLI では GH_HOST が hostname 未指定時の対象 host を決め、GH_REPO も repository context に影響します。外側 termination_report.publish からのネスト経路では偶然 sanitized env を継承しますが、新設された Codex direct allow 経路ではその前提がありません。 ([GitHub CLI]3)

    必要な修正

    すべての issue-comment read/precheck/POST/readback 呼び出しに、PR review lane と同等の sanitized env と明示的な --hostname github.com を適用してください。

    High 5: 30 秒 timeout は内部トランザクションの予算より短い

    publisher は child executor を三十秒で kill します。

    inner executor は正常系でも、marker precheck 十五秒、POST 十五秒、readback 十五秒を個別に許容します。つまり、POST が成功した後、readback 前後で親が child を kill し、「コメントは存在するが処理は失敗」という ambiguous outcome を作れます。

    根本解は executor 自己ネストの廃止です。暫定対応でも、timeout は下流最大予算と後処理を上回らせ、POST 後 timeout は通常の failure ではなく published_but_unverified として扱う必要があります。

    依存関係ゲート

    PR #1630 は現在も Draft/Open で、同じ controlled_skill_mutation_policy.py と controlled_skill_mutation_exec.py を変更しています。

    Issue #1633 自身も、PR #1630 が未マージの場合は同時変更衝突を避けるよう要求しています。したがって、上記修正とは別に、#1630 を先に確定・マージし、#1639 を最新 main へ rebase した後、policy/executor の契約レビューをやり直す必要があります。

    マージ可能にする最低条件

    1. executor の自己ネストを廃止し、本物の agent request → parent materializer 境界を実装する。
    2. Codex allow を issue_comment.publish 専用に縮小する。
    3. materialized input を content-addressed・immutable・hash-bound にする。
    4. subprocess と fake gh executable を通る真の統合テストを追加する。
    5. module trust chain、marker identity、GitHub host/env bindingを強化する。
    6. PR feat: live Issue scope snapshot materializer を追加 #1630 マージ後に rebaseし、current head に対して全 CI と敵対的レビューを再実施する。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions