Skip to content

fix: cleanup_exec.py の PR head OID 検証を squash merge に対応させる - #1344

Merged
squne121 merged 2 commits into
mainfrom
worktree-issue-1337-cleanup-exec-squash-merge
Jul 5, 2026
Merged

squne121 merged 2 commits into
mainfrom
worktree-issue-1337-cleanup-exec-squash-merge

Conversation

@squne121

@squne121 squne121 commented Jul 5, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • squash merge された PR の post-merge cleanup で verify_cleanup_authorization / verify_branch_only_cleanup_authorization が常に pr_head_oid_mismatch を返して worktree / branch 削除を誤ブロックしていた問題を修正した。
  • squash merge は headRefOid(=squash commit の新規 SHA)がローカルブランチ tip と一致しないため、GitHub 上で正しくマージ済みの PR でも既存の厳密一致判定に常に失敗していた。
  • gh pr view --json mergeCommit を追加取得し、merge_base..local_tip の path-set に限定した内容比較で「ブランチ tip の内容が squash 済みコンテンツと一致するか」を判定する _resolve_head_equivalence() を新設し、両関数の HEAD_OID_MISMATCH 判定に組み込んだ。
  • 非 squash merge(fast-forward / merge commit)や mergeCommit 欠落時は、既存の厳密一致 fail-closed 挙動をそのまま維持する(実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196 が確立した契約の supersede ではない、additive 拡張)。

受け入れ条件の達成状況

  • AC1: squash merge されたブランチについて、merge_base..local_tip の path set に限定した範囲でブランチ tip の内容が merge 済みコンテンツと一致する場合、verify_cleanup_authorization が pr_head_oid_mismatch を返さず認可されることを test_verify_cleanup_authorization_accepts_squash_merge_path_scoped_match で確認・PASS。
  • AC2: 上記 path set 限定範囲でブランチ tip の内容が merge 済みコンテンツと一致しない(真の分岐がある)場合、引き続き pr_head_oid_mismatch を返すことを test_verify_cleanup_authorization_rejects_squash_merge_content_mismatch で確認・PASS。
  • AC3: squash merge ではない通常マージで headRefOid がローカルブランチ tip と完全一致しない場合、既存どおり test_oid_mismatch_refused が拒否として PASS し続けることを確認(既存の厳密な OID 一致判定を破壊していない、pre-existing regression test)。
  • AC4: verify_branch_only_cleanup_authorization(branch-only cleanup 経路)にも AC1/AC2 と同等の squash merge 対応が適用され、既存の test_oid_mismatch_verify_branch_only_returns_false が引き続き PASS することを確認(pre-existing regression test)。
  • AC5: tests/codex/test_cleanup_exec_branch_only.py の全 39 件が PASS することを確認(既存テストを破壊していない)。
  • AC6: local branch が導入していない path(unrelated base change)に差分があっても、path-set 限定比較により誤って「一致」と判定されないことを test_squash_merge_unrelated_base_change_does_not_false_match で確認・PASS。
  • AC7: squash merge が検出された場合でも、local branch に path set 外の余分な未マージファイルが存在する場合は pr_head_oid_mismatch として拒否されることを test_squash_merge_rejects_extra_unmerged_local_files で確認・PASS。
  • AC8: gh pr view --json mergeCommit の戻り値が missing または null の場合、squash-equivalence の fallback 判定には入らず既存の fail-closed 拒否挙動が維持されることを test_squash_merge_missing_merge_commit_falls_back_to_reject で確認・PASS。
  • AC9: squash-equivalence 判定により認可された場合、verified dict に head_equivalence_authorized / head_equivalence_mode / pr_merge_commit_oid / local_delta_paths_count の additive フィールドが含まれ、既存の head_oid_match の意味論が変更されていないことを test_verified_dict_contains_additive_head_equivalence_fields で確認・PASS。

