Skip to content

実装: impl-review-loop 承認後の post-approval mergeability staleness check を追加する #1624

Closed as not planned

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "impl-review-loop が APPROVE/merge_ready:true でループを終了した後、人間マージ待ちの間に main が先行して PR が CONFLICTING/DIRTY になっても検知できない gap を解消する"
change_kind: workflow

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: impl-review-loop で APPROVE + merge_ready: true + required_auto_actions == [] により終了した PR が、人間のマージ操作までの間に stale 化(main 側の競合変更で CONFLICTING/DIRTY 化)しても、誰も気付かないまま放置される状態を防ぐ。
  • Desired Destination: impl-review-loop で承認された PR は、実際にマージされる直前に mergeable 状態が機械的に再確認され、CONFLICTING/DIRTY/BLOCKED であれば明示的に検知・記録される。

Current Validated Scope

  • .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md は TEST_VERDICT.mergeable: CONFLICTING または merge_state_status: DIRTY の検出をループ実行中(test-runner / pr-reviewer による検出)に限定しており、ループ終了後の検出経路を持たない。
  • .claude/skills/impl-review-loop/SKILL.md の「終了条件」表は verdict: APPROVE かつ merge_ready == true かつ required_auto_actions == [] の場合に「終了。PR は人間がマージ判断」とだけ記載し、終了後の再検証手順を持たない。
  • 実例: PR 実装: linked issue worktree の verified fast-forward を RTK guard で許可する #1609(Issue 実装: linked issue worktree の verified fast-forward を RTK guard で許可する #1589)で、pr-reviewer が merge_ready: true で APPROVE し、GitHub 上に verdict も投稿されたが、その後 main 側で同一ファイル群(.claude/hooks/worktree_scope_guard.py / .codex/rules/default.rules / docs/dev/hook-boundaries.md / scripts/agent-guards/git_mutation_command_policy.py)を触る2コミット(be430de1, e678fea0)が着地し、PR は mergeable: CONFLICTING / mergeStateStatus: DIRTY になった。impl-review-loop 側にはこれを検知する仕組みが存在せず、人間が GitHub の "This branch has conflicts that must be resolved" 表示で気付くまで放置される。

Remaining Parent Gaps

  • なし(単独改善のため)

Outcome

新規スクリプト .claude/skills/impl-review-loop/scripts/check_pre_merge_mergeability.py が追加され、.claude/skills/impl-review-loop/SKILL.md の終了条件と steps/conflicting-pr-escalation-runbook.md の検出条件セクションに、ループ終了後・実際のマージ操作直前に本スクリプトで mergeable 状態を再確認する手順が明記された状態。

In Scope

  • 新規スクリプト .claude/skills/impl-review-loop/scripts/check_pre_merge_mergeability.py を追加する。PR番号と(任意で)レビュー時点の reviewed_head_sha を受け取り、gh pr view --json mergeable,mergeStateStatus,headRefOid を読み取って以下を機械的に判定し、PRE_MERGE_MERGEABILITY_CHECK_RESULT_V1(JSON)を stdout に返す:
    • mergeable == "MERGEABLE" かつ mergeStateStatus が CLEAN または UNSTABLE(CI pending 等、merge-blocking ではない状態)→ status: clean、exit 0
    • mergeable == "CONFLICTING" または mergeStateStatus が DIRTY / BLOCKED → status: conflicting_or_blocked、exit 1
    • reviewed_head_sha を指定し、それが現在の headRefOid と一致しない → status: head_drifted、exit 2(stale review 警告。conflict の有無に関わらず返す)
    • gh コマンド失敗 / 非 JSON 応答 → status: api_error、exit 3
  • .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md の「検出条件」セクションに、ループ終了後(人間マージ判断の直前)に本スクリプトを実行する検出経路を追記する。
  • .claude/skills/impl-review-loop/SKILL.md の「終了条件」表の draft_pr_ready 行に、マージ実行前に check_pre_merge_mergeability.py を実行することを明記する。
  • 上記スクリプトに対する pytest(gh呼び出しは fake/mock 化し、実ネットワークアクセスは行わない)を追加する。

Out of Scope

  • conflict 自体を自動解決するロジックの変更(既存 runbook の implementation-worker 委譲フローをそのまま使う)。
  • 定期実行 cron / schedule 基盤の追加(本 Issue はスクリプト自体と手順明記のみ。定期実行の仕組み自体は別 Issue とする)。
  • GitHub Actions の merge queue / branch protection ルールの変更。
  • pr-review-judge / allowed_paths_review_gate.py 自体のロジック変更。

