Skip to content

fix: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する - #1349

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1343-fix-unauthorized-write-path
Jul 6, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1343-fix-unauthorized-write-path

Conversation

@squne121

@squne121 squne121 commented Jul 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • 契約実行ラッパー scripts/agent-guards/skill_runtime_exec.py の before/after repo-wide スナップショット比較が、.claude/worktrees/** や他 issue の .claude/artifacts/issue-refinement-loop/<他issue>/** への並行稼働セッション由来の書き込みを、実行コマンド自身の副作用と誤認して unauthorized_write_path で fail-close していたバグを修正した。
  • _snapshot_repo_paths / _find_unauthorized_repo_changes において、これら volatile な peer-session root を diff 対象から除外するようにした。allowed_write_roots 外への自プロセスの書き込み検出(.cache/outside.txt 等)は従来通り fail-close する(回帰なし)。

受け入れ条件の達成状況

  • AC1: 単一コマンド実行中に、無関係な別プロセスが .claude/worktrees/** 配下(実行コマンドの allowed_write_roots 外)へファイルを書き込んでも、skill_runtime_exec.py が unauthorized_write_path で fail しない(根拠: test_unrelated_process_write_to_worktrees_does_not_fail PASS)
  • AC2: 単一コマンド実行中に、無関係な別プロセスが .claude/artifacts/issue-refinement-loop/<別issue番号>/**(実行コマンドが対象とする issue 番号とは異なるディレクトリ)へファイルを書き込んでも、skill_runtime_exec.py が unauthorized_write_path で fail しない(根拠: test_unrelated_process_write_to_other_issue_artifacts_does_not_fail PASS)
  • AC3: 実行コマンド自身が allowed_write_roots 外(ただし .claude/worktrees/** および .claude/artifacts/issue-refinement-loop/** 等の volatile peer-session root を除く)へ実際に書き込んだ場合は、従来どおり unauthorized_write_path で fail-close する(回帰なし)(根拠: test_self_write_outside_allowed_roots_still_fails PASS)
  • AC4: 実行コマンド自身が allowed_write_roots 内へ正当に書き込んだ場合は、従来どおり成功する(回帰なし)(根拠: test_self_write_inside_allowed_roots_still_succeeds PASS)
  • AC5: 実行コマンド自身が volatile peer-session root(.claude/worktrees/** / .claude/artifacts/issue-refinement-loop/**)へ allowed_write_roots 外の書き込みを行った場合、本 Issue の race-tolerant hotfix の範囲では検出されないことが既知の制限としてテストで明示されている(根拠: test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode PASS、test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode PASS。strict attribution は別Issueのスコープ)

検証コマンド結果

  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py(6件 PASS、AC1〜AC5 対応。iteration 2 で AC5 用の新規2件を追加)
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py(既存20件 PASS、回帰なし)
  • uv run --locked pytest scripts/agent-guards/tests/(既存 + 新規 全475件 PASS)
  • ruff check --ignore E402(プロジェクト CI 方針と同一設定で警告なし)
  • pnpm typecheck / pnpm lint / pnpm test / pnpm build(TypeScript ソース非該当のため未実行。Python スクリプトのみの変更)

Allowed Paths 遵守

Checks

  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py(6件 PASS)
  • uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py(既存20件 PASS、回帰なし)
  • uv run --locked pytest scripts/agent-guards/tests/(既存 + 新規 全475件 PASS)
  • ruff check --ignore E402(プロジェクト CI 方針と同一設定で警告なし)
  • pnpm typecheck / pnpm lint / pnpm test / pnpm build(TypeScript ソース非該当のため未実行。Python スクリプトのみの変更)

Schema Change Applicability

  • decision: not_schema_change
  • reason: producer-consumer 境界をまたぐ machine-readable contract のキー/フィールドは変更していない。skill_runtime_exec.py 内部の repo-wide diff 判定ロジックの挙動修正のみ。

Schema Consumer Inventory

N/A(not_schema_change のため)

Compatibility Decision(互換性判断)

本 PR は schema 変更を含まないため、以下は全て該当なしとする。

  • change_type: N/A
  • compatibility: N/A
  • migration_required: N/A
  • migration_or_followup: N/A
  • reason: schema 変更なし

Safety Claim Matrix

skill_runtime_exec.py は root checkout からの privileged コマンド実行時に unauthorized write path を検出する fail-closed guard であり、安全境界に触れるため本セクションを記載する。

Claim Implemented? Not controlled Evidence Follow-up
実行コマンド自身が allowed_write_roots 外(.claude/worktrees/** 以外の一般 repo path、例 .cache/**)へ書き込んだ場合、従来どおり unauthorized_write_path で fail-close する yes test_self_write_outside_allowed_roots_still_fails PASS(AC3) N/A
実行コマンド自身が allowed_write_roots 内へ正当に書き込んだ場合、従来どおり成功する yes test_self_write_inside_allowed_roots_still_succeeds PASS(AC4) N/A
無関係な peer session が .claude/worktrees/** へ書き込んでも誤って fail しない yes test_unrelated_process_write_to_worktrees_does_not_fail PASS(AC1) N/A
無関係な peer session が別 issue の .claude/artifacts/issue-refinement-loop/** へ書き込んでも誤って fail しない yes test_unrelated_process_write_to_other_issue_artifacts_does_not_fail PASS(AC2) N/A
【既知の制限(Known Limitation)】 実行コマンド自身が .claude/worktrees/** や他 issue の .claude/artifacts/issue-refinement-loop/** へ意図的に allowed_write_roots 外の書き込みを行った場合、その自己書き込みは検出されず成功してしまう no(意図的な設計判断・見落としではない) volatile peer-session root は AC1/AC2 を満たすために diff 対象から丸ごと除外しているため、その代償として同じ root への自プロセスの書き込みも構造的に区別できない。プロセス単位の厳密な attribution(syscall トレース等)は標準ライブラリのみの実装方針では対応しないと Issue #1343 の Out of Scope で明示されている test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode PASS、test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode PASS(AC5。2026-07-06 人間レビュー REQUEST_CHANGES を受け Option B として契約に明記) #1346(並列エージェント実行安全性の SSOT 化 follow-up)。strict attribution が必要になった場合は別途新規 Issue で扱う

記載ルール確認: 「無限定の safe / 完全な attribution」は主張していない。保証範囲は AC1〜AC5 の VC で検証された範囲(一般 repo path への self-write 検出は維持、volatile peer-session root への self-write 検出は既知の制限として本 PR の対象外)に限定している。

Notes

補足情報は以下のとおり。

Notes for Reviewer(レビュアー向け補足)

  • 2026-07-06: 人間(OWNER)による REQUEST_CHANGES(fix: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する #1349 (comment) )を受け、対応方針を決定した。
  • 指摘内容: _VOLATILE_PEER_SESSION_ROOT_RELS(.claude/worktrees と .claude/artifacts/issue-refinement-loop)を before/after スナップショット比較の監査対象から完全除外したことで、AC1/AC2(他プロセスの誤検知解消)は満たすが、実行コマンド自身がこれらの volatile root へ allowed_write_roots 外の書き込みをした場合も検出できなくなるという副作用が生じる。
  • 採用した対応方針(Option B、人間承認済み): strict attribution(プロセス単位の syscall トレース等)は実装しない。代わりに Issue 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する #1343 の契約を明示的に狭めた(本文更新・fresh contract snapshot go 発行済み)。
    • AC3: 保証範囲から volatile peer-session root を明示的に除外する記述に変更
    • AC5(新規): volatile peer-session root への自プロセス書き込みが検出されないことを「既知の制限」としてテストで明示
  • 本 iteration(2回目)で以下を実施した:
    • scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py に AC5 対応の新規テスト2件を追加(test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode / test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode)。既存4テスト(AC1〜AC4)は変更していない。
    • Safety Claim Matrix に既知の制限を明示的に追記(見落としではなく設計上の判断であることを明記)。
    • 本セクションに Option B 採用の経緯を追記。
  • 実装コードそのもの(skill_runtime_exec.py の _VOLATILE_PEER_SESSION_ROOT_RELS 除外ロジック)は変更していない(iteration 1 の実装が Option B の契約に既に合致していたため)。

skill_runtime_exec.py の before/after repo-wide snapshot 比較が、
.claude/worktrees/** や他 issue の
.claude/artifacts/issue-refinement-loop/<他issue>/** への
並行稼働セッション由来の書き込みを実行コマンド自身の副作用と誤認し、
unauthorized_write_path で誤って fail-close していた問題を修正する。

_snapshot_repo_paths / _find_unauthorized_repo_changes において、
これら volatile な peer-session root を diff 対象から除外することで、
無関係な同時書き込みを誤検知しないようにする。allowed_write_roots 外
への自プロセスの書き込み検出(.cache/outside.txt 等)は従来通り
fail-close する。

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

github-actions Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1349 closed).

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author
TEST_VERDICT:
  result: PASS
  mergeable: MERGEABLE
  merge_state_status: BEHIND
  branch_behind_main: true
  baseline_only: false
  verification_commands_pass: 4
  verification_commands_fail: 0
  verification_skipped_count: 0
  runtime_ac_results: []

検証結果レポート

Issue #1343: 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する

AC 確認コマンド 実行結果(要約) exit code 判定
AC1 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_unrelated_process_write_to_worktrees_does_not_fail 1 passed 0 PASS
AC2 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_unrelated_process_write_to_other_issue_artifacts_does_not_fail 1 passed 0 PASS
AC3 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_outside_allowed_roots_still_fails 1 passed 0 PASS
AC4 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_inside_allowed_roots_still_succeeds 1 passed 0 PASS

総合判定

  • 全 AC PASS: YES
  • FAIL した AC: なし
  • SKIP した AC: なし
  • human_review_required: NO
  • mergeable: MERGEABLE / merge_state_status: BEHIND(head が base より古いだけで CONFLICTING ではない)

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

PR Review: #1349 (Closes #1343)

判定根拠

  • Linked issue: Closes #1343(PR本文に明記)
  • TEST_VERDICT_MACHINE(test-runner, PR #1349コメント済み): AC1〜AC4 全 PASS、verification_skipped_count=0、mergeable=MERGEABLE、merge_state_status=BEHIND
  • wait_ci_checks.sh --required: build/typecheck/lint/test/python-test/validate-generated-artifact の6 required checks 全 SUCCESS
  • deploy-pr の失敗は GitHub Pages preview の asset liveness check 404 timeout であり、本PRの Allowed Paths(scripts/agent-guards/**のみ)とは無関係。required check 対象外、他PR(#1274)でも同種の散発失敗を確認。regression ではなく infra flake と判断(follow-up として記録、blocker としない)
  • Allowed Paths gate(review_subagent 独立再計算): scripts/agent-guards/skill_runtime_exec.py(modified)/ scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py(added)の2件のみで Issue #1343 Allowed Paths と完全一致 → status: ok
  • Safety Claim Matrix: 記載あり。safety-sensitive(fail-closed guard)。Not controlled 行に follow-up #1346 明記済みで bounded
  • PR本文 hygiene: required section 見出し(## 受け入れ条件の達成状況 等)が不足 → update_pr_body_hygiene 対象
  • mergeStateStatus: BEHIND + mergeable: MERGEABLE → update_branch 対象
LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "a52ea8f6efbf2cbd947b37303dfae2e0008ffeac"
  merge_ready: false
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "BEHIND"
  blockers: []
  required_auto_actions:
    - kind: update_branch
      executor: implementation-worker
      skill: implement-issue.update_branch
      blocking_merge_ready: true
      mechanical: true
      expected_head_sha: "a52ea8f6efbf2cbd947b37303dfae2e0008ffeac"
    - kind: update_pr_body_hygiene
      executor: implementation-worker
      skill: open-pr.update_pr
      blocking_merge_ready: true
      mechanical: true
  auto_fix_applied: []
  follow_up_issue_requests:
    - summary: "deploy-pr(GitHub Pages preview asset liveness check)が本PRのdiffと無関係に180sタイムアウト404で断続的に失敗する(他PRでも散発観測)。原因調査とflaky対策のfollow-up。"
      blocking_merge_ready: false
  allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
      - scripts/agent-guards/skill_runtime_exec.py
      - scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
    changed_file_records:
      - path: scripts/agent-guards/skill_runtime_exec.py
        status: modified
        previous_path: null
        source: git_diff_name_status_find_renames_z
        provenance_complete: true
      - path: scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
        status: added
        previous_path: null
        source: git_diff_name_status_find_renames_z
        provenance_complete: true
    audited_paths:
      - path: scripts/agent-guards/skill_runtime_exec.py
        path_role: filename
        source_record_index: 0
      - path: scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
        path_role: filename
        source_record_index: 1
    violations: []
  allowed_paths_gate_source: review_subagent

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author
TEST_VERDICT:
  result: PASS
  mergeable: MERGEABLE
  merge_state_status: CLEAN
  branch_behind_main: false
  baseline_only: false
  verification_commands_pass: 4
  verification_commands_fail: 0
  verification_skipped_count: 0
  runtime_ac_results: []

検証結果レポート(update_branch 後の再検証, head_sha: f459ce1)

Issue #1343: 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する

AC 確認コマンド 実行結果 exit code 判定
AC1 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_unrelated_process_write_to_worktrees_does_not_fail PASSED 0 PASS
AC2 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_unrelated_process_write_to_other_issue_artifacts_does_not_fail PASSED 0 PASS
AC3 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_outside_allowed_roots_still_fails PASSED 0 PASS
AC4 uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_inside_allowed_roots_still_succeeds PASSED 0 PASS

総合判定

  • 全 AC PASS: YES
  • FAIL した AC: なし
  • SKIP した AC: なし
  • human_review_required: NO
  • mergeable: MERGEABLE / merge_state_status: CLEAN(update_branch により BEHIND 解消)

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

PR Review: #1349 (Closes #1343) — re-review at head f459ce1

すべての findings は独立検証済み(worker 自己申告ではない):

  • Linked issue: Closes #1343 が PR 本文に明記
  • Head sha 一致: gh pr view --json headRefOid / git fetch origin pull/1349/head ともに f459ce156e442bdbbca81e3407699868d6219936
  • Allowed Paths gate(review_subagent 独立再計算): origin/main fetch 済み最新tip(72352c84ea963fa911b5dc27145057296c4a8257)と git merge-base origin/main <head> が完全一致(drift なし)。git diff --name-status -M で差分は scripts/agent-guards/skill_runtime_exec.py(modified)/ scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py(added)の2件のみ。Issue #1343 Allowed Paths と完全一致 → status: ok
  • PR本文 hygiene: ## 受け入れ条件の達成状況 / ## 検証コマンド結果 / ## Allowed Paths 遵守 セクション全て存在・記入済み
  • TEST_VERDICT_MACHINE(head f459ce1, update_branch 後): AC1〜AC4 全 PASS、verification_skipped_count=0、mergeable=MERGEABLE、merge_state_status=CLEAN
  • CI: wait_ci_checks.sh --required で6 required checks(build/typecheck/lint/test/python-test/validate-generated-artifact)全 SUCCESS
  • Safety Claim Matrix: 記載あり。safety-sensitive(fail-closed guard)。follow-up #1346 で bounded
  • Schema Change Applicability: not_schema_change(妥当)

前回要求された required_auto_actions(update_branch, update_pr_body_hygiene)は両方解消済み。blocker なし。

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "f459ce156e442bdbbca81e3407699868d6219936"
  merge_ready: true
  mergeability:
    mergeable: "MERGEABLE"
    merge_state_status: "CLEAN"
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests:
    - summary: "deploy-pr(GitHub Pages preview asset liveness check)が本PRのdiffと無関係に断続的に失敗する事象(#1349前回レビューで記録済み)。原因調査とflaky対策のfollow-up。"
      blocking_merge_ready: false
  allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
      - scripts/agent-guards/skill_runtime_exec.py
      - scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
    changed_file_records:
      - path: scripts/agent-guards/skill_runtime_exec.py
        status: modified
        previous_path: null
        source: git_diff_name_status_find_renames_z
        provenance_complete: true
      - path: scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
        status: added
        previous_path: null
        source: git_diff_name_status_find_renames_z
        provenance_complete: true
    audited_paths:
      - path: scripts/agent-guards/skill_runtime_exec.py
        path_role: filename
        source_record_index: 0
      - path: scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
        path_role: filename
        source_record_index: 1
    violations: []
    producer_role: review_subagent
    worker_report_used_as_canonical: false
  allowed_paths_gate_source: review_subagent

@squne121

squne121 commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。
PR #1349 は #1343 の誤検知を実用上かなり減らす方向ではありますが、現Issue契約に忠実に読むと unauthorized_write_path の fail-close 境界を弱めています。既存のPRレビューは merge_ready: true としていますが、私は「#1343 AC3 の保証範囲」と「PR実装が実際に除外している範囲」の不一致をブロッカー扱いします。既存レビューでは head f459ce156...、Allowed Paths一致、AC1〜AC4 PASS、required checks SUCCESS とされています。そこは確認済みです。

確認範囲

確認したのは、PR #1349 の本文・差分・コメント・レビュー、関連Issue #1343 / #1228 / #1236 / #1346 / #1338、リポジトリ内SSOT文書、CI状況、Python / Linux の外部仕様です。PRは open / draft、head は f459ce156e442bdbbca81e3407699868d6219936、変更ファイルは2件、追加299行・削除0行です。

P0: volatile root の blanket exclusion が AC3 を破っている

今回の実装は _VOLATILE_PEER_SESSION_ROOT_RELS として .claude/worktrees と .claude/artifacts/issue-refinement-loop を定義し、その配下を peer-session noise とみなしています。 そのうえで _snapshot_repo_paths() はこれらの root を os.walk() から丸ごと prune し、_find_unauthorized_repo_changes() でも git status 差分から同root配下を除外しています。

これは AC1/AC2 の「他プロセスの同時書き込みを誤検知しない」は満たします。しかし、#1343 の AC3 は「実行コマンド自身が allowed_write_roots 外へ実際に書き込んだ場合は fail-close」と要求しています。Issue本文では、プロセス単位の追跡・allowed rootへの事前スコープ限定・無関係path除外のいずれかを選ぶ余地はありますが、AC3自体は一般の outside write fail-close を求めています。

現実には、child が .claude/worktrees/issue-9999/self-write.txt や .claude/artifacts/issue-refinement-loop/1337/self-write.json を書いても、このPRの実装では snapshot と status の両方から消えるため検出できません。これは「誤検知修正」ではなく、特定の repo 内 mutable root を監査対象から外す変更です。

P0: テストは AC3 の弱いケースしか見ていない

新規テストは peer write を再現して success を確認していますが、peer writer は別プロセスではなく Python thread です。ファイルシステム drift の再現としては有効ですが、AC文言の「別プロセス」そのものではありません。

より重大なのは self-write の negative test が .cache/outside.txt だけである点です。テストfixtureの child は SKILL_RUNTIME_TEST_OUTSIDE_WRITE == "ignored" のときだけ .cache/outside.txt を書き、AC3テストもそのケースだけを fail-close 確認しています。 つまり、今回まさに除外対象にした .claude/worktrees/** と他Issue artifact root への child自身の不正書き込み は未検証です。

このPRの Safety Claim Matrix は「volatile peer-session root への self-write は検出されない」と正直に認めていますが、テスト名とAC3の表示は「outside allowed roots は従来どおり fail-close」という印象を残しています。現契約のままなら、ここは過剰主張です。

P0: #1228 / #1236 の artifact-only boundary と緊張している

docs/dev/agent-skill-boundaries.md の privileged runtime boundary は、preflight.run の allowed_write_roots を .claude/artifacts/issue-refinement-loop/{active_issue}/ に限定しています。さらに executor は trusted PATH、allowlist env、filesystem snapshot/postcondition により ignored/transient outside write と PATH poisoning を fail-close すると定義されています。

#1228 / PR #1231 でも、root no-worktree preflight を許可する代わりに exact argv / repo binding / direct preflight block / artifact root 外 write fail-close を維持した、と整理されています。 #1236 / PR #1242 も unauthorized write path postcondition を維持し、他Issue tmp write drift を検出する回帰テストを追加した流れです。

したがって、今回の「.claude/worktrees/** と .claude/artifacts/issue-refinement-loop/** を監査対象から外す」実装は、少なくとも strictな artifact-only boundary を維持しているとは言えません。許容するなら、#1343 の契約を「stdlib race-tolerant hotfix」として明示的に狭める必要があります。

外部仕様との照合

Python の subprocess.run() は child process の起動・終了・stdout/stderr・return code を扱うAPIであり、child process tree が書いたファイルパス一覧を返すものではありません。([Python documentation]1) そのため、現在の実装のような before/after snapshot は「プロセス起因の監査」ではなく「実行時間窓内の repo drift 検出」です。

また Python の os.walk() / os.listdir() は、walk/list中にファイルが追加・削除された場合に結果へ含まれるかが未規定です。並行 writer がある状況では、snapshot 自体が完全な監査証跡ではありません。([Python documentation]2)

inotify も安易な解ではありません。directory monitoring は再帰的ではなく、新規subdirectoryには追加watchが必要で、race window や event loss を考慮する必要があります。([man7.org]3) ([man7.org]3) strict attribution を本当にやるなら、Linuxでは strace -f で child process を追跡し、%file で filename を引数に取るsyscall群を捕捉する設計が候補になります。ただしこれは Linux / ptrace 依存、trace parser、secret-safe artifact handling、fallback時 fail-closed 方針を伴う別スコープです。([man7.org]4) ([man7.org]4)

修正方針

このPRは二択で整理するべきです。

Option A: strict attribution として直す

#1343 の AC3 を文字通り守るなら、child process tree の file write attribution を導入してください。最低限、以下が必要です。

- child が .claude/worktrees/** へ書いたら unauthorized_write_path
- child が .claude/artifacts/issue-refinement-loop/<other_issue>/** へ書いたら unauthorized_write_path
- tracer / parser / platform dependency が使えない場合は silent pass ではなく fail-closed または explicit unsupported
- trace artifact は secret-safe に保存・削除・redact

この場合、PRの実装は大きく変わるので #1349 の Allowed Paths だけで足りるか再確認が必要です。

Option B: race-tolerant hotfix として契約を狭める

標準ライブラリだけで誤検知を止める暫定策としてこのPRを入れるなら、#1343 / PR本文 / レビュー判定を次のように変更してください。

- AC3 の保証範囲は .cache/** や source tree 等の non-volatile outside path に限定する。
- .claude/worktrees/** / other issue artifact root への child self-write は unsupported / not controlled と明記する。
- strict attribution は #1346 ではなく、runtime guard 実装用の別Issueに分離する。
- Safety Claim Matrix とテスト名から「outside allowed roots 全般を維持」という表現を削る。

#1346 は良いfollow-upですが、現時点の#1346はSSOT・Issue template・Required Design Referencesの整備であり、skill_runtime_exec.py 自体の strict attribution は out of scope です。 したがって、#1346を理由に runtime gap を解消済み扱いするのは不可です。

追加すべきテスト

最低限、次を追加してください。

# strict mode なら fail を期待
test_self_write_to_worktrees_still_fails
test_self_write_to_other_issue_artifacts_still_fails

# race-tolerant hotfix なら xfail / known limitation として明示
test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode
test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode

# AC文言に合わせるなら thread ではなく subprocess peer writer
test_unrelated_subprocess_write_to_worktrees_does_not_fail
test_unrelated_subprocess_write_to_other_issue_artifacts_does_not_fail

既存の test_skill_runtime_preflight_no_worktree.py 系も回帰確認に含めるべきです。PR本文では全 agent-guards tests 473件 PASS とされていますが、今回のブロッカーは「通ったテストの範囲外」にあります。

GitHubレビュー文面案

REQUEST_CHANGES

#1349 は #1343 の false positive を減らす方向としては妥当ですが、現契約のままでは merge 不可です。

Blocker:
- `_VOLATILE_PEER_SESSION_ROOT_RELS` が `.claude/worktrees` と `.claude/artifacts/issue-refinement-loop` を repo drift 検出から丸ごと除外しているため、child 自身がそれらの root へ `allowed_write_roots` 外 self-write した場合も `unauthorized_write_path` になりません。
- #1343 AC3 は「実行コマンド自身が `allowed_write_roots` 外へ書いた場合は従来どおり fail-close」と読めるため、現実装は AC3 の一般保証を満たしていません。
- 新規AC3テストは `.cache/outside.txt` のみで、今回除外した volatile roots への child self-write negative test がありません。
- PR本文の Safety Claim Matrix はこの gap を Not controlled と認めていますが、その場合は Issue/PR/テストの主張を “stdlib race-tolerant hotfix” に狭める必要があります。

Required:
1. strict attribution を実装して volatile roots への child self-write も fail-close する。
   または
2. #1343 の契約とPR本文を明示的に狭め、volatile-root child self-write は unsupported / follow-up として扱う。

少なくとも、`test_self_write_to_worktrees_still_fails` と `test_self_write_to_other_issue_artifacts_still_fails`(または known limitation の明示テスト)を追加してください。

結論として、人間が「false positive を減らす実用ホットフィックスとして、volatile root への self-write blind spot を許容する」と明示判断するならマージ可能です。そうでないなら、現PRは unauthorized_write_path guard の安全境界を縮小しているため、マージ前に契約か実装のどちらかを直すべきです。

squne121 and others added 2 commits July 6, 2026 19:23
…制限を明示する (#1343)

PR #1349への人間レビュー(REQUEST_CHANGES)を受け、Option Bを採用した。
strict attributionは実装せず、代わりにvolatile peer-session root
(.claude/worktrees/** / .claude/artifacts/issue-refinement-loop/**)への
自プロセスの書き込みが検出されないことを既知の制限としてテストで明示する。

- test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode
- test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode
- 既存4テスト(AC1-AC4)は変更なし

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

squne121 commented Jul 6, 2026

Copy link
Copy Markdown
Owner Author
TEST_VERDICT:
  result: PASS
  mergeable: MERGEABLE
  merge_state_status: CLEAN
  branch_behind_main: false
  baseline_only: false
  verification_commands_pass: 6
  verification_commands_fail: 0
  verification_skipped_count: 0
  runtime_ac_results: []

検証結果レポート(iteration 2, head_sha: f03fabf)

Issue #1343: 実装: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する(Option B 契約狭め後)

AC 確認コマンド 実行結果 exit code 判定
AC1 test_unrelated_process_write_to_worktrees_does_not_fail PASSED 0 PASS
AC2 test_unrelated_process_write_to_other_issue_artifacts_does_not_fail PASSED 0 PASS
AC3 test_self_write_outside_allowed_roots_still_fails PASSED 0 PASS
AC4 test_self_write_inside_allowed_roots_still_succeeds PASSED 0 PASS
AC5a test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode PASSED 0 PASS
AC5b test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode PASSED 0 PASS

総合判定

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

PR Review: #1349 (Closes #1343) — iteration 3 (Option B 契約狭め後の再レビュー)

iteration 3 APPROVE。Option B(契約狭め)で Issue #1343 の AC3/AC5 と PR #1349 実装・テスト・Safety Claim Matrix が整合していることを独立に確認した。

  • Issue #1343 の現行 body(sha256:9a2f2a3b4cbd4a08231cefc80cdf0d57e156eb1d4d8e192ef1a0c1ff4f8d0169)と fresh contract-review go の body_sha256 が独立再計算で完全一致。narrowed AC3・新規AC5・Out of Scope 追記を確認。
  • 新規2テスト(test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode / test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode)を実コードで読み、self-write into volatile root が returncode 0(検出されない)ことを assert しており、実装(_VOLATILE_PEER_SESSION_ROOT_RELS による snapshot/status からの丸ごと除外、iteration 1 から不変)と整合。矛盾や逆方向の fail-close 要求はない。6テスト全て head f03fabf 上でローカル再実行し PASS 確認済み。
  • Safety Claim Matrix の bounded-claim 宣言(「無限定の safe / 完全な attribution は主張していない」)を確認、過剰主張なし。
  • ci_verdict_summary.py --expected-head-sha f03fabfe... → all_pass(required checks 全 green、stale/pending/failed なし)。
  • Allowed Paths gate を独立再計算(git diff --name-status -M -z ベース、worker self-report 不使用)→ status: ok、変更2ファイルとも Allowed Paths と完全一致、rename なし。
LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "f03fabfe02a5c32d2bd37f375393fa847d268122"
  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"
    produced_by: "allowed_paths_review_gate.py"
    producer_role: "review_subagent"
    worker_report_used_as_canonical: false
    pr_number: 1349
    base_ref: "main"
    diff_base_sha: "4f2c330a3cefeab1a683a086c402504a0362acd3"
    base_sha: "4f2c330a3cefeab1a683a086c402504a0362acd3"
    head_sha: "f03fabfe02a5c32d2bd37f375393fa847d268122"
    reviewed_head_sha: "f03fabfe02a5c32d2bd37f375393fa847d268122"
    changed_files_source: "git_diff_name_status_find_renames_z"
    changed_files_count: 2
    changed_files:
      - "scripts/agent-guards/skill_runtime_exec.py"
      - "scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py"
    violations: []
    contract_fingerprint:
      issue_number: 1343
      contract_source_kind: "github_issue"
      contract_source_id: "squne121/loop-protocol#1343"
      contract_body_sha256: "sha256:9a2f2a3b4cbd4a08231cefc80cdf0d57e156eb1d4d8e192ef1a0c1ff4f8d0169"
      base_ref: "main"
      base_sha_at_snapshot: "4f2c330a3cefeab1a683a086c402504a0362acd3"
    reason: "All changed files are within allowed paths"

@squne121
squne121 marked this pull request as ready for review July 6, 2026 11:46
@squne121
squne121 merged commit 502822c into main Jul 6, 2026
29 of 30 checks passed
@squne121
squne121 deleted the worktree-issue-1343-fix-unauthorized-write-path branch July 6, 2026 11:46
squne121 added a commit that referenced this pull request Jul 6, 2026
CI log investigation (run 28757862903 / PR #1352, 28751177802 / PR
#1349, 28749187051 / PR #1345) shows the index preview URL returning a
sustained 404 for the entire previous 180s per-URL budget with no
intervening 200 response, while the same repository's deploy-main job
(same GitHub Pages Settings/Source) never exhibits this failure. This
is consistent with GitHub Pages CDN propagation lag for freshly
published pr-<n>/ subdirectories exceeding 180s on occasion, rather
than a Pages Settings/Source misconfiguration (tracked separately in
#1315). Bump the shared overall_deadline from 240s to 300s to give the
index + asset checks more headroom within the new shared-budget model.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
squne121 added a commit that referenced this pull request Jul 6, 2026
…1346)

- AC9 (P0): validate_issue_body.py の _load_required_section_labels に
  implementation kind 専用の Required Design References 必須化を追加し、
  create_issue_txn.py 経由の authoring 経路で欠落時に needs_fix を返すようにした。
  ISSUE_TEMPLATE 側の validations.required: false(AC7 の scope_signal_guard 回帰対応)
  には影響しない。
- AC10: contract_readiness_check.py の RDR001 セクション抽出を
  prose_boundary_policy.HEADING_POLICY の accepted_forms(日本語見出し含む)から
  動的に構築し、両者の heading 集合を共有した。
- AC11: RDR001 の design-doc path 判定を docs/**/*.md|yml,
  .claude/skills/**/SKILL.md, .claude/skills/**/references/**/*.md に絞り、
  Path.exists() による実在チェックを追加。autofixable を False に変更した。
