Repository navigation
feat: cleanup executor に one-shot discard lane と compare-and-delete を追加する - #2185
Conversation
…追加する (#1523) merged PR の dedicated worktree に残る local-only commit を、target+SHA-bound one-shot human confirmation を消費した場合だけ discard できる新 lane (verify_discard_authorization / run_discard_check / run_discard_consume) を 追加した。branch-only fallback は expected branch-tip OID を destructive path まで保持し、shared repository mutation lock 内で `git update-ref -d refs/heads/<branch> <expected-oid>` による compare-and-delete を行う。ancestry 判定は structural check (_verify_ancestry_for_force_delete) に統一し、 invalid object / comparison error は force delete に昇格させない。 normal / branch-only / discard 全 lane の verified payload を _verified_template() で共通 key set に正規化した (AC9)。同一 invocation 内で worktree_remove 成功後に branch -d が失敗した場合は branch-only 認可を 再検証し、拒否時は元の reason_code と actions_taken を保持する (AC10)。 post-merge-cleanup skill には、discard の handoff が executor 生成の explicit human confirmation command 限定であることを明記した (AC5)。 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URL✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2185/ The preview will be removed when this PR is closed. |
PR Review Verdict (iteration 0)Mergeability: mergeable=MERGEABLE, merge_state_status=BLOCKED (draft) Evidence Check: 10 AC Verification Commands PASS at head Blockers:
Non-blockers: none. verdict: REQUEST_CHANGES
reviewed_head_sha: "13f989ac595b65f8a802b3e8b15997939c5faf1a"
blockers:
- "Required CI check python-test-core failing at current head: ruff check reports E501 line-too-long at scripts/agent-ops/cleanup_exec.py:144 and additional E501/E402 violations in scripts/agent-ops/tests/test_cleanup_exec.py (within Allowed Paths)."
warnings: [] |
python-test-core CI job flags E501 line-too-long at cleanup_exec.py:144 and E402/E501 in scripts/agent-ops/tests/test_cleanup_exec.py. Shorten the trailing comment on BRANCH_ONLY_NON_ANCESTRY_FAILURE (string value unchanged), suppress the deliberate sys.path.insert-then-import E402 pattern with per-line noqa, and wrap the over-long docstring/assert lines without changing test semantics. PR review fix_delta: #2185 (comment)
PR Review Verdict (iteration 1)Mergeability: mergeable=MERGEABLE, live required CI checks (test/lint/build/typecheck/validate-generated-artifact) all PASS at head Evidence Check: Diff limited to declared Allowed Paths (6 files, no additions/removals). AC1-AC10 each map to a concrete code change and dedicated test. Independent re-run of cleanup regression suite (62 tests) and guard-regression suite (613 tests) both PASS. Blockers:
Non-blockers / warnings:
verdict: REQUEST_CHANGES
reviewed_head_sha: "2e15b6f3ac32df5395334b29a7761d60fb14fea2"
blockers:
- "PR body missing required structured sections: `## 受け入れ条件の達成状況` (per-AC1-10 [x]/[ ] + evidence checklist), `## 検証コマンド結果`, `## Allowed Paths 遵守`."
warnings:
- "tests/codex/test_cleanup_exec_branch_only.py has pre-existing ruff E402/F401/E501 violations outside CI's lint scope; not a blocker, follow-up candidate." |
Verdict: APPROVERe-review after PR-body-only fix (head SHA unchanged: Independently re-confirmed:
Blockers(none) verdict: APPROVE
reviewed_head_sha: "2e15b6f3ac32df5395334b29a7761d60fb14fea2"
blockers: []
warnings:
- "non-required check 'deploy-pr' is cancelled/failed on this head; not in the required-checks set so not merge-blocking per policy"
- "PR remains Draft (isDraft=true); not a reviewer blocker per policy, left for human final-merge decision" |
結論判定: レビュー対象は PR head expected OID を使った
Issue #1523 と旧 PR #1528 の OWNER レビューは、worktree 使用状態を lock 内で再検査し、 P0-1: 人間が確認した contract を、消費前に別 contract へすり替えられる問題
さらに durable write は temporary file を固定 final path へ 一方、 したがって、次の approval-substitution が成立します。
現行 guard が 加えて、discard 用 これは AC2 の「人間が実行する invocation が nonce・expiry・SHA に束縛される」と AC5 の「executor-generated exact confirmation command」を満たしません。 必須修正contract を nonce または digest ごとの immutable file にしてください。 発行時は create-no-replace とし、executor が最低限次を構造化出力する必要があります。 confirmation:
contract_id: "<nonce>"
contract_sha256: "<digest>"
pr_head_sha: "<sha>"
local_tip_sha: "<sha>"
local_only_commit_shas: [...]
expires_at: "<timestamp>"
argv:
- uv
- run
- --locked
- python3
- scripts/agent-ops/materialize_cleanup_contract.py
- --operation
- local_only_discard
- --consume
- --contract-id
- "<nonce>"
- --expected-contract-sha256
- "<digest>"
# target fields...consume は固定 current file ではなく、指定された immutable contract を claim し、digest を一致確認する必要があります。 必要な回帰テストは、A を確認後、同一 target・異なる tip の B を発行し、A の command では B を消費できないことです。 P0-2: discard の fresh verification と
|
…ommit-one-shot-cleanup-executor
…city (#1523) OWNER adversarial security review (iteration 3) fix_delta: - P0-1: discard-lane confirmation contracts are now per-nonce immutable files (create-no-replace) instead of a single fixed-path file, and --consume requires --contract-id + --expected-contract-sha256 bound to the exact reviewed instance (no fixed-path fallback). command_hash is now computed from the real two-step subprocess argv, not a synthetic never-executed shell string. - P0-2: run_discard_consume acquires the shared mutation lock FIRST and re-verifies contract expiry, worktree catalog/branch binding, clean worktree state, and live branch tip immediately before the destructive calls. worktree remove no longer uses --force (git's own dirty-check is the final guard) and branch delete uses update-ref -d CAS instead of branch -D. - P0-3: the branch-only compare-and-delete lane re-fetches the worktree catalog inside the lock (not just tip OID) so a worktree that checks the branch out mid-race is detected. - P1-1: the mutation lock now fails CLOSED (raises MutationLockError) instead of silently degrading to no-lock on any failure, resolves its path via git rev-parse --git-common-dir (correct for linked worktrees), and uses non-blocking flock with a bounded Deadline-based retry. - P1-2: post-merge-cleanup-executor/SKILL.md documents the discard-lane routing for the canonical worker, and POST_MERGE_CLEANUP_REPORT_V1 gains an additive optional discard_confirmation field. - P1-3: the same-invocation branch-only fallback now escalates to force-delete only when merge-base --is-ancestor structurally confirms non-ancestry (exit code 1); exit code 0 fails closed to a distinct reason code instead of masking an unrelated branch -d failure. - P1-4: worktree_scope_guard.py's argv allowlist explicitly allows agent-issued --check and denies agent-issued --consume for materialize_cleanup_contract.py. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ommit-one-shot-cleanup-executor
Verdict: APPROVE (iteration 3 — response to OWNER security review)Independent code-level review of PR #2185 at head
CI: all required checks pass at this head. Allowed Paths: all changed files within the OWNER-expanded 14-entry list. Blockers(none) verdict: APPROVE
reviewed_head_sha: "0cef73c9f0a846b73bd2e601ddef5c3f90cb7dba"
blockers: []
warnings:
- "worktree_scope_guard.sh/local_main_branch_guard.sh are not currently registered under .claude/settings.json PreToolUse (pre-existing condition per #1691 hook narrowing); the argv-level agent-consume-deny this PR strengthens is not live-wired for either Claude or Codex right now. Out of scope for Issue #1523/this PR (not a regression it introduces), flagged for OWNER awareness only."
- "P1-4 Codex execpolicy mirror remains an explicitly documented, appropriately scoped follow-up within Issue #1523 rather than a new issue; OWNER may want to confirm this tracking approach is acceptable before merge." |
Summary
scripts/agent-ops/cleanup_exec.pyの branch-only fallback は、authorization 時に取得した expected branch-tip OID を destructive path まで渡さず、compare-and-delete 相当の保証がなかった(TOCTOU gap)。また ancestry-failure の分類が構造化されておらず、verifiedpayload の key/type が normal / branch-only lane 間で不揃いだった。加えて merged PR の dedicated worktree に残る local-only(未公開)commit を安全に破棄する経路が存在しなかった。本 PR は現在の
main(HEAD1cc7515814d5f0142661e64cda450575eb8df7c3)から新規実装したもので、PR #1528 の未マージ branch は取り込んでいない。#1528 の branch はコード source として使用せず、その OWNER review コメント(https://github.com/squne121/loop-protocol/pull/1528#issuecomment-5013575386)のみを branch-only fallback 修正の因果ソース(historical/causal source)として参照した。_perform_branch_onlyに expected OID を引数化し、shared repository mutation lock(fix_delta P1-1 で fail-closed 化した_mutation_lock)内で live tip を再検証してからgit update-ref -d refs/heads/<branch> <expected-oid>(compare-and-delete の git-native primitive)で削除する。ref race はbranch_tip_changedを返し、branch を残す(AC7)。_verify_ancestry_for_force_deleteに構造化し、expected OID が実在する commit object であること、git merge-base --is-ancestorが構造的に意味のある exit code を返すことの両方を要求する(AC8)。同関数は fix_delta P1-3 でrequire_non_ancestorモードを追加し、same-invocation 経路専用に exit code 1 のみを許容するよう区別した(下記 Fix Delta 参照)。_verified_template()で normal / branch-only / discard 全 lane 共通のverifiedkey set を定義し、既存 key の削除・型変更なしに正規化した(AC9)。run()に same-invocation の再認可経路を追加した(AC10)。fix_delta P1-3 でこの経路のみ ancestry 構造確認を exit code 1 限定に強化。verify_discard_authorization/run_discard_check/run_discard_consumeによる local-only unpublished commit discard lane を追加した(AC1-AC3)。fix_delta P0-1/P0-2 で確認契約バインディングと破壊操作直前の再検証を全面的に強化(下記参照)。materialize_cleanup_contract.pyに--check(非破壊の候補確認)と--consume(claim-first の一回消費)を追加。fix_delta P0-1 で--consumeに--contract-id/--expected-contract-sha256を必須化。CLEANUP_EXEC_RESULT_V1の既存必須キー・型は変更せず、discard_lane: trueを additive フィールドとして追加した(AC4)。.claude/skills/post-merge-cleanup/SKILL.mdに discard lane の handoff 方針を明記(AC5)。fix_delta P1-2 で canonical worker が実際に読む.claude/skills/post-merge-cleanup-executor/SKILL.mdにも routing 手順を追加。修正差分(第 3 回イテレーション) — OWNER によるセキュリティレビューへの対応
対象コメント: https://github.com/squne121/loop-protocol/pull/2185#issuecomment-5302936220(`reviewed_head_sha`
2e15b6f3ac32df5395334b29a7761d60fb14fea2)。7 blocker + 2 warning すべてに対応した(P1-4 のみ Codex 側ミラーが未完了 — 下記参照)。P0-1: 人間による確認操作を不変な契約インスタンスへ束縛する(対応済み)
cleanup_contract_v3.pyに per-nonce immutable contract storage を追加:artifacts/agent-ops/cleanup-contracts/<nonce>.json、write_contract_create_only()(O_CREAT|O_EXCL、上書き不可)。materialize()の discard lane(--operation local_only_discard、--check無し issuance)は、issuance 応答 JSON に構造化confirmationblock(contract_id/contract_sha256/pr_head_sha/local_tip_sha/local_only_commit_shas/expires_at/ 完全argv)を返すよう変更。--consumeは--contract-id/--expected-contract-sha256を必須化し、指定 nonce の immutable file のみを対象に digest を検証してから claim する。固定パスへのフォールバックは存在しない。command_hashは実際に実行される 2 段の subprocess argv(discard_real_argv())から計算し、シンセティックな&&文字列には依存しない。peek_contract_at)し、誤った digest の consume 試行が正規 contract を「消費」してしまう(DoS)ことを防いだ。tests/codex/test_cleanup_exec_branch_only.py::TestDiscardConfirmAndConsume::test_two_contracts_coexist_and_mismatched_confirmation_rejected(2 つの独立 nonce contract が共存し、A の contract_id + B の digest は拒否され、A 自身の正しい digest のみ成功する)、::test_consume_missing_contract_id_or_digest_refusedP0-2: 破棄操作の消費処理における時刻検査後実行前競合(対応済み)
_perform_discard()を再設計:_mutation_lockを最初に獲得し、その内側で (1) contract expiry 再確認、(2) worktree catalog entry / branch binding 再取得、(3) worktree clean 状態再確認、(4) live branch tip 再確認、を破壊呼び出し直前に実施。--forceなしのgit worktree remove <path>(git 自身の dirty-check が最終防御線)、branch 削除はgit branch -Dではなくgit update-ref -d refs/heads/<branch> <expected_local_tip_sha>(真の compare-and-delete)に変更。_DISCARD_RACE_HOOK(lock 獲得直後・再検証前に発火)を追加し、6 種のうち 5 種(untracked file 出現・tracked file 変更・new commit・catalog 変化・contract 期限切れ)を regression test 化。tests/codex/test_cleanup_exec_branch_only.py::TestDiscardInLockRaceGuard(5 tests、全 PASS)P0-3: branch-only compare-and-delete の in-lock catalog 再確認(fixed)
_perform_branch_only()はロック内で worktree catalog を再取得し、対象 branch を checkout している worktree が無いことを再確認してからupdate-ref -dを実行するよう変更(従来は tip OID のみ再検証)。_BRANCH_ONLY_RACE_HOOKを追加。scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyInLockCatalogRecheck::test_branch_only_delete_refused_when_branch_checked_out_between_authorization_and_lockP1-1: 変更ロックの安全側閉塞化(対応済み)
_mutation_lock()を全面再実装: ロックファイル open 失敗・fcntl不在・flock()失敗はすべてMutationLockErrorを raise して fail-closed(従来はいずれも無言で no-lock に degrade していた)。git rev-parse --git-common-dirから解決(linked worktree で正しい repository-identity-correct path)。fcntl.flock(LOCK_EX | LOCK_NB)+Deadlineに紐づいた bounded retry。scripts/agent-ops/tests/test_cleanup_exec.py::TestMutationLockFailsClosed(5 tests: fcntl 不在 / open 失敗 / retry 枯渇 / git-common-dir 解決 / 正常系)P1-3: 同一呼び出し内の祖先確認における終了コード限定(対応済み)
_verify_ancestry_for_force_delete()にrequire_non_ancestorパラメータを追加。standalone branch-only-fallback lane は従来通り exit code 0/1 双方を許容(既存の PR-head equivalence 認可を前提とするため不変)。same-invocation 再認可経路のみrequire_non_ancestor=Trueを強制し、exit code 1(non-ancestor)のみ許容、exit code 0 は新しい distinct reason codesame_invocation_ancestry_not_confirmedで fail-closed。scripts/agent-ops/tests/test_cleanup_exec.py::TestSameInvocationFallbackRefusalMatrix::test_same_invocation_fallback_refused_when_ancestry_exit_code_zero(force-delete subprocess が一切呼ばれないことを spy で確認)、::test_same_invocation_fallback_succeeds_when_reauthorized_and_non_ancestor(真の squash-merge 相当ケースで成功することを確認)P1-2: canonical worker の discard-lane handoff 到達性(fixed)
.claude/skills/post-merge-cleanup-executor/SKILL.md(post-merge-cleanup-workerが実際に読む skill)のステップ 3 に discard レーン routing を追加:--checkprobe → issuance →confirmationblock をレポートへ転記のみ(--consumeは worker が実行しない)。POST_MERGE_CLEANUP_REPORT_V1を additive 拡張し、optionaldiscard_confirmationfield(closed-key sub-schema)を追加。scripts/check_post_merge_cleanup_boundary.pyのvalidate_report_v1で検証。tests/test_post_merge_cleanup_boundary.py(present valid / absent backward-compat / null / malformed missing-subfield / wrong-type の 5 tests 追加)scripts/check_claude_codex_agent_parity.py/tests/test_agent_parity.pyが担うが、この 2 ファイルはPOST_MERGE_CLEANUP_REPORT_V1の consumer ではない(本 schema を検証しない)ため Schema Consumer Inventory には記載していない。P1-4: 番人スクリプトの許可一覧における確認フラグと消費フラグの区別(一部対応済み)
scripts/agent-guards/worktree_scope_guard.pyの_AGENT_OPS_ARG_SPECS["scripts/agent-ops/materialize_cleanup_contract.py"]に--checkを bool_flags として追加。--consume/--contract-id/--expected-contract-sha256は意図的に spec から欠落させたままとし、_validate_agent_ops_argvの unknown-flag 拒否ロジックにより agent 発行の--consumeargv は自動的に deny される(新規ロジック追加なし、既存の allowlist-closed 設計を再利用)。tests/agent_guards/test_worktree_scope_guard.py::test_materialize_check_allowed_real_hook(実 PreToolUse hook 経由で allow)、::test_materialize_consume_denied_real_hook(bare /--flag=value/ duplicate-flag の 3 argv 形状すべてで実 hook 経由 deny を確認)scripts/ci/codex_execpolicy_matrix.pyへの同等ケース追加は本 iteration では見送った。理由: 同ファイルのexecpolicy_case_definitions()は pinned Codex CLI バイナリを実行してexpected_execpolicyを検証する構造であり、ローカル環境に Codex CLI が無いため--check/--consumeargv に対する実際の execpolicy decision を検証できない。誤ったexpected_execpolicy値を投機的に追加すると CI を壊すリスクがあるため、この項目は human/CI 環境での追加検証が必要な gap として明示的に残す(follow-up 対象)。ブロックしない警告事項への対応
rev-list <pr-head>..<local-tip>のみを見ており、全ローカル ref・remote-tracking branch・他 PR からの到達不可能性までは検証していない。固定済みのreason_code文字列(discard_no_local_only_commits等)はスキーマ互換のため変更していないが、本 PR body および docstring では「PR head 以降のコミット」という実際のスコープを明記する。current HEADフィールドをimplementation_base_sha(実装着手時の base)に改称し、実際に検証を実行した head を示すverified_head_shaを新設した(下記参照)。Runtime Verification Evidence(動作検証証跡)
implementation_base_sha:1cc7515814d5f0142661e64cda450575eb8df7c3(実装 branch はこの HEAD から分岐)verified_head_sha:4d2c78f046d99a1047358bb8e7b9f19c6a7d063a(本 fix_delta の最終検証を実行した head。origin/mainとの merge を含む)tests/codex/test_cleanup_exec_branch_only.py::TestDiscardConfirmAndConsume(10 tests)、::TestDiscardInLockRaceGuard(5 tests)scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyCompareAndDeleteRaceGuard/::TestBranchOnlyInLockCatalogRecheckscripts/agent-ops/tests/test_cleanup_exec.py::TestMutationLockFailsClosed(5 tests)scripts/agent-ops/tests/test_cleanup_exec.py::TestSameInvocationFallbackRefusalMatrix(3 tests)tests/agent_guards/test_worktree_scope_guard.py::test_materialize_check_allowed_real_hook/::test_materialize_consume_denied_real_hook(4 param cases)tests/test_post_merge_cleanup_boundary.py(5 tests)artifacts(gitignored、
artifacts/agent-ops/は per-nonce contract path と同様に repo に含めない): 実行済み証跡はローカル pytest 出力(上記コマンド)に限定。動作検証 VC の外部プロセス起動を伴う AC ではないため、artifacts/runtime-verification-*.logの追加生成は本 iteration では行っていない。受け入れ条件の達成状況
codex_execpolicy_matrix.pyミラーは human/CI 環境での追加検証待ち(未完了、理由は上記)。検証コマンド結果
Issue #1523 の Verification Commands(10 件、AC1-AC10)は iteration 2 で全 PASS 済み(変更なし)。fix_delta 追加分の検証コマンドは「Runtime Verification Evidence」セクション参照。
追加で、リポジトリ標準の必須検証を head
4d2c78f046d99a1047358bb8e7b9f19c6a7d063aで実行し全 PASS:ruff check(clean)、pnpm typecheck/pnpm lint/pnpm test/pnpm build。Checks
uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py scripts/agent-ops/tests/test_cleanup_exec.py tests/test_post_merge_cleanup_boundary.py tests/agent_guards/test_worktree_scope_guard.py scripts/ci/tests/test_codex_execpolicy_matrix.py tests/codex/test_execpolicy_matrix.py -quv run --locked ruff check .claude/scripts scripts schemas .claude/skillspnpm typecheck && pnpm lint && pnpm test && pnpm buildAllowed Paths 遵守
Issue #1523 の Allowed Paths は iteration 3 で OWNER により 14 件へ拡張された(review item 8)。本 PR の diff(
gh pr diff 2185 --name-only)はこの 14 件の範囲内に収まっている。今回変更したファイル(10 件)は以下の通り。scripts/agent-ops/cleanup_exec.py— 実行本体(ロック・再検証・削除処理)scripts/agent-ops/cleanup_contract_v3.py— 契約の不変ファイル保存・数値検証処理scripts/agent-ops/materialize_cleanup_contract.py— 発行・確認・消費コマンド本体tests/codex/test_cleanup_exec_branch_only.py— 破棄経路・競合注入の回帰試験scripts/agent-ops/tests/test_cleanup_exec.py— ロック・祖先確認・再検査の回帰試験.claude/skills/post-merge-cleanup-executor/SKILL.md— 実行担当エージェント向け手順書scripts/check_post_merge_cleanup_boundary.py— 報告書の検証器(追加項目対応)tests/test_post_merge_cleanup_boundary.py— 検証器の回帰試験scripts/agent-guards/worktree_scope_guard.py— 番人スクリプトの許可一覧tests/agent_guards/test_worktree_scope_guard.py— 番人スクリプトの実フック回帰試験iteration 2 で既に更新済みのため今回変更していないもの:
.claude/skills/post-merge-cleanup/SKILL.md。未変更(14 件のうち残り 3 件):
scripts/ci/codex_execpolicy_matrix.py/scripts/ci/tests/test_codex_execpolicy_matrix.py/tests/codex/test_execpolicy_matrix.py(P1-4 Codex 側ミラーが未完了のため)。scripts/agent-guards/git_mutation_command_policy.pyとscripts/agent-ops/worktree_catalog.pyは OWNER 指示どおり編集していない(_WorktreeExecutionLockパターンは参照のみ、Deadlineは import のみ)。Schema Change Applicability
本 PR は additive schema change を含む。
変更内容:
POST_MERGE_CLEANUP_REQUEST_V3.operationenum にOP_LOCAL_ONLY_DISCARD(local_only_discard)を追加済み(iteration 2)。当該 operation のみに適用される追加必須フィールドpr_head_sha/local_tip_shaも additive。既存worktree_remove/branch_deleteoperation の契約は不変。CLEANUP_EXEC_RESULT_V1にdiscard_lane: true(additive、iteration 2)。POST_MERGE_CLEANUP_REPORT_V1に optionaldiscard_confirmationfield を additive 追加(fix_delta P1-2、本 iteration)。materialize_cleanup_contract.pyCLI に--check/--consume/--contract-id/--expected-contract-sha256フラグを追加(iteration 2 で--check/--consume、fix_delta P0-1 で--contract-id/--expected-contract-sha256)。Schema Consumer Inventory
scripts/agent-ops/cleanup_exec.py(verify_discard_authorization等)POST_MERGE_CLEANUP_REQUEST_V3.operationの discard operation を消費scripts/agent-ops/materialize_cleanup_contract.pyPOST_MERGE_CLEANUP_REQUEST_V3.operation、CLEANUP_EXEC_RESULT_V1の両方を消費scripts/agent-guards/worktree_scope_guard.py(agent-ops argv allowlist)--check許可 /--consume拒否scripts/ci/codex_execpolicy_matrix.py(Codex CLI parity).claude/skills/post-merge-cleanup-executor/SKILL.md(canonical worker 手順)discard_confirmation転記手順scripts/check_post_merge_cleanup_boundary.py(validate_report_v1)discard_confirmationadditive field の closed-key 検証Safety Claim Matrix
scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyCompareAndDeleteRaceGuardscripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyInLockCatalogRecheckscripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyAncestryStructuralGate/::TestSameInvocationFallbackRefusalMatrixtests/codex/test_cleanup_exec_branch_only.py::TestDiscardConfirmAndConsume::test_two_contracts_coexist_and_mismatched_confirmation_rejectedtests/codex/test_cleanup_exec_branch_only.py::TestDiscardInLockRaceGuardscripts/agent-ops/tests/test_cleanup_exec.py::TestMutationLockFailsClosedmaterialize_cleanup_contract.py --consumeを発行できない(Claude 側 guard allowlist が deny する)。--checkは非破壊のため agent 発行を許可するtests/agent_guards/test_worktree_scope_guard.py::test_materialize_consume_denied_real_hookscripts/agent-ops/tests/test_cleanup_exec.py::TestSameInvocationFallbackRefusalMatrix::test_same_invocation_fallback_refusals_preserve_partial_actions_and_branchNotes
本 PR は Issue #1523 を解消する。
Closes #1523
main(HEAD1cc7515814d5f0142661e64cda450575eb8df7c3)を実装基準とした fresh implementation であり、PR feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 の未マージ branch(worktree-issue-1403-post-merge-cleanup-dedicated-branch-forc)は code source として使用していない。feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 の OWNER review コメント(https://github.com/squne121/loop-protocol/pull/1528#issuecomment-5013575386)のみを branch-only fallback 修正の因果ソースとして参照した。_verify_ancestry_for_force_delete)の standalone branch-only-fallback lane は exit code 0(通常の ancestor)・1(squash-merge 等で ancestor でない)の両方を構造的に有効な結果として許容する設計を維持している(既存の PR-head equivalence 認可を前提とするため)。fix_delta P1-3 で same-invocation 経路のみ exit code 1 限定へ強化した。cleanup_exec.py自体の CLI 引数は不変。discard lane の human-run 確認コマンドはmaterialize_cleanup_contract.py --operation local_only_discard(発行、confirmationblock を返す)→materialize_cleanup_contract.py --operation local_only_discard --consume --contract-id <nonce> --expected-contract-sha256 <digest>(消費・破壊操作)の 2 コマンド。codex_execpolicy_matrix.pyミラー未完了)は Issue 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 自体の follow-up として残す(新規 Issue は起票せず、同 Issue のクローズ前に解消するか、クローズ後は別途 human 判断でフォローアップ Issue 化する)。