Repository navigation
fix: runtime guard が repo-root .pytest_cache/** を peer pytest の disposable state として誤帰属しないようにする - #2364
Conversation
…sable state として誤帰属しないようにする skill_runtime_exec.py の _RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELS に repo-root .pytest_cache を追加し、baseline VC preflight が pytest VC を実行した際に peer pytest が書き込む .pytest_cache/v/cache/nodeids・lastfailed・plugin custom cache key を unauthorized_write_path として誤検知しないようにする。 pytest本体の cacheprovider 実装(NFPlugin/LFPlugin、いずれも pytest_sessionfinish から無条件に書き込む)を確認した結果、nodeids のみを 正当としその他を疑わしいとする技術的根拠がないため、当初案の nodeids 単体 exact-path 例外ではなく、repo-root .pytest_cache/** 全体を directory-root exclusion class(.claude/worktrees 等と同種)として扱う設計に変更した。 .pytest_cache 以外の repo-root sibling write・tracked/source file の unauthorized write・nested foo/.pytest_cache・prefix-lookalike .pytest_cache2 は引き続き fail-close する。 Closes #1526 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2364/ The preview will be removed when this PR is closed. |
|
PR #2364 を、関連 Issue #1526、先行 PR #1552 / #1572、既存 runtime guard 実装、PR コメント/レビュー、GitHub Actions、さらに pytest の公式ドキュメントと実装まで突き合わせて確認しました。 判定REQUEST_CHANGES。ただし設計方針そのものには賛成です。
特に、#1552 の ledger や #1572 の したがって、security harness をさらに増やす方向の REQUEST_CHANGES ではありません。実際の pytest の生成物を1つ取りこぼしていることと、それを検出すべきテストが真の peer process になっていない、という機能上の問題です。 P1 — pytest の cold-start 時に作られる
|
…eview fix_delta) 人間レビュー (PR #2364 review, issuecomment-5445627107) の REQUEST_CHANGES を反映。 P1-1: pytest 9.0.3 の Cache._ensure_cache_dir_and_supporting_files() は .pytest_cache を直接作らず、まず repo-root 直下に tempfile.TemporaryDirectory(prefix="pytest-cache-files-", dir=self._cachedir.parent) を作ってから rename する。この cold-start 中の 一時ディレクトリが .pytest_cache exemption ではカバーされず unauthorized_write_path になり得たため、_is_pytest_cache_cold_start_temp_path() を新設し、_find_unauthorized_repo_changes の git-status ベース filter と _snapshot_repo_paths の os.walk pruning の両方(独立した2つの検出経路)に 配線した。exemption は repo-root top-level のみで、nested な sub/pytest-cache-files-x には波及しない。 P1-2: 既存 AC7 テストは real pytest を guarded child 自身が起動し完了を 待ってから return する構造で、real pytest の子孫プロセスに過ぎず独立した sibling peer process ではなかった。test harness 自身が real pytest を subprocess.Popen で sibling として起動し、file-based sentinel で起動を 同期確認してから executor を起動する構造に書き直し、peer process の exit code も assert するようにした。 P2: lastfailed が nodeids と同様に unconditionally 書かれるという comment の説明を、pytest 9.0.3 の実装(LFPlugin は差分がある場合のみ 書込み)に合わせて修正した。 独立 SubAgent adversarial review 実施、指摘なし。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
レビューありがとうございます。ご指摘の3点(P1-1/P1-2/P2)をすべて反映しました(head P1-1:
|
Summary
Closes #1526(本 PR は Issue #1526 を close します)。
skill_runtime_exec.pyの_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSに repo-root.pytest_cacheを追加し、baseline VC preflight が pytest VC を実行する際に peer pytest が書き込む.pytest_cache/v/cache/nodeids・lastfailed・plugin custom cache key をunauthorized_write_pathとして誤検知しないようにします。なぜ通常 preflight を利用できなかったか(self-hosting control-plane deadlock): 本 Issue #1526 自身の 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 #1526 に限定した one-shot bootstrap authorization として、通常の実装前提ゲート(issue-refinement-loop / issue-contract-review / impl-review-loop の preflight gate)を経由しない直接実装・direct PR 作成を承認しました。bypass は本 Issue 1件に限定しており、他 Issue・他用途へは横展開していません。Issue reframe(nodeids-only から
.pytest_cache/**generated-state policy へ): 当初の Issue #1526 本文は.pytest_cache/v/cache/nodeids単体を exact-path 例外にし、lastfailedは引き続き unauthorized 扱いとする設計でした。しかし pytest 本体の_pytest/cacheprovider.py(NFPlugin/LFPlugin、いずれも同じpytest_configurehookimpl で登録され、pytest_sessionfinishからConfig.cache.set()経由で無条件に書き込まれる)を確認した結果、nodeidsのみを正当としその他を疑わしいとする技術的根拠は存在しないことが判明しました(lastfailedは成功のみの session でも空 dict として実際に書き込まれ、サードパーティ plugin も任意の custom key を書き込めます)。このため、Issue 本文を通常の controlled Issue transaction 経路(edit_issue_txn.py、--mode staticの readiness check のみを使用し pytest を一切実行しない)で reframe し、.pytest_cache/**全体を_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSの directory-root exclusion class(.claude/worktrees等と同種)へ加える方針に変更しました。Implementation summary:
scripts/agent-guards/skill_runtime_exec.py:_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSタプルへ repo-root.pytest_cacheを1要素追加(コメントで rationale を明記)。他のロジック分岐・既存要素・_LEDGER_*/_SHADOW_LOG_EXACT_RELの typed exact-file policy には一切触れていません。scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py(新規): 実 subprocess harness による7本の behavior-level regression test(AC1-AC7)。merge 後に必要な canonical control-plane canary: 本 PR は merge していません(人間オペレーターの明示指示により merge は行いません)。merge 後、canonical main から以下の canary を実行して control-plane recovery を確認する必要があります。
issue-refinement-loop/issue-contract-reviewを通常経路(bootstrap bypass なし)で canonical main から再実行し、preflight gate が正常に通ることを確認する。Checks
uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py -v→ 7 passed(AC1-AC7 全て)uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py -q→ 10 passed(既存 regression、回帰なし)uv run --locked pytest scripts/agent-guards/tests/test_guard_shadow_log_write_path_policy.py scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest.py scripts/agent-guards/tests/test_skill_runtime_exec_session_manifest_lifecycle.py scripts/agent-guards/tests/test_skill_runtime_exec_subagent_ledger.py -q→ 94 passed, 1 skipped(既存 regression、回帰なし)uv run --locked pytest scripts/agent-guards/tests/test_skill_runtime_preflight_bytecode_cache.py -q→ 8 件がuv_version_mismatchで fail するが、origin/main(本変更なし)に対する baseline でも同一の8件が同一理由で fail することを確認済み(本変更と無関係な pre-existing environment issue。回帰させていません)uv run --locked ruff check scripts/agent-guards/skill_runtime_exec.py scripts/agent-guards/tests/test_skill_runtime_exec_pytest_cache.py→ All checks passedSchema Change Applicability
_RACE_TOLERANT_UNATTRIBUTABLE_ROOT_RELSタプルへの要素追加のみであり、既存 consumer が受け取る JSON/YAML スキーマ、CLI 引数契約、ISSUE_*系 machine-readable contract のいずれも変更しないためです。Schema Consumer Inventory
N/A
reason: schema_change ではなく、既存 consumer の before/after 差分も発生しないためです。
Safety Claim Matrix
.pytest_cache/**以外の repo-root sibling write(例:.mypy_cache/)は引き続きunauthorized_write_pathで fail-close するtest_repo_root_sibling_write_outside_pytest_cache_is_rejectedPASSREADME.md)への unauthorized write は引き続き fail-close するtest_tracked_source_file_unauthorized_write_is_rejectedPASS.pytest_cacheのみに厳密に限定され、nestedfoo/.pytest_cacheや prefix-lookalike.pytest_cache2へは波及しないtest_exemption_is_repo_root_specific_not_nested_or_prefix_lookalikePASS_LEDGER_*(#1502/PR #1552)・_SHADOW_LOG_EXACT_REL(#1563)の typed exact-file policy は本変更で一切変更していない_LEDGER_*/_SHADOW_LOG_EXACT_REL関連コードへの変更なし。独立 SubAgent(guard-boundary-reviewer)が diff 全文を確認し確認済み.pytest_cacheの symlink/directory/FIFO/socket/device 置換の検出力は失われる(disposable cache であり canonical evidence ではないための意図的 trade-off。ローカル単一ユーザー権限 process の脅威モデル外での攻撃は対象外)Notes
open-prwrapper(open_pr.py)経由で作成しました(bootstrap bypass は Step 0f 相当の preflight gate に限定され、PR 作成経路自体は canonical route を使用)。