検証コマンド結果

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_accepts_squash_merge_path_scoped_match
1 passed (AC1)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_rejects_squash_merge_content_mismatch
1 passed (AC2)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_refused
1 passed (AC3, pre-existing regression test)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_verify_branch_only_returns_false
1 passed (AC4, pre-existing regression test)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py
39 passed (AC5, full file)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_unrelated_base_change_does_not_false_match
1 passed (AC6)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_rejects_extra_unmerged_local_files
1 passed (AC7)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_missing_merge_commit_falls_back_to_reject
1 passed (AC8)

$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verified_dict_contains_additive_head_equivalence_fields
1 passed (AC9)

$ pnpm typecheck / pnpm lint / pnpm test(92 files, 1399 tests PASS)/ pnpm build
all green

$ uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py
21 passed

Allowed Paths 遵守

Checks

以下の検証コマンドをすべて実行し、全件 PASS を確認した。

  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_accepts_squash_merge_path_scoped_match (AC1)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_rejects_squash_merge_content_mismatch (AC2)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_refused (AC3)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_verify_branch_only_returns_false (AC4)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py — 全 39 件 PASS (AC5)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_unrelated_base_change_does_not_false_match (AC6)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_rejects_extra_unmerged_local_files (AC7)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_missing_merge_commit_falls_back_to_reject (AC8)
  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verified_dict_contains_additive_head_equivalence_fields (AC9)
  • pnpm typecheck / pnpm lint / pnpm test(92 files, 1399 tests PASS)/ pnpm build
  • uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(21 件 PASS)

Schema Change Applicability

  • decision: schema_change
  • 対象: verify_cleanup_authorization / verify_branch_only_cleanup_authorization が返す verified dict、および _pr_state() が取得する gh pr view --json フィールド

Schema Consumer Inventory

# before
verified dict keys (verify_cleanup_authorization):
  root_default, worktree_in_catalog, branch_match, worktree_clean, pr_merged,
  head_branch_match, linked_issue_match, head_repo_match, base_branch_match,
  head_oid_match

_pr_state() gh pr view --json fields:
  state,mergedAt,headRefName,headRefOid,baseRefName,
  headRepositoryOwner,isCrossRepository,closingIssuesReferences
# after
verified dict keys: 上記 10 キーに加えて additive に以下を追加(既存キーの意味論は変更なし)
  head_equivalence_authorized (bool)
  head_equivalence_mode ("exact_oid" | "squash_merge_delta_match" | null)
  pr_merge_commit_oid (str | null)
  local_delta_paths_count (int | null)
同様の additive フィールドを verify_branch_only_cleanup_authorization の verified dict にも追加。

_pr_state() gh pr view --json fields: 上記に `mergeCommit` を追加(additive)
Consumer ファイル 更新有無 備考
scripts/agent-ops/materialize_cleanup_contract.py 更新不要 verify_cleanup_authorization の戻り値を dict として transparently 転送するのみで、追加キーの有無に依存するロジックはない
scripts/agent-ops/cleanup_exec.py(run() / _result() / _branch_only_result()) 更新済み(本 PR) additive フィールドを verified dict に含めて返す
tests/codex/test_cleanup_exec_branch_only.py 更新済み(本 PR) 新規 additive フィールドを検証する回帰テストを追加

Safety Claim Matrix

N/A — reason: 変更対象(scripts/agent-ops/cleanup_exec.py の内部認可ロジック)は transport / permission / sandbox / auth / mcp / .claude/skills/ / .github/workflows/ のいずれにも該当しない純粋な pytest unit test で完結するロジック修正であり、safety-sensitive パスに該当しない。既存の fail-closed 経路(mergeCommit 欠落・path-set 内容不一致・非 squash merge)は本 PR の回帰テスト(AC3/AC4/AC6-AC8)でそのまま維持されていることを確認済み。

Notes

squash merge された PR は headRefOid(squash commit SHA)がローカルブランチの
tip と一致しないため、verify_cleanup_authorization /
verify_branch_only_cleanup_authorization が常に pr_head_oid_mismatch として
誤ブロックしていた。

- `_pr_state()` に `mergeCommit` フィールドを追加
- `merge_base..local_tip` の path-set に限定した内容比較で squash-equivalence を
  判定する `_resolve_head_equivalence()` を追加し、両関数の HEAD_OID_MISMATCH
  判定に組み込んだ
- 非 squash merge / mergeCommit 欠落時は既存の厳密一致 fail-closed 挙動を維持
- `verified` dict に `head_equivalence_authorized` / `head_equivalence_mode` /
  `pr_merge_commit_oid` / `local_delta_paths_count` を additive に追加
  (`head_oid_match` の既存意味論は変更していない)
- `tests/codex/test_cleanup_exec_branch_only.py` に squash merge 回帰テスト
  (正常系・境界系)を追加

Closes #1337

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1344 closed).

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

TEST

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

Issue #1337 Verification Report

PR: #1344 (worktree-issue-1337-cleanup-exec-squash-merge)

Mergeable: MERGEABLE, Status: BLOCKED
Allowed Paths: ✓ scripts/agent-ops/cleanup_exec.py, tests/codex/test_cleanup_exec_branch_only.py

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

TEST_VERDICT_MACHINE v1

Result: PARTIAL
Mergeable: MERGEABLE
MergeStateStatus: BLOCKED
Branch Behind Main: false
Baseline Only: false
Verification Commands Pass: 3
Verification Commands Fail: 0
Verification Commands Skipped: 6

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

AC Results (Individual):

AC1: SKIP (exit 4) - new squash merge test, expected baseline
AC2: SKIP (exit 4) - new squash merge test, expected baseline
AC3: PASS - test_oid_mismatch_refused
AC4: PASS - test_oid_mismatch_verify_branch_only_returns_false
AC5: PASS - full suite (33 tests)
AC6: SKIP (exit 4) - new squash merge test, expected baseline
AC7: SKIP (exit 4) - new squash merge test, expected baseline
AC8: SKIP (exit 4) - new squash merge test, expected baseline
AC9: SKIP (exit 4) - new squash merge test, expected baseline

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

Verification Details:

PR diff touches Allowed Paths only:

  • scripts/agent-ops/cleanup_exec.py (+136 lines)
  • tests/codex/test_cleanup_exec_branch_only.py (+237 lines)

Existing Tests (AC3/AC4/AC5): PASS

  • Existing regression tests pass, validating:
    • OID mismatch rejection (AC3)
    • Branch-only cleanup OID validation (AC4)
    • Full test suite integrity (AC5, 33 tests)

New Tests (AC1/AC2/AC6-AC9): SKIP (exit code 4)

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

Contract Compliance:

Issue #1337 Scope Delta explicitly notes:
'baseline では未実装のため exit 4 になるのが期待挙動'

This verification confirms:

  • PR correctly introduces 6 new squash-merge tests
  • Exit code 4 on main is the expected baseline
  • Existing tests (AC3/AC4/AC5) pass with 33 total tests
  • No scope violations
  • Diff adheres to Allowed Paths

Final TEST_VERDICT: PARTIAL

  • Reason: Mix of PASS (AC3/AC4/AC5) and SKIP (AC1/AC2/AC6-AC9)
  • The SKIP status is expected per contract
  • When merged, all 9 ACs will be PASS
  • human_review_required: false (baseline correct, no violations)

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

TEST_VERDICT YAML:

runtime_ac_results:
AC1:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet
AC2:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet
AC3:
status: pass
exit_code: 0
tests_run: 1
note: existing regression test
AC4:
status: pass
exit_code: 0
tests_run: 1
note: existing regression test
AC5:
status: pass
exit_code: 0
tests_run: 33
note: full suite
AC6:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet
AC7:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet
AC8:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet
AC9:
status: skip
exit_code: 4
reason: no_tests_collected
note: new test not in main yet

verification_summary:
pass_count: 3
fail_count: 0
skip_count: 6
verdict: PARTIAL
mergeable: MERGEABLE
merge_blocked_by: branch_protection_rules

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probe

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line1
line2
line3

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with backtickchar

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with hash # char

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Judge 判定

(前3件のコメントはレビュー投稿手順の技術検証中に誤って投稿されたテストコメントであり、本判定とは無関係です。以下が正式な判定です。)

  • Linked Issue: #1337(Closes #1337 明記あり)
  • Allowed Paths 遵守: scripts/agent-ops/cleanup_exec.py と tests/codex/test_cleanup_exec_branch_only.py の2ファイルのみ変更(git diff --name-status -M で独立再検証。rename無し、Allowed Paths外の混入無し)。
  • CI: ci_verdict_summary.py --pr 1344 --expected-head-sha 6d0af72... の結果は status: all_pass(required checks全green、skip 5件は妥当)。
  • テスト: 実際の worktree checkout(HEAD = PR head 6d0af72)上で pytest tests/codex/test_cleanup_exec_branch_only.py -q を独立実行し 39 passed を確認(self-report非依存の再実行)。
  • AC1/AC2/AC6-AC9: 新規テスト実装をdiffで確認。_resolve_head_equivalence() が merge_base..local_tip のpath-set限定比較を行い、mergeCommit欠落・path-set外不一致・extra unmerged filesを正しくfail-closedにしている。Issue #1337のcontract-review初回REQUEST_CHANGESで指摘されたP0(full-tree比較禁止・path-set限定必須・head_oid_match意味論維持)が全て反映されている。
  • AC3/AC4/AC5: 既存回帰テスト test_oid_mismatch_refused / test_oid_mismatch_verify_branch_only_returns_false が変更されず、非squash exact-oid経路は従来どおり維持(head_ref_oid == local_tip の早期returnパスを確認)。
  • Schema Change: verified dictへの4 additiveフィールド + _pr_state() の mergeCommit フィールド追加。Schema Consumer Inventory記載あり、materialize_cleanup_contract.py は透過転送のみで影響なしとの説明をdiffでも確認(該当ファイル無変更)。
  • Safety Claim: N/A(.claude/skills/、.github/workflows/、permission/sandbox系に非該当の内部ロジック+pytest)と判断根拠が妥当。
  • PR body hygiene: 受け入れ条件の達成状況/検証コマンド結果/Allowed Paths 遵守 の正式見出しは無いが、Checksセクションに全9AC番号+検証コマンド+PASS根拠が記載されており実質的なAC coverageは充足。見出し名の不一致のみ(mechanical hygiene差分)。

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "6d0af72f104835c6e9c8aa2c63494482cd5b836d"
merge_ready: false
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions:

  • kind: update_pr_body_hygiene
    executor: implementation-worker
    skill: open-pr.update_pr
    blocking_merge_ready: true
    mechanical: true
    auto_fix_applied: []
    follow_up_issue_requests: []
    allowed_paths_gate:
    status: ok
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
    • scripts/agent-ops/cleanup_exec.py
    • tests/codex/test_cleanup_exec_branch_only.py
      producer_role: review_subagent
      worker_report_used_as_canonical: false

補足: Draft PRのため merge_ready は required_auto_actions 非空につきfalse。update_pr_body_hygiene はPR本文に正式見出しを追加する軽微な整形対応で、内容自体は既にChecksセクションに充足済み。

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "6d0af72f104835c6e9c8aa2c63494482cd5b836d"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests:

  • "ci_verdict_summary.py の HEAD_SHA_NULL_SKIPPED_EXCLUDE_RULES に ("Check Japanese Content", "PR Body Japanese Check") を追加し、pull_request_review トリガー実行での job-level skip (head_sha=null) を false failed 判定にしない改修(今回は gh api で run-level head_sha 一致・両トリガーとも conclusion:success を独立確認し false positive と判断)"
    allowed_paths_gate:
    status: "ok"
    producer_role: "review_subagent"
    worker_report_used_as_canonical: false
    changed_files_source: "git_diff_name_status_find_renames_z"
    changed_files_count: 2
    changed_files:
    • "scripts/agent-ops/cleanup_exec.py"
    • "tests/codex/test_cleanup_exec_branch_only.py"
      violations: []
      contract_source_kind: "issue_body"
      contract_source_id: "1337"

再検証サマリ

  • PR本文: ## 受け入れ条件の達成状況 / ## 検証コマンド結果 / ## Allowed Paths 遵守 見出しあり。AC1-AC9 全て [x] + 根拠(該当テスト関数名)記載を確認。
  • Mergeable: MERGEABLE / CLEAN(Draft は非 blocker)。
  • Allowed Paths gate: allowed_paths_review_gate.py を独立実行し status: ok、violations 0、changed files 2件(scripts/agent-ops/cleanup_exec.py, tests/codex/test_cleanup_exec_branch_only.py)が Issue #1337 contract の Allowed Paths と完全一致することを確認(gh pr diff --name-only でも同一)。
  • CI: ci_verdict_summary.py は exit 10(PR Body Japanese Check failed 判定)を返したが、gh api actions/runs で両トリガー run(pull_request run 28748217348 / pull_request_review run 28748134800)を直接確認した結果、両方とも run-level head_sha が現HEAD(6d0af72f...)と一致し conclusion: success。SKIPPED として現れた PR Body Japanese Check job は pull_request_review トリガー run 内の条件付き job-level skip(別 job である PR Review Japanese Check (retrospective) がそちらでは実行される設計)であり、pull_request トリガー run では PR Body Japanese Check job 自体が success。スクリプトの除外allowlistに漏れがあるための false positive と判断し、他の全 required check(typecheck/lint/test/build/e2e/python-test/actionlint/check-hook-integrity 等)は SUCCESS。blocker としては扱わない。
  • Schema Change Applicability: schema_change として明記、Schema Consumer Inventory あり(additive フィールドのみ、既存 consumer は更新不要と根拠付きで記載)。
  • Safety Claim Matrix: N/A 根拠明記(safety-sensitive パス非該当)。

@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。 方向性は正しいです。#1337 の主目的である「squash merge 済み PR で headRefOid != local_tip になり、post-merge cleanup が誤って pr_head_oid_mismatch で止まる」問題には踏み込めています。PR 本文も AC1〜AC9、Allowed Paths、schema additive 変更、検証コマンドを明記しています。変更ファイルも scripts/agent-ops/cleanup_exec.py と tests/codex/test_cleanup_exec_branch_only.py の2件に限定されています。

ただし、cleanup_exec.py は branch/worktree 削除の認可境界なので、現在の実装はまだマージ前に硬化した方がよいです。既存レビュー上は APPROVE / merge_ready: true が出ており、対象 SHA の workflow runs も success ですが、敵対的レビューとしては以下をブロッカー扱いにします。

P1: non-squash merge にも fallback が入り得る

_resolve_head_equivalence() は、厳密 OID 一致に失敗した後、mergeCommit.oid が存在すれば squash-equivalence fallback に入ります。しかし、コード上は merge commit が本当に squash merge 由来かを確認していません。mergeCommit は gh pr view --json の取得可能フィールドであり、squash 専用フィールドではありません。 ([GitHub CLI]1)

#1337 は「非 squash merge(fast-forward / merge commit)では既存の厳密な headRefOid == local_tip 判定を維持する」と明記しています。GitHub の通常 merge と squash merge は履歴形状が異なり、squash は PR 上の commit を1つにまとめて default branch に入れるため、元 commit SHA は失われます。 ([GitHub Docs]2)

修正要求: fallback 前に mergeCommit.oid の commit object 存在と parent 構造を検証してください。

# 推奨方針
# 1. git cat-file -e <merge_oid>^{commit}
# 2. git rev-list --parents -n 1 <merge_oid>
# 3. parent が 1 個の squash-equivalence candidate のみ fallback 対象にする
# 4. parent が 2 個以上の通常 merge commit は fail-closed: pr_head_oid_mismatch

これにより、「mergeCommit があるから squash 相当として比較する」という過剰許可を防げます。

P1: path set の起点が current default branch 依存

現在の _merge_base() は git merge-base local_tip default_branch を使っています。つまり path set の起点が「merge commit の parent」ではなく「現在の default branch」です。

通常ケースでは fork point が返るため動きますが、cleanup は削除認可なので、履歴が進んだ default branch、rebase/rewind、複数 merge-base のような形状に対して曖昧です。git merge-base は複数の best common ancestor を持ち得るため、単一 stdout を前提にすると履歴形状依存の判定になります。([Git]3)

修正要求: squash commit の parent を取得し、merge-base <squash_parent> <local_tip> を path-set 起点にしてください。複数 merge-base が出る場合は fail-closed が安全です。

parents = _commit_parents(project_root, merge_oid, deadline)
if len(parents) != 1:
    return False, additive

squash_parent = parents[0]
bases = _merge_bases(project_root, squash_parent, local_tip, deadline)
if len(bases) != 1:
    return False, additive

#1337 の anchor comment でも、full-tree 比較は禁止、local branch が導入した全 path set を列挙し、その全 path について local_tip と mergeCommit.oid を比較する定義が必要だと指摘されています。

P1: branch-only squash-equivalence のテストが薄い

実装は verify_cleanup_authorization と verify_branch_only_cleanup_authorization の両方で _resolve_head_equivalence() を呼んでおり、branch-only 側にも squash-equivalence が適用されています。

しかし追加テストは、squash-equivalence の正常系・不一致・extra file・missing mergeCommit・additive fields を 通常 worktree cleanup 側で確認しているだけです。 既存の branch-only テストは OID mismatch の fail-closed を確認していますが、mergeCommit を持つ squash-equivalence 正常系・拒否系は見当たりません。

#1337 の AC4 は、branch-only cleanup 経路にも AC1/AC2 と同等の squash merge 対応を要求しています。さらに #1196/#1206 は branch-only lane を git branch -D に昇格する削除経路として設計しており、当初は PR head OID mismatch 補正を out of scope としていました。

修正要求: 以下を追加してください。

uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_branch_only_accepts_squash_merge_path_scoped_match
uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_branch_only_rejects_squash_merge_content_mismatch
uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_branch_only_run_deletes_branch_after_squash_equivalence

branch-only は destructive path なので、通常 path の helper coverage だけでは不足です。

P1: git diff --name-only + splitlines() は path handling が弱い

_squash_equivalence_path_set() は git diff --name-only の text output を splitlines() で処理しています。_squash_content_matches() も git diff --name-only merge_commit_oid local_tip -- paths の stdout が空なら一致とみなしています。

Git の pathspec 比較自体は妥当ですが、ファイル名に改行・特殊文字が入るケースを考えると --name-only の line-based parse は脆いです。Git diff は --name-only と -z を組み合わせて NUL 区切り出力にできます。また一致判定には --quiet があり、差分なしなら 0、差分ありなら 1 を返し、出力も抑制します。(Git)

修正要求: path set は -z、内容一致は --quiet --no-ext-diff に変えてください。

# path set
git diff --name-only -z <base> <local_tip>

# content match
git diff --quiet --no-ext-diff <local_tip> <merge_oid> -- <paths...>
# rc == 0: match
# rc == 1: mismatch
# rc > 1: git error, fail-closed

P2: diagnostics の意味が少し曖昧

_resolve_head_equivalence() は exact OID match の場合にも head_equivalence_authorized=True を設定しています。 ただし #1337 の説明では head_equivalence_authorized は squash-equivalence 判定による認可を示す意図に読めます。PR 本文上は additive field として扱われているので即ブロッカーではありませんが、後続の report consumer には混乱要因です。

修正案: exact OID の場合は次のどちらかに統一してください。

head_oid_match: true
head_equivalence_authorized: false
head_equivalence_mode: exact_oid

