Skip to content

調査: volatile peer-session root への child プロセス自己書き込みの strict attribution を検討する #1356

Closed

Description

@squne121

Source

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: none
goal_ref: 契約実行ラッパー(scripts/agent-guards/skill_runtime_exec.py)が volatile peer-session root への自プロセス書き込みを検出できない known limitation の解消方針を検討する
change_kind: research-only

Parent Issue

なし(単独調査)

Background

Outcome

volatile peer-session root(.claude/worktrees/** 等)への child プロセス自己書き込みを厳密に attribution する方式(Option A 相当、strace ベース案含む)の実現可能性・コスト・トレードオフを整理し、採用可否と(採用する場合の)implementation Issue が起票可能な状態にする。

結論(Decision Record 参照): 条件付き採用。 Linux-only の optional strict mode(strict_strace)を prototype として実装候補にするが、現行 wrapper の default 挙動(race_tolerant_stdlib)は維持する。

In Scope

  • strace 等 process-level syscall トレースによる書き込み attribution 案の技術的実現可能性の調査(Linux 依存性、CI/ローカル環境双方での動作可否、パフォーマンスコスト)
  • trace 出力の parser 実装方針(何を自プロセスの書き込みと判定する具体的なロジック)の整理
  • trace ログ・artifact への secret 混入を防ぐ secret-safe artifact handling 方針の検討
  • strace 不可・trace 取得失敗時の fallback 方針(fail-closed とすべきか、既存の scope-excluded 方式に留めるか)の検討
  • 採用可否の判断と、採用する場合の implementation Issue 起票

Out of Scope

  • wrapper 本体・テストコードの実装変更
  • .claude/worktrees/** / .claude/artifacts/issue-refinement-loop/** 以外の既存 known limitation の見直し
  • strict attribution 以外の unauthorized_write_path 検出ロジック全体の再設計

Decision Record

decision_record_schema: v1
decision: conditional_adopt
default_mode: race_tolerant_stdlib
strict_mode_availability:
  mode_name: strict_strace
  platform: linux_only
  default: false
  requires: strace_available_and_smoke_test_passed
  unavailable_behavior: fail_closed
  failure_reason_code: strict_attribution_unavailable
  parse_failure_behavior: fail_closed
parser_scope:
  covered_syscalls:
    path_syscalls:
      - open
      - openat
      - openat2
      - creat
      - mkdir
      - mkdirat
      - rename
      - renameat
      - renameat2
      - unlink
      - unlinkat
      - symlink
      - symlinkat
      - link
      - linkat
      - truncate
      - chmod
      - chown
      - utimensat
    fd_syscalls:
      - write
      - pwrite64
      - writev
      - pwritev
      - pwritev2
      - ftruncate
      - copy_file_range
      - sendfile
    fd_table_tracking:
      - dup / dup2 / dup3
      - close
      - fcntl(F_DUPFD*)
      - fork/clone 経由の fd 継承
  uncovered_or_unguaranteed:
    - "strace の %file trace のみでは write attribution にならない(open() の file descriptor は path 変更後も同一 open file description を参照し続けるため、O_WRONLY/O_RDWR/O_CREAT/O_TRUNC/O_APPEND 等の flag と write 系 syscall の対応付けが必須)"
    - inotify は発生元 PID を含まないため不採用
    - "fanotify は PID を含むが非特権利用時に機能制限があり、本 repo の Python wrapper には過剰"
secret_artifact_policy:
  raw_trace_in_artifact_or_comment_or_stdout: forbidden
  read_write_dump_flags: forbidden
  parser_output_fields:
    - normalized_repo_relative_path
    - syscall_class
    - access_mode
    - decision
  raw_trace_storage: tmp_private_dir_deleted_after_parse
  debug_opt_in_persisted_trace:
    allowed: true
    condition: explicit_opt_in_only
    redact:
      - GH_TOKEN
      - HOME
      - absolute_temp_path
      - user_name
  trace_parse_failure_in_strict_mode: fail_closed
fallback_policy:
  attribution_modes:
    race_tolerant_stdlib:
      default: true
      strict_volatile_self_write_detection: false
      unavailable_behavior: continue
      required_notice: emit attribution_mode=race_tolerant_stdlib
    strict_strace:
      default: false
      platform: linux_only
      requires: strace_available_and_smoke_test_passed
      unavailable_behavior: fail_closed
      failure_reason_code: strict_attribution_unavailable
      parse_failure_behavior: fail_closed
unsupported_cases:
  - platform: macos
    behavior: default_unsupported_no_silent_pass
  - platform: windows
    behavior: default_unsupported_no_silent_pass
  - platform: wsl
    behavior: same_as_linux_if_strace_available_else_fail_closed_for_strict_mode
  - environment: ci_without_strace_installed
    behavior: strict_mode_unavailable_reason_code_emitted_default_mode_unaffected
implementation_issue_required: true
implementation_issue_scope_candidate:
  allowed_paths:
    - scripts/agent-guards/skill_runtime_exec.py
    - scripts/agent-guards/tests/test_skill_runtime_exec_strict_attribution.py
    - docs/dev/agent-skill-boundaries.md
  verification_candidates:
    - parser unit tests: fixture trace で常時 green
    - live strace smoke test: Linux + strace available のとき実行
    - strict mode required test: strace unavailable / parse failure は fail-closed
    - secret safety test: raw trace が stdout/stderr/artifact projection に出ない
    - regression: race_tolerant_stdlib の既存6テストは維持
not_adopted:
  - 現行 wrapper の default を strace 必須に置き換えること
  - "`%file` grep だけで strict attribution と主張すること"
  - raw trace を artifact / issue comment / stdout に保存すること
  - strace unavailable 時に silent fallback して「strict検証済み」と扱うこと
code_comment_followup:
  file: scripts/agent-guards/skill_runtime_exec.py
  note: "race_tolerant_stdlib と strict_strace で volatile root の扱いが逆転するため、implementation issue でコメントを mode-aware に修正する必要がある"

Acceptance Criteria

  • AC1: strace ベース案を含む process-level attribution 案の技術的実現可能性(Linux 依存・CI 適用可否・パフォーマンスコスト)が本 Issue 本文に整理されている
  • AC2: trace parser 方針・secret-safe artifact handling 方針・fallback 時 fail-closed 方針の 3 点それぞれについて具体的な結論または未決事項が本 Issue 本文に記載されている
  • AC3: 採用可否の結論が記載され、採用する場合は implementation Issue が起票され本 Issue からリンクされている。不採用の場合はその理由が明記され、本 Issue が close 可能な状態になっている
  • AC4: 採用判断が Decision Record として本 Issue 本文に記録されている。必須キー: decision, default_mode, strict_mode_availability, parser_scope, secret_artifact_policy, fallback_policy, unsupported_cases, implementation_issue_required
  • AC5: strace 採用時の parser 対象 syscall と非対象 syscall が列挙され、「検出できる write」と「検出できない/保証しない write」が分けて記載されている
  • AC6: CI/local/WSL/Linux/macOS/Windows の適用可否 matrix が記載されている。macOS/Windows は default unsupported とし、silent pass を禁止する
  • AC7: implementation Issue を起票する場合、strict mode が unavailable / parse failed / trace contains unsafe raw data のときの reason_code と exit behavior が AC に含まれている

Verification Commands

# AC1
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC2
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC3
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC4
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC5
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC6
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body
# AC7
# baseline-expect: pass
$ gh issue view 1356 --repo squne121/loop-protocol --json body -q .body

Allowed Paths

  • 読み取り専用。リポジトリ変更なし(既定)

Stop Conditions

  • Outcome / Scope / AC が検索可能な形で記載されていない場合は即停止
  • Allowed Paths 外への書き込みを試みた場合は即停止
  • 権限不足(permission denied)により操作が完了できない場合は即停止
  • 成果物の書き込みに失敗した場合(I/O エラー等)は即停止

Handoff Contract

Notes for Reviewer

Activity

  1. added
    phase/research
    state/queued
    agent/research
    on Jul 6, 2026
  2. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    判定

    #1356 は起票意図として妥当。ただし、現状の Issue 契約のまま implementation に流すと危険です。
    結論から言うと、strace ベースの strict attribution は Linux 限定の任意 strict mode / 実験的実装としては採用候補ですが、現行 skill_runtime_exec.py のデフォルト動作を置き換える形で即採用するのは推奨しません。

    理由は、#1356 が扱う問題は「.claude/worktrees/** 等への self-write を拾うか」だけではなく、process tree の syscall attribution、FD 経由 write、trace artifact の secret 混入、CI/ローカル差異、fallback 時の fail-open 防止まで含む safety boundary だからです。#1356 自体は research-only で、AC も「Issue 本文に整理する」形式なので、まずは Decision Record 化してから implementation issue を切るべきです。

    確認した一次情報

    #1356 は、#1343 / PR #1349 で採用された Option B の follow-up です。#1343 では volatile peer-session root への self-write は race-tolerant stdlib mode の既知制限として明示され、strict attribution は別 Issue スコープに分離されています。 #1356 には現時点でコメントはありません。

    現行実装では、_VOLATILE_PEER_SESSION_ROOT_RELS として .claude/worktrees と .claude/artifacts/issue-refinement-loop を定義し、これらを snapshot/status の監査対象から除外しています。 _snapshot_repo_paths() は os.walk() で repo を走査し、volatile root を prune します。 _find_unauthorized_repo_changes() でも git status 差分から _is_volatile_peer_session_path() を除外しているため、volatile root への self-write は構造的に検出できません。

    テストもこの制限を明示しています。.cache/outside.txt への self-write は unauthorized_write_path で fail-close しますが、.claude/worktrees/** や他 issue の .claude/artifacts/issue-refinement-loop/** への self-write は return code 0 で通ることを known limitation として固定しています。

    また、#1346 / PR #1353 で docs/dev/agent-skill-boundaries.md に Parallel Agent Runtime Safety が SSOT 化され、Strict attribution mode と Race-tolerant stdlib mode の二段階区分が追加済みです。 ドキュメント上も、現行実装は Race-tolerant stdlib mode であり、volatile root への self-write 検出は対象外と明記されています。

    P0: strace -f -e trace=%file だけでは「write attribution」にならない

    strace は syscall と signal を記録でき、-f で fork/vfork/clone 由来の child process を追跡できます。%file は filename を引数に取る syscall 群をまとめて trace できるため、候補としては妥当です。([man7.org]1)

    ただし %file は「ファイル名を参照した syscall」を見るものであって、「書き込みが発生したファイル」を完全に返すものではありません。Linux の open() は file descriptor を返し、その file descriptor は path が削除・変更されても open file description を参照し続けます。書き込み意図は O_WRONLY / O_RDWR、O_CREAT、O_TRUNC、O_APPEND 等の flag と、その後の write() 系 syscall を対応づけて初めて判定できます。([man7.org]2)

    したがって parser は最低でも次を扱う必要があります。

    - path syscall:
      open/openat/openat2/creat/mkdir/mkdirat/rename/renameat/renameat2
      unlink/unlinkat/symlink/symlinkat/link/linkat/truncate/chmod/chown/utimensat 等
    
    - fd syscall:
      write/pwrite64/writev/pwritev/pwritev2/ftruncate
      copy_file_range/sendfile 系
    
    - fd table:
      pid/tid ごとの fd -> resolved path を追跡
      dup/dup2/dup3/close/fcntl(F_DUPFD*) で fd alias を更新
      fork/clone 後の fd 継承を考慮
    

    strace 自身も、subset の syscall だけを監視して user/kernel 境界について推論する場合は注意が必要だと警告しています。([man7.org]1) つまり「%file を grep して volatile root が出たら fail」程度の実装は、strict attribution ではなく 不完全な heuristic です。

    P0: secret-safe artifact handling は Issue #1356 の最重要 AC に格上げすべき

    strace は文字列引数を C string として表示し、デフォルトでは文字列の先頭 32 byte を出力します。([man7.org]1) さらに --read / --write 系 option を使うと file descriptor の read/write データを hex/ASCII dump できます。これは secret を trace artifact に混入させる最短経路です。([man7.org]1)

    #1356 は secret-safe artifact handling を In Scope に入れていますが、AC は「方針を書く」だけです。ここは弱いです。採用可否判断の前に、少なくとも以下を契約化してください。

    - raw trace を PR artifact / issue comment / stdout に出さない
    - --read / --write dump は禁止
    - parser 出力は normalized repo-relative path, syscall_class, access_mode, decision のみに縮約
    - raw trace は tmp private dir に置き、parse 後に削除
    - debug opt-in 時だけ保存し、保存時も GH_TOKEN / HOME / absolute temp path / user name を redact
    - trace parse failure は strict mode では fail-closed
    

    現行 wrapper は child を subprocess.run(... capture_output=True, text=True, shell=False) で実行し、完了後に repo snapshot/status を比較しています。 ここへ strace を挟むなら、stdout/stderr の扱いと trace の扱いを明確に分離しないと、guard が守るべき境界より trace artifact の方が危険になります。

    P0: fallback 方針は「strict required」と「best-effort」を分けるべき

    #1356 の Open Question に fallback fail-closed 方針がありますが、ここは二値ではなく mode 別に定義すべきです。

    推奨はこれです。

    attribution_modes:
      race_tolerant_stdlib:
        default: true
        strict_volatile_self_write_detection: false
        unavailable_behavior: continue
        required_notice: emit attribution_mode=race_tolerant_stdlib
    
      strict_strace:
        default: false
        platform: linux_only
        requires: strace_available_and_smoke_test_passed
        unavailable_behavior: fail_closed
        failure_reason_code: strict_attribution_unavailable
        parse_failure_behavior: fail_closed

    GitHub-hosted runner は ubuntu-latest / ubuntu-24.04 等の Linux runner を使えますが、OS/runner label に依存します。GitHub Docs は public/private repo の Linux runner labels を示しており、Linux/macOS VM では passwordless sudo が使えるため、CI で strict mode を必須にするなら command -v strace || sudo apt-get update && sudo apt-get install -y strace のような availability step を明示すべきです。([GitHub Docs]3)

    P1: inotify は採用不可、fanotify は過剰

    inotify は event monitoring には使えますが、event 構造体には watch descriptor、mask、cookie、name があるだけで、発生元 PID は含まれていません。([man7.org]4) つまり、今回必要な「この child process tree が書いたか」の attribution には不十分です。

    fanotify はイベント metadata に PID を持ち、filesystem event の通知・interception もできます。([man7.org]5) ただし、permission event や高度な report option は capability 要件が絡み、非特権利用では機能制限があります。([man7.org]6) この repo の Python wrapper に組み込むには重すぎます。#1356 の比較対象として触れる価値はありますが、第一候補は strace の方が現実的です。

    P1: 現行コードコメントは strict attribution 導入時に誤読される

    skill_runtime_exec.py のコメントは「volatile root 配下の変更は child subprocess に帰属させてはならない」と書いています。 Race-tolerant stdlib mode の説明としては成立しますが、#1356 が strict attribution を検討する文脈では逆です。strict mode なら、child 由来であると証明できた volatile root 書き込みは unauthorized として fail-close すべきです。

    実装 Issue を切る場合は、コメントを mode-aware に直す必要があります。

    - race_tolerant_stdlib:
      volatile root は peer-session false positive 回避のため snapshot 監査から除外する
    
    - strict_strace:
      volatile root であっても child process tree 由来の allowed_write_roots 外 write は fail-close する
    

    P1: #1356 の AC は「本文更新」だけでは弱い

    現 AC は gh issue view 1356 --json body -q .body で確認する形式です。これは research issue としては最低限ですが、今回の対象は safety boundary なので、結論が曖昧なまま close できてしまいます。

    最低限、#1356 に次の AC を追加した方がよいです。

    - [ ] AC4: 採用判断を `Decision Record` として記録する。
          必須キー: decision, default_mode, strict_mode_availability,
          parser_scope, secret_artifact_policy, fallback_policy,
          unsupported_cases, implementation_issue_required。
    
    - [ ] AC5: strace 採用時の parser 対象 syscall と非対象 syscall を列挙し、
          「検出できる write」と「検出できない/保証しない write」を分けて記載する。
    
    - [ ] AC6: CI/local/WSL/Linux/macOS/Windows の適用可否 matrix を記載する。
          macOS/Windows は default unsupported とし、silent pass を禁止する。
    
    - [ ] AC7: implementation Issue を起票する場合、
          strict mode が unavailable / parse failed / trace contains unsafe raw data
          のときの reason_code と exit behavior を AC に含める。

    推奨結論

    私なら #1356 の結論はこうします。

    採用可否:
      条件付き採用。
    
    採用するもの:
      Linux-only optional strict_strace mode の prototype / implementation issue。
      default は現行 race_tolerant_stdlib mode のまま維持する。
    
    採用しないもの:
      現行 wrapper の default を strace 必須に置き換えること。
      `%file` grep だけで strict attribution と主張すること。
      raw trace を artifact / issue comment / stdout に保存すること。
      strace unavailable 時に silent fallback して「strict検証済み」と扱うこと。
    

    implementation issue を切るなら、初期スコープはこの程度に絞るのが妥当です。

    Allowed Paths 候補:
    - scripts/agent-guards/skill_runtime_exec.py
    - scripts/agent-guards/tests/test_skill_runtime_exec_strict_attribution.py
    - docs/dev/agent-skill-boundaries.md  # mode semantics の補足が必要な場合のみ
    
    Verification:
    - parser unit tests: fixture trace で常時 green
    - live strace smoke test: Linux + strace available のとき実行
    - strict mode required test: strace unavailable / parse failure は fail-closed
    - secret safety test: raw trace が stdout/stderr/artifact projection に出ない
    - regression: race_tolerant_stdlib の既存6テストは維持
    

    実装依頼プロンプトに入れるべき要点

    Issue #1356 は research-only である。まず implementation ではなく、Issue #1356 本文に Decision Record を追記せよ。
    
    必ず参照:
    - docs/dev/agent-skill-boundaries.md の “Parallel Agent Runtime Safety”
    - Issue #1343 AC3/AC5
    - PR #1349 Safety Claim Matrix
    - scripts/agent-guards/skill_runtime_exec.py
    - scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
    - .claude/skills/issue-refinement-loop/scripts/command_registry.py の allowed_write_roots
    
    調査結論:
    - strace は Linux-only optional strict mode としてのみ採用候補
    - default mode は race_tolerant_stdlib 維持
    - `%file` だけでは write attribution 不十分
    - FD table / write syscall / rename/link/truncate 系の parser scope を明記
    - raw trace artifact は保存禁止または明示 opt-in + redact
    - strict mode unavailable / parse failure は fail-closed
    - implementation issue を切る場合は reason_code / tests / allowed paths を含める
    

    現時点の最も危険な失敗モードは、「strace を入れたから strict attribution 済み」と過剰主張することです。#1356 は、その過剰主張を防ぐための research gate として使うべきです。

  3. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 6, 2026

    @squne121
    OwnerAuthor

    Close Evidence

    本 Issue は research issue として close する。

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/researchphase/researchstate/queued

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions