Skip to content

実装: isolation worktree agent の Issue comment request を issue_comment.publish controlled mutation lane へ接続する (#1633) - #1639

Merged
squne121 merged 8 commits into
mainfrom
worktree-issue-1633-isolation-issue-comment-bridge
Jul 19, 2026
Merged

squne121 merged 8 commits into
mainfrom
worktree-issue-1633-isolation-issue-comment-bridge

Conversation

@squne121

@squne121 squne121 commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

isolation worktree agent が生成する bounded Issue comment request(issue_number / repo / comment_body / marker の閉じたフィールドのみ)を、canonical main root 上の materializer(materialize_isolation_issue_comment_request())が 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 へ投稿する経路に接続した。publish_termination_report.py::_post_github_comment が保持していた唯一の raw gh issue comment production 呼び出しをこの経路へ置き換え、.codex/rules/default.rules に対応する allow エントリを追加して Claude/Codex 間の parity gap を解消し、fake gh による no-live-mutation integration test を追加した。

Closes #1633(本 Issue を解消)
Refs #1608(関連 Issue)

Fix Delta 対応(OWNER レビュー、2026-07-19)

レビューコメント で指摘された 3 点(P0 merge blocker 1 件、P1 必須 2 件)をすべて解消した。

P0(マージ阻害の重大指摘): materializer の symlink/TOCTOU 脆弱性

materialize_isolation_issue_comment_request() の書き込みが plain Path.write_text() で
predictable な出力パスへ直接書き込んでおり、namespace の祖先ディレクトリ・出力ファイル自体の
symlink/hardlink 追従・check-then-write の TOCTOU(CWE-59/61/363)が未対策だった。

対策として _write_json_atomic_symlink_safe() / _resolve_namespace_component_nofollow() を追加した:

  • namespace の各 path component を dir_fd 相対の os.mkdir / os.stat(..., follow_symlinks=False) /
    os.open(..., O_DIRECTORY | O_NOFOLLOW) で一段ずつ辿る(mkdir は既存 dirent があれば
    symlink でも追従せず EEXIST になるため race-free)
  • 出力ファイルは新規一時ファイルへ O_CREAT | O_EXCL | O_NOFOLLOW(dir_fd 相対)で書き込み、
    fsync 後に os.rename(tmp, filename, src_dir_fd=..., dst_dir_fd=...) で atomic に置換
    (POSIX rename() は宛先が symlink でも追従せずディレクトリエントリ自体を置換するため、
    pre-check と rename の間の race window に symlink が仕込まれても任意ファイル書き込みに繋がらない)
  • 出力の pre-existing dirent が symlink / directory / FIFO・device / hardlink(st_nlink != 1)
    のいずれかであれば書き込みを一切行わず fail-closed で reject

テストは .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py::TestMaterializerSymlinkSafety
に、出力 symlink(target 内容が完全に不変であることを確認)/ namespace directory 自体が symlink /
中間 directory が symlink / 出力が hardlink / 出力が directory / 出力が FIFO / concurrent
replacement 相当 / 失敗時に既存の正当な入力ファイルを破壊しない、の各ケースを追加(8 テスト)。

P1-1(必須): bounded request の検証境界がコード上恒真だった問題

materialize_isolation_issue_comment_request(*, issue_number, repo, comment_body, marker, ...) が
自分で request = {...} を再構築してから自分自身を検証しており、validator の主要チェックが
恒真になっていた。

API を実際の境界に合わせて変更した:

def materialize_isolation_issue_comment_request(
    *, request: object, expected_issue_number: int, expected_repo: str,
    project_root: Path | None = None,
) -> tuple[str | None, str]:

producer 側は新規追加した build_isolation_issue_comment_request(*, issue_number, repo, comment_body, marker)
に分離し、_post_github_comment() もこの producer 経由で request を構築してから
materialize_isolation_issue_comment_request() へ渡すよう更新した。既存の
materialize_isolation_issue_comment_request() 呼び出しテスト(test_publish_termination_report.py
の TestMaterializeIsolationIssueCommentRequest と
scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py 全体)も新シグネチャへ
追随させ、unknown field / schema mismatch / repo mismatch / issue mismatch / non-dict request の
拒否テストを新規追加した。

P1-2(必須): fallback marker が body hash のみで衝突しうる問題

CONTROLLED_EXEC_MARKER 環境変数が未設定の場合の fallback marker が sha256(body)[:32] のみで、
repository / issue number を含まず、同一 body が異なる Issue へ投稿された場合に marker が
衝突し得た。

repo + issue_number + body(NUL 区切り)のハッシュへ強化し、
TestExecMarkerInjection::test_fallback_marker_differs_across_issue_numbers_for_same_body /
test_fallback_marker_differs_across_repos_for_same_body_and_issue で同一 body でも
repo/issue_number が異なれば marker が異なることを検証した。

Checks

検証チェックリスト(すべて完了済み):

  • pnpm typecheck(型検査 完了)
  • pnpm lint(Lint 完了)
  • pnpm test(テスト 完了)
  • pnpm build(ビルド 完了)

fixed base SHA: 4ab8ec2d9495638695ef774fb8737b509585f492(実装着手前に origin/main へ再確認済み。着手時点の origin/main HEAD は 7a458860d742fe5040d5fea244109efd5f0d4b03 で対象ファイルへの変更は含まれていなかった)

Changed Files(変更ファイル一覧)

  • scripts/agent-guards/controlled_skill_mutation_policy.py — ISOLATION_ISSUE_COMMENT_REQUEST_V1 bounded schema と validate_isolation_issue_comment_request() を追加
  • .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py — materialize_isolation_issue_comment_request() 追加、_post_github_comment() を新経路へ置き換え。fix_delta で build_isolation_issue_comment_request() producer 分離・symlink/TOCTOU 安全な atomic write・fallback marker 強化を追加
  • .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py — raw gh argv 前提だった既存テスト(TestGhBodyFile / TestIntegration の一部 / TestRepoFlag / TestExecMarkerInjection)を新経路へ追随、TestMaterializeIsolationIssueCommentRequest を追加。fix_delta で TestMaterializerSymlinkSafety(8テスト)・producer/consumer分離に伴う既存テスト更新・fallback marker 衝突回避テストを追加
  • scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py — TestIsolationIssueCommentRequestSchema を追加
  • scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py(新規) — fake gh による no-live-mutation integration test(positive + 8 negative fixtures)。fix_delta で新シグネチャへ追随
  • .codex/rules/default.rules — controlled_skill_mutation_exec.py の allow エントリ追加
  • docs/dev/agent-skill-boundaries.md — 新セクション追加(bridge 設計の説明)。fix_delta で producer/consumer 分離・symlink/TOCTOU 安全性・fallback marker 強化のセクションを追加
  • docs/dev/hook-boundaries.md — Codex/Claude parity 記述の更新

AC 達成状況

  • AC1: ISOLATION_ISSUE_COMMENT_REQUEST_V1 bounded schema(閉じたキーのみ)を定義
  • AC2: parent 側 materializer 関数が request を issue-scoped namespace へ書き込み、exact argv で controlled executor を起動
  • AC3: publish_termination_report.py::_post_github_comment の raw gh issue comment 呼び出しを上記経路へ置き換え
  • AC4: fake gh による no-live-mutation 統合テスト(positive/negative 両方)を追加
  • AC5: .codex/rules/default.rules に allow エントリを追加(codex execpolicy check で decision: allow を確認済み)
  • AC6: pnpm typecheck / pnpm lint / pnpm test / pnpm build 全て pass
  • AC7: docs/dev/agent-skill-boundaries.md / docs/dev/hook-boundaries.md を更新

Scope Delta 対応

Issue 本文の Scope Delta(2026-07-19)に従い、.claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py(Allowed Paths へ追加済み)の既存テスト約20件を削除せず、新しい呼び出し経路(materializer 経由の controlled_skill_mutation_exec.py 起動)に合わせて更新した。既存テストが検証していた intent(body-file 経由の投稿・repo flag・exec marker injection・integration path)は維持し、経路のみ更新した。

Verification Commands

$ rg -n "ISOLATION_ISSUE_COMMENT_REQUEST_V1" scripts/agent-guards/controlled_skill_mutation_policy.py
# match found (AC1)

$ rg -n "def materialize_isolation_issue_comment_request" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# match found (AC2)

$ rg -n "def build_isolation_issue_comment_request" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# match found (fix_delta P1-1)

$ rg -n "_write_json_atomic_symlink_safe\|MaterializeSecurityError" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# match found (fix_delta P0)

$ test -f scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
# exit 0 (AC4)

$ rg -n "controlled_skill_mutation_exec.py" .codex/rules/default.rules
# match found (AC5)

$ rg -n "isolation_issue_comment_request" docs/dev/agent-skill-boundaries.md
# match found (AC7)

$ pnpm typecheck   # PASS
$ pnpm lint        # PASS
$ pnpm test        # PASS (97 files / 1580 tests)
$ pnpm build       # PASS

$ uv run --locked ruff check --select E,F --ignore E402 .claude/scripts scripts schemas .claude/skills
# All checks passed (CI-equivalent invocation)

$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py -q
# 71 passed (fix_delta: was ~60 before, +11 new symlink-safety / fallback-marker-collision / producer-consumer-separation tests)

$ uv run pytest scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py -q
# 11 passed

$ uv run pytest scripts/agent-guards/tests/ -q
# 1038 passed, 1 skipped

$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -q
# 1516 passed

$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q
# 21 passed

Schema Change Applicability

  • decision: schema_change
  • reason: 本 PR は ISOLATION_ISSUE_COMMENT_REQUEST_V1 という新規 bounded schema を scripts/agent-guards/controlled_skill_mutation_policy.py に追加する(docs/dev/schema-governance.md の schema_change 判定条件「新規 schema が追加される」に該当)。既存 schema の変更ではなく新規追加のため、既存 consumer への破壊的影響はない。fix_delta による materialize_isolation_issue_comment_request() のシグネチャ変更(request / expected_issue_number / expected_repo)は同一 PR 内の全 consumer(テストファイルを含む)を追随済みで、本 PR 外部の既存 consumer は存在しない。

Schema Consumer Inventory

変更対象 schema: ISOLATION_ISSUE_COMMENT_REQUEST_V1

before/after 差分:

# before
# 本 schema は存在しなかった(新規追加)。

# after
# ISOLATION_ISSUE_COMMENT_REQUEST_V1(scripts/agent-guards/controlled_skill_mutation_policy.py に定義)
# 閉じたフィールド集合: schema / issue_number / repo / comment_body / marker
# producer: build_isolation_issue_comment_request()(isolation worktree agent の生成物と同形の dict を組み立てる)
# validator: validate_isolation_issue_comment_request()(scripts/agent-guards/controlled_skill_mutation_policy.py)
# consumer: materialize_isolation_issue_comment_request(request=..., expected_issue_number=..., expected_repo=...)
#           (fix_delta P1-1 で producer から独立した consumer シグネチャへ変更)

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

rg -li --hidden --no-ignore "isolation_issue_comment_request" .
scripts/agent-guards/controlled_skill_mutation_policy.py
scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
.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

Consumer 更新状況:

Consumer ファイル 更新有無 備考
scripts/agent-guards/controlled_skill_mutation_policy.py(ISOLATION_ISSUE_COMMENT_REQUEST_SCHEMA 定数、validate_isolation_issue_comment_request()) 更新済み(producer/validator の定義そのもの、本 PR で新規追加) schema の定義元。fix_delta での変更なし
.claude/skills/issue-refinement-loop/scripts/publish_termination_report.py(materialize_isolation_issue_comment_request() が validate_isolation_issue_comment_request() を呼び出し、検証済み request を issue-scoped namespace へ書き込む) 更新済み(fix_delta でシグネチャを request/expected_issue_number/expected_repo へ変更し、producer build_isolation_issue_comment_request() を分離。書き込みも symlink/TOCTOU 安全な atomic write へ変更) 新規 schema のため既存の呼び出し規約からの破壊的変更はない(PR 内で完結)
scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py(TestIsolationIssueCommentRequestSchema) 更新済み(本 PR で新規追加) schema validator の contract test
scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py(fake gh no-live-mutation integration test) 更新済み(fix_delta で新シグネチャへ全 11 テスト追随) positive + 8 negative fixtures
.claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py(TestMaterializeIsolationIssueCommentRequest ほか) 更新済み(fix_delta で新シグネチャへ追随、TestMaterializerSymlinkSafety 8テスト・fallback marker 衝突回避2テストを新規追加) consumer 側の contract test
docs/dev/agent-skill-boundaries.md 更新済み(fix_delta のセクションを新規追加) ドキュメント consumer

Compatibility Decision(互換性判断)

  • change_type: additive
  • compatibility: backward_compatible
  • migration_required: no
  • migration_or_followup: N/A
  • reason: ISOLATION_ISSUE_COMMENT_REQUEST_V1 は本 PR で新規追加される schema であり、既存 schema(issue_contract/v1 等)のフィールド・型・意味を一切変更しない。既存 consumer は全て本 PR 内でこの新規 schema 用に新規追加されたものであり、破壊的変更の対象となる既存呼び出し元は存在しない。fix_delta による consumer シグネチャ変更も同一 PR 内の全呼び出し元を追随済み。

Safety Claim Matrix

本 PR は .claude/skills/**(issue-refinement-loop)配下と .codex/rules/default.rules、scripts/agent-guards/controlled_skill_mutation_policy.py を変更しており、.claude/skills/pr-review-judge/references/safety-claim-gate.md の safety-sensitive 判定に該当するため、以下の Safety Claim Matrix を記載する。

Claim Implemented? Not controlled Evidence Follow-up
isolation worktree agent は本ブリッジ内で gh を直接呼ばず、GitHub 認証情報も保持しない。返すのは ISOLATION_ISSUE_COMMENT_REQUEST_V1 の閉じたフィールド(schema/issue_number/repo/comment_body/marker)のみ Yes N/A scripts/agent-guards/controlled_skill_mutation_policy.py の ISOLATION_ISSUE_COMMENT_REQUEST_ALLOWED_KEYS(4キーの frozenset)と validate_isolation_issue_comment_request() が非許可キーを isolation_issue_comment_request_unknown_fields で拒否する実装 n/a
canonical main root 上の materializer(materialize_isolation_issue_comment_request())が bounded request を検証してから issue-scoped namespace(artifacts/{issue_number}/issue-metadata/issue_comment.publish/)へ書き込む。検証(閉じたキー集合・exact schema・issue_number/repo 一致・comment_body/marker 非空・marker が comment_body に埋め込まれているか)は namespace ディレクトリ作成・ファイル書き込みより前に実行される Yes N/A publish_termination_report.py::materialize_isolation_issue_comment_request() 内で validate_isolation_issue_comment_request() の呼び出しが namespace への一切のファイルシステム操作より前に置かれている(該当関数の実装順序) n/a
materializer の書き込みは symlink/hardlink 追従・TOCTOU に対して安全である。事前に仕込まれた symlink(namespace 祖先 / 出力ファイル自体)や hardlink は fail-closed で reject され、既存の正当なファイルの内容は一切変更されない Yes N/A _write_json_atomic_symlink_safe() / _resolve_namespace_component_nofollow()(dir_fd 相対の mkdir/stat/open(O_NOFOLLOW) + O_CREAT|O_EXCL 一時ファイル + rename() atomic replace)。TestMaterializerSymlinkSafety(8テスト、target/sentinel 内容の不変性を明示的に assert) n/a
materialize_isolation_issue_comment_request() の validator 呼び出しは実際に外部境界オブジェクトを検証しており、コード上恒真ではない Yes N/A シグネチャが request: object を受け取り、呼び出し元(production では build_isolation_issue_comment_request())が別関数で構築した dict を渡す。unknown field / schema mismatch / repo mismatch / issue mismatch の拒否テストが production entry point 経由で通ることを確認済み n/a
_post_github_comment() が保持していた唯一の raw gh issue comment production 呼び出しは本 PR で完全に置き換えられ、GitHub への投稿は controlled_skill_mutation_exec.py --command-id issue_comment.publish の subprocess 起動のみを経由する Yes N/A diff(subprocess.run(["gh", "issue", "comment", ...]) の削除、subprocess.run([sys.executable, CONTROLLED_SKILL_MUTATION_EXEC_SCRIPT, "--command-id", "issue_comment.publish", ...]) への置換)。fake gh を使う integration test(test_isolation_issue_comment_publish_bridge.py, positive + 8 negative fixtures)が live mutation なしでこの経路を検証 n/a
controlled_skill_mutation_exec.py 本体(command_id whitelist・repo/env binding・input-file namespace 検証・module realpath 検証・idempotency・postcondition といった実行時強制ロジック)は本 PR で一切変更していない。本 PR が追加したのは、既存の同一 executor へ渡す前段の bounded producer/materializer のみ Yes N/A git diff origin/main...HEAD --stat の変更ファイル一覧に controlled_skill_mutation_exec.py が含まれないことで確認可能(変更対象は controlled_skill_mutation_policy.py と publish_termination_report.py のみ) n/a
.codex/rules/default.rules の新規 allow エントリは uv run python3 scripts/agent-guards/controlled_skill_mutation_exec.py の exact prefix のみを許可し、Codex に raw gh 呼び出しや他の git mutation 権限を新規付与しない。これは .claude/settings.json の Claude 側既存 wildcard allow(同一 executor 対象)と同じ実行主体(single controlled executor)を指すのみで、実行時の強制(command_id whitelist 等)は executor 内部でのみ行われる(ルール自体はコメントで明記) Yes N/A .codex/rules/default.rules diff の prefix_rule(pattern = ["uv", "run", "python3", "scripts/agent-guards/controlled_skill_mutation_exec.py"], decision = "allow", ...) と直上のコメント("Runtime binding checks ... all happen inside the executor itself -- this static rule only allows the exact uv run python3 <script> invocation prefix") n/a

Allowed Paths 遵守

変更ファイルは Issue #1633 の Allowed Paths(Scope Delta で拡張済み)と完全一致:

  • scripts/agent-guards/controlled_skill_mutation_exec.py(変更なし、既存 issue_comment.publish lane をそのまま再利用)
  • 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

Allowed Paths 外の変更なし(fix_delta 対応もこの範囲内で完結)。

Notes

補足事項:

🤖 Generated with Claude Code(このプルリクエストは Claude Code によって生成されました)

…publish controlled mutation lane へ接続する (#1633)

isolation worktree agent が生成する bounded Issue comment request
(issue_number/repo/comment_body/marker の閉じたフィールドのみ)を、
canonical main root 上の 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 へ投稿する経路へ、
publish_termination_report.py::_post_github_comment の raw `gh issue comment`
呼び出しを置き換える。

- controlled_skill_mutation_policy.py に ISOLATION_ISSUE_COMMENT_REQUEST_V1
  bounded schema と validate_isolation_issue_comment_request() を追加
- publish_termination_report.py に materialize_isolation_issue_comment_request()
  を追加し、_post_github_comment() を新経路へ置き換え
- 既存 test_publish_termination_report.py の raw gh argv 前提テスト(約20件)を
  新しい呼び出し経路(materializer 経由の controlled_skill_mutation_exec.py 起動)
  に追随させ、body-file 経由投稿・repo flag・exec marker injection・
  integration path の検証意図は維持
- fake gh による no-live-mutation integration test
  (test_isolation_issue_comment_publish_bridge.py)を追加
- .codex/rules/default.rules に controlled_skill_mutation_exec.py の
  allow エントリを追加し、Claude/Codex 間の parity gap を解消
- docs/dev/agent-skill-boundaries.md / docs/dev/hook-boundaries.md を更新

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

Copy link
Copy Markdown
Contributor

Preview URL

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

The preview will be removed when this PR is closed.

squne121 and others added 2 commits July 19, 2026 18:37
…)違反を解消する (#1633)

CI の python-test job で docs/dev/agent-skill-boundaries.md:1560 の
uv run python3 scripts/agent-guards/controlled_skill_mutation_exec.py ...
例示コマンドが check_python_invocation_policy.py の
uv_run_python_script_no_locked に抵触していたため、同ファイル内の
既存の同種例示(line 1383)と同じ形式に合わせ --locked を追加した。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…査を通す (#1633)

新設した非 canonical な見出し(`## isolation worktree agent の Issue comment
request bridge` 等 4 見出し)が heading_policy SSOT に登録されていないため
prose block として日本語比率検査対象に残り、CI の
「PR Body Japanese Check / Check changed Markdown files」ジョブ
(変更された Markdown ファイル全文を per-block 検査する既存ジョブ)で
FAIL していた。各見出しに日本語併記を追加して閾値 0.1 を満たすようにした。

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

@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.

レビュー結果

Issue #1633 の contract、current head、CI、Allowed Paths、AC1〜AC7、Safety Claim Matrix、Schema Change Applicability / Schema Consumer Inventory を再照合しました。すべて充足しており、blocker はありません。

  • CI: all_pass(typecheck/lint/test/build/e2e/python-test/actionlint/node-backed-hook-tests 全 green)
  • Mergeability: MERGEABLE / CLEAN
  • Allowed Paths: 変更8ファイルは Issue #1633 の Allowed Paths(Scope Delta 込み)と完全一致
  • AC1〜AC7: 全て実コード照合で確認済み
  • Safety Claim Matrix: 5 claim すべて Evidence と一致
  • Schema Change Applicability: schema_change(additive / backward_compatible)
  • Schema Consumer Inventory: 6 consumer を独立確認、捏造なし
LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "11758655ad8e49f65db977abcbc1c03c7ca60dc8"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status
    changed_files:
      - .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
      - .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py
      - .codex/rules/default.rules
      - docs/dev/agent-skill-boundaries.md
      - docs/dev/hook-boundaries.md
      - scripts/agent-guards/controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
  allowed_paths_gate_source: review_subagent

@squne121
squne121 marked this pull request as ready for review July 19, 2026 10:10

@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.

レビュー結果(head 更新後の再確認)

PR head が main merge commit(2fd758d31d6538bb4df21efab7466d90a6d938d6)へ更新されたため、古い review(head 11758655)を再利用せず、新しい head に対して再検証しました。merge の第一親は前回 APPROVE 済みの head と完全一致し、取り込まれた差分は無関係の #1603 関連ファイルのみで、本 PR 自身の実装ファイルへの変更はありません。CI は現行 head で all_pass、Allowed Paths・AC1〜AC7・Safety Claim Matrix・Schema Consumer Inventory すべて充足を再確認しました。

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "2fd758d31d6538bb4df21efab7466d90a6d938d6"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
      - .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
      - .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py
      - .codex/rules/default.rules
      - docs/dev/agent-skill-boundaries.md
      - docs/dev/hook-boundaries.md
      - scripts/agent-guards/controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
  allowed_paths_gate_source: review_subagent

@squne121

Copy link
Copy Markdown
Owner Author

判定

REQUEST CHANGES — マージ非推奨

現行 head 2fd758d31d6538bb4df21efab7466d90a6d938d6 のCIは成功しており、変更8ファイルも Issue #1633 の Allowed Paths 内です。既存レビューも2回 APPROVE しています。

しかし、security-sensitive な materializer に executor 到達前の任意ファイル上書き経路があります。現在のテストはこの欠陥を検出しません。


Findings

P0 — materializer が予測可能なパスを無防備に write_text() しており、symlink 経由で任意ファイルを上書きできる

対象:

namespace_dir.mkdir(parents=True, exist_ok=True)

out_path = namespace_dir / "issue_comment_publish_input.json"
out_path.write_text(...)

materializer は次の固定パスに、通常のパスベースI/Oで直接書き込みます。

artifacts/{issue_number}/issue-metadata/issue_comment.publish/
  issue_comment_publish_input.json

この時点では以下を確認していません。

  • artifacts/{issue_number} から out_path までに symlink がないこと
  • out_path 自体が symlink でないこと
  • 既存ファイルが hardlink でないこと
  • 書き込み対象が安全な namespace 内の通常ファイルであること
  • 検査後にパスが差し替えられていないこと
  • 排他的・atomic に新規作成または置換されること

そのため、事前に例えば次を作れる主体がいれば、

issue_comment_publish_input.json -> ../../../../../.claude/settings.json

canonical main root 側の権限でリンク先が truncate・上書きされます。後段の controlled_skill_mutation_exec.py が symlink を拒否しても遅すぎます。ファイル破壊は executor 起動前に完了しています。

PRが追加した symlink negative test は、安全な実ファイルをmaterializeした後、別名のsymlinkをexecutorへ渡し、executorが拒否することだけを確認しています。materializerの出力パスを事前にsymlink化してからmaterializeするケースはありません。

これは単なる防御強化ではありません。CWE-59/CWE-61 が説明する典型的な link-following arbitrary-file-write に該当します。MITREも、意図した管理領域外を指すリンクをファイルAPIが辿ることで、未認可ファイルの書き込み・破壊が可能になるとしています。(CWE)

必須修正

materializer 自身が executor と同等以上の filesystem boundary を、書き込み前かつ書き込み操作と不可分な形で強制してください。

最低限:

  1. namespace の各祖先要素を lstat() し、symlink・非directoryを拒否
  2. 出力ファイルを symlink 非追従で開く
  3. 既存出力を直接 truncate しない
  4. 同一directory内に安全な一時ファイルを作り、flush/fsync後にatomic replace
  5. 一時ファイル作成にも排他的作成とlink防止を適用
  6. hardlink / unexpected link count を拒否
  7. Windows junction/reparse pointも実行環境に応じて考慮
  8. エラー時に既存の正当なinput fileを破壊しない

Linux限定なら、dir_fd と O_NOFOLLOW、O_CREAT | O_EXCL を組み合わせ、directory descriptorを基準に操作する設計が妥当です。単に resolve() や is_symlink() を先に呼ぶだけでは、検査と利用の間を差し替えられるTOCTOUが残ります。CWE-363もこの検査・利用間のlink差し替えを明示しています。(CWE)

必須テスト

少なくとも以下をmaterializer単体またはbridge統合テストへ追加してください。

def test_materializer_rejects_preexisting_output_symlink_without_touching_target():
    # target に sentinel を保存
    # predictable out_path を target への symlink にする
    # materialize を実行
    # fail closed
    # target の内容が完全に不変

加えて:

  • namespace directory 自体がsymlink
  • 中間directoryがsymlink
  • 出力がhardlink
  • 出力がdirectory/FIFO/device
  • concurrent replacement
  • materialization失敗時に既存正当ファイルが不変

P1 — 「bounded requestをparentが検証する」という境界が実装上存在せず、validatorが自己生成データを検証している

Issue #1633 は isolation worktree agent が生成する閉じたrequestを、parent-owned materializerが受け取り検証する契約です。

ところが実装はrequest objectを受け取りません。

def materialize_isolation_issue_comment_request(
    *,
    issue_number: int,
    repo: str,
    comment_body: str,
    marker: str,
    ...
):
    request = {
        "schema": CONSTANT,
        "issue_number": issue_number,
        "repo": repo,
        "comment_body": comment_body,
        "marker": marker,
    }
    validate_isolation_issue_comment_request(
        request, issue_number, repo
    )

つまり:

  • schema はparent自身が正しい定数を埋める
  • requestの issue_number と比較対象 issue_number は同じ引数
  • requestの repo と比較対象 repo も同じ引数
  • unknown field は関数シグネチャ上そもそも渡せない

このため、validatorの主要な境界チェックは実質的に恒真です。閉じたschemaを「isolation agentが生成したrequest」に対して検証しているのではなく、parentが再構築したdictを検証しています。

さらに現在の唯一のproduction callerである _post_github_comment() は、isolation agentからrequestを受領せず、自身でbodyとmarkerを生成しています。したがってPR説明の「producer → parent delegation → materializer」という構造と、実際のruntime data flowが一致していません。

影響

現時点の呼び出し元だけを見れば直ちにexploitになるとは限りません。しかし、次の問題があります。

  • AC1/AC2で主張するtrust-boundary enforcementが実装されていない
  • 将来agent outputを接続した際、どこでuntrusted requestをdeserialize・validateするか不明
  • schema validatorのテストがproduction boundaryを証明しない
  • Safety Claim Matrixの「isolation agentが閉じたdictのみを返す」というclaimがコード上で強制されていない

必須修正

APIを実際の境界に合わせるべきです。

def materialize_isolation_issue_comment_request(
    *,
    request: object,
    expected_issue_number: int,
    expected_repo: str,
    project_root: Path | None = None,
) -> tuple[str | None, str]:
    err = validate_isolation_issue_comment_request(
        request,
        expected_issue_number,
        expected_repo,
    )

検証後にのみフィールドを抽出し、executor inputへ変換してください。

validated = cast(dict[str, object], request)

materialized = {
    "schema": ISSUE_COMMENT_PUBLISH_INPUT_V1,
    "issue_number": validated["issue_number"],
    "comment_body": validated["comment_body"],
    "marker": validated["marker"],
}

production callerにも明示的なrequest生成点を置き、producerとconsumerを分離してください。

request = build_isolation_issue_comment_request(...)
materialize_isolation_issue_comment_request(
    request=request,
    expected_issue_number=issue_number,
    expected_repo=repo,
)

これにより、unknown field、schema mismatch、repo mismatch、issue mismatchのテストが実際のproduction entry pointを通るようになります。


P1 — fallback marker が body hashのみで決まり、同一bodyの別Issue・別実行で衝突する

環境変数 CONTROLLED_EXEC_MARKER がない場合、markerは次のように生成されます。

content_hash = sha256(body).hexdigest()[:32]
marker = CONTROLLED_EXEC_MARKER:{content_hash}

markerに以下が含まれません。

  • repository
  • issue number
  • command ID
  • execution/session ID
  • request schema version

同じbodyなら、異なるIssueでも同じmarkerになります。executorの検索がissue-scopedなら直接のcross-issue誤判定は抑えられますが、markerを証跡・監査・artifact correlation keyとして扱う設計では識別能力が不足します。

より問題なのは、同一Issueへ意図的に同じ本文を再投稿する正当な操作が、既存投稿のidempotent retryと区別できない点です。これは「同一intentの再試行を一度だけ実行する」のか、「同じcontentは永久に一度しか投稿しない」のかというsemanticsを暗黙に固定します。

修正案

fallback markerを少なくとも次から導出してください。

schema_version
command_id
repo
issue_number
body_sha256
stable operation id

ただしoperation IDを毎回ランダム生成するとretry idempotencyが失われます。上位orchestratorが安定したexecution IDを供給し、それをbounded requestに含めるのが適切です。現在の固定schemaを変更できないなら、少なくとも repo + issue_number + body をhash対象に含め、制約をdocsへ明記してください。


テスト評価

追加テストの量は多く、executor側の以下は確認されています。

  • absolute input path拒否
  • .. traversal拒否
  • symlink input拒否
  • schema mismatch拒否
  • repo/issue mismatch拒否
  • duplicate marker拒否
  • marker/body conflict拒否
  • fake remoteによるidempotent retry

ただし、安全性の中心であるはずの materializerの書き込みそのものは、happy path中心です。PR本文の「negative fixtures」がbridge全体を保護しているように見えますが、実際には多くがmaterialization完了後のexecutor検証です。

したがって、現CIがgreenであることは今回のblockerを否定しません。CIは現行headで成功していますが、危険なpreconditionを再現するテストが存在しないためです。


良い点

以下の方向性自体は妥当です。

  • raw gh issue comment を共有controlled executorへ集約
  • shellを介さないargv-list実行
  • explicit repo/issue binding
  • marker readbackとidempotencyの既存lane再利用
  • Codex側の権限をraw gh ではなくsingle executor prefixへ限定
  • Allowed Pathsとdocumentationの整合
  • current headに対するCI green

.codex/rules/default.rules の追加も、静的ruleだけをsecurity boundaryと誤認せず、runtime executorを実際のenforcement pointとして説明している点は適切です。

ただし、その設計思想と矛盾して、executor前段のmaterializerが無防備なfilesystem mutationを行っています。


修正後の受入条件

  1. materializerが既存symlink・中間symlink・hardlinkを安全に拒否する
  2. rejection前後でリンク先・既存正当ファイルが一切変更されない
  3. TOCTOUを避けるdescriptor-relativeまたは同等の安全な書き込み方式を採用する
  4. bounded request objectをproduction boundaryで直接検証する
  5. unknown field/schema/repo/issue mismatchのテストがmaterializer entry pointを通る
  6. marker fallbackのscope/idempotency semanticsを明示し、必要なら生成材料を強化する
  7. 現行の全CIに加え、上記adversarial testsがpassする

現状は P0 1件、P1 2件。P0修正まではmerge不可です。

…cer/consumer分離・fallbackマーカー強化

- P0: materialize_isolation_issue_comment_request() の書き込みを dir_fd 相対の
  mkdir/stat/open(O_NOFOLLOW) + O_CREAT|O_EXCL 一時ファイル + rename() atomic
  replace に置き換え、事前に仕込まれた symlink/hardlink/directory/FIFO への
  追従・TOCTOU を fail-closed で拒否するようにした(CWE-59/61/363対応)。
- P1-1: materialize_isolation_issue_comment_request() のシグネチャを
  request/expected_issue_number/expected_repo へ変更し、
  build_isolation_issue_comment_request() を producer として分離。
  validator の恒真化を解消し、_post_github_comment もこの新APIに追従。
- P1-2: CONTROLLED_EXEC_MARKER 未設定時の fallback marker を
  repo + issue_number + body のハッシュへ強化し、異なる repo/issue 間での
  marker 衝突を防止。

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

Copy link
Copy Markdown
Owner Author

レビューコメントで指摘された fix_delta(P0 マージブロッカー1件・P1必須2件)をすべて解消しました(head 77b86457865e4e275ac5b6fb501e07ac24e58a39)。

対応内容

P0(マージ阻害の重大指摘): materializer の symlink/TOCTOU 脆弱性

materialize_isolation_issue_comment_request() の書き込みを、dir_fd 相対の os.mkdir/os.stat(follow_symlinks=False)/os.open(O_DIRECTORY|O_NOFOLLOW) による namespace 段階的解決 + O_CREAT|O_EXCL|O_NOFOLLOW 一時ファイル + os.rename(src_dir_fd=..., dst_dir_fd=...) atomic replace に置き換えました。namespace 祖先ディレクトリの symlink・出力ファイル自体の symlink/hardlink/directory/FIFO はすべて fail-closed で reject し、既存の正当なファイルの内容は変更しません。

新規テスト(TestMaterializerSymlinkSafety、8テスト): 出力 symlink(target 内容不変を assert)/ namespace directory 自体が symlink / 中間 directory が symlink / 出力が hardlink / 出力が directory / 出力が FIFO / concurrent replacement 相当 / 失敗時に既存の正当な入力ファイルを破壊しない。

P1-1(必須): bounded request の検証境界がコード上恒真だった問題

materialize_isolation_issue_comment_request(*, request: object, expected_issue_number: int, expected_repo: str, project_root=None) へシグネチャを変更し、producer build_isolation_issue_comment_request(*, issue_number, repo, comment_body, marker) を分離しました。_post_github_comment() は producer 経由で request を構築してから渡すよう更新し、unknown field / schema mismatch / repo mismatch / issue mismatch / non-dict request の拒否テストを production entry point 経由で新規追加しています。

P1-2(必須): fallback marker が body hash のみで衝突しうる問題

CONTROLLED_EXEC_MARKER 未設定時の fallback marker を repo + issue_number + body(NUL区切り)のハッシュへ強化しました。同一 body でも異なる repo/issue へ投稿する場合に marker が衝突しないことをテストで検証しています。

検証結果

以下のコマンドをすべて実行し、全件 PASS を確認しました:

$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py -q
71 passed

$ uv run pytest scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py -q
11 passed

$ uv run pytest scripts/agent-guards/tests/ -q
1038 passed, 1 skipped

$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -q
1516 passed

$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py -q
21 passed

$ uv run --locked ruff check --select E,F --ignore E402 .claude/scripts scripts schemas .claude/skills
All checks passed (CI と同一 invocation)

$ pnpm typecheck && pnpm lint && pnpm test && pnpm build
全て PASS(pnpm test: 97 files / 1580 tests)

変更は既存の Allowed Paths(.claude/skills/issue-refinement-loop/scripts/publish_termination_report.py / .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py / scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py / docs/dev/agent-skill-boundaries.md)内で完結しています。PR 本文も上記対応内容を反映して更新しました。

@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.

レビュー結果(fix_delta 反映後の再確認)

OWNER の REQUEST_CHANGES レビュー(symlink/TOCTOU 脆弱性、bounded request 検証境界、fallback marker 衝突の3点)に対する修正(head 77b86457865e4e275ac5b6fb501e07ac24e58a39)を独立に再検証しました。

  • P0(symlink/TOCTOU): _resolve_namespace_component_nofollow / _write_json_atomic_symlink_safe のコードを直接確認。namespace各祖先要素のsymlink拒否(os.mkdir(dir_fd=...) + os.stat(follow_symlinks=False))、出力ファイルの O_CREAT|O_EXCL|O_NOFOLLOW、fsync 後の os.rename(src_dir_fd=..., dst_dir_fd=...) によるatomic replace、hardlink拒否(st_nlink != 1)を確認。新規 TestMaterializerSymlinkSafety(8テスト)が実際に事前symlink設置→materialize実行→fail closed→target内容不変、を検証していることをテスト本文で確認。
  • P1-1(検証境界): materialize_isolation_issue_comment_request(*, request: object, expected_issue_number, expected_repo, ...) へAPI変更され、validate_isolation_issue_comment_request() が外部提供オブジェクトを実際に検証。production caller _post_github_comment は新設の build_isolation_issue_comment_request() で生成したrequestを渡す構成に更新済み。
  • P1-2(fallback marker): f"{repo}\x00{issue_number}\x00{body}" をhash対象とする実装を確認。同一body・異なるissue/repoでmarkerが異なることを検証するテストも確認。
  • テストを自分で再実行: test_publish_termination_report.py 71 passed、test_isolation_issue_comment_publish_bridge.py 11 passed、test_controlled_skill_mutation_policy.py 45 passed。
  • CI: all_pass(現行head)。Allowed Paths: 8ファイル完全一致、逸脱なし。
LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "77b86457865e4e275ac5b6fb501e07ac24e58a39"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
      - .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
      - .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py
      - .codex/rules/default.rules
      - docs/dev/agent-skill-boundaries.md
      - docs/dev/hook-boundaries.md
      - scripts/agent-guards/controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_controlled_skill_mutation_policy.py
      - scripts/agent-guards/tests/test_isolation_issue_comment_publish_bridge.py
  allowed_paths_gate_source: review_subagent

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.

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

1 participant