Skip to content

実装: 契約実行ラッパーの unauthorized_write_path 誤検知が repo root artifacts/ 配下でも発生する問題を修正する #1409

Closed
1 of 1 issue completed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "契約実行ラッパー(scripts/agent-guards/skill_runtime_exec.py)の before/after repo-wide スナップショット比較が、session-manifest hook(.claude/hooks/session_manifest_debounce.mjs 等)自身の非同期書き込みを実行コマンドの unauthorized write と誤認し unauthorized_write_path で fail-close するバグを、hook 専用の新設 subtree artifacts/session-manifest-runtime/ を race-tolerant 除外対象に加えることで修正する(#1343 の修正範囲外だった穴。OWNER レビュー https://github.com/squne121/loop-protocol/issues/1409#issuecomment-4935283248 により repo-root artifacts/ 全体除外案は REQUEST_CHANGES、専用 subtree 方式を採用)"
change_kind: code

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: N/A(parent なし)
  • Desired Destination: N/A

Current Validated Scope

  • session-manifest hook(.claude/hooks/session_manifest_debounce.mjs / .claude/hooks/generate_session_manifest_from_hook.mjs)が書き込む runtime file(events / lock / tmp / final manifest)の出力先を、repo root 直下の artifacts/ から hook 専用の新設 subtree artifacts/session-manifest-runtime/(events/ / locks/ / tmp/ / manifests/)へ変更する
  • scripts/agent-guards/skill_runtime_exec.py の _VOLATILE_PEER_SESSION_ROOT_RELS に、repo-root artifacts/ 全体ではなく artifacts/session-manifest-runtime のみを追加する(_snapshot_repo_paths の os.walk pruning と _find_unauthorized_repo_changes / _is_volatile_peer_session_path の両方に反映)
  • 上記シンボルは「他セッション由来」に限らない実態(同一セッションの非同期 background worker)を正確に表すため _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS / _is_race_tolerant_unattributable_path へ改名する
  • 固定 sleep ベースではなく、実際の debounce process / generator を用いた同期型 lifecycle integration test を追加する
  • docs/dev/agent-skill-boundaries.md の Parallel Agent Runtime Safety inventory を更新し、新 subtree・改名後シンボル名・known limitation・実装: 契約実行ラッパーに Linux-only optional strict trace attribution mode を追加する #1363 strict mode との mode 別保証を明記する

Remaining Parent Gaps

なし

Outcome

