Skip to content

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

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "PR #1332(Issue #1323 実装、squash-merge commit 988c5293)の post-merge cleanup で誤検知した pr_head_oid_mismatch を、squash merge を正しく扱えるロジックに修正する"
change_kind: code

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue の Acceptance Criteria はすべて scripts/agent-ops/cleanup_exec.py 内の純粋なロジック(gh pr view --json の戻り値を模したフィクスチャ入力に対する path-set 比較・squash-equivalence 判定)を対象とした pytest unit test で完結する。実プロセス起動・実ネットワーク通信・実 I/O(実際の gh CLI 呼び出しや実 git worktree 操作)を要求せず、tests/codex/test_cleanup_exec_branch_only.py 内でモック化された git / gh 呼び出しに対する unit test(静的検証)のみで AC が成立する。

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: post-merge-cleanup 経路で使われる scripts/agent-ops/cleanup_exec.py の PR head OID 検証が、squash merge された PR を常に pr_head_oid_mismatch として誤ブロックしないようにする
  • Desired Destination: scripts/agent-ops/cleanup_exec.py の該当ロジック修正 + tests/codex/test_cleanup_exec_branch_only.py への回帰テスト追加

Current Validated Scope

  • scripts/agent-ops/cleanup_exec.py の verify_cleanup_authorization / verify_branch_only_cleanup_authorization 内、HEAD_OID_MISMATCH(pr_head_oid_mismatch)を返す分岐のロジック修正
  • _pr_state が取得する gh pr view --json フィールドへの mergeCommit フィールド追加(squash merge 検知・安全性判定に必須)
  • tests/codex/test_cleanup_exec_branch_only.py への squash merge シナリオ(正常系・境界系)の回帰テスト追加

Remaining Parent Gaps

なし

Outcome

scripts/agent-ops/cleanup_exec.py が、squash merge された PR に対して「ローカルブランチが導入した path set(merge_base..local_tip の diff --name-only で得られる path 集合)に限定した範囲で、ブランチ tip の内容が merge 済みコンテンツと一致する」ことをもって cleanup を許可できるようになり、tests/codex/test_cleanup_exec_branch_only.py に追加された squash merge 回帰テスト(正常系・境界系を含む)が全て PASS している状態。

In Scope

  • _pr_state() が取得する gh pr view --json の fields リストへの mergeCommit フィールド追加(squash merge 検知に必須の実装項目。例示ではなく必須要件とする)
  • squash merge が検出された場合の安全性判定を、global な tree 全体比較ではなく、merge_base..local_tip の diff --name-only で得られる path set に限定した範囲での「ブランチ tip と merge 済みコンテンツの内容比較」に切り替える実装(unrelated base の変更や無関係な別 PR 由来のファイル差分を誤検出しないため)
  • squash merge でない通常マージ(fast-forward / merge commit)では、既存の厳密な headRefOid == local_tip 一致判定を維持する
  • squash merge であっても、path-set 限定比較で実際に内容差分がある(真の分岐がある)場合、または local branch に path set 外の余分な未マージファイルがある場合は、引き続き pr_head_oid_mismatch を返し cleanup を拒否する
  • verify_cleanup_authorization と verify_branch_only_cleanup_authorization の両方に同等の修正を適用する(重複ロジックを共有ヘルパーに切り出すかは実装判断に委ねる)
  • verified dict への additive フィールド追加(既存の head_oid_match の意味論は変更しない):
    • head_equivalence_authorized(bool): squash-equivalence 判定により認可されたかどうか
    • head_equivalence_mode(例: "exact_oid" / "squash_merge_delta_match"): どの判定経路で認可されたか
    • pr_merge_commit_oid: gh pr view --json mergeCommit から得た merge commit の OID
    • local_delta_paths_count: merge_base..local_tip の path set の要素数
  • mergeCommit が missing / null の場合(squash merge の判定に必要な情報が取得できない場合)は squash-equivalence の fallback 判定に入らず、既存の fail-closed 挙動(pr_head_oid_mismatch による拒否)を維持する
  • 上記に対応する pytest 回帰テスト(境界ケースを含む)の追加

Out of Scope

  • .claude/skills/post-merge-cleanup/SKILL.md の呼び出し手順・運用フローの変更
  • .claude/skills/issue-refinement-loop 等、他 skill 側のロジック変更
  • .github/workflows/* の変更
  • .github/ci/python-test-plan.json への新規ファイル登録(既存登録済みの tests/codex/test_cleanup_exec_branch_only.py に追記するため不要)
  • 実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196(PR feat(#1196): branch-only cleanup lane in cleanup_exec #1206)が確立した headRefOid == local branch tip の厳密一致要件そのものの撤回。本 Issue はこの既存契約を supersede しない。squash-equivalence が明示的に検証された場合にのみ additive に拡張し、non-squash merge / squash-equivalence が検証不能な場合 / エラー時は既存の fail-closed 拒否挙動をそのまま維持する

Acceptance Criteria

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

Verification Commands

既存の回帰テスト(AC3/AC4)は -k <exact function name> 形式で参照する(:: node id は正誤に関わらずファイル存在チェックによる regression-gate 判定を素通りしてしまうため、-k 形式でファイル自体の存在を正しく認識させる)。新規追加するテスト(AC1/AC2/AC6-AC9)は実装 PR 側でどの class 配下に置くかを決めてよいため(Notes for Reviewer 参照)、node id は関数名のみを指定する(baseline では未実装のため no tests ran / exit 4 になるのが期待挙動であり、実装後は該当テストが解決されて実行される)。

# AC1
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_accepts_squash_merge_path_scoped_match

# AC2
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verify_cleanup_authorization_rejects_squash_merge_content_mismatch

# AC3
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_refused

# AC4
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py -k test_oid_mismatch_verify_branch_only_returns_false

# AC5
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py

# AC6
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_unrelated_base_change_does_not_false_match

# AC7
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_rejects_extra_unmerged_local_files

# AC8
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_squash_merge_missing_merge_commit_falls_back_to_reject

# AC9
$ uv run pytest tests/codex/test_cleanup_exec_branch_only.py::test_verified_dict_contains_additive_head_equivalence_fields

Allowed Paths

  • scripts/agent-ops/cleanup_exec.py
  • tests/codex/test_cleanup_exec_branch_only.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • Git 内部構造(tree / merge-base / diff 比較)
  • GitHub CLI(gh pr view の JSON フィールド仕様)

Scope Delta(該当時のみ記載)

  • 2026-07-05: Verification Commands の pytest 呼び出し形式を修正した。既存テスト参照(AC3/AC4)は -k <exact function name> 形式に直した(:: node id はクラス名の有無に関わらずファイル存在チェックが素通りし regression-gate 判定されず unexpected_pass/blocked になるため、-k 形式でファイル自体の存在を認識させ baseline pass を正しく go にする)。新規テスト参照(AC1/AC2/AC6-AC9)は関数名のみの node id(:: 形式)のまま維持する(-k <name> は baseline で 0 selected・exit 5 = 決定論的 blocked 分類になり、未実装テストの正常な baseline 状態としてより適切ではないため)。AC の意図・Allowed Paths・Outcome は変更していない。

Delivery Rule

  • 1 Issue = 1 PR で完結させる
  • 実装は .claude/worktrees/ 配下の専用 worktree で行う(Draft PR 既定)
  • Closes #(この Issue番号)を PR 本文に明記する

Background

PR #1332(Issue #1323 実装、squash-merge commit 988c5293dc70bf274cbe503b94e9c42711e2f829、main上に正しくマージ済み)のマージ後クリーンアップで、scripts/agent-ops/cleanup_exec.py の HEAD_OID_MISMATCH(pr_head_oid_mismatch)チェックが誤検知した。

  • cleanup_exec.py は worktree のローカルブランチ tip(feature branch の生コミット SHA、例: d4e4da356123944baa6bbd4aa031869f4d0fa88f)と gh pr view --json headRefOid 等から得られる PR head の SHA が一致することを要求している(verify_cleanup_authorization 内 HEAD_OID_MISMATCH 判定、verify_branch_only_cleanup_authorization 内の同等判定)
  • GitHub の squash merge では、main に取り込まれるコミット(例: 988c5293dc70bf274cbe503b94e9c42711e2f829)は feature branch のどのコミットとも異なる新規 SHA になる(内容は同一でも SHA は別)
  • そのため squash merge されたあらゆる PR で、このチェックは常に pr_head_oid_mismatch として worktree / branch 削除を拒否してしまう
  • 実際に squash merge commit と feature branch tip の差分を確認したところ、対象範囲(.claude/skills/issue-refinement-loop/ 配下)のファイルは完全一致しており、データ損失や真の分岐は無かった(差分に出たのは無関係な別 PR feat: クォータ管理と provider fallback policy を明文化・実装する #1331 由来のファイルのみ)。この「無関係な別 PR 由来のファイルのみが差分に出る」ケースこそが、比較を global な tree 全体比較ではなく path-set 限定比較にすべき理由である
  • _perform 関数のdocstring(squash-merge 時に branch -d が失敗しうる旨の既知コメント)は既に squash merge の影響を認識しているが、HEAD_OID_MISMATCH 側の判定はまだ対応していない
  • 本 Issue の squash-equivalence 拡張は、実装: post-merge-cleanup の branch-only resume lane を cleanup_exec に追加する #1196(PR feat(#1196): branch-only cleanup lane in cleanup_exec #1206)が確立した「headRefOid == local branch tip の厳密一致」という既存の fail-closed 契約を撤回するものではない。squash-equivalence が path-set 限定比較で明示的に検証された場合にのみ additive に認可範囲を広げ、non-squash merge / squash-equivalence が検証不能な場合 / エラー時は既存の拒否挙動をそのまま維持する

このリポジトリは merge 手法として squash merge を使うケースがあるため、この不整合は post-merge-cleanup フロー全体(.claude/skills/post-merge-cleanup/SKILL.md から呼ばれる cleanup 経路)に影響する再現性のある問題である。

Notes for Reviewer

  • squash merge 検知の具体的な内部実装(tree 比較を git diff --name-only + 個別ファイル内容比較で行うか、他の方法を使うか等)は実装 PR 側の判断に委ねる。本 Issue の AC は「振る舞い」(path-set 限定比較で squash merge の内容一致なら許可、内容不一致・余分な未マージファイル・mergeCommit 欠落なら拒否、非 squash merge では既存挙動維持)と「追加スキーマフィールド(verified dict の additive keys)」を固定するに留める
  • verify_cleanup_authorization と verify_branch_only_cleanup_authorization は現状 HEAD_OID_MISMATCH 判定ロジックが重複している。共有ヘルパーへの切り出しは推奨だが必須ではない(AC4 が満たされれば良い)
  • OWNER (squne121) の anchor comment: 実装: cleanup_exec.py の PR head OID 検証を squash merge に対応させる #1337 (comment)

Activity

  1. added
    phase/implementation
    agent/implementer
    enhancement
    on Jul 4, 2026
  2. squne121 commented on Jul 5, 2026

    @squne121
    OwnerAuthor

    結論

    判定: REQUEST_CHANGES。
    #1337 の問題設定は妥当です。現在の cleanup_exec.py は通常 cleanup と branch-only cleanup の両方で PR headRefOid == local branch tip を要求しており、squash merge では誤拒否が起き得ます。該当箇所は通常経路と branch-only 経路の両方にあります。

    ただし、Issue 契約のまま実装すると危険です。 特に「ブランチ tip と merge 済みコンテンツの tree / diff 内容比較」が未定義で、full-tree 比較なら観測ケースを解けず、path-scoped 比較なら未マージ変更を取りこぼすリスクがあります。cleanup_exec.py は post-merge cleanup の単一の認可境界なので、ここは曖昧なまま実装させるべきではありません。

    P0: ブロッカー

    1. 「tree / diff 内容比較」が未定義で、full-tree 比較だと #1337 の実例を解けない

    #1337 は squash merge 時に「ブランチ tip の内容が main に取り込み済みなら cleanup 許可」としていますが、比較対象が曖昧です。Issue 背景では、PR #1332 の squash merge commit と feature branch tip の差分確認で、対象範囲は一致していたが、無関係な PR #1331 由来の差分が出たと説明されています。

    つまり full-tree 比較 をすると、PR #1332 自体の変更が取り込まれていても、base 側に後から入った #1331 相当の差分に引っ張られて拒否されます。逆に 対象パスだけ比較 すると、local branch に対象外の未マージ変更が残っていても見逃す可能性があります。

    修正方針は、単純な “tree equal” ではなく、次のように定義するべきです。

    local branch が merge base から導入した全 path set を列挙し、その path set について local_tip と mergeCommit.oid の内容が一致する場合のみ squash-equivalent とみなす。比較対象外の local-only 変更を許可してはならない。

    Git の git diff <commit> <commit> は任意の 2 commit 間の差分比較に使え、--quiet は差分なしなら 0、差分ありなら 1 を返します。実装ではこの性質を使って fail-closed にできます。([Git]1) ([Git]1)

    2. squash merge だけが原因とは限らない

    #1337 本文では例として d4e4da... の local branch tip と squash merge commit 988c5293... の不一致が挙げられています。
    一方で、PR #1332 の本文には “iteration 1, PR #1332 head d4e4da3” とあり、これは途中のレビュー対応時点の head と読めます。

    ここから見ると、観測された mismatch は単に「squash merge は新 SHA になる」だけでなく、local branch が最終 PR head まで更新されていなかった可能性もあります。したがって、実装は「squash merge なら OID mismatch を広く許可」ではなく、必ず local branch の導入差分が merge commit に含まれていることを検証する必要があります。

    GitHub 公式ドキュメント上も、squash and merge は feature branch 上の複数 commit を 1 commit にまとめて default branch に入れる方式で、元 commit の SHA は失われます。([GitHub Docs]2)

    3. _pr_state に mergeCommit がないため、現状コードでは安全判定に必要な材料が不足している

    現在の _pr_state() は state, mergedAt, headRefName, headRefOid, baseRefName, headRepositoryOwner, isCrossRepository, closingIssuesReferences だけを取得しており、mergeCommit を取得していません。

    gh pr view --json は mergeCommit, headRefOid, baseRefName, headRefName, isCrossRepository, mergedAt, state などを JSON field として取得できます。#1337 の実装では _pr_state に mergeCommit を追加するのが自然です。([GitHub CLI]3)

    4. head_oid_match の意味が破綻する

    現在の verified field には head_oid_match があり、成功時は true にされます。通常経路でも branch-only 経路でも、現状は headRefOid == local_tip を満たした場合だけ true です。

    squash-equivalent で許可する場合、実際には OID は一致していません。その状態で head_oid_match: true にすると虚偽になります。一方で head_oid_match: false のまま ok=True にすると downstream の読み手が混乱します。

    Issue #1337 には、verified field の扱いが書かれていません。最低限、Issue 本文に次を追加すべきです。

    verified:
      head_oid_match: false
      head_equivalence_authorized: true
      head_equivalence_mode: squash_merge_delta_match
      pr_merge_commit_oid: "<oid>"
      local_branch_tip_oid: "<oid>"

    固定契約の変更を避けるなら、head_oid_match の意味を変えず、additive field として head_equivalence_authorized を追加するのが安全です。

    P1: 高品質化ポイント

    1. 既存の #1196 契約を上書きする変更であることを明記すべき

    Issue #1196 / PR #1206 は branch-only cleanup lane を追加したものですが、その時点では PR head OID mismatch の自動補正は Out of Scope で、branch-only cleanup の許可条件にも PR headRefOid == local refs/heads/<branch_name> が含まれていました。

    #1337 はこの安全条件を拡張する Issue です。したがって、Issue 本文に次のような明示が必要です。

    This issue intentionally supersedes the strict OID-only branch-only condition from #1196 only for verified squash-merge equivalence. Non-squash and unverifiable cases remain fail-closed with pr_head_oid_mismatch.

    2. テストは実 git DAG で作るべき

    現在の test_cleanup_exec_branch_only.py の _make_merged_pr() fixture は mergeCommit を持たず、headRefOid だけを差し替える形です。
    既存テストも “OID mismatch なら拒否” を直接確認するだけです。

    #1337 のテストは、mock だけで mergeCommit を手で注入するより、最低限 temp repo 上に次の DAG を作るべきです。

    A --- B_unrelated --- S_squash   main
     \
      L_feature                    local branch
    

    検証すべきケース:

    • L_feature の導入差分が S_squash に含まれる → 許可
    • L_feature に未マージの extra file がある → 拒否
    • L_feature の同一 path 内容が S_squash と違う → 拒否
    • mergeCommit がない / local repo に commit object がない / git diff が error → 拒否
    • non-squash の OID mismatch は既存どおり拒否

    同じ repo では #1334/#1339 で「テストが実経路に到達せず vacuous だった」問題が既に出ています。#1337 でも、mock で成功 path を作るだけのテストは避けるべきです。

    3. .github/ci/python-test-plan.json は変更不要でよい

    #1337 の Out of Scope にある通り、既存の python test plan には tests/codex/test_cleanup_exec_branch_only.py が既に含まれています。したがって、Allowed Paths が 2 ファイルだけなのは妥当です。

    推奨実装方針

    実装は OID check を消すのではなく、厳密 OID 一致を最優先し、失敗時だけ squash-equivalence fallback に入る形が安全です。

    擬似方針:

    def _authorize_pr_head_equivalence(project_root, branch_name, local_tip, pr, deadline):
        pr_head_oid = pr.get("headRefOid")
    
        # 既存挙動: exact OID match はそのまま許可
        if pr_head_oid == local_tip:
            return True, {
                "head_oid_match": True,
                "head_equivalence_authorized": False,
                "head_equivalence_mode": "exact_oid",
            }
    
        merge_commit = pr.get("mergeCommit") or {}
        merge_oid = merge_commit.get("oid")
        if not merge_oid:
            return False, {"head_oid_match": False}
    
        # merge commit が local repo に存在しないなら fail-closed
        # git cat-file -e <merge_oid>^{commit}
    
        # squash commit は通常 1 parent。
        # merge commit parent を起点に local branch が導入した path set を出す。
        # git rev-list --parents -n 1 <merge_oid>
        # git merge-base <squash_parent> <local_tip>
        # git diff --name-only -z <local_base> <local_tip>
    
        # local branch が導入した全 path について local_tip と merge_oid を比較
        # git diff --quiet --no-ext-diff <local_tip> <merge_oid> -- <paths...>
        # returncode 0: 許可
        # returncode 1: pr_head_oid_mismatch
        # other: pr_head_oid_mismatch / fail-closed

    git merge-base --is-ancestor は通常 merge の検証には有用ですが、squash merge では元 commit が default branch の祖先にならないため、それだけでは十分ではありません。merge-base は補助的に「local branch の導入差分の起点」を求める用途に限定するのがよいです。([Git]4)

    #1337 本文に追加すべき文言

    ### Squash-equivalence safety definition
    
    When `headRefOid != local_tip`, cleanup may be authorized only if all of the following are true:
    
    1. PR is already `MERGED` and has a non-null `mergeCommit.oid`.
    2. The merge commit object is available in the local repository.
    3. The merge commit is treated as a squash-equivalence candidate only when its parent structure is compatible with a squash merge.
    4. Compute the local branch delta path set from the merge commit parent / merge-base to `local_tip`.
    5. Compare `local_tip` and `mergeCommit.oid` for every path in that local branch delta path set.
    6. If any local branch delta path differs, or if any git command errors, return `pr_head_oid_mismatch`.
    7. Do not authorize by comparing only Issue Allowed Paths. The comparison must cover every path introduced by the local branch delta.
    8. Non-squash and unverifiable cases keep the existing strict `headRefOid == local_tip` behavior.
    
    Add additive verified diagnostics:
    - `head_equivalence_authorized`
    - `head_equivalence_mode`
    - `pr_merge_commit_oid`
    - `local_branch_tip_oid`
    - `local_delta_paths_count`
    
    `head_oid_match` must continue to mean literal OID equality.

    実装エージェント向けプロンプト

    Issue #1337 を実装してください。ただし、単純な full-tree 比較や Issue Allowed Paths だけの比較は禁止です。
    
    関連前提:
    - cleanup_exec.py は post-merge-cleanup の単一認可境界であり、削除系操作の安全条件を弱めないこと。
    - #1196 では branch-only cleanup が `headRefOid == local refs/heads/<branch>` を要求していた。本 Issue は squash merge equivalence に限ってその条件を additive に拡張する。
    - non-squash / unverifiable / git command error はすべて `pr_head_oid_mismatch` で fail-closed。
    
    実装要件:
    1. `_pr_state()` の `gh pr view --json` に `mergeCommit` を追加する。
    2. 通常 cleanup と branch-only cleanup の OID 判定を共有 helper に切り出す。
    3. helper はまず `headRefOid == local_tip` を従来どおり許可する。
    4. OID 不一致時のみ、`mergeCommit.oid` を使って squash-equivalence 判定に入る。
    5. local branch が導入した全 path set を git で算出し、その全 path について `local_tip` と `mergeCommit.oid` の内容が一致する場合だけ許可する。
    6. path set 外の比較だけで許可しない。Issue Allowed Paths だけで比較しない。
    7. `head_oid_match` は literal OID equality の意味を維持し、squash-equivalent 許可時は additive diagnostics として `head_equivalence_authorized` / `head_equivalence_mode` / `pr_merge_commit_oid` / `local_delta_paths_count` を記録する。
    8. `verify_cleanup_authorization` と `verify_branch_only_cleanup_authorization` の両方に同じ helper を使う。
    9. `tests/codex/test_cleanup_exec_branch_only.py` に実 git DAG ベースの squash merge 回帰テストを追加する。
    10. 既存の `test_oid_mismatch_refused` と `test_oid_mismatch_verify_branch_only_returns_false` は non-squash / no-mergeCommit ケースとして維持する。
    
    検証:
    - Issue #1337 の AC1〜AC5 のコマンドを実行。
    - 追加で、unrelated base change がある squash-equivalent ケース、local extra file がある拒否ケース、mergeCommit object missing の拒否ケースをテストする。
    

    この修正なら、#1337 の意図である “squash merge 済みなのに cleanup できない” 問題を解きつつ、cleanup_exec.py の認可境界を崩さずに済みます。

  3. squne121 commented on Jul 5, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jul 5, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-07-06T02:30:00Z)

    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1344"
      head_sha: "6d0af72f104835c6e9c8aa2c63494482cd5b836d"
      issue_number: 1337
      termination_reason: approved
      iteration: 0
      required_auto_actions: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations:
        - dedupe_key: "ci-verdict-summary-japanese-check-skip-exclude-rule-gap"
          source_url: "https://github.com/squne121/loop-protocol/pull/1344"
          source_note_id: "pr-reviewer-second-pass"
          summary: "ci_verdict_summary.py の HEAD_SHA_NULL_SKIPPED_EXCLUDE_RULES に pull_request_review トリガー由来の PR Body Japanese Check skip パターンが未登録で、false-positive blocker を出すことがある(今回は手動で run 単位に事実確認して false positive と判断した)。"
    
    ISSUE_SCOPE_ROLLUP_DECISION_V2:
      schema_version: 2
      recorded_at: "2026-07-06T02:30:00Z"
      rollup_plan_ref:
        body_sha256: null
        generated_at: null
      decision: skipped
      executed_actions: []
      skipped_reason: "single standalone implementation issue (parent_issue: none); no rollup preflight applicable"
      candidates_reviewed: []
  5. squne121 commented on Jul 5, 2026

    @squne121
    OwnerAuthor

    PR #1344 review fix delta — implementation complete in worktree, push blocked by session sandbox

    全ての OWNER レビュー指摘(P1 x4, P2 x2)を scripts/agent-ops/cleanup_exec.py / tests/codex/test_cleanup_exec_branch_only.py に実装し、worktree (.claude/worktrees/issue-1337-cleanup-exec-squash-merge, branch worktree-issue-1337-cleanup-exec-squash-merge, base head 6d0af72f) 内で 45/45 pytest PASS 済みです。

    修正内容

    1. P1: non-squash merge への fallback 誤許可 — _resolve_head_equivalence() に _commit_object_exists()(git cat-file -e) と _commit_parents()(git rev-list --parents) を追加。parent 数が exactly 1 の場合のみ squash-equivalence candidate とし、2+ parent の通常 merge commit は fail-closed。
    2. P1: path-set 起点が default branch 依存 — _merge_bases() を追加し、squash commit 自身の parent(squash_parent) と local_tip の merge-base を起点にした。merge-base が複数返る場合は fail-closed。
    3. P1: branch-only destructive path のテスト不足 — TestBranchOnlySquashEquivalence クラスに test_verify_branch_only_accepts_squash_merge_path_scoped_match / test_verify_branch_only_rejects_squash_merge_content_mismatch / test_branch_only_run_deletes_branch_after_squash_equivalence を追加。全て PASS。
    4. P1: git diff --name-only の path parse 脆弱性 — path set は git diff --name-only -z に、内容一致判定は git diff --quiet --no-ext-diff(0=match/1=mismatch/>1=fail-closed) に変更。
    5. P2: 診断フィールドの意味論 — exact OID match 時は head_equivalence_authorized: false / head_equivalence_mode: "exact_oid" に修正(squash-equivalence 認可と区別)。
    6. P2: fail-closed regression テスト追加 — test_squash_merge_merge_commit_object_missing_rejects / test_squash_merge_git_diff_error_rejects / test_non_squash_merge_commit_oid_mismatch_rejects_even_if_paths_match を追加。全て PASS。

    検証結果

    ブロッカー: このセッションから git commit/push を実行できません

    このセッションの Bash tool は root(main branch)context に固定されており、local_main_branch_guard hook が worktree への cd / git -C / シェルリダイレクト / gh api を全て fail-closed でブロックします(compound_wrapper_blocked / git_global_opts_failclosed / github_api_command)。cd 自体も permission system により拒否されました。isolation:"worktree" の実行コンテキスト(cwd が worktree 内)がこのセッションには存在しないため、修正済みファイルは worktree 上に正しく配置・検証済みですが、commit と push はできませんでした。

    control-plane(orchestrator)または人間による、以下相当の実行をお願いします。

    cd .claude/worktrees/issue-1337-cleanup-exec-squash-merge
    git add scripts/agent-ops/cleanup_exec.py tests/codex/test_cleanup_exec_branch_only.py
    git commit -m "fix: cleanup_exec.py squash-equivalence を parent数検証・path-set起点修正・-z/quiet diff化で硬化する"
    git push origin worktree-issue-1337-cleanup-exec-squash-merge

    修正済みファイルはこのブランチの worktree 上にそのまま存在しています(ディスク上、未 commit)。

  6. added a commit that references this issue on Jul 5, 2026
    65bd360
  7. squne121 commented on Jul 5, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-07-06T05:00:00Z)

    OWNER の敵対的レビュー(P1×4 / P2×2)を fix_delta (iteration 1, commit 65bd360) で全件解消し、pr-reviewer の再レビューで APPROVE / merge_ready: true を確認済み。

    IMPL_REVIEW_LOOP_RESULT_V1_ITER1:
      schema_version: 1
      status: draft_pr_ready
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1344"
      head_sha: "65bd3609ce0375a59e86b2fded3ed849db801e1d"
      issue_number: 1337
      termination_reason: approved
      iteration: 1
      required_auto_actions: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations: []
    
    ISSUE_SCOPE_ROLLUP_DECISION_V2:
      schema_version: 2
      recorded_at: "2026-07-06T05:00:00Z"
      rollup_plan_ref:
        body_sha256: null
        generated_at: null
      decision: skipped
      executed_actions: []
      skipped_reason: "single standalone implementation issue (parent_issue: none); no rollup preflight applicable"
      candidates_reviewed: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions