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: "impl-review-loop Step 5 の production consumer を import 可能な実体として追加し、LOOP_VERDICT_V2.required_auto_actions[].kind|executor|skill と TEST_VERDICT_MACHINE/v1.branch_behind_main を shadow router ではなく本物の consumer 経路で fail-closed に検証できる状態にする"
change_kind: workflowParent Issue
Parent Goal Ref
- Goal: impl-review-loop の V2 routing boundary を docs/tests に登録しただけでなく、production consumer がその boundary を実際に消費して unknown / inconsistent input を fail-closed に扱う状態にする
- Desired Destination: Step 5 routing regression が shadow 実装なしで production consumer を直接叩いて PASS する
Current Validated Scope
.claude/skills/impl-review-loop/scripts/配下に Step 5 routing 判定の importable consumer module を追加する.claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.pyの shadow helper を production consumer import ベースへ置き換える.claude/skills/impl-review-loop/tests/test_termination_gate.pyの shadow helper を production consumer import ベースへ置き換える.claude/skills/impl-review-loop/tests/fixtures/step5_routing_consumer/配下にrequired_auto_actions.kind/executor/skillとbranch_behind_main整合を検証する fixture を追加する
Remaining Parent Gaps
- GitHub REST
pulls/{pull_number}/update-branchの write-side 実装強化とexpected_head_shaの 202/403/422 handling は別 Issue で扱う - Step 5 の既存 markdown 本文自体の大幅な wording 再整理は本 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
.claude/skills/impl-review-loop/scripts/ 配下の production consumer が required_auto_actions[].kind/executor/skill と TEST_VERDICT_MACHINE/v1.branch_behind_main を fail-closed に解釈し、対応する regression test が shadow 実装なしで PASS している状態。
In Scope
- Step 5 routing 判定の共通 entrypoint を 1 箇所に実装する
required_auto_actions.kind/executor/skillの正規組み合わせを production consumer で判定し、unknown / missing / mismatched 値を fail-closed にするTEST_VERDICT_MACHINE/v1.branch_behind_mainとLOOP_VERDICT_V2.mergeability.merge_state_statusの整合条件を production consumer で判定し、不一致を fail-closed にする- 既存 regression test をローカル helper 関数ではなく production consumer import ベースへ置き換える
- fixture で
BEHIND + update_branch、body-only required_auto_actions、branch_behind_main=true + CLEAN、branch_behind_main=false + BEHINDを固定する route_loop_verdict_v2.pyは import 時に副作用を持たず、gh/git/network/subprocess を呼ばない pure consumer module として実装するrequired_auto_actionsは array-of-objects のみを受け付け、string-list / V1recommendations/ camelCase は fail-closed または schema_invalid として扱うapply_pr_review_fix_deltaはpr-review-judgeschema 外の action として fail-closed にする(許容しない)LOOP_VERDICT_V2schema とagent-skill-boundaries.mdの boundary 定義を production consumer の正本とし、step-5-mergeability-handling.mdの Bash snippet を参照しない
Out of Scope
- GitHub REST
pulls/{pull_number}/update-branchの呼び出し実装変更 - implementation-worker の
update_branchmode の write-side 挙動変更 expected_head_shaと current PR head の API レベル照合ロジックの実装pr-review-judgeproducer 側 schema の追加変更.claude/agents/test-runner.mdの schema 追加変更.claude/skills/impl-review-loop/steps/*.mdの広範な wording 整理
Acceptance Criteria
- AC1:
.claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.pyが追加され、import 時に副作用を持たず gh/git/network/subprocess を呼ばない pure consumer module である - AC2:
route_loop_verdict_v2(loop_verdict, test_verdict=None) -> RouteDecisionを public API として提供し、RouteDecisionはroute/fail_closed/reason_code/rerun_required/selected_action/errorsフィールドを持つ - AC3:
test_handoff_pr_hygiene_regression.pyとtest_termination_gate.pyからローカル shadow helper(_evaluate_termination_route/_evaluate_route/_route_required_auto_action/ ローカルALLOWED_ACTION_KINDS)を削除し、production consumer import のみで routing 判定を行う - AC4:
kind=update_branch/executor=implementation-worker/skill=implement-issue.update_branch/blocking_merge_ready=true/mechanical=trueの正規 matrix のみがroute_to_update_branchを返し、skill=implement-issue(サブコマンドなし)を含む欠落・未知・不一致はすべて fail-closed になる - AC5:
required_auto_actionsの kind / executor / skill / blocking_merge_ready / mechanical / expected_head_sha の missing / unknown / mismatched はすべて fail-closed reason_code を返す - AC6:
TEST_VERDICT_MACHINE/v1.branch_behind_mainとLOOP_VERDICT_V2.mergeability.merge_state_statusの整合 invariant を実装する。true + BEHINDのみ behind とみなし、true + CLEAN、false + BEHIND、missing、非 bool、null、UNKNOWN、CONFLICTING、DIRTY、UNSTABLE、BLOCKEDは autoupdate_branchroute に入らない - AC7:
required_auto_actionsは array-of-objects のみ受け付け、string-list [update_branch]、V1recommendations、camelCasemergeStateStatusは fail-closed または schema_invalid とする - AC8:
tests/fixtures/step5_routing_consumer/の fixture が positive case に加えて、wrong executor・wrong skill・skill=implement-issue(サブコマンドなし)・missing skill・unknown kind・apply_pr_review_fix_delta・body-only action・multiple actions・branch_behind_main不整合を含む negative case を網羅する - AC9:
rg -n "_evaluate_termination_route|_evaluate_route|_route_required_auto_action|ALLOWED_ACTION_KINDS" .claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py .claude/skills/impl-review-loop/tests/test_termination_gate.pyが非ゼロ終了(shadow helper がテストファイルに残っていない) - AC10:
uv run pytest .claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py .claude/skills/impl-review-loop/tests/test_termination_gate.py -vが PASS し、production consumer module の単体 test も node 指定で通る
Verification Commands
# AC1
$ test -f .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC2
$ rg -n "def route_loop_verdict_v2|class RouteDecision|fail_closed|reason_code|rerun_required|selected_action" .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC3
# preflight-scope: runtime_only
$ uv run pytest .claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py .claude/skills/impl-review-loop/tests/test_termination_gate.py -v
# AC4
$ rg -n "implement-issue\.update_branch|executor.*implementation-worker|kind.*update_branch|fail_closed|skill.*implement-issue[^.]" .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC5
$ rg -n "missing|unknown|mismatched|fail_closed|expected_head_sha|blocking_merge_ready|mechanical" .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC6
$ rg -n "branch_behind_main|merge_state_status|UNKNOWN|CONFLICTING|DIRTY|UNSTABLE|BLOCKED" .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC7
$ rg -n "array.of.objects|schema_invalid|string.list|recommendations" .claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py
# AC8
$ rg -n "wrong_executor|wrong_skill|apply_pr_review_fix_delta|body.only|missing_skill|unknown_kind" .claude/skills/impl-review-loop/tests/fixtures/step5_routing_consumer
# AC9
$ rg -n "_evaluate_termination_route|_evaluate_route|_route_required_auto_action|ALLOWED_ACTION_KINDS" .claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py .claude/skills/impl-review-loop/tests/test_termination_gate.py
# AC10
# preflight-scope: runtime_only
$ uv run pytest .claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py .claude/skills/impl-review-loop/tests/test_termination_gate.py -vAllowed Paths
.claude/skills/impl-review-loop/scripts/route_loop_verdict_v2.py.claude/skills/impl-review-loop/tests/test_handoff_pr_hygiene_regression.py.claude/skills/impl-review-loop/tests/test_termination_gate.py.claude/skills/impl-review-loop/tests/fixtures/step5_routing_consumer/
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- implementation-worker / GitHub update-branch API write-side 実装変更が必要と判明した場合
Required Skills
- Python / pytest
- YAML parsing
- workflow routing contract review
Scope Delta(任意)
N/A
Runtime Verification Applicability
decision: not_applicable
reason: "Workflow consumer module and regression 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/454#issuecomment-4661754386を一次ソースとして扱う
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phase
Activity
squne121 commentedon Jun 15, 2026
総合判定: REQUEST_CHANGES
#777 は方向性自体は正しいです。#454/#774 で「V2 routing boundary を docs/tests に登録する」までは進んだが、実テストは production consumer ではなく shadow helper を叩いており、
executor/skillまで routing-critical と宣言した割に fail-closed 検証が弱い。その残タスクを production consumer 化として切り出したのが #777 です。#777 自体は open でコメントは 0 件、実装 PR は確認できていません。従ってこれは「実装前の Issue contract への敵対的レビュー」です。関連の流れとしては、#630 が
LOOP_VERDICT_V2.merge_ready / required_auto_actionsを導入し、#632 がAPPROVE && merge_ready && required_auto_actions == []を termination 条件に統一し、#454/#774 がそれを docs/tests に固定した。ただし #454 は producer/consumer 本体変更を Out of Scope にしていたため、real consumer が壊れていない保証は残っていません。#778 は update_branch の write-side executor を REST +expected_head_sha+ classifier test で堅牢化する別スコープで、#777 はその前段の「誤った action を流さない consumer gate」です。Merge blocker 1: 現行テストは実装を守っていない
現在の
test_handoff_pr_hygiene_regression.pyには_evaluate_termination_route()というローカル関数があり、コメントでも「テスト検証専用のローカル実装」「scripts/ への抽出は別 Issue」と明記されています。つまり regression test が production path ではなく、テスト内の shadow router の正しさを検証しているだけです。#777 の主目的はこの構造を消すことなので、単にroute_loop_verdict_v2.pyを追加するだけでは不十分で、既存 shadow helper の削除を AC と VC に明示すべきです。同じ問題は #454 の dedicated test にもあります。
test_v2_routing_boundary_regression.pyはALLOWED_ACTION_KINDSと_route_required_auto_action()をテスト内に定義しており、production consumer ではなくローカル判定器を検証しています。この関数はkindとexpected_head_shaだけを実質的に見ており、executor/skillの fail-closed 判定をしていません。Merge blocker 2:
skillの正規値が既にズレている#777 の AC4 は
kind=update_branch / executor=implementation-worker / skill=implement-issue.update_branchを正規組み合わせにしています。一方、既存 fixturev2_update_branch_behind.ymlはskill: implement-issueです。これは軽微な表記差ではありません。skillを routing-critical field にするなら、implement-issueとimplement-issue.update_branchは別値として扱い、前者は fail-closed に落とすべきです。さらに
pr-review-judge側の schema もskill: open-pr.update_pr | implement-issue.update_branchを明記しており、update_branchではexpected_head_shaが必須です。#777 はこの schema を一次契約として採用し、古い fixture のimplement-issueを互換許容してはいけません。互換許容した瞬間、skillを routing-critical と宣言した意味が消えます。Merge blocker 3:
executor/skillを fail-closed にするテストが足りない現行 #454 test は positive case で
executor == implementation-workerとskill == implement-issueを assert しているだけです。unknown kind と expected_head_sha guard はあるが、missing executor、unknown executor、missing skill、wrong skill、skill=implement-issuevsskill=implement-issue.update_branch、executor=pr-reviewerのような adversarial case は production route に入る可能性を検証していません。agent-skill-boundaries.mdはLOOP_VERDICT_V2.required_auto_actions[].kind / executor / skill / expected_head_shaを routing-critical として登録し、unknown kind と missing/mismatched expected_head_sha は fail-closed としています。しかしexecutor/skillの negative rule が明文化されていないため、#777 側で補わないと「routing-critical と書いたが実際は読まない」状態になります。Merge blocker 4: Step 5 docs に V1/文字列リスト前提がまだ残っている
step-5-feedback-and-termination.mdはrequired_auto_actionsを YAML array of objects として parse し、unknown kind/executor/skill、blocking_merge_ready != true、expected_head_sha欠落を human escalation にする、としています。これは #777 の方向性と整合しています。しかし
step-5-mergeability-handling.md側は、Bash 抽出例でREQUIRED_AUTO_ACTIONSを[]または[update_branch]/[update_pr_body_hygiene]/[ensure_closing_keyword]として扱っています。これは array-of-objects schema と矛盾します。さらに BEHIND 分岐にはrecommendations: [update_branch]という V1 wording が残っています。#777 は「大幅な wording 再整理は Out of Scope」としていますが、production consumer の正本を作るなら、少なくともこの doc を executable source として参照しないことを明記しないと、実装者が誤って文字列リスト互換を再導入します。Merge blocker 5:
branch_behind_mainの invariant が狭すぎる#777 は
branch_behind_main=true + CLEANとbranch_behind_main=false + BEHINDの fail-closed を AC5 に入れています。これは必要ですが十分ではありません。production consumer では以下も fail-closed にすべきです。branch_behind_mainが missing、非 bool、文字列"true"、null、またはmerge_state_statusがUNKNOWN/UNSTABLE/BLOCKED/DIRTY/CONFLICTINGのときに update_branch route が発火するケースです。Step 5 docs は merge state にCLEAN、UNSTABLE、BEHIND、BLOCKED、DIRTY、CONFLICTING、UNKNOWNを扱っているので、CLEAN/BEHIND の二点だけでは境界条件を網羅していません。Merge blocker 6:
apply_pr_review_fix_deltaの扱いが schema と衝突している#454 の shadow helper は
ALLOWED_ACTION_KINDSにapply_pr_review_fix_deltaを含めています。しかしpr-review-judgeの required_auto_actions schema はensure_closing_keyword | update_pr_body_hygiene | update_branchの 3 種を列挙しています。#777 が production consumer を作るなら、apply_pr_review_fix_deltaを許容するのか、別 schema の action として拒否するのかを明示する必要があります。曖昧に許可すると、producer schema 外の action が consumer で通る fail-open になります。Web 調査に基づく実装上の注意
update_branchは安全な “recommendation” ではなく、PR branch を更新する write operation です。GitHub REST のUpdate a pull request branchは base branch の HEAD を PR branch に merge し、GitHub App では head repository contents write、fine-grained token では Pull requests write permission が必要です。またexpected_head_shaが PR head と一致しない場合は 422、通常の応答として 202/403/422 が定義されています。したがって consumer はupdate_branchaction を厳格に検証し、少しでも schema が崩れたら #778 の executor へ渡す前に止めるべきです。([GitHub Docs]1)gh pr update-branchはデフォルトで base branch を PR branch に merge commit として取り込む挙動です。#777 自体は CLI/REST を呼ばない consumer scopeに限定すべきですが、だからこそ「この consumer は一切gh/ network / git を呼ばない」という無副作用制約を AC に入れるべきです。([GitHub CLI]2)GitHub REST は secondary rate limit でも 403/429 を返し、
retry-afterやx-ratelimit-resetに従わない継続リトライは integration ban につながり得ます。これは #778 の executor 側責務ですが、#777 の consumer が retry や API 呼び出しを持ち込むとスコープ破壊になります。([GitHub Docs]3)YAML は PR comment 由来の semi-untrusted input なので、production consumer は必ず
yaml.safe_load相当を使い、yaml.loadを使ってはいけません。PyYAML 公式ドキュメントは untrusted source に対するyaml.loadを unsafe と警告しています。pytest 側は
.claude/skills/.../scripts配下の importable module を読むため、import 経路も固定すべきです。pytest は test module / conftest import 時にsys.pathや import mode の影響を受けるため、曖昧な path hack は shadow import や同名 module 衝突の温床になります。([pytest]4)#777 の AC はこう書き換えるべき
現在の AC1-AC7 は概ね正しいが、検証の粒度が甘いです。以下まで上げないと、#454/#774 の二の舞になります。
推奨する consumer API
route_loop_verdict_v2.pyは Markdown 手順の再実装ではなく、workflow contract の小さな判定器にするべきです。理由は単純です。string route だけ返すと、
fail_closed_expected_head_sha_guardとhuman_escalationとnot_approvedがテスト上は同じ “not update_branch” に潰れます。#777 が防ぎたいのは「たまたま route しなかった」ではなく、「なぜ route しなかったかを machine-readable に固定する」ことです。そのまま実装すると起きる失敗例
最も危険なのは、既存 fixture の
skill: implement-issueをそのまま正規値として通してしまうケースです。#777 の AC はimplement-issue.update_branchを要求しているのに、既存 fixture はimplement-issueです。この差分を吸収すると、将来implement-issue.delete_branchやimplement-issue.mergeのような別 mode を誤って同一 skill とみなす余地ができます。次に危険なのは、
merge_state_status == BEHINDだけでroute_to_update_branchを返す実装です。required_auto_actionsがない BEHIND、branch_behind_main=falseの BEHIND、またはexpected_head_sha欠落の BEHIND は、どれも update_branch executor に渡してはいけません。#778 側に TOCTOU guard があるとしても、consumer が壊れた payload を流してよい理由にはなりません。最後に、
step-5-mergeability-handling.mdの Bash snippet をそのまま production consumer の仕様として採用するのも危険です。そこではrequired_auto_actionsを文字列リスト的に扱っており、object schema のexecutor/skill/expected_head_shaを検証できません。#777 の production consumer は、この Markdown snippet ではなくLOOP_VERDICT_V2schema と boundary doc を正本にすべきです。Issue #777 に投稿するレビューコメント案
結論
#777 は実装すべきですが、現状の contract のままでは「shadow helper を別ファイルに移しただけ」の PR が通ります。合格条件は、
route_loop_verdict_v2.pyというファイルの存在ではなく、LOOP_VERDICT_V2.required_auto_actionsとTEST_VERDICT_MACHINE/v1.branch_behind_mainの不正入力を production consumer が理由付きで fail-closed に落とすことです。特にskill=implement-issueを許容しないこと、executor/skillの negative test を追加すること、Step 5 docs の V1/string-list wording に引きずられないことが merge-ready の最低ラインです。squne121 commentedon Jun 15, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 15, 2026
CONTRACT_REVIEW_RESULT_V1
fix(#777): PR #932 fix_delta — Blocker1-4 / Extra5-7 を route_loop_ver…
impl(#777): Step 5 routing を production consumer 化し shadow router tes…