scripts/agent-guards/skill_runtime_exec.py が、実行セッション自身の PostToolUse / SubagentStop hook が専用 subtree artifacts/session-manifest-runtime/ 配下へ非同期に書き込む session manifest 関連ファイル(events / lock / tmp / atomic rename / final manifest)を、実行コマンド自身の unauthorized write と誤認せず、unauthorized_write_path で誤って fail-close しない状態になる。一方で artifacts/ 配下のそれ以外の領域(artifacts/<issue>/issue-metadata/** を含む controlled mutation の入力・marker namespace や、その他 child command による任意の書き込み)は、従来どおり監査対象として残る。対応する実際の lifecycle に基づく統合テストと known-limitation テストが追加され、全件 PASS している状態。

In Scope

  • .claude/hooks/session_manifest_debounce.mjs および .claude/hooks/generate_session_manifest_from_hook.mjs の出力先パス構築ロジックを、repo root 直下 artifacts/*.json / artifacts/.lock-* / artifacts/.tmp-* から artifacts/session-manifest-runtime/{events,locks,tmp,manifests}/ へ変更する
  • scripts/agent-guards/skill_runtime_exec.py の _VOLATILE_PEER_SESSION_ROOT_RELS(_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS へ改名)に artifacts/session-manifest-runtime のみを追加する(repo-root artifacts/ 全体は追加しない)
  • _is_volatile_peer_session_path(_is_race_tolerant_unattributable_path へ改名)と _snapshot_repo_paths の os.walk pruning ロジックの両方が新 subtree のみを正しく除外し、artifacts/<issue>/issue-metadata/** 等それ以外の artifacts/ 配下は引き続き監査対象のままであることを確認する
  • 既存の .claude/worktrees / .claude/artifacts/issue-refinement-loop 除外ロジックと同一パターンで実装する(新しい除外機構は導入しない)
  • 実際の .claude/hooks/session_manifest_debounce.mjs(または debounce worker)を別プロセスとして起動し、ready-file または同等の同期バリアで「wrapper の before snapshot 完了」を待ってから lock 作成・metadata 更新・temporary file 作成・atomic rename・event file 削除・failed rename を実行する、固定 sleep に依存しない同期型 integration test を scripts/agent-guards/tests/ に追加する
  • child command 自身が新 subtree の外側(artifacts/unrelated/**、artifacts/<issue>/issue-metadata/**、artifacts/.env を含む)へ書き込んだ場合は、従来どおり unauthorized_write_path で fail-close することを検証する回帰テストを追加する
  • race-tolerant stdlib mode では child 自身による新 subtree への self-write を区別できないことを、既存の test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode と同じパターンの known-limitation テストとして明示する
  • docs/dev/agent-skill-boundaries.md の Parallel Agent Runtime Safety セクションを更新し、volatile/race-tolerant-unattributable root inventory に artifacts/session-manifest-runtime を追加し、改名後のシンボル名・known limitation・#1363(strict_strace mode)との mode 別契約(race_tolerant では subtree を無条件除外するが、strict_strace では traced child による同 subtree への write は fail-close する)を明記する

Out of Scope

Acceptance Criteria

  • AC1: 実際の .claude/hooks/session_manifest_debounce.mjs(または同等の generator process)を別プロセスで起動し、ready-file/barrier で before-snapshot 完了後に artifacts/session-manifest-runtime/ 配下へ書き込む同期型 integration test で、修正前コードでは unauthorized_write_path が再現し、修正後コードでは成功することを示す
  • AC2: race-tolerant stdlib mode で、artifacts/session-manifest-runtime/** への peer/background write(新規ファイル作成・既存ファイル更新の両方)が unauthorized_write_path を誤検知しないことを確認する
  • AC3: child command 自身が artifacts/session-manifest-runtime/ の外側(artifacts/unrelated/** / artifacts/<issue>/issue-metadata/** / artifacts/.env を含む)へ実際に書き込んだ場合は、従来どおり unauthorized_write_path で fail-close する(回帰なし)
  • AC4: race-tolerant stdlib mode では child command 自身による artifacts/session-manifest-runtime/ への self-write を hook 由来の write と区別できないことを、known-limitation テストとして明示する
  • AC5: lock 作成・metadata 更新・temporary file 作成・atomic rename・event file 削除・failed rename という実際の writer lifecycle を、固定 sleep のみに依存しない同期バリアで検証する
  • AC6: 既存の .claude/worktrees / .claude/artifacts/issue-refinement-loop 除外に対する既存6テスト(test_unrelated_process_write_to_worktrees_does_not_fail / test_unrelated_process_write_to_other_issue_artifacts_does_not_fail / test_self_write_outside_allowed_roots_still_fails / test_self_write_inside_allowed_roots_still_succeeds / test_self_write_to_worktrees_is_known_unsupported_in_stdlib_mode / test_self_write_to_other_issue_artifacts_is_known_unsupported_in_stdlib_mode)が引き続き全件 PASS する
  • AC7: #1363(Linux-only optional strict trace attribution mode)へのハンドオフとして、race_tolerant_stdlib mode では artifacts/session-manifest-runtime/** の peer/background write を無条件で無視するが、strict_strace mode(#1363 で実装予定)では traced child process による同 subtree への write を fail-close すべきであり、tracer 外の peer/hook process による write は誤帰属してはならないという mode 別契約が docs/dev/agent-skill-boundaries.md に明記されている
  • AC8: docs/dev/agent-skill-boundaries.md の Parallel Agent Runtime Safety セクションの volatile/race-tolerant-unattributable root inventory が artifacts/session-manifest-runtime を含むよう更新され、改名後のシンボル名(_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS)と known limitation が記載されている

Verification Commands

実装前は AC1〜AC5・AC7・AC8 対応の test/file/記述がまだ存在しないため、
対応する VC はいずれも baseline で fail する(AC1〜AC5 は未作成ファイル
test_skill_runtime_exec_session_manifest_lifecycle.py への pytest nodeid 指定で
collection error、AC7・AC8 は rg が該当記述なしで exit 1)。AC6 は既存回帰のため
baseline から PASS する。

# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py::test_real_debounce_process_write_to_session_manifest_runtime_does_not_fail

# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py::test_race_tolerant_stdlib_excludes_session_manifest_runtime_subtree

# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py::test_self_write_outside_session_manifest_runtime_still_fails

# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py::test_self_write_to_session_manifest_runtime_is_known_unsupported_in_stdlib_mode

# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py::test_real_debounce_process_lock_rename_and_failed_rename_lifecycle

# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py

# AC7
$ rg -n "strict_strace" docs/dev/agent-skill-boundaries.md

# AC8
$ rg -n "artifacts/session-manifest-runtime" docs/dev/agent-skill-boundaries.md

Allowed Paths

  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py
  • .claude/hooks/session_manifest_debounce.mjs
  • .claude/hooks/generate_session_manifest_from_hook.mjs
  • .claude/hooks/tests/test_session_manifest_debounce.py
  • .claude/hooks/tests/test_generate_session_manifest_from_hook.py
  • docs/dev/agent-skill-boundaries.md

Runtime Verification Applicability

  • decision: immediate
  • reason: 本 Issue の障害は Claude Code の async: true PostToolUse hook、detached debounce worker、複数プロセス、filesystem の write/rename/delete タイミングの重なりに起因するため、process 起動・プロセス間同期・実際の I/O タイミングを伴う runtime 動作検証が必要であり、static verification(unit test のみ)では不十分である
  • required_evidence:
    • 実際の hook payload(.claude/hooks/session_manifest_debounce.mjs の実行ログ)
    • child process と background debounce worker との同期証跡(ready-file/barrier 経由)
    • 作成・rename・削除された repo-relative path の実測値
    • skill_runtime_exec.py の実行 return code と reason_code
    • race_tolerant mode と(将来の)strict mode の ownership matrix
      applicable_acs: AC1, AC2, AC3, AC4, AC5(実プロセス起動・実ファイル I/O タイミングを伴うため runtime 検証必須。AC6〜AC8 は既存回帰確認 / ドキュメント記述確認のため static verification で十分)
      execution_environment: ローカル Linux(wsl2-ubuntu)環境上で、.claude/hooks/session_manifest_debounce.mjs(Node.js, node 実行可能であること)を実プロセスとして subprocess.Popen 等で別プロセス起動できること。ネットワークアクセス不要。CI(GitHub Actions ubuntu-latest runner)でも同条件で再現可能
      skip_conditions: node 実行系が利用できない、または別プロセス起動権限がサンドボックスで禁止されている環境では該当 AC の runtime 検証をスキップし、fallback_policy に従う。static-only な CI lane(pnpm lint 等)では対象外
      fallback_policy: runtime 実行環境が利用できない場合は、当該 AC の VC 実行結果を human_judgment として扱い、実装者は known-limitation として PR 本文にスキップ理由と代替の static 検証結果(該当テストファイル・関数の存在確認、コードレビューによるロジック確認)を明記する。fallback 時に AC を go として自己申告してはならない
      artifact_requirements: 同期型 integration test の実行ログ(pytest 標準出力、debounce worker の stdout/stderr、ready-file 生成タイムスタンプ)を scripts/agent-guards/tests/ 配下のテスト実行結果として保存し、PR の Verification Commands 実行結果に添付する

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • #1363 の strict_strace mode 実装そのものに踏み込む必要が生じた場合(本 Issue は mode 別契約の明記までに限定する)

Required Skills

なし

Required Design References

Scope Delta(任意)

N/A

Notes for Reviewer

  • 発端: 2026-07-09、Issue 実装: ChatGPT GitHub retro E2E proof と Issue/PR operation session index を追加する #1405 の issue-refinement-loop 実行中に uv run python3 scripts/agent-guards/skill_runtime_exec.py --command-id preflight.run --issue-number 1405 --repo squne121/loop-protocol を root から複数回連続実行し、毎回 unauthorized_write_path で失敗した。報告された unauthorized path は毎回 artifacts/private-agent-session-manifest-posttooluse-*.json / ...-subagentstop-*.json という、当該コマンドを実行しているセッション自身の PostToolUse hook(.claude/hooks/session_manifest_debounce.mjs、async 実行)が書き込むファイルだった。原因の正確な記述は「当該コマンド自身の PostToolUse hook が割り込む」ではなく、「同一セッションの先行 PostToolUse event から非同期継続している debounce worker、または concurrent Stop/SubagentStop hook が、後続の skill_runtime_exec.py 実行区間と重なって artifacts/ を更新する」である。
  • OWNER レビュー(https://github.com/squne121/loop-protocol/issues/1409#issuecomment-4935283248)は、当初提案の「repo-root artifacts/ 全体を _VOLATILE_PEER_SESSION_ROOT_RELS に追加する」修正を REQUEST_CHANGES とした。理由は、artifacts/ が session-manifest 専用の disposable telemetry namespace ではなく、controlled mutation policy が artifacts/{issue}/issue-metadata/{command-id}/ を machine-readable な入力・marker namespace として使用しているため、artifacts/ 全体を除外すると provenance detector としての機能が失われる点にある。
  • 採用した設計は、OWNER レビューの「第一選択」である hook-owned namespace の分離(artifacts/session-manifest-runtime/ への出力先変更 + 当該 subtree のみを race-tolerant 除外対象に追加)。「次善策」(root 直下の厳密な path matcher による部分除外)は、child が同じ filename pattern を偽装できる spoofability を残すため不採用とした。
  • inotify / fanotify / Landlock はいずれも本 Issue の解決策としては不採用(inotify は書き込み元プロセスを区別できない、fanotify の recursive directory monitoring は race を伴う、Landlock は将来の prevention mode 候補だが本 Issue の snapshot-diff 方式の小規模修正には過大なため別 Issue に分離)。

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

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

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES。現行の契約のまま実装を開始すべきではありません。

    #1409 の障害診断自体には妥当性があります。リポジトリ設定では Bash|Edit|Write の PostToolUse に非同期 session-manifest hook が登録され、debounce worker は detached process として継続し、最終的にリポジトリ直下の artifacts/ に lock、temporary file、manifest を書き込みます。したがって、別のコマンドの before/after snapshot 中に同一セッション由来のバックグラウンド書き込みが混入し、unauthorized_write_path が誤検知する状況は成立します。

    しかし提案されている「artifacts/ 全体を _VOLATILE_PEER_SESSION_ROOT_RELS に追加する」修正は、誤検知の除去範囲を大幅に超えます。これは局所的な false-positive 修正ではなく、リポジトリ直下 artifacts/** 全域を unauthorized-write 監査から外す変更です。既存の #1343 / PR #1349 で明示的に受容した known limitation を、性質の異なるファイル群まで無条件に拡大しています。

    2026年7月10日時点で #1409 はコメント0件で、検索した範囲では対応PRも確認できませんでした。以下は実装差分ではなく、Issue契約そのものに対する敵対的レビューです。なお、本件の重大性はOSレベルのセキュリティ境界ではなく、リポジトリが定義する guardrail と provenance integrity の劣化として評価しています。リポジトリ自身も hook を完全なセキュリティ境界とは位置付けていません。

    Blocker 1 — artifacts/** 全体の除外は、無制限の false-negative aperture を作る

    現在の実装では volatile root は os.walk() の走査時点で再帰ごと prune され、git status の差分でも同じ prefix が除外されます。ここに artifacts を追加すると、その配下で child command が行った作成、更新、削除、rename 等は、race-tolerant stdlib mode から構造的に見えなくなります。

    この副作用は推測ではありません。既存テストは、child command 自身が .claude/worktrees/** や別Issueの .claude/artifacts/issue-refinement-loop/** に書き込んでも成功することを、意図的な known limitation として固定しています。PR #1349 の Safety Claim Matrix も、人間の REQUEST_CHANGES 後にこの制限を明文化して承認された経緯を記録しています。

    対して #1409 の AC3 は「artifacts/** と既存 volatile root 以外への書き込みが失敗すること」しか要求していません。つまり、新たに作る最大の盲点をテスト対象から意図的に外した構造です。最低でも次のテストが必要です。

    test_self_write_to_repo_root_artifacts_is_known_unsupported_in_stdlib_mode
    

    ただし、このテストを追加して known limitation として受容するだけでは、次の Blocker 2 を解消できません。

    Blocker 2 — artifacts/ は純粋な disposable telemetry namespace ではない

    このリポジトリでは、リポジトリ直下 artifacts/ は単なる session-manifest 出力先ではありません。controlled mutation policy は artifacts/{issue_number}/issue-metadata/{command-id}/ を入力・marker namespace として使用し、issue_body.update、issue_comment.publish、contract_snapshot.publish などの操作に関係する machine-readable data を配置します。ポリシー上の write root 自体も artifacts/ です。

    したがって artifacts/** 全体を監査対象外にすると、例えば child command が次のようなファイルを変更しても、この wrapper は検出できなくなります。

    artifacts/1409/issue-metadata/issue-body.update/input.json
    artifacts/1409/issue-metadata/issue-comment.publish/marker.json
    artifacts/1409/issue-metadata/contract-snapshot.publish/...
    artifacts/unrelated-or-future-consumer-input.json
    

    controlled executor 側には schema、binding、symlink、readback 等の追加検証があるため、これだけで直接的なremote mutation bypassが成立するとまでは断定しません。しかし、「どのプロセスが、どの意図で、その入力を作成・変更したか」という独立した provenance detector が消えることは確実です。skill_runtime_exec.py が本来検出しようとしている unauthorized side effect の範囲と正面から衝突します。

    修正は artifacts/ 全体ではなく、session-manifest hook が排他的に所有する専用namespaceだけに限定すべきです。

    Blocker 3 — Issue契約が現行の readiness rule に違反している

    #1409 は issue_kind: implementation であるにもかかわらず、Required Design References が「なし」です。現行の contract readiness checker は「なし」を placeholder として扱い、implementation issue には少なくとも1件の実在する repository-relative design document を要求します。この契約は現在の checker で RDR001 になる構造です。

    さらに SSOT の Parallel Agent Runtime Safety は volatile root として .claude/worktrees/**、.claude/artifacts/** 等を列挙していますが、リポジトリ直下 artifacts/** は含んでいません。#1409 は normative root inventory を変更する提案であるにもかかわらず、Allowed Paths に設計文書がなく、SSOT更新も不可能です。

    最低限、次を Required Design References に追加する必要があります。

    docs/dev/agent-skill-boundaries.md#Parallel Agent Runtime Safety
    docs/dev/runtime-verification-policy.md#Runtime Verification Applicability
    docs/dev/hook-boundaries.md
    Issue #1343
    PR #1349 Safety Claim Matrix と human REQUEST_CHANGES
    Issue #974
    Issue #1356
    Issue #1363
    

    Allowed Paths にも少なくとも docs/dev/agent-skill-boundaries.md を追加すべきです。

    Blocker 4 — Runtime Verification not_applicable は、Issueの主張と矛盾している

    リポジトリの runtime verification policy では、not_applicable は process launch、communication、I/O なしに static verification だけで保証できる場合の判断です。#1409 の障害は async hook、detached worker、複数プロセス、filesystem timing の重なりを原因としており、「process起動・I/O・runtime動作検証は不要」という記述は成立しません。

    また因果関係の記述にも修正が必要です。Claude Code の公式仕様では PostToolUse は tool call が成功した後に発火し、async: true の hook はClaude Codeが完了を待たずにバックグラウンドで継続します。したがって skill_runtime_exec.py を実行している当該 Bash tool call 自身の PostToolUse が、同じ wrapper の内部 snapshot 区間に割り込むことはありません。重なる可能性があるのは、先行tool callから残っている async hook、debounce worker、または同時進行の SubagentStop/Stop 系処理です。([Claude]1) (Claude)

    Issueの原因記述は次のように直すべきです。

    誤:
    当該コマンド自身の PostToolUse hook が artifacts/ を更新する
    
    正:
    同一セッションの先行 PostToolUse event から非同期継続している
    debounce worker、または concurrent Stop/SubagentStop hook が、
    後続の skill_runtime_exec 実行区間と重なって artifacts/ を更新する
    

    Runtime Verification Applicability は immediate が妥当です。

    Major 5 — 提案テストが実際のwriter lifecycleを再現していない

    #1409 のACは「新規ファイル」と「既存ファイル更新」の2形態だけですが、実際のsession-manifest実装は以下を行います。

    • artifacts/session-manifest-debounce/events/*.json

    • worker.lock の作成、metadata更新、削除

    • root artifacts/.lock-*

    • root artifacts/.tmp-*

    • temporary fileからfinal manifestへのatomic rename

    • failure時の .failed rename

    • final private-agent-session-manifest-*.json

    既存の concurrency test helper も「unrelated process」というテスト名に反して、実際には同じpytest process内の threading.Thread と固定sleepを使っています。race-tolerant snapshotの簡易回帰テストとしては機能しますが、今回の「同一セッションの別background process」という因果関係の証拠にはなりません。

    さらに Python の公式仕様では、os.walk() がdirectory listingを生成中に追加・削除されたfileを含むかどうかは未規定です。sleep依存テストは実行環境によって false green / flaky になり得ます。([Python documentation]2)

    必要なのは固定sleepではなく、次のような同期型integration testです。

    1. 実際の session_manifest_debounce.mjs または generator を別processで起動する。
    2. ready-file、pipe、または test-only barrier で「wrapperのbefore snapshot完了」を待つ。
    3. barrier解放後にlock、temp、rename、unlinkを実行する。
    4. child command終了後の判定を検証する。
    5. 現行コードでは失敗し、修正後コードでは対象namespaceに限って成功することを示す。

    Major 6 — #1363 の strict attribution mode と契約が衝突する

    #1363 は同じ skill_runtime_exec.py に Linux-only optional strict_strace mode を追加し、race-tolerant modeで除外されるrootについても、child process由来と証明できたwriteはfail-closeする設計です。#1409 はこのIssueを参照せず、merge順序、mode別挙動、test ownershipを定義していません。

    strict modeでは、artifacts/session-manifest-... namespaceを race-tolerant用の除外リストに追加したとしても、child-attributed writeまで除外してはいけません。次のhandoffを明文化すべきです。

    race_tolerant_stdlib:
      同時進行のhook-owned namespace driftは無視する
      同namespaceへのchild self-writeはknown limitation
    
    strict_strace:
      tracerの子孫外にあるpeer/hook processのwriteは無視する
      traced child/process treeによる同namespaceへのwriteはfail-close
    

    外部仕様上も、strace -f は fork/vfork/clone の子孫を追跡しますが、%file はpathname引数を取るsyscallだけです。既にopen済みのFDに対する write()、pwrite*()、ftruncate() 等をpathに帰属させるには %desc 系syscall、FD table、dup/fork inheritance、--decode-fds=path 相当の処理が必要です。#1356 / #1363 の設計がこの複雑さを要求しているのは妥当です。([man7.org]3) ([man7.org]3) ([man7.org]3)

    Major 7 — 「gitignored safe scratchだから全体除外可能」は不正確

    .gitignore には確かに artifacts/ が local scratch prefix として登録されています。しかし #974 が定義したsafe scratch例外は、単にgitignoredであることを条件としていません。untracked、safe prefix、非機密、symlink componentなし、containment確認などの複数条件を満たす直接のWrite/Edit系操作に限定され、Bash child process全体への包括的な許可は延期されています。

    したがって、

    artifacts/ は gitignored
    → child commandによる artifacts/** 全域の変更を監査しなくてよい
    

    という推論は成立しません。gitignoreはversion-control policyであり、write authorityやprovenance trustを付与するものではありません。

    外部技術調査を踏まえた実装判断

    inotify:不採用

    inotify eventには書き込み元user/process情報がなく、自分自身のwriteと他processのwriteを区別できません。また mmap 系変更を捕捉せず、recursive monitoringにもraceがあります。今回のattribution問題の解決策にはなりません。([man7.org]4)

    fanotify:主方式としては不採用

    fanotify はeventにPIDを含められますが、directory monitoringは標準ではrecursiveではなく、新規subdirectoryへのmark追加にはraceがあり、queue overflow時にはevent lossも発生します。権限、kernel configuration、platform portabilityを含めると、stdlib default modeの代替としては過大です。([man7.org]5) ([man7.org]5) ([man7.org]5)

    strace:Linux-only optional strict modeとして妥当

    #1356 / #1363 の方針どおり、defaultにはせず、availability check、parse failure fail-close、raw trace非公開、child tree + FD attributionを満たす場合に限定すべきです。--read / --write dumpはfile contentを含み得るため使用しない判断も妥当です。

    Landlock:将来のLinux strict-prevention modeとして優先検討

    Linux Landlock はunprivileged processが自分自身と将来の子孫をfilesystem rulesetで制約でき、write、create、remove、rename、truncateを実行前に拒否できます。事後snapshotやtrace parsingより構造的に強く、専用telemetry namespaceとallowed artifact rootだけにwrite権限を与える設計に適しています。([Linux カーネル ドキュメント]6) ([Linux カーネル ドキュメント]6) ([Linux カーネル ドキュメント]6)

    ただし、sandbox適用前にopenされたFDは制約外で、chmod、chown、utime 等は現時点で完全には制約できません。ABI/kernel support検査と、適用前FDの管理が必要です。したがって #1409 の小規模修正に混ぜず、将来のLinux-only prevention modeとして分離するのが妥当です。([Linux カーネル ドキュメント]6) ([Linux カーネル ドキュメント]6)

    推奨する設計

    第一選択:hook-owned namespaceを分離する

    session-manifest関連の全runtime fileを、例えば次の専用subtreeに集約します。

    artifacts/session-manifest-runtime/
    ├── events/
    ├── locks/
    ├── tmp/
    └── manifests/
    

    race-tolerant modeで除外するのは、このsubtreeだけです。

    _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS = (
        ".claude/worktrees",
        ".claude/artifacts/issue-refinement-loop",
        "artifacts/session-manifest-runtime",
    )

    _VOLATILE_PEER_SESSION_ROOT_RELS という名前も修正対象です。今回のwriterは「peer session」とは限らず、同一セッションの非同期background workerです。_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS 等の方が実際の保証内容を正確に表します。

    この設計なら以下を維持できます。

    artifacts/session-manifest-runtime/**       race-tolerantでは除外
    artifacts/<issue>/issue-metadata/**         引き続き監査
    artifacts/arbitrary-output/**               引き続き監査
    artifacts/.env                              引き続き監査
    

    このため、#1409 の「session manifestの出力先変更はOut of Scope」は撤回が必要です。出力先を変えずにroot全体を除外する方が、明らかに大きい設計変更だからです。

    次善策:root直下の厳密なpath matcher

    互換性上どうしてもmanifestをroot直下に残す場合は、少なくとも以下だけを除外します。

    artifacts/session-manifest-debounce/**
    artifacts/.lock-<validated-stable-key>
    artifacts/.tmp-<validated-uuid>
    artifacts/.tmp-<validated-uuid>.failed
    artifacts/private-agent-session-manifest-(posttooluse|subagentstop|stop)-<validated-fields>.json
    

    ただし race-tolerant modeではchild自身が同じfilename patternを偽装できるため、専用subtreeより弱い方式です。このspoofabilityをknown limitationとして明記する必要があります。

    修正後の最低限のAcceptance Criteria

    AC1:
    実際の session_manifest_debounce / generator process を用いた
    同期型integration testで、現行mainでは unauthorized_write_path が再現し、
    修正後はhook-owned専用namespaceの同時writeに限って成功する。
    
    AC2:
    race_tolerant_stdlib modeで、
    artifacts/session-manifest-runtime/** のpeer/background writeは誤検知しない。
    
    AC3:
    child command自身による以下へのwriteは unauthorized_write_path になる。
    - artifacts/unrelated/**
    - artifacts/<issue>/issue-metadata/**
    - artifacts/.env
    - artifacts/session-manifest-runtime の外側すべて
    
    AC4:
    race_tolerant_stdlib modeではchild自身による
    hook-owned namespaceへのwriteを区別できないことを、
    known limitation testとして明示する。
    
    AC5:
    lock作成、metadata更新、temporary file作成、atomic rename、
    event file削除、failed renameの実際のlifecycleを検証する。
    固定sleepだけに依存しない。
    
    AC6:
    既存6件の #1343 regression testsを維持する。
    
    AC7:
    #1363へのhandoffを明記する。
    strict_strace modeではtraced childによるhook-owned namespaceへのwriteを
    fail-closeし、tracer外peer processのwriteは誤帰属しない。
    
    AC8:
    docs/dev/agent-skill-boundaries.md のvolatile/unattributable root inventory、
    known limitation、mode別保証を更新する。
    

    Runtime Verificationは次の形が適切です。

    decision: immediate
    reason: >
      実際の障害は Claude Code async hook、detached debounce worker、
      filesystem write/rename/delete と skill_runtime_exec snapshot の
      lifecycle overlapに依存するため。
    required_evidence:
      - actual hook payload
      - child/background process synchronization evidence
      - created/renamed/deleted relative paths
      - executor return code and reason_code
      - race_tolerant and strict-mode ownership matrix

    Allowed Pathsも少なくとも次まで拡張すべきです。

    scripts/agent-guards/skill_runtime_exec.py
    scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
    .claude/hooks/generate_session_manifest_from_hook.mjs
    .claude/hooks/session_manifest_debounce.mjs
    .claude/hooks/tests/test_generate_session_manifest_from_hook.py
    関連するdebounce tests
    docs/dev/agent-skill-boundaries.md
    docs/dev/hook-boundaries.md
    必要なら docs/schemas/agent-session-manifest.md
    

    最終レビューコメント

    障害の存在は認めるが、artifacts/ 全体をvolatile rootに追加する解決策は受け入れられない。これはsession-manifest由来のfalse positiveを除去する局所修正ではなく、controlled mutation inputを含むroot artifacts全域へのchild self-writeを監査不能にする変更である。#1343 / PR #1349で受容したknown limitationを拡張するなら、少なくとも同等のSafety Claim Matrix、self-write negative test、SSOT更新、runtime integration evidenceが必要である。推奨はsession-manifest runtime filesを専用subtreeへ移し、race-tolerant modeでそのsubtreeだけを除外すること。Required Design References: なし、Runtime Verification: not_applicable、#1363とのmode contract未定義も修正すること。現状は REQUEST_CHANGES。

  3. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    Refinement Loop 実行状態報告(isolation worktree 経由)

    実行したコマンドと結果

    1. uv run --locked python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py --issue-number 1409 --repo squne121/loop-protocol --anchor-comment-url https://github.com/squne121/loop-protocol/issues/1409#issuecomment-4935283248
      • STATUS: pass / NEXT_ACTION: proceed(planner_fail_closed: false、blockers: [])
    2. plan_refinement_loop.py(同じ planner input を stdin 投入)で decisions を確認
      • investigation_policy.required = true(target_paths に scripts/agent-guards/skill_runtime_exec.py 等)
      • web_research_policy.required = true(ただし critical_external_claims の中身は VC の pytest -k コマンド文字列・AC本文であり、外部仕様主張の誤検知の可能性が高い。実際に外部 web 調査が必要な技術的主張は見当たらなかった)
      • scope_delta_decision.status = fail_closed, reason = no_anchor_scope_reframe_v1_payload, implementation_go = false(アンカーコメントに構造化 ANCHOR_SCOPE_REFRAME_V1 payload が無いため、Allowed Paths 等の自動拡張は不可)
    3. コードベース調査(scripts/agent-guards/skill_runtime_exec.py、scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py、.gitignore)
      • _VOLATILE_PEER_SESSION_ROOT_RELS は現状 .claude/worktrees と .claude/artifacts/issue-refinement-loop のみで、repo root 直下 artifacts/ は未登録であることを確認(Issue の障害診断自体は技術的に正確)。
      • 既存テストファイルに Issue 記載の VC 対象テスト名 test_unrelated_write_to_repo_root_artifacts_does_not_fail / test_existing_repo_root_artifacts_file_update_does_not_fail は未実装(baseline: pytest -k で exit 5 / collected 0 selected を確認)。AC3/AC4 が指す既存テスト名は既に存在し PASS 済み。
    4. uv run --locked python3 .claude/skills/review-issue/scripts/check_issue_contract.py --issue 1409 --repo squne121/loop-protocol --json
      • VERDICT: approve(blocking_issues: [])。ただしこれは C1〜C13 の構造的・決定論的チェックのみであり、契約の技術的妥当性(設計判断の是非)は対象外。

    重要な未反映事項: アンカーコメントの REQUEST_CHANGES が Issue 本文に未反映

    アンカーコメント(#1409 (comment) 、OWNER・squne121)は REQUEST_CHANGES 判定であり、現行の Issue 契約のままでの実装着手に反対しています。要旨:

    • Blocker 1: artifacts/ 全体を _VOLATILE_PEER_SESSION_ROOT_RELS に追加する現行案は、誤検知除去の範囲を大幅に超え、repo root artifacts/** 全域を unauthorized-write 監査から外してしまう。
    • Blocker 2: artifacts/ は disposable telemetry 専用ではなく、controlled mutation policy の write root(artifacts/{issue_number}/issue-metadata/...)でもあるため、全域除外は provenance detector を消してしまう。
    • Blocker 3: issue_kind: implementation にもかかわらず Required Design References: なし は readiness rule 違反(RDR001 相当)。SSOT(docs/dev/agent-skill-boundaries.md の Parallel Agent Runtime Safety)が repo root artifacts/** を volatile root として列挙しておらず、SSOT 更新も必要。
    • Blocker 4: Runtime Verification Applicability: not_applicable は矛盾(非同期 hook・detached worker・複数プロセス・filesystem timing が絡むため immediate が妥当)。原因記述(「当該コマンド自身の PostToolUse hook が更新する」)も不正確で、正しくは「先行 tool call から継続する async debounce worker / 並行 Stop・SubagentStop hook」。
    • Major 5: 提案 AC が固定 sleep ベースの模擬同時実行であり、実際の lock/temp/atomic rename/failed rename ライフサイクルを検証していない。
    • Major 6: #1363(strict_strace mode 追加)との mode 別保証の handoff が未定義。
    • Major 7: 「.gitignore で scratch 領域だから監査除外してよい」という推論は worktree_scope_guard に local main scratch 出力先の安全な例外 (LOCAL_MAIN_SCRATCH_ALLOW_V1) を追加する #974 の safe scratch 例外の前提(untracked / safe prefix / Write・Edit 系操作限定)と矛盾。

    推奨設計(第一選択)は、artifacts/ 全体ではなく専用 subtree artifacts/session-manifest-runtime/ のみを race-tolerant 除外対象にし、artifacts/<issue>/issue-metadata/** 等は引き続き監査対象に残すというもので、AC1〜AC8 の全面差し替え、Required Design References の追加、Runtime Verification: immediate への変更、Allowed Paths の拡張(.claude/hooks/session_manifest_debounce.mjs 等を含む)を要求しています。

    なぜ本文を自動書き換えしなかったか

    • scope_delta_decision が fail_closed(reason: no_anchor_scope_reframe_v1_payload, implementation_go: false)であり、このアンカーコメントには機械可読な ANCHOR_SCOPE_REFRAME_V1 payload が含まれていないため、Allowed Paths 拡張や AC 全面差し替えを自動反映する権限が preflight/planner レベルで fail-close されています。
    • 提案されている修正は単純な文言修正ではなく、実装方針そのもの(_VOLATILE_PEER_SESSION_ROOT_RELS 全体除外 → 専用 subtree 方式への転換)と検証方式(sleep ベース → 同期 integration test)を変更する設計判断であり、review-issue の決定論的チェック(構造チェックのみ)が approve を返したことは、この設計判断の妥当性を保証しません。
    • 本エージェントが codebase-investigator 相当の調査で確認できたのは「障害の技術的原因診断は正確」という点のみで、OWNER が求める再設計(artifacts/session-manifest-runtime/ の新設、.claude/hooks/session_manifest_debounce.mjs 側の出力先変更是非を含む)を implementation contract として確定するには、人間の設計判断が必要と判断しました。

    次アクション(人間判断が必要)

    1. アンカーコメントが提案する「専用 subtree 方式(第一選択)」と「root 直下の厳密な path matcher(次善策)」のどちらを採用するか決定してください。
    2. 決定後、Issue 契約(In Scope / Out of Scope / Acceptance Criteria / Verification Commands / Allowed Paths / Required Design References / Runtime Verification Applicability)を、上記アンカーコメントの「修正後の最低限の Acceptance Criteria(AC1〜AC8)」に沿って全面改稿する必要があります。
    3. 改稿後、issue-refinement-loop / review-issue を再実行し、構造チェックと意味論的内容の双方が揃った状態で issue-contract-review に進めてください。

    現時点で Issue 本文は変更していません。VERDICT(決定論的チェック)は approve ですが、OWNER アンカーコメントの REQUEST_CHANGES が実質的なブロッカーです。

  4. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    Issue 本文を OWNER レビュー(専用subtree方式)に沿って全面改訂

    OWNER anchor comment(https://github.com/squne121/loop-protocol/issues/1409#issuecomment-4935283248)の REQUEST_CHANGES を反映し、本文を書き換えました(body_sha256: sha256:be201f55f376778f22b64cd7c950efd796fe441d7608a65965147fd1513f6b77)。

    採用した設計判断

    • repo-root artifacts/ 全体除外案を撤回し、hook 専用の新設 subtree artifacts/session-manifest-runtime/(events/ / locks/ / tmp/ / manifests/)へ session-manifest hook の出力先を変更した上で、この subtree のみを race-tolerant 除外対象に加える「第一選択」方式を採用しました。次善策(root 直下の path matcher)は spoofability の懸念があり不採用としています。
    • _VOLATILE_PEER_SESSION_ROOT_RELS / _is_volatile_peer_session_path を _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS / _is_race_tolerant_unattributable_path へ改名する方針を In Scope に追加しました(実際の保証内容が「他セッション由来」に限らないため)。

    Blocker / Major の解消状況

    review-issue 検証結果

    .claude/skills/review-issue/scripts/check_issue_contract.py --issue 1409 --repo squne121/loop-protocol --json を実行し、verdict: approve(C1〜C11 全 pass、C12/C13 は n/a)を確認済みです。

    次のステップとして issue-contract-review(実装着手前 preflight)に進めます。

  5. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-10T12:58:37Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1409
      body_sha256: "sha256:ea50f8c3f2004fd0b17568ce7625451043049dd88b83240e1dbea6a5dff3d69d"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  6. squne121 commented on Jul 10, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-07-10T13:26:02Z)

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