Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "merged PR の dedicated worktree に残る local-only commit の one-shot discard と、branch-only fallback の expected OID compare-and-delete を lane 固有の fail-closed boundary で安全に実行する"
change_kind: workflow
source_pr: "#1528"
supersedes: [1625]Parent Issue
なし(PR #1505 の post-merge cleanup から得た単独 follow-up)
Parent Goal Ref
- Goal: マージ済み PR の dedicated cleanup を、未公開ローカル commit がある場合も監査可能な人間確認の後に限定して完了できるようにする。
- Desired Destination:
cleanup_exec.pyの既存 fail-closed 境界を保ったまま、専用 worktree に限る one-shot discard lane を追加する。
Current Validated Scope
cleanup_exec.pyがpr_head_oid_mismatchを返す、PR fix(ci): review shadow と再実行を provenance 集約する (#1456) #1505 の merged dedicated worktree / branch のような状態を、既存の通常 cleanup から区別して再検査する。- 新 lane は、PR head が local branch の祖先であり、差分が local-only commit に限られ、worktree に未コミット変更がない場合だけ、明示確認を待つ。
- one-shot confirmation の発行・消費・expiry は既存 cleanup contract の durable / replay-safe 機構に閉じ、bare git cleanup を許可しない。
- branch-only fallback の authorization 時 expected branch-tip OID を destructive path まで保持し、shared repository mutation lock 内で ref / worktree 使用状態を再検査する。
git update-ref -d refs/heads/<branch> <expected-oid>相当の compare-and-delete に成功した場合だけ fallback branch を削除する。- expected OID の commit object・comparison ref・mergednessを構造的に検証し、ref race、invalid object、ref lock、I/O error、comparison error、非 ancestry failure は fail-closed とする。
- normal cleanup と branch-only fallback の
verifiedpayload の key / type を固定し、既存外部 result schema を維持する。
Remaining Parent Gaps
なし(単独 follow-up)。remote branch delete、repo-wide residue sweep、任意の worktree の削除は別スコープである。
Outcome
更新された cleanup executor・one-shot confirmation contract・回帰テストにより、dedicated worktree の local-only commit は target-bound / expiring / one-shot confirmation を消費した場合だけ discard lane で破棄でき、branch-only fallback は expected OID の compare-and-delete 成功時だけ branch を削除できる。confirmation 不在・expiry・replay・state/ref 変化・invalid object・非 ancestry failure では削除せず、構造化 refuse を返す。
In Scope
pr_head_oid_mismatchのうち、merged PR head が local branch tip の祖先で、追加分が dedicated branch の local-only commit である候補だけを検出する executor lane。- 対象 PR・branch・worktree realpath・PR head SHA・local tip SHA・確認 nonce・expiry を束縛する one-shot confirmation contract と consume 後 tombstone。
- 人間が実行する確認済み invocation だけが、内部 subprocess array で
git worktree remove --forceとgit branch -Dを実行する経路。 - confirmation 不在、SHA 不一致、expiry / replay、PR 未マージ、fork / base / linked issue 不一致、path/catalog/branch 不一致、未コミット変更、または local-only commit 以外の状態で fail-closed する回帰テスト。
- post-merge cleanup の human handoff を、bare git ではなく executor の生成した exact confirmation command に限定する記載。
- branch-only fallback の expected OID を shared mutation lock 内の compare-and-delete まで束縛する。
- ref 更新 race、invalid object、ref lock、I/O error、comparison error、non-ancestry failure の fallback refusal を回帰テストで固定する。
- same-invocation fallback refusal 時の
actions_taken、branch 残存、force-delete subprocess 非実行を検証する。 - normal cleanup / branch-only fallback の
verifiedpayload を固定 key/type に正規化する。
Out of Scope
- bare
git worktree remove --force、baregit branch -D、hook / execpolicy allowlist の許可または緩和。 - remote branch delete、任意 branch / worktree の force delete、PR 未マージ時の削除、worktree 内の未コミット変更の破棄。
cleanup_exec.pyの既存通常 cleanup / branch-only fallback の認可条件を弱めること。- PR feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 の未マージ branch を実装基準・変更取込元にすること。feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 owner review を branch-only fallback 修正の因果ソースとし、current
mainを基準に本 Issue の単一 PR で実装する。
Acceptance Criteria
- AC1: merged PR の head SHA が local branch tip の祖先で、target が
.claude/worktrees/配下の catalog 登録済み dedicated worktree、branch が PR head branch と一致し、worktree に未コミット変更がない場合だけ、executor は local-only commit の SHA 列と確認必要状態を構造化出力する。 - AC2: 人間が実行する確認 invocation は target PR、worktree realpath、branch、PR head SHA、local tip SHA、nonce、expiry に束縛され、すべてが再検査時に一致する一回だけの contract を消費した場合のみ内部
git worktree remove --forceとgit branch -Dを実行する。 - AC3: confirmation 不在、期限切れ、replay、target SHA 不一致、PR 未マージ、cross-repo、base / linked issue / path / catalog / branch 不一致、local-only でない history、または未コミット変更では、削除を実行せず fail-closed reason_code と空の
actions_takenを返す。 - AC4: 成功・部分失敗とも既存
CLEANUP_EXEC_RESULT_V1の必須キー集合と型を維持し、discard lane の action / verification fields は additive にのみ追加する。 - AC5: post-merge-cleanup skill は bare git ではなく executor による explicit human confirmation command だけを handoff とし、one-shot contract の発行または確認を agent 自身の承認とみなさない。
- AC6: existing normal cleanup / branch-only cleanup の成功・拒否テストは維持され、未公開 commit discard lane を使わない既存 CLI invocation の挙動は変わらない。
- AC7: branch-only fallback は authorization 時の expected branch-tip OID を destructive path まで渡し、shared mutation lock 内の compare-and-delete が expected OID と一致した場合だけ branch を削除する。ref 更新 race は
branch_tip_changedを返し、更新後 branch を残す。 - AC8: branch-only fallback は expected OID が有効な commit object で、comparison ref に対する mergedness 不成立が構造的に確認された場合だけを扱う。invalid object、ref lock、I/O error、comparison error、その他の non-ancestry failure では force delete を実行しない。
- AC9: normal cleanup と branch-only fallback は既存
CLEANUP_EXEC_RESULT_V1の外部キー集合・型を維持し、verifiedpayload の key/type を回帰テストで検証する。 - AC10: same-invocation branch-only fallback の各拒否条件では
actions_takenは既に成功した worktree remove だけを保持し、branch は残り、force-delete subprocess は呼ばれず、既存 reason code を返す。
Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "fixture repository と stubbed merged PR metadata により、confirmation の発行・consume・replay拒否、対象 SHA binding、内部 delete argv、既存 lane 非回帰を決定論的に観測できる"
applicable_acs: [AC1, AC2, AC3, AC6, AC7, AC8, AC9, AC10]
execution_environment: "WSL2 Ubuntu 24.04; uv locked environment; git executable。GitHub PR metadata は unit test で stub し、実行対象は fixture 内 temporary repository に限定する"
skip_conditions: ["uv locked environment または git executable が利用できない場合は SKIP: reason を記録して exit 77 とし、PASS と扱わない"]
fallback_policy: "確認 contract を省略する経路、fixture 外の worktree、または bare git command の成功を PASS とみなさない。環境不足・再現不能時は実装を停止して human judgment に戻す"
artifact_requirements:
- "artifacts/runtime-verification-discard-AC1-<timestamp>.log"
- "artifacts/runtime-verification-discard-AC2-<timestamp>.log"
- "artifacts/runtime-verification-discard-AC3-<timestamp>.log"
- "artifacts/runtime-verification-branch-fallback-AC7-<timestamp>.log"
- "artifacts/runtime-verification-branch-fallback-AC8-<timestamp>.log"
- "artifacts/runtime-verification-branch-fallback-AC9-<timestamp>.log"
- "artifacts/runtime-verification-branch-fallback-AC10-<timestamp>.log"
- "PR 本文の Runtime Verification Evidence に current HEAD、confirmation binding / consume / replay verdict、expected OID、compare-and-delete result、refusal reason、既存 lane 非回帰を記録する"Verification Commands
# AC1
$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
# AC2
$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
# AC3
$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
# AC4
$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
# AC5
$ rg -n "explicit human confirmation command" .claude/skills/post-merge-cleanup/SKILL.md
# AC6
$ uv run --locked pytest tests/codex/test_cleanup_exec_branch_only.py -q
# AC7
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_compare_and_delete_refuses_tip_change -q
# AC8
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_refuses_invalid_object_and_non_ancestry_errors -q
# AC9
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_branch_only_fallback_preserves_verified_payload_schema -q
# AC10
$ uv run --locked pytest scripts/agent-ops/tests/test_cleanup_exec.py -k test_same_invocation_fallback_refusals_preserve_partial_actions_and_branch -qAllowed Paths
scripts/agent-ops/cleanup_exec.pyscripts/agent-ops/cleanup_contract_v3.pyscripts/agent-ops/materialize_cleanup_contract.pytests/codex/test_cleanup_exec_branch_only.pyscripts/agent-ops/tests/test_cleanup_exec.py.claude/skills/post-merge-cleanup/SKILL.md.claude/skills/post-merge-cleanup-executor/SKILL.mdscripts/check_post_merge_cleanup_boundary.pytests/test_post_merge_cleanup_boundary.pyscripts/agent-guards/worktree_scope_guard.pytests/agent_guards/test_worktree_scope_guard.pyscripts/ci/codex_execpolicy_matrix.pyscripts/ci/tests/test_codex_execpolicy_matrix.pytests/codex/test_execpolicy_matrix.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- human confirmation を executor 内で検証可能な target-bound one-shot contract として表現できない場合
- bare git cleanup、hook / execpolicy allowlist の緩和、または任意 branch / worktree への force delete 許可が必要になった場合
- PR 未マージ、remote branch delete、GitHub 権限 / branch protection policy の変更が必要になった場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- discard lane と branch-only fallback の destructive boundary を lane 固有に分離できない場合、または compare-and-delete と expected OID 再検査を同一 shared mutation lock 内で実現できない場合
Required Skills
- Python
Required Design References
docs/dev/workflow.mddocs/dev/agent-skill-boundaries.mddocs/dev/github-ops.md.claude/skills/post-merge-cleanup/SKILL.mdscripts/agent-ops/cleanup_exec.pyscripts/agent-ops/cleanup_contract_v3.py
Scope Delta
- 追加: merged PR の dedicated worktree に残った local-only commit を、target-bound / expiring / one-shot confirmation で限定して破棄する executor lane。
- 削除: なし。
- 変更:
pr_head_oid_mismatchを通常 cleanup で無条件に許容せず、discard lane は確認待ちに隔離し、branch-only fallback は expected OID compare-and-delete にだけ到達させる。 - 追加(OWNER directive, PR feat: cleanup executor に one-shot discard lane と compare-and-delete を追加する #2185 レビュー item 8):
post-merge-cleanup-executorcanonical worker が discard lane の human confirmation handoff を生成・伝達できるようにする(POST_MERGE_CLEANUP_REPORT_V1の additive フィールド拡張含む)。materialize_cleanup_contract.pyの--check/--consumeフラグをworktree_scope_guard.pyと Codex execpolicy matrix の allowlist に明示的に位置付ける(agent issuance は allow、agent--consumeは Claude/Codex とも deny、human exact consume のみ成功)。
Source
- source_url: fix(ci): review shadow と再実行を provenance 集約する (#1456) #1505
- supersedes_issue: 実装: branch-only cleanup fallback の認可 OID を compare-and-delete で束縛する #1625
- branch_only_source_url: feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 (comment)
- dedupe_key: "follow-up:squne121/loop-protocol:pr/1505:cleanup-unpublished-commit-one-shot-discard-v1"
- desired_destination:
cleanup_exec.pyと cleanup contract の、human-confirmed dedicated discard lane。 - validated_scope_delta: existing cleanup executor が PR head と異なる未公開 local commit を fail-closed で拒否した。manual bare git delete ではなく、限定した one-shot executor を追加する。
- decision: 決定論的 executor / contract 修正を採用する。prompt 注記または bare git workaround は監査性・replay 防止・target binding を満たさないため採用しない。
Delivery Rule
- 1 Issue = 1 PR
- 実装: branch-only cleanup fallback の認可 OID を compare-and-delete で束縛する #1625 は本 Issue に supersede され、実装: branch-only cleanup fallback の認可 OID を compare-and-delete で束縛する #1625 単独の実装・PR は作成しない。
- fix(cleanup): retry branch-only authorization in same run (#1403) #1496 は closed・未マージであり、feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 も未マージであるため、これらを開始前提にしない。current
mainを read-back した state を実装基準とし、feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 の未マージ変更は取り込まない。 - 作業前に issue-contract-review で fresh
CONTRACT_REVIEW_RESULT_V1 status: goを取得する。 - destructive confirmation command は人間が実行する。SubAgent は bare git cleanup を実行しない。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jul 19, 2026
Contract Review Result
squne121 commentedon Jul 19, 2026
Contract Review Result
squne121 commentedon Jul 19, 2026
Contract Review Result
squne121 commentedon Aug 15, 2026
implement-issue: 実装完了 (2026-08-15T13:43:05Z)
.claude/worktrees/issue-1523-commit-one-shot-cleanup-executorworktree-issue-1523-commit-one-shot-cleanup-executor1cc7515814d5f0142661e64cda450575eb8df7c3)からの fresh implementation。PR feat(cleanup): 同一実行内の branch-only fallback を追加 #1528 の branch はコード source として使用せず、OWNER review コメントのみ因果ソースとして参照。fix: resolve ruff E501/E402 in cleanup_exec test suite (#1523)
squne121 commentedon Aug 15, 2026
impl-review-loop: 完了 (2026-08-15T14:25:00Z)
deploy-prpreview-deploy job — not a required status check, not a conflict)fix: harden discard-lane confirmation binding and mutation-lock atomi…
squne121 commentedon Aug 15, 2026
impl-review-loop: 完了 (2026-08-16T00:00:00Z)
feat: cleanup executor に one-shot discard lane と compare-and-delete を…
squne121 commentedon Aug 15, 2026
post-merge-cleanup: 完了 (2026-08-16T00:15:00Z)
実施内容
.claude/worktrees/issue-1523-commit-one-shot-cleanup-executor/worktree-issue-1523-commit-one-shot-cleanup-executor(PR feat: cleanup executor に one-shot discard lane と compare-and-delete を追加する #2185 マージ済みのため)origin/mainへ fast-forward