Acceptance Criteria

  • AC1: check_pre_merge_mergeability.py は mergeable: MERGEABLE かつ mergeStateStatus: CLEAN(または UNSTABLE)の PR に対して status: clean を返し exit 0 で終了する。
  • AC2: check_pre_merge_mergeability.py は mergeable: CONFLICTING または mergeStateStatus が DIRTY/BLOCKED の PR に対して status: conflicting_or_blocked を返し exit 1 で終了する。
  • AC3: reviewed_head_sha を指定した場合、現在の headRefOid と不一致であれば status: head_drifted を返し exit 2 で終了する。
  • AC4: gh 呼び出しが失敗する、または非 JSON 応答の場合は status: api_error を返し exit 3 で終了する。
  • AC5: .claude/skills/impl-review-loop/SKILL.md に check_pre_merge_mergeability.py の実行タイミング(終了条件表の draft_pr_ready 行)が明記されている。
  • AC6: .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md の検出条件セクションに、ループ終了後の post-approval 検出経路として check_pre_merge_mergeability.py が記載されている。

Runtime Verification Applicability

runtime_verification_applicability:
  decision: immediate
  reason: "gh CLI 呼び出しの成功/失敗、JSON parse、mergeable/mergeStateStatus の分岐判定、exit code を実際に subprocess 実行して検証する必要があり、静的 grep だけでは AC1-AC4 の分岐ロジックを検証できないため。"
  applicable_acs: [AC1, AC2, AC3, AC4]
  execution_environment: "gh CLI 呼び出しは fake/mock(subprocess.run を monkeypatch 等で差し替え)し、実ネットワークアクセス・実 GitHub API 呼び出しは行わない。"
  skip_conditions: "pytest 実行環境が存在しない場合のみ SKIP とし、SKIP は PASS として扱わない。"
  fallback_policy: "runtime verification が環境要因で実行不能な場合は human_judgment として停止し、static-only 判定へのフォールバックは行わない。"
  artifact_requirements: "pytest 実行ログ(各分岐の exit code とstatus値を含む)をテスト assertion メッセージまたは CI ログに残す。"

Verification Commands

# AC1
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_check_pre_merge_mergeability.py::test_returns_clean_status_for_mergeable_clean_pr

# AC2
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_check_pre_merge_mergeability.py::test_returns_conflicting_status_for_conflicting_or_dirty_pr

# AC3
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_check_pre_merge_mergeability.py::test_returns_head_drifted_when_reviewed_head_sha_mismatches

# AC4
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_check_pre_merge_mergeability.py::test_returns_api_error_on_gh_failure

# AC5
$ rg -n "check_pre_merge_mergeability" .claude/skills/impl-review-loop/SKILL.md

# AC6
$ rg -n "check_pre_merge_mergeability" .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md

Allowed Paths

  • .claude/skills/impl-review-loop/scripts/check_pre_merge_mergeability.py(新規)
  • .claude/skills/impl-review-loop/tests/test_check_pre_merge_mergeability.py(新規)
  • .claude/skills/impl-review-loop/SKILL.md
  • .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md

Stop Conditions

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

Required Skills

  • Python
  • pytest
  • GitHub CLI(gh pr view)の JSON 出力仕様

Required Design References

  • .claude/skills/impl-review-loop/steps/conflicting-pr-escalation-runbook.md
  • .claude/skills/impl-review-loop/SKILL.md(終了条件表)
  • docs/dev/agent-skill-boundaries.md

Scope Delta(任意)

N/A

Scope Collision Preflight

ISSUE_OVERLAP_PREFLIGHT_RESULT_V1 は decision: overlap_requires_comment、policy_class: C1、GitHub search/read-back ともに ok。

Delivery Rule

  • 1 Issue = 1 PR とし、dedicated linked worktree で実装して Draft PR を作成する。
  • 実装前に issue-contract-review で fresh CONTRACT_REVIEW_RESULT_V1 status: go を取得する。
  • normal commit / push のみを使用し、force push、guard bypass、hook disable を行わない。

Activity

  1. squne121 commented on Jul 19, 2026

    @squne121
    OwnerAuthor

    マージ完了後のコンフリクトは検知できないでしょ

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions