Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "implement-issue の update_branch 実行契約を、Claude Code/Codex CLI Hook の block/allow に依存せず、update_branch.py 自体の入力検証・race guard・postcondition readback で完結する canonical branch-update executor へ統一する"
change_kind: code
preflight_scope: implementation
runtime_verification:
required: true
mode: immediate
evidence_type: executor-contract-subprocess-testsParent Issue
なし(単独改善)
Depends On
なし。旧版は #1403(branch force delete lane、CLOSED)を local_main_branch_guard.py 共有編集の前提として記載していたが、本改訂は local_main_branch_guard.py を Allowed Paths から除外するため、この依存は解消する。
Parent Goal Ref
- Goal:
implementation-workerのupdate_branchmode が、決定論的な.claude/skills/implement-issue/scripts/update_branch.pyを production code/Skill/Agent が使用する canonical supported path として使用する(導入: AIエージェント運用をminimal harnessへ縮退し、過剰なcontrol-planeを廃止する #1860 Owner Decision: 「唯一の実行経路」は canonical supported path の意味に限定し、raw command が技術的に不可能であるとは主張しない) - Desired Destination:
update_branch.pyが repository/PR番号/full SHA/caller/update method を API 呼び出し前に自己検証する.claude/skills/implement-issue/SKILL.mdと.claude/agents/implementation-worker.mdが、rawgh apiのインライン例を持たず、update_branch.pyの canonical invocation のみを production caller として記載する- raw update-branch endpoint(
gh api -X PUT .../update-branch系)が wrapper 内部実装以外の production caller に存在しないことが static inventory で示される update_branch.pyの exact invocation は root checkout の default branch から実行できる(Hook block/allow の有無に関わらず)
Current Validated Scope
current main(.claude/skills/implement-issue/scripts/update_branch.py、control-plane が直接 git show HEAD: で読取り確認済み)は既に次を実装している。
expected_head_shaの事前照合(_get_current_head_sha()で PR head を取得しcurrent_head_sha != expected_head_shaならstatus: blocked/reason_code: expected_head_sha_mismatchを返し API を呼ばない — race guard)- REST
PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch(gh api -i -X PUTを list argv で起動、shell 文字列を経由しない) - 202 Accepted 後の bounded poll(
poll_max/poll_interval引数、既定 12 回・5 秒間隔) - 403(
permission_blocked+_get_permission_diagnostics())/422(expected_head_shamismatch 再分類 orvalidation_failed)/429・secondary rate limit(_is_secondary_rate_limit()+_rate_limit_diagnostics())/transport error(returncode 非 0 かつ HTTP status 不明)の分類 - 更新成功後の
rerun_required: {verification: true, pr_review: true, reason: pr_head_changed_by_update_branch}postcondition
一方で、次は未実装または契約と不整合であることを確認済み。
--pr-numberはargparseのtype=intのみで正数チェックがない--repoに対する format/canonical repository 一致の検証がない--expected-head-shaに対する完全長 hexadecimal 文字列の検証がない--callerは任意文字列を許容し allowlist がない.claude/skills/implement-issue/SKILL.md:319に rawgh api -i -X PUT repos/$REPO/pulls/$PR_NUMBER/update-branchを直接実行するインライン bash 例が存在し、update_branch.pyを経由しない production caller になっている(static inventory の反例).claude/agents/implementation-worker.md:14の Bash 許可例外一覧に rawgh api -X PUT .../update-branchがそのまま記載されている.claude/hooks/local_main_branch_guard.sh/.claude/hooks/worktree_scope_guard.shは current main の.claude/settings.jsonのhooks.PreToolUseから削除済み(commitf971a95d, PR chore: local_main_branch_guard / worktree_scope_guard の2 hook を緊急停止する #1691)であり、.codex/hooks.jsonにも branch/worktree 系の PreToolUse blocking hook は一切登録されていない(SessionEnd/SubagentStopの advisory hook のみ)。Hook source file 自体(.sh/scripts/agent-guards/local_main_branch_guard.py等)は repo に現存するが runtime wiring から切断されている
Remaining Parent Gaps
なし
Outcome
implement-issue の update_branch Contract が、raw gh api の直接実行やインライン bash 例ではなく、次の canonical wrapper invocation のみを production caller として記載する契約へ変更されている。
uv run --locked python3 \
.claude/skills/implement-issue/scripts/update_branch.py \
--pr-number <pull-request-number> \
--repo squne121/loop-protocol \
--expected-head-sha <reviewed-head-sha> \
--caller impl-review-loop.step-5 \
--update-method merge_onlyupdate_branch.py は、次の入力検証を API 呼び出し前に自己完結で行う。
pr_number > 0repo == squne121/loop-protocolexpected_head_shaが完全長 hexadecimal commit SHAcallerが既知の production caller allowlist(impl-review-loop.step-5等)に含まれるupdate_method == merge_only- 上記いずれかに違反する場合、GitHub API を呼ばず
validation_failed(または既存の対応する reason code)を返す
.claude/skills/implement-issue/SKILL.md と .claude/agents/implementation-worker.md のどちらにも raw gh api -X PUT .../update-branch のインライン実行例・許可例外が残っておらず、両ファイルは update_branch.py の canonical invocation のみを参照する。static inventory(repository 全体 grep)により、raw update-branch endpoint 文字列が update_branch.py 内部実装以外に存在しないことを示す。
safety は Hook block/allow ではなく、次の decision で構成する(#1860 Owner Decision)。
update_branch.py自身の入力検証(上記)- repository binding(
--repoの厳密一致) - race guard(
expected_head_sha事前照合、mismatch 時は API 呼び出しをスキップ) - postcondition readback(更新後の実際の head SHA 取得と
rerun_requiredの設定) - FakeGhRunner を使った executor contract test(202/403/422/429/transport の分岐を決定論的に検証)
- 実際の diff・実テスト・current-head CI・independent review(PR review)・human stop
In Scope
update_branch.py の executor 契約強化、production caller(SKILL.md/implementation-worker.md/Step 5 routing)の統一、raw endpoint の static inventory、executor contract test を対象とする。Claude/Codex Hook、settings、Codex rules は対象外(次節参照)。
1. implement-issue 契約を update_branch.py に統一する
.claude/skills/implement-issue/SKILL.mdの## update_branch Contractを修正する- worker向け呼び出し形式を raw
gh apiインライン bash 例(現 319 行目)からupdate_branch.pyinvocation のみへ変更する - raw
gh apiは wrapper 内部実装としてのみ使用可能と明記する gh pr update-branchは引き続き使用しないUPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1の schema は維持する- wrapper が request schema を CLI引数へマッピングする規則を明記する
2. implementation-worker の許可コマンドを修正する
.claude/agents/implementation-worker.mdの Bash許可例外(現 14 行目)を次の形式へ変更する
uv run --locked python3 .claude/skills/implement-issue/scripts/update_branch.py ...
- raw
gh api -X PUT .../update-branchを許可例外として記載しない update_branchmode は wrapper(production supported path)を経由することを明記する。raw command が技術的に実行不可能であるとは主張しない
3. Step 5 routing の実行経路を修正する
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdの BEHIND 分岐を修正するimplementation-workerがupdate_branch.pyを実行することを明記する- REST呼び出し、202 poll、403 / 422分類は wrapper内部の責務とする
- orchestrator は
UPDATE_BRANCH_RESULT_V1のみを消費する
4. update_branch.py の入力境界を強化する
.claude/skills/implement-issue/scripts/update_branch.py に、次の入力検証を追加する(execute_update_branch 内、GitHub API 呼び出し前)。
pr_number > 0repo == squne121/loop-protocolexpected_head_shaが完全長 hexadecimal SHA(正規表現で検証)callerが明示的な production caller allowlist に含まれるupdate_method == merge_only(既存実装済み)- 不正入力時は GitHub APIを呼ばず
validation_failedまたは既存の対応 reason code を返す(既にupdate_methodについては実装済み。他の入力にも同一パターンを適用する) - GitHub CLI は既存どおり list argv で起動する(shell文字列を経由しない)
- 全ての
gh pr view/gh apiに明示的な repository bindingを使用する(既存実装済み、regression として維持) - production invocation では poll回数・poll間隔を callerから弱められない(productionから呼ぶ際の既定値を固定し、callerが緩和できないことをテストで固定する)
5. raw update-branch endpoint の static inventory を追加する
update_branch.py 以外の production path(.claude/skills/**/*.md、.claude/agents/*.md、.claude/skills/**/scripts/*.py、scripts/**/*.py)に、raw gh api ... update-branch または gh pr update-branch の実行例・呼び出しが存在しないことを検証する static inventory test を追加する。テスト fixture・Hook fixture・adversarial test 内の文字列(block/deny を検証する既存 Hook test 等)は inventory の対象から明示的に除外する(それらは実行例ではなく、無効化された Hook のための historical fixture である)。
Out of Scope
.claude/settings.jsonの変更.codex/rules/default.rulesの変更- Claude Code/Codex CLI Hook(
local_main_branch_guard、worktree_scope_guard等)の新規追加・復旧・修正 - Hook repair hint(
HOOK_COMMAND_REPAIR_HINT_V1等)の新規追加 - Hook parity/Hook subprocess テストの新規追加
- raw
gh api PUT .../update-branchの allowlist 追加 - raw
gh apiの実行を技術的に不可能にするという主張 gh pr update-branchの使用- GraphQL
updatePullRequestBranch - rebase update
- merge以外のupdate method
- Claude / Codexで別々のparserを実装すること
- GitHub repository setting / branch protectionの変更
UPDATE_BRANCH_RESULT_V1の不要なschema変更branch_force_delete_deniedの分類・repair hint・force delete allow/deny matrix・post-merge-cleanup guidance(実装: post-merge-cleanup の dedicated branch force delete lane を許可する #1403 の責務、変更しない)
Acceptance Criteria
- AC1:
implement-issue/SKILL.mdの update_branch Contract が rawgh apiのインライン bash 例ではなくupdate_branch.pyの canonical invocation のみを production caller として記載している - AC2:
implementation-worker.mdの Bash許可例外がupdate_branch.pyinvocationへ変更され、rawgh api update-branchが許可例外から削除されている - AC3: Step 5 BEHIND routing が
update_branch.pyをworker実行経路として参照している - AC4:
update_branch.pyが PR番号(正数)、repo(canonical 一致)、SHA(完全長 hex)、caller(allowlist)、update methodをAPI呼び出し前に検証し、違反時は GitHub API を呼ばず reason_code を返す - AC5: production path(
.claude/skills/**、.claude/agents/*.md、scripts/**)に rawgh api .../update-branchまたはgh pr update-branchの実行例・呼び出しがupdate_branch.py内部実装以外に存在しないことが static inventory test で確認できる(Hook fixture/adversarial test 内の文字列は明示的 allowlist で除外する) - AC6:
update_branch.pyの既存 202 / 403 / 422 / 429 / transport error contract testsが回帰なくPASSする - AC7: 既存の FakeGhRunner executor contract test(
test_given_preflight_mismatch_when_execute_then_block_before_rest_call)が、expected_head_shamismatch 時に API 呼び出しをスキップすること(race guard)を回帰なく検証し続けている - AC8: production invocation の poll 回数・poll 間隔が caller から緩和できないことがテストで固定されている
- AC9:
.claude/settings.json/.codex/rules/default.rules/.claude/hooks/**/scripts/agent-guards/local_main_branch_guard.py/.codex/hooks.jsonのいずれも本 Issue の diff に含まれない
Runtime Verification Applicability
runtime_verification_applicability:
decision: immediate
reason: "update_branch.py の入力検証・race guard・HTTP分類・postconditionは FakeGhRunner を使った subprocess/関数呼び出しレベルの決定論的テストでローカル検証できる。Hook wrapper のsubprocess起動は本 Issue のスコープ外であり証明対象にしない。"
applicable_acs:
- AC4
- AC5
- AC6
- AC7
- AC8
execution_environment: "WSL2 Ubuntu / repository pytest harness"
skip_conditions:
- "python3、uv のいずれかが存在せず、pytest を起動できない場合"
fallback_policy: "実 subprocess/関数呼び出しテストを実行できない場合、静的 grep のみでPASS扱いにせずruntime verificationをdeferredまたはblockedとして人間判断へ送る"
artifact_requirements:
- "update_branch REST contract test output"
- "raw update-branch static inventory test output"Verification Commands
# AC1
$ rg -n "update_branch.py" .claude/skills/implement-issue/SKILL.md
# baseline-expect: pass
$ rg -n "gh api -i -X PUT" .claude/skills/implement-issue/SKILL.md# AC2
$ rg -n "update_branch.py" .claude/agents/implementation-worker.md
# baseline-expect: pass
$ rg -n "update-branch" .claude/agents/implementation-worker.md# AC3
$ rg -n "update_branch.py" .claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md# AC4
$ uv run --locked pytest tests/agent_ops/test_update_branch_input_validation.py -v# AC5
$ uv run --locked pytest tests/agent_ops/test_update_branch_static_inventory.py -v# AC6
# baseline-expect: pass
$ uv run --locked pytest .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -v# AC7
# baseline-expect: pass
$ uv run --locked pytest .claude/skills/implement-issue/tests/test_update_branch_rest_contract.py -k "preflight_mismatch" -v# AC8
$ uv run --locked pytest tests/agent_ops/test_update_branch_poll_bounds.py -v# AC9
# baseline-expect: pass
$ git diff --name-only origin/main... -- .claude/settings.json .codex/rules/default.rules .claude/hooks scripts/agent-guards/local_main_branch_guard.py .codex/hooks.jsonAllowed Paths
.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/impl-review-loop/steps/step-5-mergeability-handling.md.claude/agents/implementation-worker.mdtests/agent_ops/test_update_branch_static_inventory.pytests/agent_ops/test_update_branch_input_validation.pytests/agent_ops/test_update_branch_poll_bounds.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- Hook、settings、Codex rules の変更が実装に必要と判明した場合(本 Issue のスコープ外であり着手しない)
UPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1の互換性を破壊する変更が必要な場合- repository permission / branch protection変更が必要な場合
- 外部サービス利用、権限昇格、既存テストの大規模改変が必要になった場合
Required Skills
- Python
- GitHub CLI / REST API
- pytest / FakeGhRunner パターン
Required Design References
.claude/skills/implement-issue/SKILL.md.claude/skills/implement-issue/scripts/update_branch.py.claude/agents/implementation-worker.md.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.md
Delivery Rule
1 Issue = 1 PR- 実装開始前に
issue-contract-reviewで freshCONTRACT_REVIEW_RESULT_V1 status: goを取得する - Dedicated worktreeを作成する
- Draft PRを既定とする
- PR本文に executor contract test の evidence を記載する
- live GitHub update-branchはruntime verificationとして実行しない
Scope Delta
旧Issue #1429の「raw gh api update-branch を Claude/Codex Hook で拒否し、正規 wrapper へ誘導する」設計を撤回する(#1860 Owner Decision: Hook は Child C/本系列の authority・security boundary・dependency・AC にしない)。
新しい設計では以下を採用する。
- safety は
update_branch.py自身の入力検証・race guard・postcondition readback・executor contract test・実 diff・実テスト・current-head CI・independent review・human stop で構成する - Hook block/allow、repair hint、Codex rules、settings permission による raw command の技術的拒否は実装しない
- raw update-branch endpoint が wrapper 内部以外に存在しないことは、Hook による拒否ではなく static inventory test で示す
- production caller(SKILL.md/implementation-worker.md)から raw
gh apiのインライン例を削除し、update_branch.pyの canonical invocation のみを記載する
Notes for Reviewer
- 本改訂は issue-refinement-loop(実装: Agent/Skill の重複を削減し progressive disclosure へ移行する #1732 Child C 改訂作業の一部)により、旧版(2026-07-XX 起票、Hook block/allow・Codex rules・settings.json 変更・Hook parity subprocess test を In Scope としていた版)を全面差し替えしたものである。旧版の historical comment は削除・改変していない。
- 撤回した理由:
#1860Owner Decision により、Claude Code/Codex CLI Hook はこの系列の authority・security boundary・dependency・AC にしないことが確定した。Hook は「local workflow guardrail であり security boundary ではない」(Claude Code 公式 Hooks reference、disableAllHooksで無効化可能、exit code 1 は non-blocking)ことが web research で確認されている。また現在local_main_branch_guard/worktree_scope_guardは.claude/settings.jsonのhooks.PreToolUseから既に削除済み(commitf971a95d, PR chore: local_main_branch_guard / worktree_scope_guard の2 hook を緊急停止する #1691)であり、Hook を dependency にすると現状の runtime と矛盾する。 - 維持した理由:
update_branch.pyの入力検証・race guard(expected_head_sha)・202 bounded poll・HTTP分類・postcondition readback は、Hook の有無に関わらず GitHub API 呼び出しの安全性を担保する実体であり、そのまま維持する。 update_branch.pyの内部gh api呼び出しはPythonのlist argv経由であり、shell command ではない- GitHub API response handlingは既存
FakeGhRunnercontract testsで継続検証する
Activity
squne121 commentedon Jul 11, 2026
you asked
message time: 2026-07-11 08:46:56
#1429
内容について関連Issue、PR、リポジトリ資産、コメントを参照した上で敵対的レビューして。
取り扱う技術や配布物の実装をWEB検索し高品質化してほしい。
chatgpt response
Issue #1429の本文・コメント・リンクされたIssue/PR・関連実装・リポジトリ規約を追い、外部仕様と照合して欠陥、曖昧さ、検証不足を優先度付きで整理します。変更操作は行わず、レビュー結果のみ返します。
現時点で、Issue本文のテスト配置指定と実際の専用テスト構成に不整合の兆候があります。また、リポジトリ設定では
allow_update_branchが無効であり、hook例外追加だけで運用目的を達成できるかは別途検証が必要です。ここから実装境界とGitHub API仕様を突き合わせます。設計上の核心は、既存の決定論的
update_branch.pyがあるにもかかわらず、root から生のgh apiを広く許可しようとしている点です。加えて、Issue の Allowed Paths は実際の guard テスト資産と一致せず、着手前 contract gate も未充足です。結論
判定: REQUEST_CHANGES。現状の Issue #1429 は、そのまま実装しても目的を達成できない可能性が高く、セキュリティ境界も過度に拡張します。
問題認識自体は正しいです。
implement-issueはPUT /pulls/{number}/update-branchの実行を契約している一方、local_main_branch_guardは既存の GET allowlist に一致しないgh apiをgh_api_not_allowedで遮断します。しかし、生の
gh apiをlocal_main_branch_guard.pyだけで許可する設計は不十分です。重大な指摘
P0-1:
local_main_branch_guardだけ直しても、次のworktree_scope_guardに止められるHook の実行順序は
secret → local_main → worktreeです。Issue #1429 が提案する変更で最初の guard を通過しても、worktree_scope_guardはgh api -X PUT ...を明示的にmutatingと分類します。active Issue と対応 worktree が解決されている場合、root から許可される例外は次のような exact executor に限定されています。
生の
gh apiはこの例外に該当しません。root の cwd が expected worktree 外であれば、最終的に block されます。PR #1421 は
worktree-issue-1420-...ブランチ上にあるため、Issue #1429 の発端となったフローでは、この条件に入る可能性が高いです。必要な修正:
local_main_branch_guardとworktree_scope_guardの双方が利用する shared policy / exact executor lane として設計する必要があります。P0-2: 生の
gh api許可は、既存の決定論的 wrapper を迂回している既に
.claude/skills/implement-issue/scripts/update_branch.pyが存在し、以下を実装しています。headRefOid照合expected_head_sha不一致時の API 呼び出し前停止Issue #1429 の raw-command classifier が確認できるのは、コマンドの外形だけです。次は確認できません。
IMPLEMENTATION_WORKER_REQUEST_V2由来かreviewed_head_shaと一致しているかimpl-review-loop.step-5かしたがって、条件に合う文字列を作れる caller は、同一リポジトリ内の任意の数値 PR に対して update を試行できます。
リポジトリには既に「raw mutation ではなく、共有 policy と exact executor を両 guard が消費して split-brain を防ぐ」という設計があります。
推奨: raw
gh apiは引き続き block し、既存update_branch.pyの canonical invocation だけを両 guard で許可してください。P0-3: 「default branch 上のみ」という条件が実装位置と一致していない
Issue は root checkout の default branch 上でのみ許可する意図ですが、指定された挿入位置は
gh_api_not_allowedより前です。この位置では、まだroot_stateが計算されていません。root_stateの判定は gh API 判定より後です。そのため、classifier が repo・PR番号・SHAしか検査しなければ、次の状態でも allow されます。
必要条件:
cwd == canonical main rootcurrent_branch == resolved default branchこれらを shared policy 内で検証すべきです。
P1-1: Allowed Paths とテスト対象が誤っている
Issue が Allowed Paths に含めている
scripts/agent-guards/tests/test_git_mutation_command_policy.pyは、local_main_branch_guardをテストしていません。git_mutation_command_policyのrtk git add/commit/pushを対象とする別のテストです。実際の専用テストは次です。
.claude/hooks/tests/test_local_main_branch_guard.pytests/codex/test_local_main_branch_guard.py.claude/hooks/tests/test_worktree_scope_guard.pyClaude / Codex の両テストには、既に raw
gh apimutation の回帰ケースがあります。Issue 本文は「専用テストがあればそちらを使用」としながら、その専用ファイルを Allowed Paths に含めていません。これは AC2 と Stop Conditions の自己矛盾です。
また、Verification Command が
rg "update-branch"だけでは、過剰許可、wrong repo、duplicate flags、drifted root、Codex parity、二段目 guard の block を一切検出できません。P1-2: Issue は implementation-ready ではない
Issue #1429 にはコメントがなく、fresh な Contract Snapshot /
CONTRACT_REVIEW_RESULT_V1 status: goが存在しません。implement-issue自身は次を開始条件にしています。go未充足なら停止する契約です。
Issue #1429 には Runtime Verification Applicability もありません。これは hook の allow/block を変更する runtime-sensitive Issue なので、
decision: immediateが妥当です。さらに、open な Issue #1403 が同じ
local_main_branch_guard.py、Claude/Codex parity tests、hook-boundaries docs を変更対象にしています。並行実装による競合と policy split を避けるため、少なくとも依存関係または統合順序を明記すべきです。P1-3: 許可するコマンド文法が固定されていない
実際の
implement-issue契約は、単なるではありません。
-i、Accept header、API version header を含む canonical command を定義しています。一方、GitHub CLI には次の挙動があります。
-f/-Fを付けると、明示しなければ method が POST に変わる-F value=@fileはファイルを読み込める--inputで任意 body を渡せる{owner}/{repo}は cwd またはGH_REPOから展開される--hostname、--preview、--paginateなど追加の意味を持つ flag がある(GitHub CLI)
raw command を許可するなら、少なくとも以下を拒否する必要があります。
-F、--field、--input--hostname-f--method=PUTなど canonical 以外の alias0、負数、巨大値現在の Issue はこの negative matrix を定義していません。
P1-4: fork・権限・repository setting の成立条件が未検証
GitHub の update-branch endpoint は単なる PR metadata 更新ではなく、base branch の HEAD を PR head branch に merge する操作です。GitHub App の場合は Pull Requests write に加え、head repository の Contents write 権限も必要です。fork PR では endpoint の owner/repo が base repo と一致していても、実際の書き込み先は別の head repository になり得ます。(GitHub Docs)
したがって、endpoint slug を現在の checkout に固定するだけでは十分ではありません。少なくとも次を preflight する必要があります。
headRepository.nameWithOwnerbaseRepository.nameWithOwnerisCrossRepositorymaintainerCanModifyまた、レビュー時点の GitHub connector metadata では、このリポジトリの
allow_update_branchはfalseでした。この設定がtrueの場合、branch freshness が merge 条件でなくても behind branch update を常時許可します。falseではその保証がないため、branch rules と実 PR を使った runtime verification が必要です。(GitHub Docs)P2: reason code とドキュメントの監査性が不足している
REASON_GITHUB_REMOTE_OPSを再利用すべきではありません。既存の分類では、これは主に Issue / PR comment や edit などの metadata operation 用です。update-branch は PR head の commit graph を変更する操作なので、同じ監査分類に混ぜるとログ上の意味が失われます。 (GitHub Docs)推奨値は例えば次です。
また、
docs/dev/hook-boundaries.mdは hook 責務の正本で、現在は allowlist 外gh apiをすべて block すると明記しています。Issue の Allowed Paths にこの正本が含まれていないため、実装後に policy/document drift が残ります。推奨する設計
推奨案: exact executor lane
生の
gh apiは許可せず、以下の canonical command だけを許可します。実装方針:
update_branch_command_policy.pyのような shared policy を作る。local_main_branch_guardとworktree_scope_guardが同じ判定関数を使用する。update_branch.py内で reviewed SHA / current PR / fork policy を検証する。gh apiは従来どおりgh_api_not_allowedにする。Issue #1429 に最低限必要な Scope Delta
Allowed Paths には少なくとも以下が必要です。
scripts/agent-guards/local_main_branch_guard.py.claude/hooks/worktree_scope_guard.py.claude/skills/implement-issue/scripts/update_branch.py.claude/skills/implement-issue/tests/test_update_branch_rest_contract.py.claude/hooks/tests/test_local_main_branch_guard.py.claude/hooks/tests/test_worktree_scope_guard.pytests/codex/test_local_main_branch_guard.py.claude/skills/implement-issue/SKILL.md.claude/agents/implementation-worker.mddocs/dev/hook-boundaries.md.claude/settings.jsonAcceptance Criteria には、次を追加すべきです。
gh api update-branchは引き続き拒否されるIssue #1429 は「raw API の narrow allowlist追加」ではなく、「既存 update_branch wrapper を両 guard 共通の exact executor lane に接続する Issue」へ再 refinement するのが妥当です。
you asked
message time: 2026-07-11 09:10:48
implement-issue の PUT /pulls/{number}/update-branch 実行契約を update_branch.pyに修正する
生の gh api PUT /pulls/{number}/update-branch を実行しようとした際にブロックしながらupdate_branch.pyの実行へ誘導するClaudeCodeとCodexCLIのhooksを作成する。
実装時はClaudeCodeとCodexCLIのhooksの動作検証をする。
chatgpt response
Issue #1429を「raw
gh apiの許可」から「update_branch.pyを唯一の実行経路とし、raw API は拒否しつつ修復コマンドへ誘導する」契約へ組み替えます。Claude Code/Codex CLI双方の実hook検証までACとVCに固定します。既存構成では Claude Code と Codex CLI の各 wrapper が同じ
local_main_branch_guard.pyを呼ぶため、独立hookを重複追加するより、共通policyと既存hookを拡張する方が整合的です。update_branch.pyの exact invocation は両guardで許可し、raw APIは最初のguardで専用理由コードと修復ヒントを返す構成にします。方針は妥当です。既存の Claude Code/Codex CLI wrapper は同じ
local_main_branch_guard.pyを呼ぶため、新しい独立hookを増やさず、共通policy・両guard・既存hook入口を拡張します。また、
update_branch.pyには既に race guard、REST呼び出し、202後のpoll、エラー分類が実装されています。これを唯一の実行経路として契約化します。**Document Title: **
実装: update_branch.py を唯一の branch update 経路にし raw gh api を Claude/Codex hooks で拒否・誘導する
Machine-Readable Contract
Parent Issue
なし(単独改善)
Parent Goal Ref
implementation-workerのupdate_branchmode が、決定論的な.claude/skills/implement-issue/scripts/update_branch.pyを唯一の実行経路として使用するgh api -X PUT .../update-branchは引き続き hook で拒否されるupdate_branch.pyの正規コマンドが machine-readable repair hint として提示されるupdate_branch.pyの exact invocation は root checkout の default branch から実行できるCurrent Validated Scope
.claude/skills/implement-issue/scripts/update_branch.pyは既に次を実装しているexpected_head_shaの事前照合PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch.claude/skills/implement-issue/SKILL.mdは現在、worker が rawgh apiを直接実行する形式を契約しており、実装済み wrapper と契約が一致していない.claude/hooks/local_main_branch_guard.shと Codex CLI の.codex/hooks/local_main_branch_guard.shは、共通のscripts/agent-guards/local_main_branch_guard.pyを呼び出しているgh apiはlocal_main_branch_guard.pyのgh_api_not_allowedで拒否されるが、update_branch.pyへの専用誘導がないupdate_branch.py実行はworktree_scope_guard.pyの exact executor 例外にも登録する必要があるRemaining Parent Gaps
なし
Outcome
implement-issueのupdate_branch Contractが、rawgh apiの直接実行ではなく、次の canonical wrapper invocation を使用する契約へ変更されている。Claude Code / Codex CLI から次のような raw API を実行しようとした場合は、既存の
local_main_branch_guardhook が exit 2 で拒否する。拒否時の stderr には、専用の reason code と
HOOK_COMMAND_REPAIR_HINT_V1が出力され、update_branch.pyの canonical invocation へ誘導される。一方、canonical
update_branch.pyinvocation は、以下の条件をすべて満たす場合に限り、local_main_branch_guardとworktree_scope_guardの双方で許可される。update_branch.pyと realpath 一致squne121/loop-protocolと一致--repoがsqune121/loop-protocol--pr-numberが正の整数--expected-head-shaが完全長の hexadecimal commit SHA--callerがimpl-review-loop.step-5--update-methodがmerge_only--flag=value、shell wrapper、compound command、leading env assignmentが存在しないClaude Code と Codex CLI の実hook wrapperを subprocess で起動するテストにより、raw API の拒否、repair hint、canonical wrapper の許可、stdout/stderr contract が検証されている。
In Scope
1. implement-issue 契約を update_branch.py に統一する
.claude/skills/implement-issue/SKILL.mdの## update_branch Contractを修正するgh apiからupdate_branch.pyinvocation へ変更するgh apiは wrapper 内部実装としてのみ使用可能と明記するgh pr update-branchは引き続き使用しないUPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1の schema は維持する2. implementation-worker の許可コマンドを修正する
.claude/agents/implementation-worker.mdの Bash許可例外を次の形式へ変更するgh api -X PUT .../update-branchを許可例外として記載しないupdate_branchmode は wrapper以外を使用しないことを明記する3. Step 5 routing の実行経路を修正する
.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdの BEHIND 分岐を修正するimplementation-workerがupdate_branch.pyを実行することを明記するUPDATE_BRANCH_RESULT_V1のみを消費する4. update_branch.py の入力境界を強化する
.claude/skills/implement-issue/scripts/update_branch.pyに、少なくとも次の入力検証を追加または固定する。pr_number > 0repo == squne121/loop-protocolexpected_head_shaが完全長 hexadecimal SHAcaller == impl-review-loop.step-5update_method == merge_onlyvalidation_failedまたは既存の対応 reason code を返すgh pr view/gh apiに明示的な repository bindingを使用する5. shared update-branch command policy を追加する
scripts/agent-guards/update_branch_command_policy.pyを新設し、両guardから使用する。提供する判定は少なくとも次の2種類とする。
raw API attempt detector
次の endpoint を対象とする raw
gh api呼び出しを識別する。識別結果は allow に使用せず、専用の block reason と repair hint の選択にのみ使用する。
exact executor classifier
次の script invocation のみを認識する。
以下を拒否する。
python -c/tmp配下の wrapperbash -c/bash -lc/sh -cenv VAR=...--flag=value6. local_main_branch_guard の block / allow を追加する
scripts/agent-guards/local_main_branch_guard.pyに以下を追加する。raw API block
raw
gh api .../update-branchを検出した場合:一般的な
gh_api_not_allowedより前に専用分類するが、allowにはしない。canonical wrapper allow
exact
update_branch.pyinvocation の場合:malformed な wrapper-like command は generic default allowへ落とさず fail-closed にする。
7. worktree_scope_guard に exact executor 例外を追加する
.claude/hooks/worktree_scope_guard.pyが shared policy を使用し、active issue worktree が存在する場合でも、canonical root/default branchからの exactupdate_branch.pyinvocation を許可する。gh apiは例外対象にしないlocal_main_branch_guardと独立した判定実装を複製しない8. repair hint を追加する
scripts/agent-guards/hook_repair_hints.pyにraw_update_branch_api_requires_wrapper用の専用hintを追加する。repair hintには raw command全文、認証情報、環境変数、header値を出力しない。
9. Claude Code / Codex CLI command permission を整合させる
.claude/settings.jsonに canonicalupdate_branch.pyinvocation の許可を追加する.codex/rules/default.rulesに canonicalupdate_branch.pyinvocation の exact allow ruleを追加するgh api update-branchを静的allow ruleとして追加しないcodex execpolicy checkで検証する10. hook boundary document を更新する
docs/dev/hook-boundaries.mdに以下を追加する。gh api update-branchはraw_update_branch_api_requires_wrapperでblockupdate_branch.pyは exact executorとしてallowupdate_branch.pyが担当する11. Claude Code / Codex CLI の実hook動作を検証する
mock関数だけでなく、実際の shell wrapperを subprocess で起動する。
Claude Code
対象:
検証:
update_branch.pyの修復コマンドCodex CLI
対象:
検証イベント:
PreToolUsePermissionRequest検証:
hook動作検証では実際のGitHub branch更新を実行しない。raw APIはhookで実行前に拒否し、canonical wrapperについてはhook classifierのallow判定までを実wrapperで検証する。wrapper内部のREST処理は
FakeGhRunnerを使用した既存contract testで検証する。Out of Scope
gh api PUT .../update-branchのallowlist追加gh apiの実行許可gh pr update-branchの使用updatePullRequestBranchgh apiに対するrepair hint拡張UPDATE_BRANCH_RESULT_V1の不要なschema変更Acceptance Criteria
implement-issue/SKILL.mdの update_branch Contract が rawgh apiではなくupdate_branch.pyの canonical invocation を実行経路としているimplementation-worker.mdの Bash許可例外がupdate_branch.pyinvocationへ変更され、rawgh api update-branchが許可例外から削除されているupdate_branch.pyをworker実行経路として参照しているupdate_branch.pyが PR番号、repo、SHA、caller、update methodをAPI呼び出し前に検証するupdate_branch_command_policy.pyが canonical wrapperのexact argvとcontextを判定するgh api .../update-branchはraw_update_branch_api_requires_wrapper/gh_api_update_branch_raw_deniedでblockされるHOOK_COMMAND_REPAIR_HINT_V1が canonicalupdate_branch.pycommandを提示するlocal_main_branch_guardを通過するworktree_scope_guardを通過するgh apiは従来どおりgh_api_not_allowedでblockされる.claude/settings.jsonと.codex/rules/default.rulesがcanonical wrapperを許可し、raw APIを新規allowしていないdocs/dev/hook-boundaries.mdが専用reason code、wrapper-only policy、Claude/Codex parityを記述しているupdate_branch.pyの既存202 / 403 / 422 / 429 / transport error contract testsが回帰なくPASSするRuntime Verification Applicability
Verification Commands
Allowed Paths
.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/impl-review-loop/steps/step-5-mergeability-handling.md.claude/agents/implementation-worker.mdscripts/agent-guards/update_branch_command_policy.pyscripts/agent-guards/tests/test_update_branch_command_policy.pyscripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/hook_repair_hints.py.claude/hooks/worktree_scope_guard.py.claude/hooks/tests/test_local_main_branch_guard.py.claude/hooks/tests/test_worktree_scope_guard.pytests/codex/test_local_main_branch_guard.py.claude/settings.json.codex/rules/default.rulesdocs/dev/hook-boundaries.mdVerification-Only Paths
以下は実装時に編集せず、実hook entrypointとしてsubprocess実行する。
.claude/hooks/local_main_branch_guard.sh.claude/hooks/worktree_scope_guard.sh.codex/hooks/local_main_branch_guard.sh.codex/hooks/worktree_scope_guard.sh.codex/hooks.jsonStop Conditions
gh api update-branchをallowしなければ実現できないと判明した場合UPDATE_BRANCH_REQUEST_V1/UPDATE_BRANCH_RESULT_V1の互換性を破壊する変更が必要な場合Required Skills
Required Design References
.claude/skills/implement-issue/SKILL.md.claude/skills/implement-issue/scripts/update_branch.py.claude/agents/implementation-worker.md.claude/skills/impl-review-loop/steps/step-5-mergeability-handling.mdscripts/agent-guards/local_main_branch_guard.pyscripts/agent-guards/hook_repair_hints.pyscripts/agent-guards/controlled_skill_mutation_policy.py.claude/hooks/worktree_scope_guard.py.claude/hooks/local_main_branch_guard.sh.codex/hooks/local_main_branch_guard.shdocs/dev/hook-boundaries.mdDelivery Rule
1 Issue = 1 PRissue-contract-reviewで freshCONTRACT_REVIEW_RESULT_V1 status: goを取得するScope Delta
旧Issue #1429の「raw
gh api update-branchをallowlistへ追加する」設計を撤回する。新しい設計では以下を採用する。
update_branch.py内部だけで実行Notes for Reviewer
local_main_branch_guardwrapperが存在するため、共通guardとshared policyを拡張するupdate_branch.pyの内部gh api呼び出しはPythonのlist argv経由であり、hookが受け取る生のBash commandではないFakeGhRunnercontract testsで継続検証するこの内容なら、旧 #1429 の raw allowlist 方針を完全に撤回し、wrapper-only設計と実hook検証を一つのIssueに固定できます。GitHub上のIssue本文はまだ変更していません。
[-]実装: local_main_branch_guard に gh api update-branch の allowlist 例外を追加する[/-][+]実装: update_branch.py を唯一の branch update 経路にし raw gh api を Claude/Codex hooks で拒否・誘導する[/+]squne121 commentedon Jul 11, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jul 11, 2026
Contract Review Result
fix: overlap_readback_waiver 期限切れの決定を明文化する (#1518) (#1522)
squne121 commentedon Jul 20, 2026
Sequencing 決定(OWNER 判断、#1657 側 overlap preflight にて記録)
#1657(
実装: worktree mutation guard を AI エージェント非依存の shared core へ移行する)を最優先とし、先にマージする。本 Issue(#1429)の Allowed Paths には.claude/hooks/worktree_scope_guard.pyとscripts/agent-guards/local_main_branch_guard.pyが含まれるが、#1657 はworktree_scope_guard.pyを.claude/hooks/からscripts/agent-guards/worktree_scope_guard.pyへ移設する計画である。本 Issue の実装着手前に、以下を確認すること:
worktree_scope_guardへの allowlist 追加は、移設後の配置(scripts/agent-guards/worktree_scope_guard.py)を対象にする.claude/hooks/worktree_scope_guard.pyは 実装: worktree mutation guard を AI エージェント非依存の shared core へ移行する #1657 マージ後は薄い adapter(または削除済み)になっている可能性があるため、本 Issue の Allowed Paths / In Scope の該当箇所は 実装: worktree mutation guard を AI エージェント非依存の shared core へ移行する #1657 マージ後に readback して更新することblocked_by: #1657として本 Issue の着手順序を記録する(#1657 側 overlap preflight の HUMAN_C1_DECISION_V1 記録: #1657 (comment) )。squne121 commentedon Aug 5, 2026
#1732 系列 issue-refinement-loop による本文改訂(2026-08-05)
#1860(Minimal harness decision)の Owner Decision を反映し、本 Issue の本文を全面改訂しました。撤回した契約:
local_main_branch_guard/worktree_scope_guard)による rawgh api update-branchの block/allowHOOK_COMMAND_REPAIR_HINT_V1repair hint.claude/settings.json/.codex/rules/default.rulesの変更理由:
#1860Owner Decision により、Claude Code/Codex CLI Hook はこの系列の authority・security boundary・dependency・AC にしないことが確定しました。Hook は「local workflow guardrail であり security boundary ではない」(Claude Code 公式 Hooks reference:disableAllHooksで無効化可能、exit code 1 は non-blocking)ことを web research で確認しています。また現在local_main_branch_guard/worktree_scope_guardは.claude/settings.jsonのhooks.PreToolUseから既に削除済み(commitf971a95d, PR #1691)であり、Hook を dependency にすると現状の runtime と矛盾していました。維持した契約(executor safety):
update_branch.py自身の入力検証(PR番号・repo・SHA形式・caller・update method)expected_head_shaによる race guard(GitHub API 呼び出し前の事前照合)update_branch.pyの race guard・202 poll・HTTP分類・postcondition は既に current main に実装済みであることを control-plane がgit show HEAD:で直接確認済みです(本 Issue は主に入力検証の強化と、SKILL.md/implementation-worker.md からの raw API インライン例の除去を扱います)。本改訂は #1732 系列の issue-refinement-loop の一部です。旧本文は削除せず、上記コメントの下に新本文として反映します。
squne121 commentedon Aug 5, 2026
issue-refinement-loop iteration 2(review needs-fix 対応)
前回改訂に対する issue-reviewer レビューで、Verification Commands の VC パターンに関する blocker が指摘されました。以下を修正しました。
# baseline-expect: pass注記を追加-kフィルタで既存テストファイルの未実装テスト関数を参照していた VC を、新規専用テストファイルtests/agent_ops/test_update_branch_input_validation.pyの参照へ変更(Issue 実装: VC baseline-fail 用 pytest command を canonical form に正規化して contract-review 往復を削減する #1285 / PR feat: VC baseline-fail pytest command を canonical form に正規化する compiler を追加 #1305 の VC パターン規約に準拠)test_given_preflight_mismatch_when_execute_then_block_before_rest_call、current main に実在確認済み)への参照へ変更し、回帰確認の意味であることを明記tests/agent_ops/test_update_branch_poll_bounds.pyへの参照へ変更issue-contract-review の pre-edit static readiness check で
status: goを再確認済みです。squne121 commentedon Aug 5, 2026
issue-refinement-loop iteration 3(review needs-fix 対応、最終)
前回(iteration 2)の再レビューで、AC1/AC2 の VC アノテーションに誤りがあることが判明しました。control-plane が
git grep -n "update_branch.py" HEAD -- .claude/skills/implement-issue/SKILL.md .claude/agents/implementation-worker.mdを直接実行して確認したところ、現時点でこの文字列はどちらのファイルにも存在しません(exit 1)。一方、gh api -i -X PUT(SKILL.md)とupdate-branch(implementation-worker.md)は現時点で実在します(exit 0)。このため、各 AC の VC 2行のうち 1行目(
update_branch.pyの存在確認)は通常の baseline-fail 想定のまま(# baseline-expect: pass注記を削除)とし、2行目(raw API 例の存在確認)にのみ# baseline-expect: passを残しました。修正後、
contract_readiness_check.py --mode preflight-staticでstatus: goを再確認済みです。[-]実装: update_branch.py を唯一の branch update 経路にし raw gh api を Claude/Codex hooks で拒否・誘導する[/-][+]実装: update_branch.py を canonical branch-update executor に統一し、入力・race・postcondition を自己検証する[/+]squne121 commentedon Aug 5, 2026
タイトル更新(issue-refinement-loop 追記)
旧タイトル「実装: update_branch.py を唯一の branch update 経路にし raw gh api を Claude/Codex hooks で拒否・誘導する」は、本文改訂(Hook block/allow の撤回)と矛盾していたため、Owner Decision の推奨タイトルへ変更しました。
新タイトル: 実装: update_branch.py を canonical branch-update executor に統一し、入力・race・postcondition を自己検証する
squne121 commentedon Aug 5, 2026
impl-review-loop: 完了 (2026-08-05T12:21:39Z)
e2e/ci-verdict-summaryjob 失敗は本 PR の変更(update_branch.py 等)と無関係な既存 VRT(title-menu / combat HUD / pause dialog スクリーンショット)フレークであり blocker としない。mergeable: MERGEABLE、conflict なし。fix(update-branch): static inventory を回避不能にし postcondition を祖先検証で固める
squne121 commentedon Aug 5, 2026
impl-review-loop: 完了 (2026-08-05T13:54:23Z)
経緯サマリ
実装: update_branch.py を canonical branch-update executor に統一する (#1999)
squne121 commentedon Aug 5, 2026
post-merge-cleanup: 完了 (2026-08-05T14:10:57Z)
補足
worker(post-merge-cleanup-worker)の cleanup_exec は worktree が detached HEAD 状態だったため
worktree_branch_mismatchで自動削除を拒否した(status: partial,human_review_required: true)。人間承認を得た上で、PR #1999 が MERGED・Issue #1429 が CLOSED・worktree に未コミット変更なし・remote branch が既に削除済みであることを確認してから、git worktree remove .claude/worktrees/issue-1429-update-branch-canonical-executorとgit branch -D worktree-issue-1429-update-branch-canonical-executorを手動実行しクリーンアップを完了した。fix(#2102): wire main-drift reconciliation into production routing an…
fix(loop): main drift evidence を再束縛する (#2102) (#2118)