または field 名を head_authorized に改める。ただし後者は schema surface を増やすので、今回は前者が安全です。

P2: missing object / git error のテストが足りない

mergeCommit=None の fail-closed テストはありますが、mergeCommit.oid が存在するが local repo に object がないケース、git diff / merge-base が error になるケースは未検証です。

#1337 の anchor comment は、mergeCommit object missing / git diff error は fail-closed で検証すべきケースとして挙げています。

追加テスト案:

uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_merge_commit_object_missing_rejects
uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_git_diff_error_rejects
uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_non_squash_merge_commit_oid_mismatch_rejects_even_if_paths_match

最小マージ条件

このPRは、以下を満たせば merge-ready と見てよいです。

  1. mergeCommit.oid の commit object 存在確認を追加する。
  2. merge commit parent 数を見て、2-parent 以上の通常 merge commit では squash-equivalence fallback に入らない。
  3. path set 起点を current default branch ではなく squash commit parent ベースに寄せる。
  4. branch-only squash-equivalence の正常系・拒否系テストを追加する。
  5. git diff --name-only の path parse を -z 化し、内容一致判定を --quiet --no-ext-diff 化する。
  6. missing object / git error / non-squash merge commit の fail-closed テストを追加する。

現状のPRは #1337 の主問題を解く方向にありますが、削除系 executor の認可境界としては「squash-only fallback の証明」と「branch-only destructive path の直接テスト」が不足しています。

…path比較に硬化する

