Repository navigation
Closed
Labels
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "impl-review-loop Step 5 BEHIND 分岐の update_branch 委譲先 contract 定義と expected_head_sha race guard 追加"
change_kind: workflowParent Issue
なし(単独改善)
Parent Goal Ref
- Goal: impl-review-loop Step 5 の BEHIND 分岐で
gh pr update-branch実行責務をimplementation-workerに正式委譲し、expected_head_shaを使った race-safe な branch update 手順を定義する - Desired Destination:
implementation-workerskill にupdate_branchcontract セクション追加、impl-review-loop Step 5 の委譲手順を明文化
Current Validated Scope
.claude/skills/implement-issue/SKILL.mdへのupdate_branchcontract セクション追加(UPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1schema を含む).claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdの BEHIND 分岐 routing 記述の委譲手順具体化(gh api -X PUT呼び出し手順、202 polling 条件、422 body 分類、expected_head_sha guard 追記).claude/agents/implementation-worker.mdへのgh api -X PUT repos/.../pulls/.../update-branch実行権限の明文化(Bash 許可例外として)
Remaining Parent Gaps
なし(本 Issue は単独 follow-up)
Outcome
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md、implement-issue SKILL.md、.claude/agents/implementation-worker.md の更新が完了し、pnpm typecheck && pnpm lint && pnpm test && pnpm build が PASS した状態で PR がマージ可能になっている
In Scope
implementation-worker(implement-issueが担う worker role)へのupdate_branch受け口 contract 定義gh api -i -X PUT "repos/$REPO/pulls/$PR_NUMBER/update-branch" -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" -f expected_head_sha="$EXPECTED_HEAD_SHA"を使用する(gh pr update-branchではない — expected_head_sha オプションなし)- 202(accepted)後: headRefOid が EXPECTED_HEAD_SHA から変わるまで poll(最大 bounded retry)し、mergeStateStatus が UNKNOWN/BEHIND のままなら bounded retry した上で Step 2(test-runner) → Step 4(pr-review-judge) → Step 5 を再実行する
- 403(forbidden): permission_diagnostics(auth_actor, head_repo, base_repo, fork_pr, maintainer_can_modify, required_permissions)を出力して human_escalation へ
- 422(validation failed): body を確認し
expected_head_sha mismatch→ stale_verdict(Step 4 re-review)、その他 validation failure → human_escalation、secondary rate limit → bounded_backoff_or_human_escalation で分岐する(422 全体を stale sha mismatch とは断定しない)
impl-review-loopStep 5 BEHIND 分岐 routing の委譲手順を具体化(現在は「具体的な実行手順は implementation-worker 側」で未定義)- 更新成功後(202 + head 更新確認後)の再実行フロー明示: Step 2(test-runner)→ Step 4(pr-review-judge)→ Step 5 再実行
- REST
PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branchは merge update 固定とする(linear history / rebase-required リポジトリは out-of-scope、403/validation failure 時は human_escalation) - 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56(LOOP_VERDICT YAML キーの snake_case 統一)が未完了の間、Step 5 の
mergeStateStatus/merge_state_status混在を吸収する互換読み取り処理を Step 5 の更新に含める(または 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56 を本 Issue の dependency として明記する) .claude/agents/implementation-worker.mdの Bash 制約にgh api -X PUT .../update-branchを許可例外として追加するUPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1schema の contract 化(implement-issue/SKILL.mdに追記)
Out of Scope
gh pr update-branchの実際の CI / automation 実行(本 Issue は docs / workflow skill 記述の更新のみ)implementation-workerの新規 skill ファイル作成(既存implement-issueSKILL.md への追記で対応する)- race condition の完全排除(expected_head_sha による失敗検出まで。自動 retry loop の設計は別 Issue)
- PR feat(#67): impl-review-loop Step 5 に BEHIND 分岐と auto update-branch を追加し schema を拡張する #446 / Issue 実装: impl-review-loop Step 5 に BEHIND 分岐と auto update-branch を追加し schema を拡張する #67 の再オープンや変更の取り消し
- GraphQL
updatePullRequestBranchmutation(本 Issue は REST merge 固定で対応する) - 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56(snake_case 統一)の実装(本 Issue では互換読み取り処理または dependency 明記のみ)
- 202 後の CI 完了待機や CI 結果の検証(head 更新確認まで)
Acceptance Criteria
- AC1:
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdの BEHIND 分岐 routing にgh api -X PUT repos/$REPO/pulls/$PR_NUMBER/update-branchとexpected_head_shabody パラメータ、および UPDATE_BRANCH_REQUEST_V1 / UPDATE_BRANCH_RESULT_V1 への参照が明記されている - AC2:
implement-issueSKILL.md にupdate_branchcontract セクションが追加されており、gh api -X PUT .../update-branch -f expected_head_sha=の呼び出し形式と 202 / 403 / 422 の分岐処理が記述されている - AC3: 202 Accepted 後の headRefOid poll(head が EXPECTED_HEAD_SHA から変わるまで待機)と bounded retry 条件、その後の Step 2 → Step 4 → Step 5 再実行フローが step-5-mergeability-handling.md に明示されている
- AC4: 422 受信時の処理が body 内容で分類されている(
expected_head_shamismatch → stale_verdict + Step 4 re-review、その他 validation failure → human_escalation、secondary rate limit → bounded_backoff_or_human_escalation) - AC5: 403 受信時に permission_diagnostics(auth_actor, fork_pr, maintainer_can_modify を含む)を出力して human_escalation に倒すフローが contract に含まれている
- AC6: Step 5 update_branch が REST merge 固定であること(linear history / rebase-required は out-of-scope、対象外 PR は human_escalation)が step-5-mergeability-handling.md または implement-issue SKILL.md に明記されている
- AC7:
.claude/agents/implementation-worker.mdにgh api -X PUT .../update-branch実行が Bash 許可例外として追記されているか、implement-issue/SKILL.mdの update_branch contract がその旨を明示している - AC8: Step 5 の
mergeStateStatus/merge_state_status混在を吸収する互換読み取り処理が step-5-mergeability-handling.md に追加されているか、実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56 が本 Issue の dependency として明記されている - AC9:
pnpm typecheck && pnpm lint && pnpm test && pnpm buildが PASS する(ドキュメント変更のみのため既存テストを壊さない)
Verification Commands
# AC1
$ rg "expected_head_sha" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "gh api -X PUT" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "UPDATE_BRANCH_REQUEST_V1\|UPDATE_BRANCH_RESULT_V1" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
# AC2
$ rg "update_branch" .claude/skills/implement-issue/SKILL.md
$ rg "expected_head_sha" .claude/skills/implement-issue/SKILL.md
$ rg "202\|403\|422" .claude/skills/implement-issue/SKILL.md
# AC3
$ rg "202" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "headRefOid\|poll" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "bounded retry" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
# AC4
$ rg "422" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "stale_verdict\|human_escalation\|bounded_backoff" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
# AC5
$ rg "403" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "permission_diagnostics\|fork_pr\|maintainer_can_modify" .claude/skills/implement-issue/SKILL.md
# AC6
$ rg "merge.*fixed\|linear.*history\|rebase.*out.of.scope\|merge update" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "merge.*fixed\|linear.*history\|rebase.*out.of.scope\|merge update" .claude/skills/implement-issue/SKILL.md
# AC7
$ rg "update-branch" .claude/agents/implementation-worker.md
$ rg "update_branch" .claude/skills/implement-issue/SKILL.md
# AC8
$ rg "mergeStateStatus\|merge_state_status" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
$ rg "56\|snake_case\|dependency" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
# AC9
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm buildRuntime Verification Applicability
decision: not_applicable
reason: ドキュメント・skill 記述のみの変更であり、runtime 挙動を直接変更しない。
Allowed Paths
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md.claude/skills/implement-issue/SKILL.md.claude/agents/implementation-worker.md
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
implementation-workerが独立した新規 skill ファイルとして作成済みで本 Issue の Allowed Paths と不一致になった場合(人間判断を仰ぐ)- 実装: LOOP_VERDICT / TEST_VERDICT_MACHINE の YAML キー名を snake_case に統一する #56(snake_case 統一)の実装と本 Issue の Step 5 変更が直接競合し、互換処理追加では解決できないと判明した場合(人間判断を仰ぐ)
Required Skills
なし
Scope Delta(任意)
N/A
Source
本 Issue は PR #446(Issue #67: impl-review-loop Step 5 BEHIND 分岐と auto update-branch)の review で defer された follow-up items を追跡する。
- PR feat(#67): impl-review-loop Step 5 に BEHIND 分岐と auto update-branch を追加し schema を拡張する #446 review コメント(Iterator: impl-review-loop issue 実装: impl-review-loop Step 5 に BEHIND 分岐と auto update-branch を追加し schema を拡張する #67)
- 人間判断: 2026-05-28 A' 選択時の deferred items(
update_branch実行責務の implementation-worker 委譲 +expected_head_shaguard)
dedupe_key: follow-up:squne121/loop-protocol:pr/446:update-branch-worker
Delivery Rule
1 Issue = 1 PR- Worktree:
.claude/worktrees/issue-<N>-update-branch-worker - Draft PR 既定
Activity
squne121 commentedon May 30, 2026
結論
REQUEST_CHANGES。#453 は方向性は正しいが、このまま実装 Issue として流すと、責務境界・権限・race guard・検証条件がまだ弱いです。
#453 の目的は、#446 で Step 5 に入った直接
gh pr update-branch実行を、implementation-worker側の正式 contract に移し、expected_head_shaで race-safe にすることです。これは妥当です。#446 の diff では Step 5 が直接gh pr update-branch "$PR_NUMBER"を実行する手順になっており、expected_head_shaガードはありません。([GitHub]1)ただし #453 の本文は、実装前 contract としてはまだ危険です。
ブロッカー
1. Allowed Paths と「implementation-worker 相当ファイル」の記述が矛盾している
#453 の Current Validated Scope は「
.claude/skills/implement-issue/SKILL.mdまたは.claude/skills/implementation-worker/SKILL.md」への contract 追加を許容していますが、Allowed Paths は.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdと.claude/skills/implement-issue/SKILL.mdの 2 ファイルだけです。([GitHub]2)さらに実際の
implementation-workeragent 定義には、Bash 制約として「pnpm 系と.claude/skills/*/scripts/配下のスクリプト実行に限定」「git push / gh pr create は open-pr skill 経由のみ」と書かれています。gh api -X PUT .../update-branchは明確に GitHub への書き込み操作なので、agent 定義または責務境界ドキュメントで許可しないと、contract だけ追加しても実行者側が拒否・逸脱する可能性があります。([GitHub]3)修正要求: Allowed Paths に最低限
.claude/agents/implementation-worker.md、必要ならdocs/dev/agent-skill-boundaries.mdを追加するか、「implement-issue/SKILL.mdのupdate_branchcontract が implementation-worker の Bash 許可例外として扱われる」ことを明文化してください。2.
gh pr update-branchではexpected_head_shaを渡せない#453 は
expected_head_sha付き REST API を in-scope にしています。これは正しい選択です。GitHub REST API のUpdate a pull request branchはexpected_head_shaを body parameter として受け取り、HEAD が一致しない場合は422 Unprocessable Entityを返す、と公式に説明されています。([GitHub Docs]4)一方、GitHub CLI の
gh pr update-branchは PR 番号・URL・branch と--rebaseしか documented option がなく、expected_head_shaを渡す option はありません。([GitHub CLI]5)修正要求: contract では
gh pr update-branchではなく、少なくとも次のようなgh api経由を正本にしてください。Issue の AC も「
expected_head_shaという語がある」ではなく、「gh api -X PUT repos/.../pulls/.../update-branchと bodyexpected_head_shaがある」まで要求すべきです。3.
202 Acceptedを「更新完了」と扱うと危険GitHub REST API の update-branch は
202 Acceptedを返します。これは「要求を受け付けた」であって、PR head が更新済み・CI が再実行済み・mergeStateStatus が再計算済みという意味ではありません。公式レスポンス例も “Updating pull request branch.” です。([GitHub Docs]4)#453 は 202 後に Step 2 → Step 4 → Step 5 を再実行するとしていますが、polling 条件が不足しています。([GitHub]2)
修正要求: 202 後は以下を contract 化してください。
202直後に Step 2 を叩くと、旧 head の CI 結果を読んで false approve するリスクがあります。4.
422 = stale head sha mismatchと断定しているGitHub docs は
422を「Validation failed, or the endpoint has been spammed」と説明しています。expected_head_shamismatch も 422 ですが、422 全部が stale race とは限りません。([GitHub Docs]4)修正要求: 422 は body を見て分類してください。
5. 403 の原因分析が浅い
GitHub REST API は update-branch に
"Pull requests" repository permissions (write)を要求します。また GitHub App として head repository を書き換える場合は、head repository の contents write 権限も必要です。([GitHub Docs]4)修正要求: 403 は単に forbidden で止めるのではなく、少なくとも以下を出力 contract に含めるべきです。
fork PR や
maintainer_can_modify=falseの場合、worker が安全に branch update できない可能性があります。6. REST API は merge update 固定。rebase / linear history 方針と衝突し得る
REST の update-branch は base branch の HEAD を PR branch に merge する APIです。([GitHub Docs]4)
gh pr update-branchも default は merge commit で、--rebase指定時だけ rebase です。([GitHub CLI]5)GraphQL の
updatePullRequestBranchにはupdateMethodがあり、MERGEとREBASEが定義されています。([GitHub Docs]6)修正要求: #453 は次のどちらかに決めるべきです。
REST merge 固定にする
「linear history / rebase-required repository は out-of-scope。403/validation failure 時は human escalation」と明記する。
GraphQL mutation に寄せる
expectedHeadOid+updateMethod: MERGE | REBASEを contract 化する。現状の「REST API を使う」だけでは、リポジトリ方針と衝突したときの判断が曖昧です。
7. #56 の snake_case 統一 Issue と競合しやすい
#56 は
LOOP_VERDICT / TEST_VERDICT_MACHINEの YAML キーをsnake_caseに統一する open issue です。対象はpr-review-judge/SKILL.mdのmergeStateStatus:、Step 5 の grep pattern、impl-review-loop/SKILL.md、SSOT ドキュメントです。([GitHub]7)#453 は Step 5 を触るため、
mergeStateStatus/merge_state_statusの混在をさらに固定化する危険があります。修正要求: #453 は #56 を dependency にするか、Step 5 側で一時的に両方を読む互換処理を AC に入れてください。
8. Outcome と AC/VC が不整合
#453 の Outcome は
pnpm testとuv run pytestが PASS した状態を要求していますが、AC5 と Verification Commands はpnpm typecheck && pnpm lint && pnpm test && pnpm buildだけです。([GitHub]2)修正要求:
uv run pytestを必須にするなら AC/VC に入れる。不要なら Outcome から削る。現状は実装者と reviewer の判定基準が割れます。改善後の Issue 方針
#453 は close ではなく 修正して実装可能です。推奨する到達状態は次です。
GitHub GraphQL の
MergeStateStatusにはBEHIND,BLOCKED,CLEAN,DIRTY,DRAFT,HAS_HOOKS,UNKNOWN,UNSTABLEが定義されています。#453 の Step 5 更新でも、この enum を欠落なく扱うか、対象外 enum を明示的に human escalation へ倒す必要があります。([GitHub Docs]6)GitHub に貼るレビューコメント案
[-]改善: impl-review-loop の update_branch 実行責務を implementation-worker に正式委譲し expected_head_sha guard を追加する[/-][+]実装: impl-review-loop の update_branch 実行責務を implementation-worker に正式委譲し expected_head_sha guard を追加する[/+]squne121 commentedon May 30, 2026
Contract Snapshot (2026-05-30T07:41:25Z)
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md.claude/skills/implement-issue/SKILL.md.claude/agents/implementation-worker.md.claude/worktrees/issue-453-update-branch-workerworktree-issue-453-update-branch-workersqune121 commentedon May 30, 2026
implement-issue: 実装完了 (2026-05-30T07:48:03Z)
.claude/worktrees/issue-453-update-branch-workerworktree-issue-453-update-branch-workerfix(#453): B2-B4 mergeStateStatus parser / delegation-only step-5 / u…
docs(#453): add update_branch contract with expected_head_sha guard t…
squne121 commentedon May 30, 2026
post-merge-cleanup: 完了 (2026-05-30T08:16:33Z)