Skip to content

feat: cleanup executor に one-shot discard lane と compare-and-delete を追加する - #2185

Merged
squne121 merged 5 commits into
mainfrom
worktree-issue-1523-commit-one-shot-cleanup-executor
Aug 15, 2026
Merged

squne121 merged 5 commits into
mainfrom
worktree-issue-1523-commit-one-shot-cleanup-executor

Conversation

@squne121

@squne121 squne121 commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

scripts/agent-ops/cleanup_exec.py の branch-only fallback は、authorization 時に取得した expected branch-tip OID を destructive path まで渡さず、compare-and-delete 相当の保証がなかった(TOCTOU gap)。また ancestry-failure の分類が構造化されておらず、verified payload の key/type が normal / branch-only lane 間で不揃いだった。加えて merged PR の dedicated worktree に残る local-only(未公開)commit を安全に破棄する経路が存在しなかった。

本 PR は現在の main(HEAD 1cc7515814d5f0142661e64cda450575eb8df7c3)から新規実装したもので、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)。
  • ancestry 判定を _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 共通の verified key 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 手順を追加。
  • 既存 normal cleanup / branch-only cleanup 回帰テストは維持し、削除・弱体化していない(AC6)。

修正差分(第 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 に構造化 confirmation block(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())から計算し、シンセティックな && 文字列には依存しない。
  • claim(一回消費の atomic rename)より前に digest を非破壊で peek(peek_contract_at)し、誤った digest の consume 試行が正規 contract を「消費」してしまう(DoS)ことを防いだ。
  • evidence: 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_refused

P0-2: 破棄操作の消費処理における時刻検査後実行前競合(対応済み)

  • _perform_discard() を再設計: _mutation_lock を最初に獲得し、その内側で (1) contract expiry 再確認、(2) worktree catalog entry / branch binding 再取得、(3) worktree clean 状態再確認、(4) live branch tip 再確認、を破壊呼び出し直前に実施。
  • worktree 削除は --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)に変更。
  • 破壊呼び出し後に postcondition read-back(worktree path 不在 + branch ref 不在)を追加。
  • テスト用 race-injection seam _DISCARD_RACE_HOOK(lock 獲得直後・再検証前に発火)を追加し、6 種のうち 5 種(untracked file 出現・tracked file 変更・new commit・catalog 変化・contract 期限切れ)を regression test 化。
  • evidence: 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 のみ再検証)。
  • テスト用 race-injection seam _BRANCH_ONLY_RACE_HOOK を追加。
  • evidence: scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyInLockCatalogRecheck::test_branch_only_delete_refused_when_branch_checked_out_between_authorization_and_lock

P1-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。
  • evidence: 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 code same_invocation_ancestry_not_confirmed で fail-closed。
  • evidence: 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 を追加: --check probe → issuance → confirmation block をレポートへ転記のみ(--consume は worker が実行しない)。
  • POST_MERGE_CLEANUP_REPORT_V1 を additive 拡張し、optional discard_confirmation field(closed-key sub-schema)を追加。scripts/check_post_merge_cleanup_boundary.py の validate_report_v1 で検証。
  • evidence: tests/test_post_merge_cleanup_boundary.py(present valid / absent backward-compat / null / malformed missing-subfield / wrong-type の 5 tests 追加)
  • 補足: Claude/Codex 双方の parity infra は 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 発行の --consume argv は自動的に deny される(新規ロジック追加なし、既存の allowlist-closed 設計を再利用)。
  • evidence: 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/--consume argv に対する実際の execpolicy decision を検証できない。誤った expected_execpolicy 値を投機的に追加すると CI を壊すリスクがあるため、この項目は human/CI 環境での追加検証が必要な gap として明示的に残す(follow-up 対象)。

ブロックしない警告事項への対応

  • 「local-only unpublished」という用語は rev-list <pr-head>..<local-tip> のみを見ており、全ローカル ref・remote-tracking branch・他 PR からの到達不可能性までは検証していない。固定済みの reason_code 文字列(discard_no_local_only_commits 等)はスキーマ互換のため変更していないが、本 PR body および docstring では「PR head 以降のコミット」という実際のスコープを明記する。
  • Runtime Verification Evidence セクションの旧 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 を含む)
  • confirmation binding / consume / replay / digest-mismatch verdict: tests/codex/test_cleanup_exec_branch_only.py::TestDiscardConfirmAndConsume(10 tests)、::TestDiscardInLockRaceGuard(5 tests)
  • expected OID / compare-and-delete / in-lock catalog re-check: scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyCompareAndDeleteRaceGuard / ::TestBranchOnlyInLockCatalogRecheck
  • mutation lock fail-closed: scripts/agent-ops/tests/test_cleanup_exec.py::TestMutationLockFailsClosed(5 tests)
  • same-invocation ancestry gate: scripts/agent-ops/tests/test_cleanup_exec.py::TestSameInvocationFallbackRefusalMatrix(3 tests)
  • guard allowlist real-hook: tests/agent_guards/test_worktree_scope_guard.py::test_materialize_check_allowed_real_hook / ::test_materialize_consume_denied_real_hook(4 param cases)
  • report schema additive field: tests/test_post_merge_cleanup_boundary.py(5 tests)
$ 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 -q
388 passed in 22.81s

$ uv run --locked ruff check .claude/scripts scripts schemas .claude/skills
All checks passed!

$ pnpm typecheck && pnpm lint && pnpm test && pnpm build
(全 PASS。pnpm test: 112 files / 1872 tests passed)

artifacts(gitignored、artifacts/agent-ops/ は per-nonce contract path と同様に repo に含めない): 実行済み証跡はローカル pytest 出力(上記コマンド)に限定。動作検証 VC の外部プロセス起動を伴う AC ではないため、artifacts/runtime-verification-*.log の追加生成は本 iteration では行っていない。

受け入れ条件の達成状況

  • AC1-AC10: iteration 2 時点で達成済み(変更なし)。evidence は上記 iteration 2 セクション参照。
  • fix_delta P0-1 〜 P1-3: 上記 Fix Delta セクションの evidence 参照。
  • fix_delta P1-2: 上記 Fix Delta セクションの evidence 参照。
  • [~] fix_delta P1-4: Claude 側 guard allowlist は完了(evidence あり)。Codex 側 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

  • 対象テストスイート一式を実行し全 388 件成功を確認した: 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 -q
  • 静的解析(ruff)を実行し警告ゼロを確認した: uv run --locked ruff check .claude/scripts scripts schemas .claude/skills
  • 型検査・lint・単体テスト・ビルドの標準品質ゲートを全て通過した: pnpm typecheck && pnpm lint && pnpm test && pnpm build

Allowed 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 を含む。

  • decision: schema_change
  • additive_only: true

変更内容:

  • POST_MERGE_CLEANUP_REQUEST_V3.operation enum に OP_LOCAL_ONLY_DISCARD(local_only_discard)を追加済み(iteration 2)。当該 operation のみに適用される追加必須フィールド pr_head_sha / local_tip_sha も additive。既存 worktree_remove / branch_delete operation の契約は不変。
  • CLEANUP_EXEC_RESULT_V1 に discard_lane: true(additive、iteration 2)。
  • POST_MERGE_CLEANUP_REPORT_V1 に optional discard_confirmation field を additive 追加(fix_delta P1-2、本 iteration)。
  • materialize_cleanup_contract.py CLI に --check / --consume / --contract-id / --expected-contract-sha256 フラグを追加(iteration 2 で --check/--consume、fix_delta P0-1 で --contract-id/--expected-contract-sha256)。

Schema Consumer Inventory

# Before
POST_MERGE_CLEANUP_REQUEST_V3.operation: worktree_remove または branch_delete のみ
CLEANUP_EXEC_RESULT_V1: discard_lane フィールドなし
POST_MERGE_CLEANUP_REPORT_V1: discard_confirmation フィールドなし
materialize_cleanup_contract.py CLI: --check / --consume / --contract-id / --expected-contract-sha256 なし

# After
POST_MERGE_CLEANUP_REQUEST_V3.operation: OP_LOCAL_ONLY_DISCARD を追加(additive)
CLEANUP_EXEC_RESULT_V1: discard_lane: true を追加(additive)
POST_MERGE_CLEANUP_REPORT_V1: discard_confirmation を追加(optional, additive)
materialize_cleanup_contract.py CLI: --check / --consume / --contract-id / --expected-contract-sha256 を追加
Consumer ファイル 更新有無 備考
scripts/agent-ops/cleanup_exec.py(verify_discard_authorization 等) 更新済み POST_MERGE_CLEANUP_REQUEST_V3.operation の discard operation を消費
scripts/agent-ops/materialize_cleanup_contract.py 更新済み POST_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) 未更新 fix_delta P1-4 gap。pinned Codex CLI 環境での追加検証が必要(Safety Claim Matrix の該当行を参照)
.claude/skills/post-merge-cleanup-executor/SKILL.md(canonical worker 手順) 更新済み discard lane routing + discard_confirmation 転記手順
scripts/check_post_merge_cleanup_boundary.py(validate_report_v1) 更新済み discard_confirmation additive field の closed-key 検証

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
branch-only fallback の force delete は expected branch-tip OID を再検証してからのみ実行される(TOCTOU race を compare-and-delete で閉じる) yes - scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyCompareAndDeleteRaceGuard -
branch-only fallback は in-lock で worktree catalog / branch-usage を再確認してから branch を削除する(tip OID の CAS のみに依存しない) yes - scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyInLockCatalogRecheck -
ancestry 判定に失敗した場合は force delete を実行しない。same-invocation 経路は exit code 1(構造的 non-ancestor)のみ許容し exit code 0 は distinct reason code で fail-closed する yes - scripts/agent-ops/tests/test_cleanup_exec.py::TestBranchOnlyAncestryStructuralGate / ::TestSameInvocationFallbackRefusalMatrix -
discard lane の human confirmation は per-nonce immutable file + digest binding により、reissue された別 contract を誤って consume することはない yes - tests/codex/test_cleanup_exec_branch_only.py::TestDiscardConfirmAndConsume::test_two_contracts_coexist_and_mismatched_confirmation_rejected -
discard consume の破壊呼び出しは shared mutation lock 獲得後・直前に fresh 再検証(expiry / catalog / clean / tip)を行い、race で出現した未追跡ファイル・変更・新規コミット・catalog 変化・期限切れは全て fail-closed で拒否される yes - tests/codex/test_cleanup_exec_branch_only.py::TestDiscardInLockRaceGuard -
mutation lock はロック取得不能時(fcntl 不在・open 失敗・flock 枯渇)に fail-closed し、無言で lock 無しに degrade しない yes - scripts/agent-ops/tests/test_cleanup_exec.py::TestMutationLockFailsClosed -
agent は materialize_cleanup_contract.py --consume を発行できない(Claude 側 guard allowlist が deny する)。--check は非破壊のため agent 発行を許可する yes(Claude 側のみ) Codex 側 execpolicy ミラー未検証 tests/agent_guards/test_worktree_scope_guard.py::test_materialize_consume_denied_real_hook #1523
同一 invocation 内の branch-only 再認可は、拒否時に force-delete subprocess を一切呼び出さない yes - scripts/agent-ops/tests/test_cleanup_exec.py::TestSameInvocationFallbackRefusalMatrix::test_same_invocation_fallback_refusals_preserve_partial_actions_and_branch -

Notes

本 PR は Issue #1523 を解消する。
Closes #1523

…追加する (#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]>
@github-actions

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2185/

The preview will be removed when this PR is closed.

@squne121

Copy link
Copy Markdown
Owner Author

PR Review Verdict (iteration 0)

Mergeability: mergeable=MERGEABLE, merge_state_status=BLOCKED (draft)

Evidence Check: 10 AC Verification Commands PASS at head 13f989ac595b65f8a802b3e8b15997939c5faf1a. pnpm typecheck/lint/test/build PASS. However required CI check python-test/python-test-core FAILS: ruff check reports E501/E402 violations at current head in Allowed Paths files.

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)
@squne121

Copy link
Copy Markdown
Owner Author

PR Review Verdict (iteration 1)

Mergeability: mergeable=MERGEABLE, live required CI checks (test/lint/build/typecheck/validate-generated-artifact) all PASS at head 2e15b6f3ac32df5395334b29a7761d60fb14fea2.

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:

  • PR body missing required structured sections: ## 受け入れ条件の達成状況(AC1-10 の [x]/[ ] + evidence checklist), ## 検証コマンド結果, ## Allowed Paths 遵守。AC evidence exists inline in ## Summary/## Checks but not in the canonical per-AC checklist format.

Non-blockers / warnings:

  • tests/codex/test_cleanup_exec_branch_only.py has pre-existing (not introduced by this PR) ruff E402/F401/E501 debt outside CI's lint scope. Not a blocker; candidate for follow-up cleanup.
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."

@squne121

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE

Re-review after PR-body-only fix (head SHA unchanged: 2e15b6f3ac32df5395334b29a7761d60fb14fea2). The previous iteration's sole blocker — missing ## 受け入れ条件の達成状況 / ## 検証コマンド結果 / ## Allowed Paths 遵守 sections — is resolved; all three are now present with substantive, verifiable content.

Independently re-confirmed:

  • headRefOid matches expected 2e15b6f3ac32df5395334b29a7761d60fb14fea2
  • Issue 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 live AC1–AC10 text and Verification Commands (10) match the PR body's tables exactly
  • gh pr diff --name-only (6 files) exactly matches Issue's Allowed Paths (no extras, no omissions)
  • Canonical required-CI evaluator (wait_ci_checks.py --required) at exact head SHA: all 6 required checks (lint/test/typecheck/build/python-test/validate-generated-artifact) SUCCESS
  • Schema Change Applicability (not_schema_change) is consistent with diff (additive-only internal contract extension, no external consumer)
  • Safety Claim Matrix is populated with concrete evidence bindings for all destructive-operation claims

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"

@squne121
squne121 marked this pull request as ready for review August 15, 2026 14:17
@squne121

Copy link
Copy Markdown
Owner Author

結論

判定: REQUEST_CHANGES。現状のままマージ不可です。

レビュー対象は PR head 2e15b6f3ac32df5395334b29a7761d60fb14fea2。PR は現在 open・非 Draft・mergeable で、既存の再レビューは required CI と AC 対応を根拠に APPROVE を出しています。

expected OID を使った update-ref compare-and-delete、claim-first rename、symlink-safe な contract IO、agent guard が --consume を許可していない点は妥当です。しかし Issue #1523 が要求する次の安全境界は成立していません。

  • 人間が確認した 特定の contract instance と実行 invocation の束縛
  • 検証から破壊操作までの worktree dirty state/branch tip/branch 使用状態の保持
  • 全 worktree mutation 経路で共有される、取得失敗時に fail-close する repository lock
  • canonical worker から人間への exact confirmation command の handoff

Issue #1523 と旧 PR #1528 の OWNER レビューは、worktree 使用状態を lock 内で再検査し、update-ref 単体を共有 lock の代替にしないことまで明示しています。


P0-1: 人間が確認した contract を、消費前に別 contract へすり替えられる

問題

materialize() は固定パス artifacts/agent-ops/cleanup_contract.json に contract を書き、返すのは contract_path、operation、expires_at だけです。exact confirmation command、nonce、contract digest、PR head SHA、local tip SHA は出力されません。

さらに durable write は temporary file を固定 final path へ os.rename() しており、既存 contract を置換できます。

一方、--consume invocation に含まれるのは PR 番号、Issue 番号、worktree path、branch 名だけです。nonce、expiry、SHA、contract digest、contract ID は渡されません。consume は実行時点で固定パスに存在する contract を claim します。

したがって、次の approval-substitution が成立します。

  1. SHA X を指す contract A を worker が発行し、人間が破棄対象を確認する。
  2. 人間が consume する前に別 process/agent が branch を SHA Y へ進める。
  3. 同じ target 引数で contract B を再発行する。固定パス上の A は B に置換される。
  4. 人間は表示済みの、A と B で同一の generic --consume command を実行する。
  5. consume は B を claim し、fresh verification も Y と一致するため、人間が確認していない Y を破棄する。

現行 guard が --consume を allowlist に含めていないため、単純な agent self-consume は遮断されています。しかし plain issuance は許可されているため、contract 置換は防げません。

加えて、discard 用 command_hash は実際の human invocation ではなく、実行されない literal "&&" を含む合成 argv から計算されています。consume 時にも human --consume argv から再計算されていません。したがって、この hash は人間の確認操作にも、実際の二つの destructive subprocess にも束縛されていません。

これは AC2 の「人間が実行する invocation が nonce・expiry・SHA に束縛される」と AC5 の「executor-generated exact confirmation command」を満たしません。

必須修正

contract を nonce または digest ごとの immutable file にしてください。

artifacts/agent-ops/cleanup-contracts/<nonce>.json

発行時は 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 を一致確認する必要があります。command_hash を残すなら synthetic Git command ではなく、実際の confirmation argv に対して計算してください。

必要な回帰テストは、A を確認後、同一 target・異なる tip の B を発行し、A の command では B を消費できないことです。


P0-2: discard の fresh verification と --force 削除の間に TOCTOU があり、未コミット変更または新 commit を失う

問題

run_discard_consume() は次の順で処理します。

  1. contract claim/schema/expiry 検査
  2. verify_discard_authorization() による clean state、catalog、PR、SHA の fresh verification
  3. SHA binding 比較
  4. _perform_discard() を呼び出す
  5. _perform_discard() の中で初めて lock を取得
  6. git worktree remove --force
  7. git branch -D

つまり worktree clean state、catalog binding、branch tip は lock の外で検査され、lock 内では一切再検査されません。

Git 公式仕様上、通常の git worktree remove は dirty worktree を拒否しますが、--force はその防護を明示的に解除します。(Git)

Git 2.47.3 で独立再現しました。

clean_probe_bytes=0
dirty_after_probe=?? valuable.txt;
valuable_file_after=deleted
worktree_dir_after=deleted

すなわち、clean probe 後に untracked file が生成されると、その後の git worktree remove --force はそれを無警告で消します。

新 commit の競合はさらに重大です。

  1. fresh verification 時点では local tip が X。
  2. 検証後、別 process が commit Y を追加する。worktree は再び clean。
  3. _perform_discard() が worktree を force-remove。
  4. git branch -D が current tip Y を無条件削除。

contract が束縛していたのは X ですが、実際に失われるのは未確認の Y です。現在の test_consume_sha_binding_changed_refused は consume 呼び出し前に branch を進めるケースしか検査しておらず、fresh verification と _perform_discard() の間の競合を扱っていません。

必須修正

discard の破壊区間を次の順に変更してください。

  1. fail-close な shared lock を取得
  2. contract expiry を再確認
  3. worktree catalog と branch binding を再取得
  4. worktree clean state を再確認
  5. live branch tip と expected local tip を再確認
  6. git worktree remove <path> を --force なしで実行
  7. git update-ref -d refs/heads/<branch> <expected-local-tip> で CAS delete
  8. worktree absence/branch absence の postcondition readback

この構成なら、検査後に untracked file が生えた場合は non-force remove が拒否し、新 commit が追加された場合は branch CAS が拒否して commit を残せます。

必要なテストは _perform_discard() 直前へ race hook を入れ、以下を個別に注入することです。

  • untracked file
  • tracked file modification
  • new commit
  • catalog entry replacement
  • branch binding replacement
  • contract expiry

いずれも未確認データが削除されないことを検証してください。


P0-3: branch-only compare-and-delete は、branch が別 worktree で checkout された競合を閉じていない

問題

verify_branch_only_cleanup_authorization() は最初の検査時には、別 worktree が対象 branch を使用していないことを確認しています。しかし _perform_branch_only() の lock 内で再確認するのは次だけです。

  • live branch tip
  • ancestry result
  • update-ref -d ... <expected_oid>

worktree catalog と branch 使用状態は再取得していません。

Git の update-ref -d <ref> <old-oid> が保証するのは、ref の current OID が old OID と一致する場合だけ削除することです。branch が worktree で checkout 中かどうかは保証対象ではありません。(Git)

Git 2.47.3 で次を再現しました。

oid=a8622450bbef51cce76b18e259d53e66f12382c1
head_before=refs/heads/topic
update_ref_rc=0
ref_after=missing
head_after=refs/heads/topic

linked worktree の HEAD が refs/heads/topic を指したままでも、update-ref -d は成功し、branch ref は消えました。

実際の競合シーケンスは次です。

  1. verifier が「branch はどの worktree でも使用されていない」と判定。
  2. 別 process がその branch を新しい worktree へ checkout。
  3. _perform_branch_only() が expected OID 一致だけを確認。
  4. update-ref -d が成功。
  5. 新 worktree は存在しない branch を指す状態になる。

これは旧 PR #1528 の OWNER レビューが明示的に要求した「shared lock 内で worktree catalog/branch 非使用状態を再検査する」を未達のまま残しています。

必須修正

単に _perform_branch_only() 内で再度 list_worktrees() するだけでは不十分です。現在の lock を worktree add/checkout/remove/branch cleanup の全 controlled mutation path が共有していないためです。

最低条件は次です。

  • repository/common-dir identity に基づく一つの mutation lock
  • controlled な worktree add/checkout/remove/branch delete が同じ lock を使用
  • lock 内で catalog と branch 使用状態を再検査
  • expected OID の CAS delete
  • delete 後に全 worktree の HEAD と ref absence を readback

必要な race test は、verifier 終了後・delete 直前に別 worktreeへ対象 branchを checkoutし、branch refと新 worktreeの双方が残ることです。


P1-1: _mutation_lock は fail-open、repository identity 非対応、無期限 blocking

問題

新しい _mutation_lock() は以下の失敗をすべて黙殺して、lock なしで destructive path を続行します。

  • lock file の open 失敗
  • fcntl が利用不能
  • flock() の失敗

さらに LOCK_EX は blocking 呼び出しで、Deadline や timeout を使用しません。

flock は advisory lock にすぎず、同じ規約に参加しない process は無視できます。また LOCK_NB を付けない lock acquisition は競合中に block します。([man7.org]3) Python API も LOCK_NB と EACCES/EAGAIN による bounded retry を提供しています。([Python documentation]4)

lock path を <project_root>/.git/loop-protocol-cleanup.lock と決め打ちしている点も不適切です。linked worktree の top-level .git は directory ではなく gitfile であり、Git は $GIT_DIR/$GIT_COMMON_DIR を直接仮定せず git rev-parse --git-path を使うよう明記しています。([Git]1)

このリポジトリには既に、trusted Git context を確立し、git rev-parse --git-path で lock path を取得し、LOCK_EX | LOCK_NB と bounded retry を使う実装があります。新規の弱い lock を追加する合理性はありません。

また contract expiry は lock acquisition 前に一度だけ検査されます。例えば TTL 1 秒の contract が lock 待ちで 2 秒経過しても、全体 Deadline が残っていれば期限切れ後に破壊操作へ進みます。

必須修正

既存 _WorktreeExecutionLock 相当を一般化して再利用してください。

  • git rev-parse --git-common-dir/--git-path による repository identity
  • symlink-safe/owner・mode 検査済み lock file
  • LOCK_EX | LOCK_NB
  • Deadline に連動した bounded retry
  • open/acquire 失敗は structured refusal
  • lock 取得後に contract expiry と全 live state を再検査
  • lock 不在 platform は unsupported として fail-close

最低限必要なテストは、open error、fcntl unavailable、flock error、lock timeout、lock 待ち中 expiry です。


P1-2: canonical worker から discard lane へ到達できず、AC5 の handoff は実装ではなく文言だけ

問題

post-merge-cleanup-worker は frontmatter で post-merge-cleanup-executor Skill だけを読み、top-level post-merge-cleanup/SKILL.md は読まないと明示されています。

ところが discard lane の新しい説明は top-level orchestrator Skill にしか追加されていません。

worker が実際に読む canonical executor Skill は、次のように規定しています。

  • cleanup は cleanup_exec.py だけを使う
  • status: refused は unresolved_cleanup_items に記録
  • materialize_cleanup_contract.py は agent 向け cleanup path ではなく defense-in-depth

したがって pr_head_oid_mismatch から --check、contract issuance、human handoff へ遷移する手順がありません。

さらに POST_MERGE_CLEANUP_REPORT_V1 は closed-key schema であり、confirmation command、contract ID、SHA、expiry を返すフィールドが存在しません。

そして前述のとおり、materializer 自体も exact command を生成していません。

AC5 の verification は単に次の文字列が Skill に存在することを rg で確認しているだけです。

explicit human confirmation command

これは end-to-end handoff の検証ではありません。PR 本文自身が AC5 の証拠をこの文字列検索だけにしています。

必須修正

canonical worker flow を次のように拡張する必要があります。

  1. pr_head_oid_mismatch を discard-candidate probe へ route
  2. structured commit list を取得
  3. immutable contract を発行
  4. exact confirmation argv と bound facts を report へ格納
  5. main thread がその field だけを人間へ handoff
  6. human consume 後、postcondition report を再取得

この修正には少なくとも以下が必要です。

  • .claude/skills/post-merge-cleanup-executor/SKILL.md
  • POST_MERGE_CLEANUP_REPORT_V1 の正本/validator
  • worker boundary tests
  • Claude/Codex parity tests

これらは現在の Issue #1523 の Allowed Paths 外です。したがって hidden scope expansion ではなく、Issue contract と Allowed Paths の明示更新が必要です。


P1-3: same-invocation fallback が ancestry 以外の branch -d failure でも escalation する

問題

normal cleanup では、worktree remove 後に git branch -d が失敗すると、stderr の原因を構造分類せず、branch_delete_failed: という prefix だけで branch-only reauthorization に入ります。

その後の _verify_ancestry_for_force_delete() は merge-base --is-ancestor の exit code 0 と 1 の両方を許可します。テストにも test_ancestry_gate_accepts_ordinary_ancestor が追加されています。

しかし exit code 0 は「expected tip は comparison ref の ancestor」、つまり mergedness は成立している状態です。その状態で branch -d が失敗したなら、原因は「not fully merged」ではありません。ref lock、branch 使用状態、permission、object/repository anomaly など別の failure です。それを update-ref delete へ昇格するのは、元 failure の防護を迂回します。

Issue #1523 の AC8 は「mergedness 不成立が構造的に確認された場合だけ」としており、旧 OWNER レビューも exit code 1 だけを escalation 条件にするよう要求しています。

PR 本文は exit 0 を許可する設計変更を明示していますが、Issue contract は更新されていません。

必須修正

少なくとも same-invocation fallback では次の分類にしてください。

  • merge-base --is-ancestor == 1
    squash-equivalence 等の既存認可が成立した場合だけ CAS delete 候補
  • == 0
    original branch -d failure は ancestry failure ではないため停止
  • >= 2、invalid object、I/O/lock error
    fail-close

standalone branch-only resume で exit 0 を維持したいなら、same-invocation と別 policy mode に分離し、Issue contract も更新する必要があります。

必要なテストは、branch -d を人工的に失敗させつつ merge-base が 0 を返すケースで、update-ref が一度も呼ばれないことです。


P1-4: not_schema_change/consumer inventory「該当なし」は事実と整合しない

PR は schema change applicability を not_schema_change、consumer inventory を「該当なし」としています。既存 APPROVE もこの判断を受け入れています。

しかし実際には次を変更しています。

  • POST_MERGE_CLEANUP_REQUEST_V3.operation の enum 追加

  • discard operation の条件付き必須フィールド追加

  • CLEANUP_EXEC_RESULT_V1 の新 lane field

  • 新 reason code 群

  • materializer CLI の --check/--consume

実在する consumer には少なくとも以下があります。

  • worktree_scope_guard.py の agent-ops argv allowlist
  • Codex execpolicy matrix
  • post-merge-cleanup executor Skill
  • POST_MERGE_CLEANUP_REPORT_V1 validator
  • Claude/Codex cleanup parity tests

現行 guard の materializer arg spec は --check/--consume を含んでいません。human-only consume の観点では --consume deny は正しいものの、worker が --check を実行する設計とも整合しません。

Schema Consumer Inventory を作り直し、最低限次を固定する必要があります。

  • agent issuance は allow
  • agent --check の扱いを明示
  • agent --consume は Claude/Codex とも deny
  • human exact consume は成功
  • alias、wrapper、--flag=value、duplicate flag、env-prefix でも境界を迂回できない
  • report schema が confirmation handoff を保持する

非ブロッキングだが修正すべき事項

「unpublished」は検証されていない

実装が確認しているのは rev-list <pr-head>..<local-tip> であり、「merged PR の head に含まれない commit」です。他の local ref、remote-tracking branch、別 PR に到達可能かは確認していません。したがって local-only unpublished という名称は強すぎます。

post_pr_head_commits 等へ名称変更するか、各 SHA の reachability evidence を追加してください。remote refs を根拠にする場合は stale remote-tracking state と live remote の区別も必要です。

Runtime evidence の head 表記が矛盾している

PR 本文の Runtime Verification Evidence には current HEAD: 1cc751... とありますが、検証コマンド結果は PR head 2e15b6... に束縛されています。前者は実装開始時の base SHA であり、「current HEAD」という名称は誤りです。

implementation_base_sha と verified_head_sha を別フィールドにしてください。