OWNER の敵対的レビュー (PR #1344) の P1/P2 指摘に対応する。

- _resolve_head_equivalence(): merge commit object の存在確認と parent 数検証
  (parent==1 のみ fallback 対象、2parent 以上の通常 merge commit は fail-closed)
  を fallback 前に追加
- path-set 起点を current default branch でなく squash commit の parent 基準の
  merge-base に変更し、複数 merge-base の場合は fail-closed にする
- _squash_equivalence_path_set() を `git diff --name-only -z` に、内容一致判定を
  `git diff --quiet --no-ext-diff` (0/1/>1 で fail-closed) に変更
- 厳密 OID 一致時は head_equivalence_authorized: false / head_equivalence_mode:
  exact_oid に統一
- branch-only squash-equivalence の正常系・拒否系・削除確認テストを追加
  (TestBranchOnlySquashEquivalence)
- merge commit object missing / merge-base git error / 非 squash 2-parent
  merge commit の fail-closed 回帰テストを追加

Closes #1337
@squne121

squne121 commented Jul 5, 2026

Copy link
Copy Markdown
Owner Author

TEST_VERDICT: PASS - All 9 ACs and all 6 new regression tests verified to PASS. PR head 65bd360 confirmed at worktree. Mergeable=MERGEABLE. Allowed Paths constraint satisfied.

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review Judge 判定(iteration 1 再審査 / OWNER adversarial review への fix_delta 対応確認)

OWNER の P1×4 + P2×2 それぞれを head 65bd360 の実 diff・実テスト実行で独立検証した。

  • P1(1) non-squash fallback: _commit_object_exists()(cat-file -e <oid>^{commit}) + _commit_parents()(rev-list --parents -n1) を追加し、parent数が1でない(2+ parent の通常 merge commit)は squash-equivalence に入らず fail-closed。test_non_squash_merge_commit_oid_mismatch_rejects_even_if_paths_match は実際に git merge --no-ff で本物の2-parent merge commitを作り、feature.txt内容が一致していても拒否されることを確認しており、trivialでない。反映済み。
  • P1(2) path-set起点: _merge_bases() が merge-base --all <squash_parent> <local_tip> を使い、squash commitの親(_commit_parentsの[0])を起点にし、複数merge-baseはfail-closed。current default branch依存を解消。test_squash_merge_git_diff_error_rejects で _merge_bases がNoneを返すケース(git error相当)もfail-closedを確認。反映済み。
  • P1(3) branch-only系テストの薄さ: TestBranchOnlySquashEquivalence クラスで verify_branch_only_cleanup_authorization を直接呼ぶ正常系・拒否系に加え、test_branch_only_run_deletes_branch_after_squash_equivalence は実際に run() を呼び、実 git branch削除(git rev-parse --verify refs/heads/<branch> が失敗することを確認)まで検証する destructive path のend-to-endテスト。superficialでない。反映済み。
  • P1(4) -z / --quiet --no-ext-diff: _squash_equivalence_path_set() は git diff --name-only -z + NUL split、_squash_content_matches() は git diff --quiet --no-ext-diff を使用し returncode 0/1/その他(fail-closed)を明示的に分岐。反映済み。
  • P2(1) exact_oid の意味論: exact match時は head_equivalence_authorized=False / head_equivalence_mode="exact_oid" に統一(OWNER提案の前者案採用)。test_verified_dict_contains_additive_head_equivalence_fields で head_oid_match=False(squash-equivalence時)と非混同を確認。反映済み。
  • P2(2) missing object / git error / non-squash のテスト不足: test_squash_merge_merge_commit_object_missing_rejects(存在しないSHAでcat-file失敗→拒否)、test_squash_merge_git_diff_error_rejects(_merge_basesをNoneにpatch→拒否)、test_non_squash_merge_commit_oid_mismatch_rejects_even_if_paths_match(本物の2-parent merge commit)の3件を追加。反映済み。

独立再実行

  • uv run pytest tests/codex/test_cleanup_exec_branch_only.py -q(.claude/worktrees/issue-1337-cleanup-exec-squash-merge、HEAD=65bd3609、self-report非依存で再実行)→ 45 passed(既存39 + 新規6)。
  • ci_verdict_summary.py --pr 1344 --expected-head-sha 65bd3609... → status: all_pass、head_sha一致、skip 5件は既知の除外対象のみ。
  • allowed_paths_review_gate.py を独立実行(issue #1337 contractのsha256/fingerprintをissue本文から再計算し binding) → status: ok、violations 0、changed files 2件が Allowed Paths と完全一致(rename無し)。
  • ruff check で tests/codex/test_cleanup_exec_branch_only.py に F401/E402 計8件検出したが、base(main)時点の同ファイルでも同一8件が既存していることを確認済み(このPRによる新規混入ではない、CI lintも実際にgreen)。

その他

  • PR本文: ## 受け入れ条件の達成状況(AC1-9全て[x]+根拠テスト名) / ## 検証コマンド結果 / ## Allowed Paths 遵守 / ## Schema Change Applicability(schema_change) / ## Schema Consumer Inventory(additiveのみ、既存consumer更新不要の根拠あり) / ## Safety Claim Matrix(N/A、根拠明記) すべて具備。
  • Mergeable: MERGEABLE / CLEAN。Draft状態だが blocker ではない。
  • Closes #1337 明記あり。

blocker なし。OWNERの6項目の修正要求は全て実コード・実テストで裏付けられており、rubber stamp ではなく実体験証を伴う独立確認の結果としてAPPROVEとする。

LOOP_VERDICT_V2

verdict: APPROVE
reviewed_head_sha: "65bd3609ce0375a59e86b2fded3ed849db801e1d"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
status: "ok"
producer_role: "review_subagent"
worker_report_used_as_canonical: false
changed_files_source: "git_diff_name_status_find_renames_z"
changed_files_count: 2
changed_files:
- "scripts/agent-ops/cleanup_exec.py"
- "tests/codex/test_cleanup_exec_branch_only.py"
violations: []
contract_source_kind: "issue_body"
contract_source_id: "1337"

@squne121
squne121 marked this pull request as ready for review July 5, 2026 18:33
@squne121
squne121 merged commit 72352c8 into main Jul 5, 2026
22 checks passed
@squne121
squne121 deleted the worktree-issue-1337-cleanup-exec-squash-merge branch July 5, 2026 18:33
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.

実装: cleanup_exec.py の PR head OID 検証を squash merge に対応させる

1 participant