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: "#454"
goal_ref: "implementation-worker の update_branch executor が current head preflight・expected_head_sha・REST classifier・bounded poll を一体として fail-closed に消費し、実行経路を叩く contract test で固定できる状態にする"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: impl-review-loop の
required_auto_actions.kind=update_branchが stale verdict を信用せず、implementation-worker 側で GitHub REST update-branch contract を fail-closed に実装できる状態にする - Desired Destination: update_branch repair executor が
expected_head_shaと current PR head preflight を伴う REST update-branch semantics を classifier / poll / rerun signaling まで含めて実装し、success 後 rerun 必須・mismatch / permission / validation / secondary rate limit / head unchanged を決定論的に区別できる
Current Validated Scope
.claude/agents/implementation-worker.mdのupdate_branchmode とIMPLEMENTATION_WORKER_RESULT_V2を、current PR head preflight・reason_code 分類・rerun_required schema 整合まで更新する.claude/skills/implement-issue/SKILL.mdのUPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1とIMPLEMENTATION_WORKER_REQUEST_V2関連節を、REST executor wrapper 前提の contract に更新する.claude/skills/implement-issue/scripts/update_branch.pyを追加し、request validation・preflight・REST call・response classification・bounded poll を deterministic に実装する.claude/skills/implement-issue/tests/test_update_branch_rest_contract.pyを追加し、fake gh runner / fake poller で executor contract を検証する.claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.pyの update_branch 関連 expectation を新 schema / rerun_required 表現に合わせて更新する
Remaining Parent Gaps
- Step 5 production consumer が
required_auto_actions.kind/executor/skillとbranch_behind_mainを fail-closed に消費する回帰は別 Issue で扱う - GitHub CLI / GraphQL / rebase 方式の branch update 対応は本 Issue の対象外
- docs/dev/agent-skill-boundaries.md の inventory 変更は 実装: impl-review-loop の V2 routing boundary(required_auto_actions / branch_behind_main)を docs/dev/agent-skill-boundaries.md と tests に登録する #454 側の完了状態を維持し、本 Issue では再編集しない
Outcome
implementation-worker の update_branch executor が API call 前に current PR head と expected_head_sha の一致を確認し、GitHub REST update-branch の 202 / 403 / 422 / 429 と head unchanged を fail-closed に分類し、before/after head SHA・rerun_required・reason_code を一貫した schema で返し、専用 contract test が PASS している状態。
In Scope
expected_head_sha未指定時に即 block し、さらに current PR head とexpected_head_shaの事前照合を API call 前に行うgh pr update-branchではなく RESTgh api -X PUT repos/{owner}/{repo}/pulls/{pull_number}/update-branchを唯一の update 経路として固定する- REST response を
202 Accepted/403 permission denied/422 expected_head_sha mismatch/422 validation failed/403|429|422 secondary rate limit/transport errorに分類する 202 Accepted後の bounded poll で head が変化しないケースをtimeoutではなくhead_unchanged_after_accepted系の deterministic failure として固定する- success 後に verification と pr-review の両方の rerun が必須であることを、worker result schema と contract test で固定する
- pytest が Markdown の存在確認ではなく update_branch executor の classifier / preflight / poll result builder を fake gh runner で検証するようにする
Out of Scope
- Step 5 production consumer の
required_auto_actions.kind/executor/skillmatrix hardening branch_behind_mainとmerge_state_statusの整合判定open-pr/update_pr_body_hygiene/ensure_closing_keywordの実装変更- GraphQL
updatePullRequestBranchmutation や rebase update 対応 .github/workflows/ci.ymlの CI 登録変更
Acceptance Criteria
- AC1:
.claude/skills/implement-issue/scripts/update_branch.pyがexpected_head_sha未指定をblockedとし、current PR head とexpected_head_shaが一致しない場合も API call を行わずexpected_head_sha_mismatchで fail-closed にする - AC2:
.claude/skills/implement-issue/SKILL.mdと.claude/agents/implementation-worker.mdがgh pr update-branchを禁止し、RESTgh api -X PUT repos/{owner}/{repo}/pulls/{pull_number}/update-branchを唯一の許可経路として記載している - AC3: update_branch executor が
202 Accepted/403 permission_denied/403|429|422 secondary_rate_limit/422 expected_head_sha_mismatch/422 validation_failed/transport_errorを reason_code 付きで区別する - AC4:
202 Accepted後に bounded poll しても head が変化しないケースがhead_unchanged_after_acceptedの deterministic failure として定義され、timeout扱いに戻っていない - AC5: 成功時の worker result が
before_head_sha/after_head_sha/update_method/rerun_requiredを保持し、rerun_requiredは verification と pr_review の両方を同時に表現できる schema に統一されている - AC6:
.claude/skills/implement-issue/tests/test_update_branch_rest_contract.pyが fake gh runner / fake poller を使ってmissing expected_head_sha、preflight mismatch、202 success、202 head unchanged、403 permission denied、403|429 secondary rate limit、422 mismatch、422 validation failure、transport errorを検証する - AC7:
uv run pytest .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -vが PASS する - AC8:
uv run pytest .claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.py .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -vが PASS する
Verification Commands
# AC1
$ test -f .claude/skills/implement-issue/scripts/update_branch.py
# AC2
# preflight-scope: pr_review_only
$ rg -n "gh pr update-branch.*禁止|gh api -X PUT|pulls/\\{pull_number\\}/update-branch" .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.md .claude/skills/implement-issue/scripts/update_branch.py
# AC3
# preflight-scope: pr_review_only
$ rg -n "permission_denied|secondary_rate_limit|validation_failed|expected_head_sha_mismatch|transport_error" .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.md .claude/skills/implement-issue/scripts/update_branch.py
# AC4
# preflight-scope: pr_review_only
$ rg -n "head_unchanged_after_accepted|head unchanged after accepted|head did not change after accepted" .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.md .claude/skills/implement-issue/scripts/update_branch.py
# AC5
# preflight-scope: pr_review_only
$ rg -n "before_head_sha|after_head_sha|update_method|rerun_required" .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.md .claude/skills/implement-issue/scripts/update_branch.py
# AC6
$ test -f .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py
# AC7
# preflight-scope: pr_review_only
$ uv run pytest .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -v
# AC8
# preflight-scope: pr_review_only
$ uv run pytest .claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.py .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -vAllowed Paths
.claude/agents/implementation-worker.md.claude/skills/implement-issue/SKILL.md.claude/skills/implement-issue/scripts/update_branch.py.claude/skills/implement-issue/tests/test_update_branch_rest_contract.py.claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- update_branch 以外の repair mode(
update_pr_body_hygiene/ensure_closing_keyword/apply_pr_review_fix_delta)まで同一 PR に押し込む必要が出た場合 required_auto_actions.kind/executor/skillconsumer 側や Step 5 production routing 側の修正まで必要と判明した場合- GraphQL / rebase / merge queue など別 branch update transport まで同時に扱う必要が出た場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
open-prcontract 変更が前提でないと fix できないと判明した場合
Required Skills
- Python / pytest
- GitHub REST API contract review
- workflow result schema design
Scope Delta(任意)
- owner comment
https://github.com/squne121/loop-protocol/issues/778#issuecomment-4683400462を一次ソースとして、Markdown contract 固定中心のスコープから executor wrapper + classifier test 中心の root-cause scope へ再定義した
Runtime Verification Applicability
decision: not_applicable
reason: "Workflow docs, Python wrapper, and contract tests only. No runtime game behavior changed."Delivery Rule
1 Issue = 1 PR- Draft PR 既定
Refs #454を PR 本文に含める- owner comment
https://github.com/squne121/loop-protocol/issues/778#issuecomment-4683400462を一次ソースとして扱う
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 11, 2026
総合判定: REQUEST_CHANGES
Issue #778 の方向性は妥当です。GitHub REST の
Update a pull request branchはexpected_head_shaを受け取り、不一致時は422 Unprocessable Entityを返すため、stale verdict 対策としてexpected_head_shaを必須化する設計自体は正しいです。GitHub 公式 docs でも、この endpoint は base branch の HEAD を PR branch に merge し、expected_head_shaが PR HEAD と一致しない場合は 422 になると説明されています。([GitHub Docs]1)ただし、現状の Issue #778 は 「堅牢な executor 実装」ではなく「Markdown contract と pytest での仕様固定」に寄りすぎています。このまま実装すると、AI agent が Markdown を読んで shell 断片を実行する前提のまま残り、race / status 分類 / retry / poll / result schema の実効性が弱いです。
確認した一次情報
Issue #778 は、
implementation-workerのupdate_branchmode を GitHub RESTupdate-branch+expected_head_sha+ TOCTOU guard + contract test で堅牢化する open Issue です。対象ファイルは.claude/agents/implementation-worker.md、.claude/skills/implement-issue/SKILL.md、.claude/skills/implement-issue/tests/test_update_branch_rest_contract.pyに限定されています。親 Issue #454 は、
TEST_VERDICT_MACHINE/v1.branch_behind_mainとLOOP_VERDICT_V2.required_auto_actions[].kind|executor|skill|expected_head_shaを routing-critical boundary として登録するものです。 その実装 PR #774 は merged で、boundary doc と fixture tests を追加しています。Issue #778 自体にコメントはありません。 一方、#454 の owner comment は PR #774 について「方向性は正しいが、実際の routing consumer を壊さない保証になっていない」と REQUEST_CHANGES しており、
executor/skillの検証不足や stale head 検証の弱さを指摘しています。Blocker 1:
rerun_requiredの schema が既に矛盾している現行
.claude/agents/implementation-worker.mdのIMPLEMENTATION_WORKER_RESULT_V2はrerun_required: verification | pr_review | noneという単一値 enum です。 しかし同じファイルのupdate_branch説明では、成功後は verification と pr-review の両方が必要なのに、rerun_required: trueを返すと書かれています。Issue #778 の AC4 も「verification / pr-review の再実行が必須」としているため、現在の enum では表現できません。
修正案:
または:
単一 enum のままにするなら、
verification_and_pr_reviewを追加する必要があります。これは schema/type 変更なので、Issue #778 の Stop Conditions にある「固定契約の変更が必要になった場合」と衝突します。ここは Issue 本文側を先に直すべきです。Blocker 2: secondary rate limit を 422 固定で扱うのは危険
Issue #778 は
secondary_rate_limitを 422 分岐の一部として扱っています。しかし GitHub の rate limit docs は、secondary rate limit 超過時は通常403 Forbiddenまたは429 Too Many Requestsと、secondary rate limit を示す error message が返ると説明しています。retry-after があれば従い、なければ少なくとも 1 分待ち、継続失敗時は exponential backoff すべきです。([GitHub Docs]2)Update a pull request branchendpoint の 422 は「Validation failed, or the endpoint has been spammed」としか書かれていません。([GitHub Docs]1) つまり、secondary_rate_limitを 422 のみで分類する contract は不完全です。修正案:
reason_codeは次のように分類してください。secondary_rate_limitは403 | 429 | 422の body/header を見て分類する。422 専用にしない。Blocker 3: 現状の test は「本物の executor」を叩かない危険が高い
PR #774 の fixture regression test は、test 内に
_route_required_auto_action()という簡易 routing 関数を定義して fixture を読む形でした。これは実際のimpl-review-loopconsumer やimplementation-workerの実行経路を叩いていません。Issue #778 でも同じ構造にすると、
test_update_branch_rest_contract.pyは「Markdown に文字列がある」「fixture とテスト内の簡易関数が一致する」ことしか保証しません。実際のgh api呼び出し、preflight、HTTP response parsing、poll、result schema 生成は壊れていても pass します。修正案:
Issue #778 は Allowed Paths に次を追加するべきです。
そして shell 断片ではなく、薄い deterministic wrapper を置くべきです。
pytest はこの wrapper の pure classification / fake gh runner / fake poller を検証する。live GitHub API は叩かない。
Blocker 4: AC3 の「head unchanged」は現行 contract とズレている
現行
implement-issue/SKILL.mdのUPDATE_BRANCH_RESULT_V1では、202 Accepted 後に head が変わらない場合をtimeoutとしています。Issue #778 はこれを deterministic failure として扱う要求ですが、AC / result schema 上の具体的な status / reason_code が不足しています。
修正案:
timeoutではなく、次のように固定する。これは「GitHub が 202 を返したが、bounded poll で PR head が変わらなかった」という独立 failure です。timeout と混ぜると、API 遅延・GitHub 障害・既に最新・consumer の BEHIND 判定ミスを区別できません。
Blocker 5:
gh pr update-branch禁止は正しいが、理由をもう少し厳密に書くべきIssue #778 の AC6 は
gh pr update-branchを使わず RESTgh api -X PUT .../update-branchを使うとしています。これは妥当です。GitHub CLI の
gh pr update-branchmanual には--rebaseと--repoはありますが、expected_head_sha相当の flag は確認できません。(GitHub CLI) 一方 REST endpoint はexpected_head_shaを body parameter として受け取ります。([GitHub Docs]1)修正文:
追加すべき contract test
Issue #778 の AC5 は良い出発点ですが、不足があります。最低限、次を fixture / unit test にしてください。
Issue #778 本文への具体的な修正提案
Allowed Paths を変更
現状の Allowed Paths だけでは、実行可能 wrapper を追加できません。堅牢化を名乗るなら追加してください。
script 追加を許可しないなら、Issue title を次に弱めるべきです。
AC4 を schema 矛盾込みで修正
AC5 を実装経路検証に変更
AC に secondary rate limit 修正を追加
実装方針
最小の堅牢実装は次です。
処理順序は固定。
最終コメント
Issue #778 は、#454 / PR #774 の follow-up として必要です。ただし現状のままでは 「REST contract を安全に消費する executor」ではなく「agent が読む手順書の追記」になるリスクが高いです。
特に直すべきは次の 4 点です。
rerun_requiredの boolean / enum / 複数 rerun 表現の矛盾を解消する。head unchanged after 202をtimeoutではなく専用reason_codeにする。この 4 点を Issue 本文に入れてから実装に回すのが安全です。
squne121 commentedon Jun 11, 2026
Issue #778 の本文を、owner comment ベースの root-cause scope に更新しました。
変更点:
.claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.pyを追加検証結果:
check_vc_scope.py: PASSguard-issue-body.py: all_passedcontract_readiness_check.py --mode execute: status=gosqune121 commentedon Jun 11, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 11, 2026
CodexCLI作業ログ
squne121 commentedon Jun 11, 2026
Contract Snapshot (2026-06-11T18:20:07Z)
Allowed Paths:
squne121 commentedon Jun 11, 2026
Contract Snapshot (2026-06-11T18:20:07Z)
.claude/agents/implementation-worker.md.claude/skills/implement-issue/SKILL.md.claude/skills/implement-issue/scripts/update_branch.py.claude/skills/implement-issue/tests/test_update_branch_rest_contract.py.claude/skills/implement-issue/tests/test_implementation_worker_request_v2_contract.py.claude/worktrees/issue-778-update-branch-rest-contractworktree-issue-778-update-branch-rest-contractfix: sync update-branch repair contract (#778)
fix: harden update_branch REST executor (#778) (#809)