マージ条件

  1. human confirmation を immutable contract ID/digest に束縛し、executor が exact argv を生成する。
  2. discard の live verification を destructive lock 内へ移し、worktree remove --force と branch -D を廃止する。
  3. branch-only delete 前に lock 内で worktree catalog/branch 使用状態を再検査する。
  4. repository-common、bounded、fail-close な shared mutation lock を全 controlled worktree mutation 経路へ適用する。
  5. contract expiry を破壊操作直前に再検査する。
  6. same-invocation ancestry escalation は exit code 1 のみに限定する。
  7. canonical worker/report schema/validator に confirmation handoff を実装する。
  8. Issue 実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する #1523 の Allowed Paths と schema consumer inventory を更新する。
  9. approval substitution、dirty-after-check、commit-after-check、checkout-after-check、lock failure/timeout/expiry の race regression tests を追加する。
verdict: REQUEST_CHANGES
reviewed_head_sha: "2e15b6f3ac32df5395334b29a7761d60fb14fea2"

blockers:
  - severity: P0
    summary: "human consume invocation is not bound to an immutable contract instance; a reissued same-target contract can replace the reviewed contract"
  - severity: P0
    summary: "discard verification occurs outside the destructive lock; --force worktree removal and branch -D can delete state created after verification"
  - severity: P0
    summary: "branch-only update-ref can delete a branch that became checked out in another worktree after authorization"
  - severity: P1
    summary: "mutation lock fails open, is not repository-common, blocks without Deadline, and does not recheck expiry"
  - severity: P1
    summary: "canonical post-merge-cleanup worker/report path cannot produce or hand off the claimed exact human confirmation command"
  - severity: P1
    summary: "same-invocation fallback accepts merge-base exit 0 and can bypass non-ancestry branch deletion failures"
  - severity: P1
    summary: "schema change and consumer inventory are incorrectly classified as not applicable"

warnings:
  - "local-only unpublished is not proven; implementation only computes commits beyond the merged PR head"
  - "Runtime Verification Evidence labels the implementation base SHA as current HEAD"

squne121 and others added 3 commits August 16, 2026 00:43
…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]>
@squne121

Copy link
Copy Markdown
Owner Author

Verdict: APPROVE (iteration 3 — response to OWNER security review)

Independent code-level review of PR #2185 at head 0cef73c9f0a846b73bd2e601ddef5c3f90cb7dba against all 7 numbered blockers in the OWNER's review (#2185 (comment)):

  • P0-1 (approval-substitution): fixed. Per-nonce immutable contract files (O_CREAT|O_EXCL), --consume requires --contract-id+--expected-contract-sha256, command_hash binds to real executed argv. Regression test reproduces the exact substitution scenario end-to-end.
  • P0-2 (discard TOCTOU): fixed. Verification re-done inside the mutation lock immediately before the destructive call. git worktree remove without --force; branch delete via update-ref -d <ref> <expected-oid> (true CAS), not branch -D. 5 race-injection regression tests mutate real fs/git state and confirm refusal.
  • P0-3 (branch-only catalog race): fixed. Worktree catalog re-fetched inside the lock; refuses if branch is checked out elsewhere.
  • P1-1 (lock fail-open): fixed. MutationLockError raised (never silently swallowed) on any failure mode; lock path via git rev-parse --git-common-dir; LOCK_EX|LOCK_NB with Deadline-bounded retry.
  • P1-3 (same-invocation ancestry exit-0): fixed. Same-invocation path requires ancestry exit code 1 only; distinct reason code on exit 0. Standalone branch-only lane's original behavior intentionally unchanged (pre-existing separate authorization).
  • P1-2 (canonical worker handoff): fixed at the correct file — confirmed via post-merge-cleanup-worker frontmatter it reads post-merge-cleanup-executor/SKILL.md, which now documents the discard routing.
  • P1-4 (Codex execpolicy mirror): partial, legitimately scoped as documented follow-up. Claude-side guard fix is real and tested; codex_execpolicy_matrix.py isn't actually the enforcement point for --consume deny (that's worktree_scope_guard.py, shared logic). Not a regression this PR introduces.

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."

@squne121
squne121 merged commit acb422b into main Aug 15, 2026
26 checks passed
@squne121
squne121 deleted the worktree-issue-1523-commit-one-shot-cleanup-executor branch August 15, 2026 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: 明示的人間確認で未公開 commit を one-shot cleanup executor から破棄する

1 participant