Skip to content

実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "independent peer pytest が生成する repo-root .pytest_cache/** の generated state を executor child の不正書込みへ誤帰属せず、.pytest_cache/** 以外の repository integrity boundary は従来どおり fail-close する"
change_kind: code

Parent Issue

なし(単独改善。#1516 の anchor-bound preflight が runtime guard の誤検知で停止したための follow-up)

Parent Goal Ref

Current Validated Scope

Remaining Parent Gaps

Outcome

skill_runtime_exec.py と regression test が、独立した peer pytest process による repo-root .pytest_cache/**(cache/nodeids、cache/lastfailed、plugin 独自 config.cache key を含む)の作成・更新では guarded execution を誤停止させない一方、.pytest_cache/** 以外の repository 上の許可外書込みおよび tracked/source file への不正変更は引き続き unauthorized_write_path で fail-close する状態になる。

Background

root executor は実行前後の repository snapshot を比較し、active issue artifact root 外の差分を fail-close する。#1516 の正規 preflight は child / wrapper / hook に pytest 起動経路が見つからないにもかかわらず、peer test process が更新したとみられる .pytest_cache/v/cache/nodeids により停止した。

当初案は .pytest_cache/v/cache/nodeids 単体を exact-path 例外にし、cache/lastfailed は引き続き unauthorized 扱いとするものだったが、pytest 本体の _pytest/cacheprovider.py 実装(NFPlugin.pytest_sessionfinish / LFPlugin.pytest_sessionfinish、いずれも同じ pytest_configure hookimpl で登録され、同じ Config.cache.set() API を介して pytest_sessionfinish から無条件に書き込まれる)を確認した結果、nodeids のみを正当としその他を疑わしいとする技術的根拠は存在しないことが判明した。cache/lastfailed は成功のみの session でも空 dict {} として実際に書き込まれ、サードパーティ plugin も cache fixture 経由で .pytest_cache/v/cache/<custom-key> へ任意の key を書き込める。

このため、修正方針を「.pytest_cache/v/cache/nodeids の exact-path 例外」から「repo-root .pytest_cache/** 全体を、既存の _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS directory-root exclusion class(.claude/worktrees 等と同種の disposable / generated / volatile state 分類)へ追加する」設計へ reframe する。.pytest_cache/ は repo-root .gitignore(.gitignore:69)で無視されており、pytest 自身が .pytest_cache/CACHEDIR.TAG と .pytest_cache/.gitignore(*)を自動生成して disposable/regenerable であることを自己宣言している。_LEDGER_* / _SHADOW_LOG_EXACT_REL のような typed exact-file policy は、canonical evidence・append-only log 等「特定の意味を持つ安定ファイル」の symlink/directory/FIFO/socket/device 置換を検出する目的のものであり、その保護対象は .pytest_cache/** のような純粋な disposable キャッシュツリーには当てはまらない。

preflight wrapper の直接実行、cache 削除、環境変数による argv 迂回、-p no:cacheprovider や repository 外 cache_dir を production fix として採用することは引き続き行わない(テストランナー自身の fixture 汚染回避に限定してテスト側だけで使うことは許容する)。

Bootstrap 経緯(本 Issue 固有)

本 Issue 自身の Verification Commands も pytest を使うため、通常の issue-refinement-loop / issue-contract-review の baseline VC preflight(--mode execute で実際に pytest を起動する経路)が、対象バグそのものにより .pytest_cache を unauthorized_write_path と誤判定し、本 Issue を通常経路で前進不能にする自己参照デッドロックが実測で確認された(preflight.run.with_human_context --issue-number 1526 が .pytest_cache/v/cache/nodeids で fail-close)。これを受け、人間オペレーターが本 Issue に限定した one-shot bootstrap authorization として、通常の実装前提ゲート(issue-refinement-loop / issue-contract-review / impl-review-loop の preflight gate)を経由しない直接実装・直接 PR 作成を承認した。本文の reframe 自体は --mode static(pytest 非実行)のみを使う edit_issue_txn.py controlled transaction 経由で行っており、broken gate をこの範囲では回避していない。

In Scope

  • repo-root .pytest_cache/** を _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS の volatile / generated-state exclusion として追加する
  • .pytest_cache/v/cache/nodeids の create/update を許可する
  • .pytest_cache/v/cache/lastfailed の create/update を許可する
  • plugin/custom cache key を含む .pytest_cache/** 配下の generated state を許可する
  • .pytest_cache/** 以外の repo-root sibling write は引き続き unauthorized_write_path とする negative control regression test
  • exemption の root-specificity(.pytest_cache そのものだけであり、nested foo/.pytest_cache/** や .pytest_cache2/** のような prefix 類似 path には適用されないこと)の検証
  • 独立 OS process(実際の pytest サブプロセス)を使った behavior-level regression test

Out of Scope

  • executor child 自身の Allowed Write Roots の拡張
  • ledger(_LEDGER_*)/shadow-log(_SHADOW_LOG_EXACT_REL)の typed exact-file policy の変更
  • repository root 全体(.pytest_cache 以外を含む)の exemption
  • nested foo/.pytest_cache 等、任意ディレクトリ配下の .pytest_cache への exemption 拡張
  • .pytest_cache の内容整合性・セキュリティハーネス(symlink/FIFO 置換の thorough detection 等)
  • writer の strict process attribution
  • グローバルな pytest 設定変更(cache_dir の repository 外移動、-p no:cacheprovider の production 適用等)

Acceptance Criteria

  • AC1: peer pytest による .pytest_cache/v/cache/nodeids の create/update が guarded execution を停止させない
  • AC2: failing peer pytest による .pytest_cache/v/cache/lastfailed の create/update も guarded execution を停止させない
  • AC3: plugin/custom cache key を含む .pytest_cache/** 内の generated state も guarded execution を停止させない
  • AC4: .pytest_cache/** 外の repo-root sibling write は引き続き unauthorized_write_path で fail-close する
  • AC5: tracked/source file への unauthorized modification は引き続き fail-close する
  • AC6: exemption は repo-root .pytest_cache のみに限定され、nested foo/.pytest_cache や prefix 類似 path(.pytest_cache2 等)には適用されない
  • AC7: 独立 OS process(実 pytest subprocess)を使った behavior-level regression test が存在し PASS する

Runtime Verification Applicability

  • decision: not_applicable
  • reason: ローカル fixture の executor snapshot / attribution 判定を対象とし、外部サービスや runtime smoke を必要としない

Verification Commands

# AC1
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_peer_pytest_nodeids_write_is_permitted -q

# AC2
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_peer_pytest_lastfailed_write_is_permitted -q

# AC3
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_peer_pytest_custom_cache_key_write_is_permitted -q

# AC4
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_repo_root_sibling_write_outside_pytest_cache_is_rejected -q

# AC5
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_tracked_source_file_unauthorized_write_is_rejected -q

# AC6
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -k test_exemption_is_repo_root_specific_not_nested_or_prefix_lookalike -q

# AC7
$ uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -q

Allowed Paths

  • scripts/agent-guards/skill_runtime_exec.py
  • scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • .pytest_cache より広い repository root exemption が必要と判明した場合
  • SubAgent 調査で .pytest_cache root exemption に重大な current-main-specific contradiction が見つかった場合

Required Skills

  • Python 3
  • pytest

Required Design References

  • docs/dev/agent-skill-boundaries.md#Parallel Agent Runtime Safety
  • docs/dev/workflow.md#Scope Collision Preflight
  • scripts/agent-guards/skill_runtime_exec.py

Scope Delta(任意)

N/A

Delivery Rule

Notes for Reviewer

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jul 14, 2026
  2. squne121 commented on Aug 27, 2026

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES — #1526 は問題自体は実在しますが、現在の Issue contract のまま実装するのは非推奨です。
    特に「.pytest_cache/v/cache/nodeids だけを exact-path 例外にする」という設計は、観測された1ケースに過適合しています。個人趣味開発でワークフロー継続性を優先するなら、Issue を reframe してから実装するのが妥当です。

    #1526 の発端となった障害には実証があります。#1516 の refinement 再開時に preflight.run.with_anchor が unauthorized_write_path で停止し、問題のパスが .pytest_cache/v/cache/nodeids だったこと、正規 child/wrapper/hook から pytest 起動経路を特定できなかったことまで記録されています。したがって「false positive が存在しない」というレビューではありません。

    敵対的レビュー結果

    Severity | 指摘 | 評価 -- | -- | -- P0 | Issue の前提が stale | 本文は「#1502 は OPEN、未マージなので待つ」「既存 _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に exact nodeids を追加する」という前提です。 しかし #1502 は 7月17日に closed 済みで、PR #1552 も merged。 P0 | nodeids 限定は pytest の実際の write model と矛盾 | pytest の cache provider は nodeids だけを書くものではありません。lastfailed、任意の config.cache key、stepwise 等も同じ cache namespace を使います。 P0 | AC2 が legitimate peer pytest を意図的に false-positive にする | #1526 は lastfailed の変更を明示的に fail-close させます。ところが通常の「失敗する pytest」がまさに lastfailed を更新します。つまり peer pytest が成功すると許容、失敗すると runtime guard が unrelated write として停止する設計になります。 P1 | 非正規生成物を security/integrity boundary として扱いすぎ | このリポジトリ自身が .pytest_cache/ を .gitignore しています。 pytest 自身も .pytest_cache 内に「version control に commit しない」ための .gitignore を生成します。(pytestドキュメンテーション) P1 | typed exact-file policy の横展開が不適切 | ledger や shadow log は canonical evidence / append-only log なので、型・inode・内容遷移を検証する価値があります。一方 pytest cache は disposable cache です。同じハードニングを適用する合理性がありません。 P1 | Out of Scope が解法を先に縛っている | 「directory-wide exclusion 不可」「cache redirect/argv 回避不可」を先に固定しており、障害の性質より過去のガード設計を優先しています。個人開発の目的とは逆です。 P2 | regression test が observed case の再現に寄りすぎ | nodeids positive / lastfailed negative の2点だけでは、pytest plugin が新しい cache key を使った瞬間に同じ Issue が再発します。

    これなら「false positive は消えるが、実際に保護したい repository state は引き続き止める」という契約になります。

    #1526 の具体的な disposition

    そのまま implementation に流すべきではありません。reframe_in_place が適切です。

    タイトルも現在の

    runtime guard が peer pytest nodeids を child write と誤帰属しないようにする

    より、

    runtime guard が peer pytest の generated .pytest_cache state を unauthorized repo write と誤判定しないようにする

    程度まで抽象度を上げた方がよいです。

    Issue 本文の #1502 が未マージ という dependency は削除。#1502 / PR #1552 を 既に成立した設計背景として書き直すべきです。#1526 自身にはコメントがなく、2026年7月14日の作成以来本文も実質更新されていないため、新しい判断で契約を更新して問題ありません。

    また、PR #1552 自身でも overlap preflight の unrelated false-positive が原因で正規 wrapper を bypass して PR を作成した経緯があります。 この repository はすでに 「安全用ハーネスの false positive が実作業を阻害する」コストを現実に何度も払っています。#1526 でさらに cache key 単位の policy を増やすのは、その問題をもう一段増幅します。

    最終評価

    問題の重要度: Medium
    実害はあるものの repository correctness を壊すバグではなく、guard の usability defect です。

    現 Issue contract の品質: Low / stale
    観測事象は正しいものの、解法が path-specific すぎ、現在の main と pytest の write semantics の双方に合っていません。

    推奨: REQUEST_CHANGES → reframe_in_place → .pytest_cache/** volatile-root exemption を最小実装。

    nodeids 専用 typed exception、lastfailed negative control、pytest cache の symlink/FIFO/content integrity harness は、今回の用途では削った方が品質が上がります。守る価値のある canonical state に厳しい guard を集中させ、捨てられる cache は作業を止めない、という境界がこのリポジトリには合っています。

    ## 判定

    REQUEST_CHANGES — #1526 は問題自体は実在しますが、現在の Issue contract のまま実装するのは非推奨です。
    特に「.pytest_cache/v/cache/nodeids だけを exact-path 例外にする」という設計は、観測された1ケースに過適合しています。個人趣味開発でワークフロー継続性を優先するなら、Issue を reframe してから実装するのが妥当です。

    #1526 の発端となった障害には実証があります。#1516 の refinement 再開時に preflight.run.with_anchor が unauthorized_write_path で停止し、問題のパスが .pytest_cache/v/cache/nodeids だったこと、正規 child/wrapper/hook から pytest 起動経路を特定できなかったことまで記録されています。したがって「false positive が存在しない」というレビューではありません。

    敵対的レビュー結果

    Severity 指摘 評価
    P0 Issue の前提が stale 本文は「#1502 は OPEN、未マージなので待つ」「既存 _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に exact nodeids を追加する」という前提です。 しかし #1502 は 7月17日に closed 済みで、PR #1552 も merged。
    P0 nodeids 限定は pytest の実際の write model と矛盾 pytest の cache provider は nodeids だけを書くものではありません。lastfailed、任意の config.cache key、stepwise 等も同じ cache namespace を使います。
    P0 AC2 が legitimate peer pytest を意図的に false-positive にする #1526 は lastfailed の変更を明示的に fail-close させます。ところが通常の「失敗する pytest」がまさに lastfailed を更新します。つまり peer pytest が成功すると許容、失敗すると runtime guard が unrelated write として停止する設計になります。
    P1 非正規生成物を security/integrity boundary として扱いすぎ このリポジトリ自身が .pytest_cache/ を .gitignore しています。 pytest 自身も .pytest_cache 内に「version control に commit しない」ための .gitignore を生成します。([pytestドキュメンテーション]1)
    P1 typed exact-file policy の横展開が不適切 ledger や shadow log は canonical evidence / append-only log なので、型・inode・内容遷移を検証する価値があります。一方 pytest cache は disposable cache です。同じハードニングを適用する合理性がありません。
    P1 Out of Scope が解法を先に縛っている 「directory-wide exclusion 不可」「cache redirect/argv 回避不可」を先に固定しており、障害の性質より過去のガード設計を優先しています。個人開発の目的とは逆です。
    P2 regression test が observed case の再現に寄りすぎ nodeids positive / lastfailed negative の2点だけでは、pytest plugin が新しい cache key を使った瞬間に同じ Issue が再発します。

    一番大きい問題: lastfailed は「不正な近似パス」ではない

    pytest 公式ドキュメントでは cache provider はデフォルト有効で、config.cache を他 plugin も自由に利用できます。公式の --cache-show の例ですら cache/lastfailed と cache/nodeids の双方が表示されています。([pytestドキュメンテーション]2)

    さらに現在の pytest 実装を見ると、NFPlugin.pytest_sessionfinish() は通常の test session 終了時に cache/nodeids を保存します。一方 LFPlugin は test failure を lastfailed に記録し、状態が変われば session finish で cache/lastfailed を保存します。つまり、

    nodeids = 正常な peer write
    lastfailed = suspicious write

    という #1526 の分類には pytest 側の意味論的根拠がありません。どちらも cacheprovider の正常動作です。 ([GitHub]3)

    さらに pytest plugin は config.cache.set("plugin-name/key", ...) のような独自値を保存できます。公式にもその用途が明記されています。([pytestドキュメンテーション]2)

    したがって exact-path 方式を続けると、

    nodeids → 例外追加
    lastfailed → 次の false positive
    stepwise → 次の false positive
    plugin 固有 cache → 次の false positive

    という whack-a-mole になります。

    現在の repository architecture ともズレている

    #1502 / PR #1552 後の skill_runtime_exec.py は、単純な path allowlist ではありません。_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS は明確に directory-root exclusion class として残し、canonical ledger については _LEDGER_STABLE_EXACT_REL と transient protocol entries を別の typed transition policy で処理しています。

    その後の #1563 / PR #1572 でも、canonical な .guard_shadow_log.jsonl は ledger と同様に typed exact-file policy を採用し、append-only、non-regular substitution、truncate 等まで検証しています。PR #1572 は merged 済みです。

    これは設計としては一貫しています。ただし、ここで重要なのは canonical ledger / audit log と disposable pytest cache を同格に扱わないこと です。

    ledger は後続 consumer が読む正本です。shadow log は監査証跡です。.pytest_cache はそのどちらでもありません。

    推奨する reframe

    個人趣味開発という前提なら、私は repo-root の .pytest_cache/** 全体を volatile/generated state として runtime guard の repo-integrity 判定から外す 方針を推します。

    つまり _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に、

    ".pytest_cache",

    を追加する方向です。

    #1526 は「directory-wide exclusion は不可」と断言していますが、ここは撤回した方がよいです。現在の tuple はもともと「writer provenance を stdlib snapshot では判別できず、並行 process が正当に変更する directory」を対象にしています。 .pytest_cache はその分類にかなり素直に当てはまります。

    これによって .pytest_cache 自体が symlink/FIFO に置換されたケース等を runtime guard が検出しなくなる点はあります。しかし、そこを守ることで得られる実用価値がほぼありません。同一ユーザー権限のローカル process が pytest cache を悪意を持って細工できる状況を threat model に入れるなら、repo snapshot guard ではなく別の isolation が必要です。

    特にこのリポジトリでは .pytest_cache/ 自体を既に gitignore しています。 ソース、contract、artifact、credential、実行バイナリなどを守るのと、pytest の disposable cache を守るのは分けるべきです。

    pytest 側での isolation は第二候補

    よりクリーンな方法は pytest cache を repository 外へ移すことです。pytest は cache_dir を公式設定として提供しており、絶対パスを指定でき、CLI からもたとえば -o cache_dir=/tmp/mycache のように上書きできます。([pytestドキュメンテーション]4)

    cache 自体が不要な自動テストなら cacheprovider を無効にする方法もあります。pytest 公式は pytest -p no:NAME をサポートしており、cache plugin の内部名は cacheprovider です。したがって -p no:cacheprovider が正規の無効化方法です。([pytestドキュメンテーション]2) ([pytestドキュメンテーション]5)

    ただし #1516 で問題になったのは executor が所有していない peer pytest です。executor 自身の argv だけを変更しても、別 terminal / 別 agent が普通に pytest を走らせれば .pytest_cache は更新されます。このため根本的な guard false-positive 対策としては、cache redirect より runtime guard 側で .pytest_cache/** を無関係な generated state と認識する方が堅いです。

    executor が自分で起動する pytest についてだけ、追加で cache を repo 外へ隔離するのは有効です。

    改訂するなら Acceptance Criteria はこうする

    現状の AC1〜AC4 は捨ててよいです。特に AC2 の「lastfailed は fail-close」は逆方向です。

    改訂AC 契約
    AC1 independent peer pytest が .pytest_cache/v/cache/nodeids を create/update しても guarded command は停止しない
    AC2 failing peer pytest が .pytest_cache/v/cache/lastfailed を create/update しても停止しない
    AC3 peer pytest/plugin が .pytest_cache/** 内に別 cache key を生成しても停止しない
    AC4 .pytest_cache/** 以外の repo-root sibling file を peer process が変更すれば従来どおり unauthorized_write_path
    AC5 artifact root 外の tracked/source file 変更は従来どおり fail-close
    AC6 .pytest_cache の exemption は repo-root のその directory に限定し、foo/.pytest_cache や類似文字列には波及しない
    AC7 independent OS process を使った「peer pytest + guarded executor」の behavioral regression を1〜2本置く。path predicate の大量 unit test は作らない

    これなら「false positive は消えるが、実際に保護したい repository state は引き続き止める」という契約になります。

    #1526 の具体的な disposition

    そのまま implementation に流すべきではありません。reframe_in_place が適切です。

    タイトルも現在の

    runtime guard が peer pytest nodeids を child write と誤帰属しないようにする

    より、

    runtime guard が peer pytest の generated .pytest_cache state を unauthorized repo write と誤判定しないようにする

    程度まで抽象度を上げた方がよいです。

    Issue 本文の #1502 が未マージ という dependency は削除。#1502 / PR #1552 を 既に成立した設計背景として書き直すべきです。#1526 自身にはコメントがなく、2026年7月14日の作成以来本文も実質更新されていないため、新しい判断で契約を更新して問題ありません。

    また、PR #1552 自身でも overlap preflight の unrelated false-positive が原因で正規 wrapper を bypass して PR を作成した経緯があります。 この repository はすでに 「安全用ハーネスの false positive が実作業を阻害する」コストを現実に何度も払っています。#1526 でさらに cache key 単位の policy を増やすのは、その問題をもう一段増幅します。

    最終評価

    問題の重要度: Medium
    実害はあるものの repository correctness を壊すバグではなく、guard の usability defect です。

    現 Issue contract の品質: Low / stale
    観測事象は正しいものの、解法が path-specific すぎ、現在の main と pytest の write semantics の双方に合っていません。

    推奨: REQUEST_CHANGES → reframe_in_place → .pytest_cache/** volatile-root exemption を最小実装。

    nodeids 専用 typed exception、lastfailed negative control、pytest cache の symlink/FIFO/content integrity harness は、今回の用途では削った方が品質が上がります。守る価値のある canonical state に厳しい guard を集中させ、捨てられる cache は作業を止めない、という境界がこのリポジトリには合っています。

  3. squne121 commented on Aug 27, 2026

    @squne121
    OwnerAuthor

    推奨は 選択肢2の修正版「2′」 です。つまり、#1526 だけを one-shot の bootstrap recovery として preflight 依存から外し、先に制御面を復旧する方針です。ただし、現在の #1526 に書かれている「nodeids exact path だけ例外化」はそのまま実装しない方がよいです。

    理由は明確です。#1526 の本文はいまだに「#1502 が未マージなので待つ」としていますが、#1502 は 2026年7月17日に完了済みです。さらに最新レビューは、nodeids 限定設計を REQUEST_CHANGES とし、.pytest_cache/** を generated/volatile state として扱うよう reframe_in_place を推奨しています。

    この reframe は pytest の実装とも整合します。現在の pytest は正常終了時に cache/nodeids を書くだけでなく、失敗状態に応じて cache/lastfailed も書きます。また config.cache は plugin が独自 key を永続化するための公開 API です。したがって nodeids=許可 / lastfailed=拒否 は、成功した peer pytest は通るのに失敗した peer pytest は guard に止められる、という不自然な境界になります。 ([GitHub]1)

    リポジトリ側でも .pytest_cache/ は既に Git 管理対象外です。現在の _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS 自体が「並行 writer を stdlib snapshot では帰属できない directory root」のためのクラスなので、canonical ledger や audit log と違って disposable な pytest cache をここへ分類する方が設計として自然です。

    選択肢1は推奨しません。 entrypoint を implement-issue に替えても同じ skill_runtime_exec.py を通れば循環を切れないからです。また、この種の control-plane false positive については PR #1552 でも、正規 wrapper が無関係な blocker で停止した際に、理由と検証証跡を残して直接 PR を作成した前例があります。したがって「guard を恒久的に無効化」するのではなく、#1526 の復旧作業だけ procedural gate を限定 bypass するのが妥当です。

    Claude Code には以下を渡すのがよいです。

    Issue #1526 を、壊れている control-plane 自身を復旧する bootstrap recovery として処理してください。

    今回の作業では、通常の issue-refinement-loop / issue-contract-review / impl-review-loop を実装前提ゲートとして使用しないでください。現在それらの Step 0f / baseline VC preflight 自体が Issue #1526 の対象バグにより .pytest_cache を unauthorized_write_path と誤判定し、#1526 自身を前進不能にする自己参照デッドロックが確認されています。

    この人間指示を、Issue #1526 に限定した one-shot bootstrap authorization として扱ってください。

    最終目的

    1. 実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526 の stale な Issue contract を現在の repository / pytest semantics に合わせて reframe_in_place する。
    2. preflight gate を介さず、専用 worktree で 実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526 を実装する。
    3. regression test と既存 runtime-guard regression を実行する。
    4. 独立 SubAgent review を行い、指摘を解消する。
    5. commit / push し、Draft PR を作成する。
    6. merge はしない。
    7. PR 作成まで完了したら結果を報告する。

    重要な設計方針

    現在の #1526 本文にある、

    • .pytest_cache/v/cache/nodeids だけを race-tolerant exception にする
    • .pytest_cache/v/cache/lastfailed は引き続き unauthorized とする
    • .pytest_cache directory-wide exclusion は禁止する

    という契約をそのまま実装してはいけません。

    最新の #1526 コメント、現在の pytest cacheprovider 実装、current main の skill_runtime_exec.py を再確認してください。

    現時点の第一候補は、

    repo-root の .pytest_cache/** を disposable / generated / volatile state と分類し、_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に repo-root .pytest_cache を追加する

    という設計です。

    pytest は正常な session でも cache/nodeids を更新し、失敗時には cache/lastfailed を更新します。また plugin は config.cache で独自 key を生成できます。したがって nodeids 単体の allowlist は採用しないでください。

    一方で、以下は維持してください。

    • .pytest_cache/** 以外の unauthorized repository write は fail-close。
    • tracked/source file の unauthorized write は fail-close。
    • issue artifact root 等の既存境界は変更しない。
    • ledger / shadow log の typed exact-file policy は変更しない。
    • executor child の Allowed Write Roots は拡張しない。
    • runtime guard 全体を無効化しない。
    • pytest cache を消すことで問題を隠さない。
    • -p no:cacheprovider や external cache_dir は今回の production fix にしない。
    • exemption は repo root の .pytest_cache だけとし、foo/.pytest_cache/**、.pytest_cache2/** 等へ波及させない。

    ただし SubAgent の調査で、この設計が current main の実装上明確に不適切である証拠が出た場合は、勝手に別設計を実装せず、証拠と代案をまとめて停止してください。


    Phase 1: 現状確認

    最初に mutation を行わず、以下を確認してください。

    既存 user change、untracked file、他 worktree を削除・reset・stash しないでください。

    Phase 2: 第一波 SubAgent 調査

    必ず SubAgent を使ってください。

    main thread は、編集を開始する前に少なくとも次の3つの read-only SubAgent を並列起動してください。

    SubAgent A: runtime-policy-investigator

    調査対象:

    • current skill_runtime_exec.py の snapshot / race-tolerant policy
    • directory-root exclusion と typed exact-file policy の責務差
    • .pytest_cache root exemption の blast radius
    • repo-root のみへの限定が現在の matcher で成立するか
    • 既存 regression test で守るべき invariant

    mutation 禁止。

    SubAgent B: pytest-semantics-investigator

    調査対象:

    • 現在使用中の pytest version
    • pytest 本体の cacheprovider 実装
    • cache/nodeids
    • cache/lastfailed
    • stepwise 等の cache
    • plugin の config.cache
    • cache_dir
    • -p no:cacheprovider

    公式 pytest documentation / source を優先してください。

    「nodeids だけ正当で lastfailed は suspicious」という分類に技術的根拠があるかを敵対的に検証してください。

    mutation 禁止。

    SubAgent C: contract-bootstrap-reviewer

    調査対象:

    mutation 禁止。

    SubAgent 共通制約

    • SubAgent からさらに SubAgent を起動しない。
    • repository mutation をしない。
    • GitHub mutation をしない。
    • 結論だけでなく根拠となる file/function/comment を報告する。

    3 SubAgent 全員の作業完了を待ってください。

    全員が完了する前に Issue 編集・コード編集・worktree implementation を開始してはいけません。

    main thread で3結果を突き合わせ、矛盾を解消してから方針を確定してください。


    Phase 3: #1526 を reframe_in_place

    調査結果が上記第一候補を支持する場合、Issue #1526 の契約を実装前に更新してください。

    通常の refinement preflight は今回の defect そのものにより使用不能なので、その gate の成功を reframe の前提にしないでください。

    GitHub mutation は以下の順で選んでください。

    1. repository に、skill_runtime_exec.py の broken preflight を通らずに利用できる既存 controlled Issue transaction helper があるならそれを使う。
    2. それも同じ壊れた preflight を必須とするなら、実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526 の本文更新だけは bootstrap exception として direct GitHub Issue edit を使ってよい。

    raw/direct mutation を他 Issue や他用途へ横展開してはいけません。

    Issue body の reframe は最低限次を反映してください。

    Goal / Outcome

    nodeids 単体ではなく、

    independent peer pytest が生成する repo-root .pytest_cache/** state を executor child の unauthorized write と誤帰属しない。一方 .pytest_cache/** 以外の repository integrity boundary は従来どおり fail-close する。

    という目的へ変更する。

    dependency

    In Scope

    • repo-root .pytest_cache/** の volatile generated-state exemption
    • nodeids
    • lastfailed
    • plugin/custom cache key
    • outside-cache unauthorized write の negative control
    • root-specificity の検証
    • independent OS process を使う behavioral regression

    Out of Scope

    • executor child の Allowed Write Roots 拡大
    • ledger / shadow-log policy の変更
    • repository root 全体の exemption
    • arbitrary nested .pytest_cache
    • pytest cache integrity/security harness
    • strict process attribution
    • global pytest configuration変更

    Acceptance Criteria

    少なくとも次へ置き換えてください。

    • AC1: peer pytest による .pytest_cache/v/cache/nodeids create/update が guarded execution を停止させない。
    • AC2: failing peer pytest による .pytest_cache/v/cache/lastfailed create/update も停止させない。
    • AC3: plugin/custom cache key を含む .pytest_cache/** 内の generated state も停止させない。
    • AC4: .pytest_cache/** 外の repo-root sibling write は引き続き unauthorized_write_path。
    • AC5: tracked/source file の unauthorized modification は引き続き fail-close。
    • AC6: exemption は repo-root .pytest_cache のみに限定され、nested foo/.pytest_cache や prefix 類似 path には適用されない。
    • AC7: independent OS process を使った behavior-level regression が存在し PASS する。

    Allowed Paths は原則として現在の2ファイルを維持してください。

    • scripts/agent-guards/skill_runtime_exec.py
    • scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py

    この2ファイル外の tracked code change が必要なら実装せず停止してください。


    Phase 4: 専用 worktree で直接実装

    最新 origin/main を基点に #1526 専用 worktree / branch を作成してください。

    既存 worktree を破壊・再利用しないでください。

    main thread が実装を所有し、調査 SubAgent に mutation をさせないでください。

    第一候補の実装では、_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に repo-root .pytest_cache を追加します。

    コメントには、

    • pytest cache は canonical evidence ではない
    • concurrent peer pytest が正常に書く generated state である
    • stdlib snapshot では writer attribution ができない
    • ledger / shadow log のような canonical typed exact-file policy とは異なる

    ことを簡潔に記載してください。

    不必要な abstraction / policy registry / schema / security harness は追加しないでください。

    個人趣味開発の repository なので、今回の優先順位は:

    1. workflow が安定して前進する
    2. source / canonical artifact の integrity は守る
    3. disposable cache の過剰な hardening はしない

    です。

    Phase 5: Regression test

    新規:

    scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py

    を使用してください。

    既存 guard tests の fixture / subprocess pattern を再利用し、sleep 頼みの race test は避けてください。必要なら pipe/event/barrier で同期してください。

    少なくとも behavior-level で以下を固定してください。

    • independent process / pytest による nodeids write → 許可
    • failing peer pytest による lastfailed write → 許可
    • .pytest_cache 内の別/custom key → 許可
    • 同じ実行中の .pytest_cache 外 sibling write → 拒否
    • nested foo/.pytest_cache/... → 拒否
    • prefix 類似 .pytest_cache2/... → 拒否

    可能なら大量の path-predicate unit test より、1〜2本の現実的な independent-process behavioral test と、小さな specificity test を優先してください。

    テストランナー自身の pytest cache が fixture を汚染する場合に限り、テストランナー側だけ -p no:cacheprovider や repository 外 cache_dir を使って isolation して構いません。ただし、それを production fix や Issue の解決策にしてはいけません。


    Phase 6: focused validation

    最低限、以下の relevant suites を current repository の実名に合わせて実行してください。

    • 新規 test_skill_runtime_exec_pytest_cache.py
    • existing unauthorized-write-path regression
    • subagent ledger regression
    • shadow-log write-path regression
    • session-manifest/runtime-root regression
    • changed Python files に対する既存 lint / Ruff 等

    テストファイル名が current main で異なる場合は、実在する対応 suite を選んでください。

    無関係な既知 flake を修正するために Allowed Paths を拡大しないでください。

    失敗した場合:


    Phase 7: 第二波 SubAgent adversarial review

    実装とテストが完了したら、main thread は再度 read-only SubAgent を最低2つ起動してください。

    Reviewer 1: guard-boundary-reviewer

    確認:

    • .pytest_cache 以外の fail-close を広げていないか
    • nested/prefix path が accidentally exempt されないか
    • ledger / shadow-log policy に regression がないか
    • 差分が最小か

    Reviewer 2: pytest-regression-reviewer

    確認:

    • test が実際の pytest cache semantics を表しているか
    • nodeids だけへの過適合に戻っていないか
    • lastfailed/custom key を含むか
    • test が実装詳細だけを assert する false-green になっていないか

    mutation 禁止、nested delegation 禁止。

    両 Reviewer の完了を待ってください。

    P0/P1 相当の指摘があれば main thread で修正し、focused validation を再実行してください。

    解消不能なら PR を「成功」として作らず停止してください。


    Phase 8: commit / Draft PR

    最終 diff を確認し、tracked change が #1526 の reframe 後 Allowed Paths に収まっていることを確認してください。

    commit → push してください。

    PR 作成については、この bootstrap defect が open-pr wrapper の preflight にも波及する可能性があります。

    PR は Draft。

    PR body には最低限以下を明示してください。

    • Closes #1526
    • なぜ通常 preflight を利用できなかったか
    • self-hosting control-plane deadlock だったこと
    • bypass は 実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526 bootstrap に限定したこと
    • Issue を nodeids-only から .pytest_cache/** generated-state policy に reframe した理由
    • implementation summary
    • test results
    • .pytest_cache/** 外の fail-close が維持されること
    • ledger / shadow-log typed policy は不変であること
    • post-merge に canonical control-plane canary が必要なこと

    merge しないでください。


    Phase 9: 完了報告

    次をまとめて報告してください。

    post-merge canary としては、#1526 が main に入った後に初めて、通常の issue-refinement-loop / issue-contract-review を canonical main から再実行してください。

    その後、pytest VC を持ち今回実際にブロックされていた Issue(#2339 等)を1件 canary として通常ループで通し、control-plane recovery を確認するのが望ましいです。

    PR 作成時点ではまだ main に修正が入っていないので、#2339 を無理に通常ループへ流して「復旧済み」と判定してはいけません。

    絶対停止条件

    以下だけは自律継続せず停止してください。

    • secret / credential の取得・表示・commit が必要
    • force push、history rewrite、既存 user worktree の削除等の破壊的操作が必要
    • 実装: runtime guard が peer pytest nodeids を child write と誤帰属しないようにする #1526 の reframe 後 Allowed Paths 外の tracked code change が必須
    • .pytest_cache より広い repository root exemption が必要
    • source / canonical artifact の fail-close を弱める必要がある
    • unrelated genuine validation blocker を bypass する必要がある
    • SubAgent 調査で .pytest_cache root exemption に重大な current-main-specific contradiction が見つかった

    それ以外の通常の実装判断、テスト修正、rebase、commit、push、Draft PR 作成については人間承認を待たず進めてください。

    この形なら、「壊れている安全ハーネスを通過するために安全ハーネスを直せない」状態だけを例外扱いし、通常運用へ戻る地点も明確です。特に重要なのは、PR 作成を完了条件にせず「merge 後に #1526 → #2339 の順で canonical preflight canary を通す」ことを recovery closure として残しておく点です。

  4. self-assigned this
    on Aug 27, 2026
  5. squne121 commented on Aug 28, 2026

    @squne121
    OwnerAuthor

    post-merge-cleanup: 完了 (2026-08-28)

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: post-merge-cleanup
      follow_up_issues:
        - request_dedupe_key: "follow-up:squne121/loop-protocol:pr/2364:canary-control-plane"
          status: created
          issue:
            number: 2369
            url: "https://github.com/squne121/loop-protocol/issues/2369"
          reason: null
      note_only_observations: []

    worktree/branch cleanup: issue-1526-runtime-guard-pytest-cache 削除済み(PR #2364, merge commit cc5e3633)。superseded PR なし。parent issue なし。stash 復元済み。human_review_required: false。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent/implementerenhancementphase/implementation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions