Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "issue-refinement-loop の root review producer が repo 内 tmp/ に置く per-invocation scratch を、canonical executor の before/after snapshot が検査する範囲の外へ移し、同一 checkout で並行する review が正当な repair_action.apply child を unauthorized_write_path で停止させないようにする。child 自身の同一 path への書込みは引き続き拒否する。"
change_kind: code
dedupe_key: "root-review-pipeline:scratch-placement-outside-executor-snapshot:v1"Parent Issue
none(単独改善)
Parent Goal Ref
- Goal: 正当な
repair_action.applyを、peer(同一 checkout で並行する root review producer)の一時書込みで不必要に停止させない。不正な child write の検出は維持する。 - Desired Destination: N/A(単独改善。調査: repair_action.apply の root_review_pipeline tmp 書き込み拒否を因果帰属する #3035 の調査結論
confirmed_defectの最小修復を所有する)。
Current Validated Scope
- 調査 Issue #3035 が current main
5680a88970d93b2f73b9e92766e23b03347fcdbbで production のskill_runtime_exec.pyの_dispatch_child_and_check_postconditions()を invocation-owned fixture 上で実行し、次を観測した(command ID はrepair_action.apply、child は正常終了)。- child 単独: outer exit 0。
- child 実行中に独立 peer が
tmp/root_review_pipeline_<id>/root_review_pipeline_body_<id>.mdを作成して保持(peer-add)、または before 時点で存在した同 path を削除(peer-cleanup): child 正常でも outer exit 2unauthorized_write_path。検出経路は filesystem snapshot 差分のみ(git status 差分はtmp/が ignored で折り畳まれるため出ない)。child の stdout / stderr は relay されず、semantic result は失われる。 - peer が before 後に作成し after 前に完全削除(transient-peer)、および child 自身が scratch を作成し after 前に削除(child-own-scratch-transient): outer exit 0。
- child 自身が同 path を作成(unauthorized-child): outer exit 2。peer-add と outer 結果が同一で、outer は writer を区別できない。
- 現行
.claude/skills/issue-refinement-loop/scripts/run_root_review_pipeline.pyはtmp_root = _REPO_ROOT / "tmp"配下にtempfile.TemporaryDirectory(dir=..., prefix="root_review_pipeline_")を作り、pinned body と history snapshot を置く(produceの実行時間中だけ存在)。run_refinement_preflight.pyはこの producer を呼ばない(repair_action.applyの child ではない)。同一 checkout でproduce(同一セッションの未 join background task、または独立セッション)がrepair_action.applyの before/after の間に走ると、上記 peer-add / peer-cleanup に該当する。 - incident(実装: Claude Code Auto memoryの保存判断を整理し、Issue/PR進捗の重複記録を抑制する #3031 の refinement 中、HEAD
60f0fc838e8b76a84c769a72b6361cd58e958e4d)の writer は未確定。拒否 path が producer の命名(root_review_pipeline_<random>/root_review_pipeline_body_<random>.md)と一致することだけが確認済みで、同一セッション background task か独立 peer かは本 Issue の前提にしない。 - 同一 root cause を所有する既存 Issue は無い。実装: repair_action.apply の unauthorized_write_path false negative を解消する #2584(CLOSED)は
tmp/directory node のみ、実装: Auto mode の固定 /tmp scratch 上書き false-deny を run-scoped temporary workspace で解消する #2860 は model 生成の固定 scratch、実装: canonical executor の Vitest results cache write を writer attribution に基づき狭域で判定する #2887 は Vitest results cache、実装: root review outer timeout と invocation-local budget の parity を固定する #2610(CLOSED)は background launch と completion join の契約。
Remaining Parent Gaps
なし(単独改善)。
Background
executor 側で tmp/root_review_pipeline_* を一括除外すると、child が同 path に書いた違反も検出できなくなる(#3035 の unauthorized-child と同一 path の negative control が成立しない)。そのため producer 側の scratch placement を修正する。attempt 用 scratch は既に tempfile.mkdtemp(prefix="root_review_pipeline_attempt_")(dir 無指定)で作られている。dir 無指定の temp は TMPDIR / TEMP / TMP に従い repo 外を保証しないため(PR #3040 OWNER REQUEST_CHANGES P2)、attempt scratch も outer scratch と同じ失敗クラスを共有する。TMPDIR の変更や directory 名の一意化だけでは、scratch が repo の walk 範囲内に在る限り解決しない(TemporaryDirectory(dir=repo/tmp) は TMPDIR に依存せず、既に random suffix で一意)。
Outcome
run_root_review_pipeline.py produce の per-invocation scratch(pinned body、history snapshot、中間結果)が repo root 配下の tmp/ に現れず、独立 peer として並行する produce が repair_action.apply の outer 検査に差分を出さない。同時に、child 自身が tmp/root_review_pipeline_*/... へ書いた場合の unauthorized_write_path(exit 2)は維持される。
Runtime Verification Applicability
decision: not_applicable
reason: "outer executor の検査は pytest 内で実 subprocess の executor / child / 独立 peer を使う hermetic fixture により決定論的に検証できる。外部サービス・live Claude-GPT smoke・実 GitHub mutation を要しない。fixture を起動できない環境では pytest が失敗し SKIP を PASS に読み替えない。"
applicable_acs: []
execution_environment: "Linux、git、uv、pytest。tmp_path 上の隔離 git repository。"
skip_conditions: "該当なし(runtime 検証は pytest で完結。起動不能は FAIL)。"
fallback_policy: "fallback 経由の成功を PASS としない。"
artifact_requirements: "なし(pytest の結果のみ)。"In Scope
run_root_review_pipeline.pyのproduceが作る scratch directory(pinned body と history snapshot を含む)を、executor の_snapshot_repo_paths()が走査する repo root の外に置く。scratch の親は resolved real path(symlink 解決後)が検査対象 checkout(_REPO_ROOT)の外であることを producer 内で検証し、TemporaryDirectory(dir=...)/mkdtemp(dir=...)に明示する。通常の temp が外部ならそれを使い、repo 内を指す場合は OS の外部 temp 親(/tmp等)へ切り替える。外部親を用意できない場合は原因を明示して失敗し、repo 内へ黙示 fallback しない。outer scratch(produce)と checker attempt scratch(run_checker_pipeline_once)は同一の親選択ロジックを共有する。production のグローバルTMPDIR/tempfile.tempdirは書き換えない。- 回帰テストを
.claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_scratch_placement.pyに追加する(python-test-plan.jsonは当該 tests directory を既に含む)。- produce の scratch path が repo root 配下の
tmp/以下に作られないこと。 - hermetic fixture(
tmp_path上のgit initrepo、production の_dispatch_child_and_check_postconditions()、command IDrepair_action.apply)で、修正後の placement を再現する独立 peer の書込みが outer exit 0 になること。 - negative control: child 自身が
tmp/root_review_pipeline_<id>/root_review_pipeline_body_<id>.mdを作成した場合は outer exit 2unauthorized_write_pathが維持されること(修復前 placement を再現する peer の同 path 書込みが exit 2 になることも、修復前の failure class の再現として同じテストに含める)。 - 既存の executor 回帰(
test_skill_runtime_exec_unauthorized_write_path.py、test_issue_metadata_write_capability.py)が緑のままであること。
- produce の scratch path が repo root 配下の
- scratch が repo の
tmp/配下にある前提の既存テストtest_root_review_timeout_diagnostics.pyの cleanup assertion を、新 placement でも「repo に scratch が残らない」ことを検証する形に更新する(Scope Delta 1)。
Out of Scope
skill_runtime_exec.pyの除外拡張(tmp/root_review_pipeline_*の prefix 除外、tmp/**の allow、writer attribution の新機構、guard の無効化)。TMPDIR環境変数の変更、SKILL.mdの運用文言変更だけで済ませること、実装: root review outer timeout と invocation-local budget の parity を固定する #2610 の background + join 契約の変更。- 実装: Auto mode の固定 /tmp scratch 上書き false-deny を run-scoped temporary workspace で解消する #2860(固定 scratch)・実装: canonical executor の Vitest results cache write を writer attribution に基づき狭域で判定する #2887(Vitest cache)・実装: repair_action.apply の unauthorized_write_path false negative を解消する #2584(directory node)の再実装。
- incident 時点の writer の追跡、新しい恒久 CI gate / schema / wrapper / permission layer。
Acceptance Criteria
- AC1:
produceの outer scratch(pinned body / history snapshot)と checker attempt scratch が、resolved real path で checkout の外に作られ、repo root 配下のtmp/以下に作られない。TMPDIR/TEMP/TMPのいずれかが fixture checkout 内(<fixture checkout>/tmp)を指す場合、および symlink 経由で checkout 内へ戻る場合でも同様であり、外部親が無い場合は repo 内へ fallback せず明示エラーで失敗する。 - AC2: hermetic fixture で、修正後の placement を再現する独立 peer の書込みがあっても、正当な
repair_action.applychild が outer exit 0 で完走する。 - AC3: negative control として、child 自身の
tmp/root_review_pipeline_<id>/root_review_pipeline_body_<id>.mdへの書込みは outer exit 2unauthorized_write_pathのまま検出され、同 path を修復前 placement で peer が書いた場合の exit 2 も再現テストで固定される。 - AC4: 既存の executor 回帰と root review pipeline の既存テスト、および型・lint・テスト・build が PASS する。
- AC5: readiness timeout 経路の実 scratch(pinned body file / outer scratch directory / checker attempt scratch)が
produce終了後に存在しないことが、実際に使われた path の捕捉により直接検証される(test_root_review_timeout_diagnostics.py、既存 readiness artifact / diagnostic assertion は維持)。
Verification Commands
# AC1
$ uv run --locked pytest -q .claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_scratch_placement.py
# AC2
$ uv run --locked pytest -q .claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_scratch_placement.py
# AC3
$ uv run --locked pytest -q .claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_scratch_placement.py
# AC5
$ uv run --locked pytest -q .claude/skills/issue-refinement-loop/tests/test_root_review_timeout_diagnostics.py
# AC4
$ uv run --locked pytest -q scripts/agent-guards/tests/test_skill_runtime_exec_unauthorized_write_path.py
$ uv run --locked pytest -q scripts/agent-guards/tests/test_issue_metadata_write_capability.py
$ uv run --locked pytest -q .claude/skills/issue-refinement-loop/tests/test_root_review_canonical_delivery.py
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildAllowed Paths
- .claude/skills/issue-refinement-loop/scripts/run_root_review_pipeline.py
- .claude/skills/issue-refinement-loop/tests/test_root_review_pipeline_scratch_placement.py
- .claude/skills/issue-refinement-loop/tests/test_root_review_timeout_diagnostics.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合(
produceの stdout JSON / artifact 契約・exit code の変更を含む) - 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- pinned body を受け取る downstream が repo 外の temporary directory と run-owned artifact subdirectory のどちらも受理しない場合は修正を設計し直さず、観測した受理条件を記録して停止する
- 修正が
skill_runtime_exec.pyの除外拡張や writer attribution を要求する形になった場合は停止する(本 Issue の対象外) - 同一 path の child 書込み negative control が exit 2 を返さなくなった場合は停止する
Required Skills
なし
Required Design References
- docs/dev/workflow.md
- .claude/skills/issue-refinement-loop/SKILL.md
- scripts/agent-guards/skill_runtime_exec.py
- 調査: repair_action.apply の root_review_pipeline tmp 書き込み拒否を因果帰属する #3035
Scope Delta
Scope Delta 1(PR #3040 の CI で判明): 既存の .claude/skills/issue-refinement-loop/tests/test_root_review_timeout_diagnostics.py::test_production_path_diagnostic_survives_cleanup_in_transport_and_full_artifact が assert list((tmp_path / "tmp").iterdir()) == [] で「produce の scratch は repo の tmp/ 配下に作られ、終了後に空になる」ことを前提にしており、scratch を system temp へ移すと tmp/ 自体が作られず FileNotFoundError になる(python-test-core の唯一の失敗)。この前提は #3039 の修復対象 placement そのものなので、当該 1 ファイルを Allowed Paths に追加し、assertion を「repo の tmp/ 配下に scratch が残らない(tmp/ が無い場合も許容)」へ更新する。テストの削除・skip・assertion の弱体化(scratch 残存の検出をやめること)は行わない。他の Out of Scope は変更しない。
Scope Delta 2(PR #3040 OWNER REQUEST_CHANGES #6110302496 / 追加根拠 #6110375908): 「dir 無指定の system temp は必ず repo 外」という本文の前提は誤りで、tempfile.gettempdir() は TMPDIR / TEMP / TMP に従い repo 内を指しうる。producer の親選択を resolved path 検証付きへ修正し、outer scratch と attempt scratch の両方に適用する。TMPDIR=<fixture checkout>/tmp の adversarial regression と timeout 経路の実 scratch cleanup 直接観測を追加する。Allowed Paths 3 件は変更しない。child 自身の同一 path 書込みの exit 2(AC3)は維持し、production のグローバル temp 設定は変更しない。本更新は OWNER の明示的委任入力に基づく。
Delivery Rule
1 Issue = 1 PR。専用 worktree を使い Draft PR 既定。PR 本文に Closes #<この Issue 番号> を設定する。#3035(調査)は close target にしない。
Notes for Reviewer
Scope Collision: #2860 は repo 内 tmp/ に run-scoped scratch を置く方針を持つため、同種の scratch が executor の snapshot に入る hazard を共有する。ただし対象 producer / command が異なり、#2860 の scope は本 Issue に移さない。#3035 の evidence は #3035 の ## 調査 terminal report (#3035) コメントを参照する。
Activity
squne121 commentedon Oct 11, 2026
root-owned entry router audit
route: stop
reason: review_verdict_blocked
squne121 commentedon Oct 11, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
squne121 commentedon Oct 11, 2026
Contract Review Result
squne121 commentedon Oct 11, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
test: scratch が repo の tmp/ に残らないことの検証を tmp/ 不在でも成立させる (#3039)
squne121 commentedon Oct 11, 2026
追加の同根再発候補: checker attempt scratch も
dir=None(PR #3040 OWNER review 後の source 追加確認)TemporaryDirectory(dir=None)は checkout 外を保証しない)d2f28f675d4fb6331553f0ff8ee0c1b234d88476.claude/skills/issue-refinement-loop/scripts/run_root_review_pipeline.py::run_checker_pipeline_once()にscratch_dir = Path(tempfile.mkdtemp(prefix="root_review_pipeline_attempt_"))が残存(およそ L1069)。review_result.json、readiness_result.json、merged_review_result.jsonをこの配下へ書き、finally: shutil.rmtree(...)で削除する。_cmd_produce()の outer scratch(およそ L1497)だけを外部親へ明示固定しても、checker attempt の subprocess 環境でTMPDIR/TEMP/TMPが同じ checkout 内を向けば、この別のmkdtemp(dir=None)も repo 内へ配置され得る。Pythontempfile.gettempdir()は当該環境変数に従い、結果がキャッシュされる。produceとrepair_action.applyの同時実行による当該 attempt path の拒否は未実測。元 incident の writer を確定する主張ではない。推奨: #3039 の同一 failure class と同一 Allowed Path 内で、outer scratch に加えて attempt scratch の配置を bounded に監査する。新しい helper / parent selection を設けるなら producer 内の両呼出しで共通利用し、解決後の親が current checkout 外であることを確認して
dir=を指定する。fresh subprocess のTMPDIR=<fixture checkout>/tmpで両経路を実測し、実装前は再現され実装後は残らないこと、timeout cleanup と child-owned unauthorized write 拒否(exit 2)が維持されることを確認する。グローバル環境変数の変更、executor のtmp/**除外拡張、新しい恒久 gate は不要。新規の重複 implementation Issue は起票せず、既存 #3039 の OWNER REQUEST_CHANGES 修正・回帰テストに吸収する。
fix: root review producer の scratch 親を resolved path で checkout 外に固定する (
test: 実 _cmd_produce を TMPDIR 汚染下で駆動し outer scratch の外部配置を固定する (#3039)
squne121 commentedon Oct 12, 2026
Contract Review Result
squne121 commentedon Oct 12, 2026
Contract Review Result
squne121 commentedon Oct 12, 2026
Contract Review Result