- AC12 (P1): agent-skill-boundaries.md の Parallel Agent Runtime Safety を
  Strict attribution mode(将来課題)と Race-tolerant stdlib mode(PR #1349
  Option B の既知の制限を明記)の二段階に分けて書き直し、矛盾を解消した。
- AC13: ssot-registry.md の diff を agent-skill-boundaries エントリのみに限定し、
  無関係な title/description 変更を revert した。
squne121 added a commit that referenced this pull request Jul 6, 2026
* docs: 並列エージェント実行安全性を SSOT 化し Required Design References を追加する (#1346)

- docs/dev/agent-skill-boundaries.md に「## Parallel Agent Runtime Safety」セクションを
  追加し、repo-wide snapshot を自プロセス副作用とみなさない旨・volatile roots の扱い・
  self-write bypass を作らない negative test 要求を明文化した。
- docs/dev/ssot-registry.md の agent-skill-boundaries エントリに parallel/concurrent/race
  の discovery keyword とセクション参照を追加した。
- docs/dev/workflow.md の SSOT Routing Table に参照動線を追加した。
- .github/ISSUE_TEMPLATE/implementation.yml に Required Design References セクションの
  ひな形を追加した。
- .claude/skills/create-issue/references/body-authoring.md に Required Design References
  セクションの執筆指針を追加した。
- .claude/skills/issue-contract-review/scripts/contract_readiness_check.py に
  Required Design References の静的検査(RDR001)を追加した。implementation issue で
  同セクションが空 / N/A / none のみ / repo-relative design-doc path なしの場合に
  needs_fix を返す。セクション自体が存在しない場合は RVA の前例に倣い既存 fixture の
  意味を変えない(AC6)。
- .claude/skills/issue-contract-review/scripts/tests/test_required_design_references.py
  を新規追加し、AC4/AC6 の挙動をテストで固定した。

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

* fix: body-authoring.md の新規見出しの日本語比率不足を解消する

PR Body Japanese Check が per-block 判定で `## Required Design
References Authoring Guidance` 見出し(heading_policy 未登録のため
prose 扱い)の日本語比率 0.068 で fail していたため、見出しの日本語
併記を増補して閾値 0.1 を満たすようにした。

* fix: ssot-registry.md の既存 prose block の日本語比率不足を解消する

PR Body Japanese Check は変更 .md ファイル全体を per-block で判定するため、
Issue #1346 の変更点だけでなく既存の英語主体 prose block も日本語比率 0.1 以上が必要。
7 件の該当 block(title/description/heading)に日本語併記を追加し、
既存の技術的内容・YAML キー構造は変更しない。

* fix: docs/dev/workflow.md への任意の参照動線追加を revert する

PR Body Japanese Check が workflow.md 内の既存英語主体 prose block により
FAILURE していたため、Issue #1346 の AC1-AC6 に必須でない任意変更(SSOT
Routing Table への参照行追加)を取り消す。AC1-AC6 の Verification
Commands は本ファイルに依存しないため、revert 後も全て PASS することを
確認済み。

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

* fix: parallel_exclude 登録に伴い test_python_test_plan.py の debounce 固定表明を更新する (#1346)

Scope Delta 2回目対応。.github/ci/python-test-plan.json の parallel_exclude に
test_required_design_references.py を登録したことで
test_real_plan_serial_lane_has_debounce の「parallel_exclude は空である」
という固定表明が破壊されるため、既知の1件のみを許容する形に更新する。

* Revert "fix: parallel_exclude 登録に伴い test_python_test_plan.py の debounce 固定表明を更新する (#1346)"

This reverts commit 04309a7.

* fix: Required Design References セクションを GitHub Issue Form 必須化しない

Issue Form 側の validations.required: true が、Required Design References
セクションを持たない既存 issue body fixture との組み合わせで
plan_refinement_loop.py の必須セクション欠落チェックを早期 return させ、
scope_signal_guard_decision_v2 計算前に fail_closed_reasons を積んでいた。
これにより test_scope_signal_guard_lane_split.py の全件が
KeyError: 'scope_signal_guard_decision_v2' で失敗していた(xdist/並列実行は無関係)。

実質的な必須性チェックは AC4 で追加した contract_readiness_check.py の
check_required_design_references() が既に担っているため、
Issue Form 側は required: false に変更する。

あわせて誤った仮説(AC4 テスト追加による xdist worker バケット変化)に
基づき追加していた .github/ci/python-test-plan.json の
parallel_exclude エントリと scripts/ci/tests/test_python_test_plan.py の
debounce 固定表明変更を revert する。

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

* fix: HEADING_POLICY に Required Design References 見出しを登録する (#1346)

Scope Delta 3回目対応。.github/ISSUE_TEMPLATE/implementation.yml の
required-design-references を required: false に修正した結果、
test_scope_signal_guard_lane_split.py の回帰は解消したが、新たに
test_heading_policy.py::TestInventoryCoversTemplateHeadings が
"Required Design References" 見出しの HEADING_POLICY 未登録を検出したため、
prose_boundary_policy.py の HEADING_POLICY インベントリに同見出しを
既存エントリと同形式で登録する(AC8)。

* fix: Required Design References の authoring 必須化と SSOT 記述の敵対的レビュー対応 (#1346)

- AC9 (P0): validate_issue_body.py の _load_required_section_labels に
  implementation kind 専用の Required Design References 必須化を追加し、
  create_issue_txn.py 経由の authoring 経路で欠落時に needs_fix を返すようにした。
  ISSUE_TEMPLATE 側の validations.required: false(AC7 の scope_signal_guard 回帰対応)
  には影響しない。
- AC10: contract_readiness_check.py の RDR001 セクション抽出を
  prose_boundary_policy.HEADING_POLICY の accepted_forms(日本語見出し含む)から
  動的に構築し、両者の heading 集合を共有した。
- AC11: RDR001 の design-doc path 判定を docs/**/*.md|yml,
  .claude/skills/**/SKILL.md, .claude/skills/**/references/**/*.md に絞り、
  Path.exists() による実在チェックを追加。autofixable を False に変更した。
- AC12 (P1): agent-skill-boundaries.md の Parallel Agent Runtime Safety を
  Strict attribution mode(将来課題)と Race-tolerant stdlib mode(PR #1349
  Option B の既知の制限を明記)の二段階に分けて書き直し、矛盾を解消した。
- AC13: ssot-registry.md の diff を agent-skill-boundaries エントリのみに限定し、
  無関係な title/description 変更を revert した。

* fix: AC9 regression修正とssot-registry.md Japanese Check再発対応 (#1346)

- materialize_child_issues.py の required_section_labels() を
  validate_issue_body.py の _load_required_section_labels() と揃え、
  implementation kind に Required Design References を必須追加する
  特例を適用する(生成 body の必須セクション乖離を解消)。
- test_guard_issue_body.py の make_implementation_body() fixture に
  Required Design References セクションを追加し、AC9 regression
  (assert False is True)を解消する。
- ssot-registry.md の7つの prose block(agent-skill-boundaries 以外の
  既存エントリ)に、スコープ・情報量を変えない最小限の日本語訳併記を
  追加し、Japanese Content Check(threshold 0.1)を再度満たす。

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
squne121 added a commit that referenced this pull request Jul 6, 2026
* fix: deploy-pr preview asset liveness check retry/backoff/deadline (#1357)

The `Verify preview assets are live` step in deploy-pages.yml failed
intermittently with 404 timeouts unrelated to PR diff content (observed
during PR #1349 review, also seen on PR #1274). This tunes the
fetch_pages_url_with_bounded_retry polling logic:

- Replace the fixed `sleep 5` retry interval with an exponential bounded
  backoff (initial_delay=2s, max_delay=20s, doubling per attempt).
- Introduce a single overall_deadline shared across the index page and
  every asset URL, instead of each URL getting its own independent 180s
  budget that stacks with the number of assets checked.
- Extend the retriable HTTP status set with 409 (Pages deployment
  conflict during a concurrent publish) and 425 (too early / origin not
  yet ready), with an inline comment documenting why each status is
  treated as transient.
- Emit structured retry logs (label=preview-index|preview-asset,
  attempt=, elapsed=, next_sleep=) to make future flake investigation
  from CI logs tractable.

deploy-main job logic and the gh-pages commit message string are
untouched; only the deploy-pr job's live asset check step changed.

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

* fix: bump deploy-pr preview overall_deadline to 300s (#1357)

CI log investigation (run 28757862903 / PR #1352, 28751177802 / PR
#1349, 28749187051 / PR #1345) shows the index preview URL returning a
sustained 404 for the entire previous 180s per-URL budget with no
intervening 200 response, while the same repository's deploy-main job
(same GitHub Pages Settings/Source) never exhibits this failure. This
is consistent with GitHub Pages CDN propagation lag for freshly
published pr-<n>/ subdirectories exceeding 180s on occasion, rather
than a Pages Settings/Source misconfiguration (tracked separately in
#1315). Bump the shared overall_deadline from 240s to 300s to give the
index + asset checks more headroom within the new shared-budget model.

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

* fix: address REQUEST_CHANGES on deploy-pages.yml live check fix (#1357)

- Blocker: overall_deadline を実際にhard deadlineにする。curl --max-time を
  残り時間でcap(attempt_max_time)し、curl実行前に残り時間<=0ならエラーで
  抜ける。retryのsleep前にも残り時間を再計算しnext_sleepをcapする。
- Major: retry対象statusのコメントをobserved/defensiveの区別に修正。
  今回実観測されたのは404のみ。403/409/425等は今回未観測のdefensive retryと
  明記(425文字列自体はAC7維持のため残す)。
- Minor: asset URL fetchにも ?cache_bust=${GITHUB_SHA} を追加し index/asset
  で診断の一貫性を揃える。

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

* fix: address low-risk items from adversarial review on #1358

- add timeout-minutes: 7 to the "Verify preview assets are live" step
  as a defense-in-depth guard against holding the shared deploy-pages
  concurrency group indefinitely
- clear stale "${output}.tmp" before each curl attempt in
  fetch_pages_url_with_bounded_retry so a prior attempt's tmp content
  cannot leak into a later attempt's deadline-exceeded diagnostics
- soften the retry-eligible status comment: it no longer implies a
  documented GitHub Pages/CDN transient-behavior contract; the
  non-404 codes are described as defensive-only and unobserved for
  #1357

Live-preview head-SHA verification is intentionally out of scope here
and tracked as a separate follow-up issue per the review feedback.

Closes #1357

---------

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.

実装: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する

1 participant