Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "契約実行ラッパー(scripts/agent-guards配下)の before/after repo-wide スナップショット比較が、並行稼働する他セッション/他エージェントの書き込みを実行コマンド自身の副作用と誤認し unauthorized_write_path で fail-close するバグを修正する"
change_kind: codeParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: N/A(parent なし)
- Desired Destination: N/A
Current Validated Scope
scripts/agent-guards/skill_runtime_exec.pyの unauthorized write 検出ロジックを、実行コマンド自身のプロセスによる書き込みのみに限定するよう修正する- 対応するユニットテストの追加
Remaining Parent Gaps
なし
Outcome
scripts/agent-guards/skill_runtime_exec.py が、同一リポジトリ内で他セッション/他エージェントが並行して .claude/worktrees/** や .claude/artifacts/** 等へ書き込みを行っていても、それらを自プロセスの副作用と誤認せず、unauthorized_write_path で誤って fail-close しない状態になり、対応するユニットテストが追加されて全件 PASS している状態。
In Scope
scripts/agent-guards/skill_runtime_exec.pyの before/after スナップショット比較ロジックを調査し、無関係な同時書き込みを diff に混入させている原因箇所を特定する- 対象コマンドが実際に書き込んだパスのみを diff 対象にする(プロセス単位の書き込み追跡、対象パスの
allowed_write_roots配下への事前スコープ限定、または同時書き込みが疑われる無関係パスの除外のいずれか、実装時に選定する) - 上記修正に対応するユニットテスト(複数プロセスが並行して無関係パスに書き込む状況を模したテスト)を追加する
- volatile peer-session root(.claude/worktrees/** / .claude/artifacts/issue-refinement-loop/**)への実行コマンド自身の書き込みは、本Issueのrace-tolerant hotfixのスコープでは検出対象外(既知の制限)であることを、AC・テスト・PR本文・Safety Claim Matrixに明示する
Out of Scope
allowed_write_rootsの値そのものの変更(各コマンド定義はcommand_registry.pyの既存契約を維持する)issue-refinement-loopや他 skill 側の呼び出しフローの変更local_main_branch_guard等、他の hook / guard スクリプトの変更- child process による volatile peer-session root(.claude/worktrees/** / .claude/artifacts/issue-refinement-loop/**)への自プロセス書き込みの厳密な追跡(process-level file write attribution、strace等によるsyscallトレース等)。stdlibのみによるrace-tolerant hotfixの範囲外とし、必要であれば別Issueで扱う
Acceptance Criteria
- AC1: 単一コマンド実行中に、無関係な別プロセスが
.claude/worktrees/**配下(実行コマンドのallowed_write_roots外)へファイルを書き込んでも、skill_runtime_exec.pyがunauthorized_write_pathで fail しない - AC2: 単一コマンド実行中に、無関係な別プロセスが
.claude/artifacts/issue-refinement-loop/<別issue番号>/**(実行コマンドが対象とする issue 番号とは異なるディレクトリ)へファイルを書き込んでも、skill_runtime_exec.pyがunauthorized_write_pathで fail しない - AC3: 実行コマンド自身が allowed_write_roots 外(ただし .claude/worktrees/** および .claude/artifacts/issue-refinement-loop/** 等の volatile peer-session root を除く)へ実際に書き込んだ場合は、従来どおり unauthorized_write_path で fail-close する(回帰なし)
- AC4: 実行コマンド自身が allowed_write_roots 内へ正当に書き込んだ場合は、従来どおり成功する(回帰なし)
- AC5: 実行コマンド自身が volatile peer-session root(.claude/worktrees/** / .claude/artifacts/issue-refinement-loop/**)へ allowed_write_roots 外の書き込みを行った場合、本Issueのrace-tolerant hotfixの範囲では検出されないことが既知の制限としてテストで明示されている(strict attributionは別Issueのスコープ)
Verification Commands
# 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
# 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
# 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
# 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
# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -k test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_modeAllowed Paths
- scripts/agent-guards/skill_runtime_exec.py
- scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
Runtime Verification Applicability
- decision: not_applicable
- reason: 本 Issue の Acceptance Criteria は全て
uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py配下のユニットテストで検証され、プロセス起動・ネットワーク I/O・実行時 runtime 動作検証は不要なため(静的検証: unit test のみで完結する)。
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Required Skills
なし
Scope Delta(任意)
N/A
Notes for Reviewer
-
発端: Issue 実装: issue-contract-review の VC preflight に同一command dedup/replay と bounded parallel execution を追加する #1338 の issue-refinement-loop Step 0f 実行中に、
uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1338 --repo squne121/loop-protocolを3回連続実行し、全てunauthorized_write_pathで失敗した。報告された unauthorized path は毎回異なり、かつ issue 1338 とは無関係(別セッションの private agent session manifest、別エージェントの pr-review-judge worktree fixture、issue 1337 の refinement artifact)だった。target_issueは毎回 1338 と正しく認識されていたため、原因は本コマンドの読み取り対象や引数ではなく、before/after スナップショット比較の対象範囲がリポジトリ全体(または.claude/worktrees/**/.claude/artifacts/**全体)に及んでいることだと推測される。 -
実装方針は「プロセス単位の書き込み追跡(例: 起動した子プロセスの working directory やコマンドの
allowed_write_rootsに限定して diff を取る)」を優先候補とするが、具体的な実装は担当者の調査結果に委ねる。 -
本 Issue が解消するまでの間、
issue-refinement-loop等skill_runtime_exec.py経由のコマンドは、他セッションが同時に稼働している状況下で断続的に誤ブロックされ得る。 -
2026-07-06: PR fix: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する #1349 に対する人間レビュー(REQUEST_CHANGES, https://github.com/squne121/loop-protocol/pull/1349#issuecomment-4891683548)を受け、AC3 の保証範囲を volatile peer-session root 除外で明示的に狭めた(Option B)。strict attribution(Option A)は不採用、必要なら別Issueで扱う。
Activity
squne121 commentedon Jul 5, 2026
you asked
message time: 2026-07-06 01:23:28
#1343
内容について関連Issue、PR、リポジトリ資産、コメントを参照した上で敵対的レビューして。
取り扱う技術や配布物の実装をWEB検索し高品質化してほしい。
chatgpt response
対象Issueと周辺文脈を確認し、リポジトリ内の実装・ドキュメント・関連PR/Issueまで横断してから、外部実装の調査結果と照合してレビューします。まずGitHub側の一次情報を取りに行きます。
Issue #1343 自体はコメントなしでした。現行実装を見ると、
skill_runtime_exec.pyはコマンド実行の前後で repo-wide snapshot とgit statusを比較しており、Issue本文の推測どおり、他プロセスの同時書き込みを自コマンドの副作用として拾う構造です。判定
要修正。#1343 の問題認識は正しいが、このまま実装に渡すと「誤検知は減るが guardrail が抜ける」実装が入り得ます。
Issue #1343 は open で、Issue 自体にはコメントがありません。観測事象は、
skill_runtime_exec.pyの before/after repo-wide snapshot 比較が、他セッションの.claude/worktrees/**や別 issue の.claude/artifacts/**書き込みを、自コマンドの副作用として誤認してunauthorized_write_pathにしている、というものです。これは現行コードと整合します。P0: 現行実装は「プロセス起因」ではなく「時間窓の repo drift」を見ている
_git_status_paths()は repo 全体に対してgit status --porcelain=v1 --untracked-files=all --ignored=matching -zを実行しています。つまり ignored/untracked も含めて、同時に増えた path を拾います。_snapshot_repo_paths()も repo root からos.walk()し、.gitと target issue の allowed artifact root 以外を広く snapshot しています。 その後、child 実行前の snapshot/status と child 実行後の snapshot/status を比較し、差分があればunauthorized_write_pathとして fail-close しています。この方式では、child process が書いたのか、別エージェントが同じ repo 内に書いたのかを区別できません。Python の
os.walk()自体も、walk 中に file が追加・削除された場合に list に含まれるかは unspecified としているため、並行書き込み下の snapshot は監査証跡として弱いです。(Python documentation)P0: 「無関係 path を除外するだけ」の実装は AC3 を破る
#1343 の AC1/AC2 だけを見ると、
.claude/worktrees/**や.claude/artifacts/issue-refinement-loop/<other issue>/**を無視すれば通ります。しかし、それを blanket exclusion にすると、child が意図的に同じ path へ書いた場合も見逃します。これは AC3「自プロセスが allowed_write_roots 外へ書いたら従来通り fail-close」と衝突します。この guard の契約上、
preflight.runの allowed write root は.claude/artifacts/issue-refinement-loop/{active_issue}/だけです。policy 側も registry 側も同じ root を正本化しています。さらに #1228 は root からの
preflight.runを許可した代わりに、artifact-only write postcondition を維持する契約です。#1236 もunauthorized write pathpostcondition を二次防波堤として維持すると明記しています。 既存テストにも、child が.cache/outside.txtを書くとunauthorized_write_pathで落ちる regression が存在します。P0: 「プロセス単位の書き込み追跡」は標準 subprocess だけでは成立しない
Python の
subprocess.run()/Popenは child process の起動、stdout/stderr、return code、cwd/env の制御を提供しますが、child process tree が書いた file path の一覧は返しません。(Python documentation)inotify も primary solution には不適です。Linux man page は、inotify event にはその event を起こした user/process 情報がなく、自プロセス由来か他プロセス由来かを区別する簡単な方法がないと明記しています。さらに recursive ではなく、queue overflow で event loss も起こり得ます。(man7.org)
本当に「child process tree が実際に触った path だけ」を検出するなら、Linux では
strace -fのような syscall tracing が候補になります。strace -fは fork/vfork/clone で作られた child process を追跡でき、%fileは filename を引数に取る syscall 群を trace できます。(man7.org) (man7.org) ただしこれは新しい runtime dependency / Linux 前提 / trace parser / secret-safe log handling を導入するため、現在の Allowed Paths と stop condition のまま暗黙採用するべきではありません。P0: #1343 は実装モードを二択で固定すべき
現契約の「プロセス単位の書き込み追跡、対象パスの
allowed_write_roots配下への事前スコープ限定、または同時書き込みが疑われる無関係パスの除外のいずれか」は危険です。これらは安全性が同等ではありません。採るべき方針はどちらかです。
strict attribution mode
strace等で child process tree の file syscall を追跡し、AC3 を.claude/worktrees/**や他 issue artifact への self-write まで含めて保証する。採用するなら、Issue に Linux/strace 依存、trace parser、fallback 時の fail-closed、secret-safe artifact 方針を明記する。race-tolerant stdlib mode
標準ライブラリだけで実装し、既知の peer-session volatile roots の誤検知を避ける。ただしこの場合、AC3 は「一般の repo path、例:
.cache/**や source tree への self-write は fail-close」のように狭める必要があります。.claude/worktrees/**や他 issue artifact への self-write を検出できるとは主張しない。現状の #1343 は、1 の保証を言いながら 2 の簡易実装を許す形になっています。ここが最大のリスクです。
P1: 既存 regression を必ず巻き込むべき
新規テストファイルだけで AC1/AC2 を満たすと、#1228/#1236 の安全回帰を見落とします。既存の
test_skill_runtime_preflight_no_worktree.pyには、fixture child が target artifact に正常書き込みする経路、.cache/へ不正書き込みする経路、stale worktree env、outside artifact projection を再現する harness が既にあります。最低限、#1343 の Verification Commands に次を追加した方がよいです。
uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.py \ -k "artifact_only_write_postcondition or stale_worktree or artifact_projection"Allowed Paths は、既存 harness を直接修正・再利用するなら
scripts/agent-guards/tests/test_skill_runtime_preflight_no_worktree.pyも追加してください。新規ファイルだけで完結させるなら、既存 helper を雑に duplicate せず、self-write bypass ケースを必ず入れるべきです。追加すべき Acceptance Criteria
#1343 の AC3 は粗すぎます。少なくとも以下を追加してください。
実装レビュー観点での結論
#1343 は採用すべきですが、実装前に契約を硬くしてください。
特に禁止すべき実装は次です。
推奨する issue 本文の追記はこれです。
この追記なしで実装に進めると、最もあり得る失敗は「#1343 の誤検知は消えたが、root
preflight.runの artifact-only write boundary が弱くなった」というものです。今回の guard は安全境界なので、false positive 修正よりも false negative を作らない契約設計を優先すべきです。you asked
message time: 2026-07-06 02:01:21
このGitHub Issueを起表することになった要因としては、エージェントスキルの作成時において、ローカルでAIエージェントが複数並列で作業するという設計思想が反映されていなかったことが要因だと思います。
再発防止のため、エージェントスキルの変更を行うときに、参照するべき運用設計書をAIエージェントにトークン消費を少なく読み込ませるような動線の確保が必要だと思いました。
人間からの提案としては、GitHub Issueに参照するべきドキュメントのファイルパスやマークダウンであれば、セクション名を明示することが効果的なのではないかと思いました。
また、AIエージェント運用設計に同じ環境で複数並列でも作業が破綻しないことが要件として書かれているか確認してほしいです。
chatgpt response
設計要因の仮説は妥当そうです。リポジトリ内の運用設計書・Skill境界ドキュメントに「同一環境で複数エージェントが並列稼働する前提」が明文化されているか、まず文書側を検索します。
現時点の検索では、「worktree」「artifact root」「stale state」は文書化されていますが、「同一ローカル環境で複数AIエージェントが並列稼働すること」を正面から要求化した記述はまだ見えていません。関連しそうな設計文書を数本、狙って確認します。
確認結果としては、あなたの仮説はかなり妥当です。
現在の文書体系には、worktree 分離・Allowed Paths・root/main 保護・stale runtime state・CWD 誤認の設計はあります。しかし、今回の #1343 の直接原因である 「同一ローカル環境で複数 AI エージェント/複数セッションが同時に repo 内へ書き込む」前提は、運用要件として十分に明文化されていません。
確認したこと
docs/dev/workflow.mdは SSOT を最上位に置き、Skill / SubAgent は正本ではなく「AI 向け実行コンテキスト」層だと定義しています。また、Skill に長文 SSOT を重複保持せず、必要な section / script / reference を段階的に読む progressive disclosure を優先すると明記しています。これは、あなたの「Issue に参照すべき doc path と section を明示する」提案と方向性が一致します。同じく
workflow.mdには、AI エージェントは実装着手前に対象トピックの SSOT を SSOT Routing Table から確認する、とあります。ただし現在の routing table は「SubAgent / Skill 責務境界」「workflow」「runtime-verification」などの大分類であり、並列エージェント運用・共有 repo 内の race 耐性を明示的に引けるトピックがありません。docs/dev/agent-skill-boundaries.mdは、Skill / SubAgent 定義に詳細を埋めるとコンテクスト汚染になるため、この文書を正本にする、と書いています。さらに、SubAgent は隔離されたコンテクストで動く実行者、Skill は再現可能な手順書であり、共通説明は references または本ドキュメントに置くべきだとしています。一方で、#1343 に直接関係する
Privileged Skill Runtime Command Boundaryは、preflight.runの root allow、allowed write root、filesystem snapshot/postcondition、repo tree outside allowed artifact root への変更検出を定義していますが、snapshot 取得中に他セッションが同じ repo tree に書くという並行実行モデルまでは扱っていません。implement-issueskill には worktree 作成、.claude/worktrees/配置、worktree 内の絶対パス指定、Allowed Paths 重複チェックがあります。ただしこれは主に「自分の実装作業をどこで行うか」「Allowed Paths が他 Issue と競合するか」の話であり、別セッションの書き込みを runtime guard が自分の副作用と誤認しないことまでは要件化していません。docs/dev/agent-runtime-ops.mdは Codex runtime、permission profile、sandbox、write guard を扱っています。CODEX_ALLOWED_PATHS_MODEには CI/自動化は strict、interactive は workspace、shadow は観測用という整理がありますが、これも「同一 repo で複数 agent が同時稼働する場合の race-safe 要件」ではありません。context-mode-cwd-quarantine.mdには、wrong-tree 実行が read-only でも証跡を誤らせる、という重要な考え方があります。これは #1343 と近い設計思想ですが、対象は CWD / MCP execution-like tools の quarantine であり、複数 agent の同時書き込みによる repo snapshot drift ではありません。結論
現状の設計書には、次の要素はあります。
preflight.runの privileged boundaryしたがって、#1343 の根本要因は「実装者が見落とした」というより、Skill runtime / guardrail 設計時に “single agent が唯一の writer” に近い暗黙前提が残っていたことだと見てよいです。
再発防止として入れるべき動線
人間提案の「Issue に参照すべきドキュメント path と Markdown section 名を明示する」は有効です。むしろ既存 SSOT 方針と整合しています。
workflow.mdは、SSOT を編集したら prompt 層・guardrail 層も同 PR で更新すること、できない場合は follow-up と未反映リスクを記録することを求めています。ただし、単なる任意記述だと忘れられます。Issue テンプレートまたは contract schema に、以下のような section を追加するのがよいです。
追加すべき SSOT
既存文書に追記するなら、第一候補は
docs/dev/agent-skill-boundaries.mdです。理由は、Skill / SubAgent 定義に共通説明を埋めず、この文書を正本にする方針がすでにあります。追加する section 名は、例えばこれがよいです。
## Parallel Agent Runtime Safety(並列エージェント実行安全性)入れるべき要件は短くてよいです。
さらに
docs/dev/ssot-registry.mdに、この新 section を discovery できる keyword を足すべきです。現在の registry はagent-skill-boundariesにagent, skill, subagent, control-plane, data-planeなどはありますが、parallel,concurrent,race,same repo,shared environment相当の keyword がありません。#1343 に追記するなら
#1343 には、次を
Required Design Referencesとして追記するのが最小です。別 Issue として起こすなら
起票するなら、タイトルはこれがよいです。
Allowed Paths は最低限これです。
contract_readiness_check.pyまで入れる理由は、Required Design References を「書いてあるとよい」ではなく、implementation issue の readiness / contract review で検出できるようにするためです。自然言語の注意だけだと再発防止として弱いです。squne121 commentedon Jul 5, 2026
Contract Review Result
squne121 commentedon Jul 5, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 5, 2026
並列エージェント実行安全性の SSOT 化 follow-up を起票しました: #1346
squne121 commentedon Jul 5, 2026
implement-issue: 実装完了 (2026-07-05T18:47:00Z)
.claude/worktrees/issue-1343-fix-unauthorized-write-pathworktree-issue-1343-fix-unauthorized-write-pathtest_skill_runtime_preflight_no_worktree.py)20/20 PASS、scripts/agent-guards/tests/全473件 PASSsqune121 commentedon Jul 6, 2026
Contract Review Result (refresh — supersedes issuecomment-4886983919)
test: 動作検証済みAC5テストを追加しvolatile peer-session rootへの自プロセス書き込みが検出されない既知の…
fix: 契約実行ラッパーの unauthorized_write_path 誤検知を修正する (#1349)