Skip to content

調査: SubAgent の Bash/Write/Edit tool 経由操作が pre-existing untracked file を意図せず削除・上書きする guard gap を調査する #2762

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: research
parent_issue: "none"
goal_ref: "SubAgent の Bash/Write/Edit tool 経由の操作が pre-existing untracked file を意図せず削除・上書きすることを防ぐ既存の仕組みが repository 内にあるかを調査し、無ければ対応方針を決定する"
change_kind: research-only

Parent Issue

なし(単独改善)

Outcome

SubAgent の Bash/Write/Edit tool 呼び出し経由での pre-existing untracked file の意図しない削除・上書きに対する防止策の対応方針が決定され、本 Issue 本文または comment に調査結果(既存の仕組みの有無・追加すべき hook/guard の候補)が記録された上で、方針が「実装が必要」の場合は実装 follow-up Issue が起票され本 Issue から link されている状態。方針が「実装不要(許容リスク)」の場合はその判断理由が本 Issue に記録され、本 Issue が close 可能な状態。

In Scope

Out of Scope

  • hook/guard の実コード実装(方針決定後に別 implementation Issue で行う)
  • 今回誤削除されたと自己申告された .codebase-investigator-context-2677.md 自体の復元・追跡(当該ファイルは .claude/agents/codebase-investigator.md の設計上 /tmp 配下に生成されるべき transient artifact であり、repo root への存在自体が本来の設計と異なる)
  • .claude/agents/codebase-investigator.md 側の CONTEXT_FILE 生成先変更(別件)

Acceptance Criteria

  • .claude/hooks/ 配下の hook 設定を確認し、SubAgent の Bash/Write/Edit tool 呼び出しに対する pre-existing untracked file 削除・上書き防止の既存カバレッジ有無が本 Issue 本文または comment に記載されている
  • scripts/agent-guards/controlled_skill_mutation_exec.py の postcondition guard パターンが SubAgent tool 境界へ拡張可能かどうかの技術的所見が本 Issue 本文または comment に記載されている
  • 対応方針(hook 追加 / guard 拡張 / 運用強化のみ / 対応不要)が決定され、判断理由とともに本 Issue に記録されている
  • 対応方針が「実装が必要」の場合、実装 follow-up Issue が起票され本 Issue からリンクされている。「実装不要」の場合、その理由が本 Issue に明記されている

Verification Commands

$ gh issue view THIS_ISSUE_NUMBER --json body,comments

上記コマンドの出力に、調査結果・対応方針が本文または comment に記録されていることを確認する(THIS_ISSUE_NUMBER は本 Issue の番号に置換する)。

$ gh issue list --search "FOLLOW_UP_ISSUE_TITLE_KEYWORD" --state open --json number,title,url

実装が必要な場合、上記コマンドの出力に follow-up Issue が起票され本 Issue と相互リンクしていることを確認する(FOLLOW_UP_ISSUE_TITLE_KEYWORD は follow-up Issue のタイトルキーワードに置換する)。

Allowed Paths

  • 読み取り専用。リポジトリ変更なし(既定)
  • 調査対象として .claude/hooks/ および scripts/agent-guards/controlled_skill_mutation_exec.py を参照可能(変更は行わない)

Stop Conditions

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

Handoff Contract

Background

Issue #2728 のレビュー中、前回サイクルで issue-creator SubAgent がリポジトリ直下の pre-existing untracked file .codebase-investigator-context-2677.md を rm -f で誤削除したと自己申告した。今回 codebase-investigator SubAgent による bounded read-only investigation で以下を確認した(current main、squne121/loop-protocol)。

  1. .codebase-investigator-context-*.md の canonical producer は .claude/agents/codebase-investigator.md であり、/tmp 配下に timestamp 付きファイル名で生成する transient artifact として設計されている。つまりこのファイル種別は本来リポジトリ直下(repo root)に存在すべきものではない。
  2. Issue 調査: authority_transport.consume の外側 timeout と内側予算の不整合を調査し対応方針を決定する #2677 は本ファイル名パターンとは無関係な別内容の OPEN Issue("調査: authority_transport.consume の外側 timeout と内側予算の不整合を調査し対応方針を決定する")であり、このファイルの producer/owner ではない。
  3. scripts/agent-guards/controlled_skill_mutation_exec.py には、skill mutation execution context において pre-existing untracked file の削除を検知・拒否する postcondition guard が存在する(test_rejects_deleted_preexisting_untracked_file でテスト済み。判定ロジックは _compare_repo_transition 参照)。
  4. しかし、この guard は controlled_skill_mutation_exec.py 経由の mutation にのみ適用され、SubAgent が直接使う Bash(rm 等)や Write/Edit tool 経由の操作には適用されない。つまり SubAgent が task scope 外の pre-existing untracked file を、skill mutation guard を経由せずに削除できてしまう boundary gap が存在する。
  5. gh issue list --search で "SubAgent untracked file delete guard" 等を検索したが、この具体的な gap を扱う既存 OPEN/CLOSED Issue は見つからなかった。近い関連 Issue として 実装: temp residue の再検査付き削除 executor を追加する #1616(temp residue 再検査付き削除 executor、OPEN)、実装: active issue worktree 外への Write/Edit/Bash mutation を hook で遮断する #960(active issue worktree 外への Write/Edit/Bash mutation を hook で遮断、CLOSED)、実装: controlled_skill_mutation_exec の postcondition が事前存在 untracked ファイルを誤検知する不具合を修正する #2163(controlled_skill_mutation_exec.py の postcondition 誤検知修正、CLOSED)があるが、いずれも本件(SubAgent レベルでの pre-existing untracked file 削除保護の欠如)とは scope が異なる。

今回具体的な実害(重要ファイルの喪失)は確認されていない(削除されたファイル自体が /tmp 配下に生成されるべき transient artifact だった可能性が高い)が、一般化すると任意の pre-existing untracked file(人間の作業中ファイル等)が同様に削除されうる guard gap であるため、優先度は低いが follow-up として調査 Issue を起票する。

Source

Notes for Reviewer

Activity

  1. added
    phase/research
    state/queued
    agent/research
    on Sep 25, 2026
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