Repository navigation
Closed
Labels
Description
背景
#824 の impl-review-loop で scope-rollup-runner SubAgent が ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1 を返さず、orchestrator が deferred フォールバックしていました。marker 欠落は scope rollup 結果なしではなく、終了契約不成立として扱う必要があります。
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "#824"
goal_ref: "scope-rollup marker 欠落を control-plane 失敗として検知し停止する"
change_kind: workflow
Parent Issue
Parent Goal Ref
- Goal: scope-rollup marker 検証の control-plane 強化
- Desired Destination: impl-review-loop が marker 欠落時に
human_review_requiredへ停止し、raw fallback を禁止する
Current Validated Scope
impl-review-loop/steps/preparation.mdの判定でISSUE_SCOPE_ROLLUP_RUN_RESULT_V1検証を厳格化するmarker_missing / marker_malformed / marker_ambiguousをISSUE_SCOPE_ROLLUP_DECISION_V2.runner_resultのstatus/reject_reasonに反映する- marker 不在・不正時は
human_review_requiredかつtermination_reason: human_escalationに固定し、raw JSON fallback を禁止する - 参照先
.mdを.claude/agents/scope-rollup-runner.mdに統一する
Remaining Parent Gaps
- なし
Outcome
impl-review-loop は scope-rollup-runner の最終応答に valid な ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1 が欠ける場合、human_escalation へ遷移し、LOOP_STATE の termination_cause と scope_rollup_decision に marker 欠落情報を保存する。
In Scope
marker_missing / marker_malformed / marker_ambiguousをrunner_resultとして保存- raw
result.raw_plan_locationの pre-verification 直接読み取り禁止 runner_unavailableとmarker_*系を別状態として扱うISSUE_SCOPE_ROLLUP_RUN_RESULT_V1の validator/parser を追加impl-review-loop側のhuman_review_required経路を追加
Out of Scope
- ゲームシステム本体の機能追加・修正
- 大規模な UI やアセット変更
- 既存テスト大規模追加(新規追加は最小限の fixture に限定)
Acceptance Criteria
- AC1:
scope-rollup-runnerの最終応答に valid fencedISSUE_SCOPE_ROLLUP_RUN_RESULT_V1が存在しない場合、impl-review-loop orchestrator はhuman_escalationに遷移する。 - AC2: 遷移時の
LOOP_STATE.termination_reasonはhuman_escalation、termination_causeはscope_rollup_marker_missingになる。 - AC3:
ISSUE_SCOPE_ROLLUP_DECISION_V2.runner_resultにmarker_missing / marker_malformed / marker_ambiguousを保存する。 - AC4: marker 欠落・不正時に raw
result.raw_plan_locationの直接読み取りを禁止する。 - AC5:
runner_unavailableは valid marker が返された場合のみ成立する状態として扱う。 - AC6:
scope-rollup-runnerで marker 欠落時はhuman_review_requiredとして停止する。 - AC7:
.claude/agents/scope-rollup-runner.toml参照の混入を.md参照へ統一する。
Verification Commands
# AC1
$ uv run python3 .claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py \
--assistant-output-file /tmp/scope_rollup_subagent_output.txt \
--repo squne121/loop-protocol \
--issue-number 841 \
--invocation-id fake-invocation-id \
--expected-script-sha deadbeef \
--requested-at 2026-06-13T10:14:29.005846+00:00
# AC2
$ uv run python3 .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py \
--issue-number 841 \
--repo squne121/loop-protocol \
--anchor-comment-url https://github.com/squne121/loop-protocol/issues/841#issuecomment-4698224807
# AC3
$ uv run python3 .claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py \
--assistant-output-file /tmp/scope_rollup_subagent_output.txt \
--repo squne121/loop-protocol \
--issue-number 841 \
--invocation-id fake-invocation-id \
--expected-script-sha deadbeef \
--requested-at 2026-06-13T10:14:29.005846+00:00
# AC4
$ uv run python3 .claude/skills/impl-review-loop/scripts/verify_scope_rollup_result.py --help
# AC5
$ uv run python3 .claude/skills/impl-review-loop/scripts/verify_scope_rollup_result.py --help
# AC6
$ uv run python3 .claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py \
--assistant-output-file /tmp/scope_rollup_subagent_output.txt \
--repo squne121/loop-protocol \
--issue-number 841 \
--invocation-id fake-invocation-id \
--expected-script-sha deadbeef \
--requested-at 2026-06-13T10:14:29.005846+00:00
# AC7
$ uv run python3 .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・enum / スキーマ・型)変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
Runtime Verification Applicability
decision: not_applicable
derived_test_plan:
- parser/fallback 系の fixture 検証
Allowed Paths
.claude/skills/impl-review-loop/steps/preparation.md.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py.claude/skills/impl-review-loop/scripts/verify_scope_rollup_result.py.claude/skills/impl-review-loop/tests/.claude/agents/scope-rollup-runner.md
Required Skills
- Python
参考
.claude/skills/impl-review-loop/steps/preparation.md.claude/agents/scope-rollup-runner.md
Activity
squne121 commentedon Jun 13, 2026
判定: REQUEST_CHANGES
#841 の方向性は正しいです。
scope-rollup-runnerの marker 欠落をdeferredにして Step 3 へ進める現在設計は、scope collision 検出を「失敗しても進める」扱いにしており、オーケストレーターの control-plane として危険です。#841 は、marker 欠落を fail-closed / human escalation に変える Issue として実装すべきです。#841 自体にコメントはなく、議論の根拠は #824、PR #837、scope-rollup-runner/preparation.md/ scope rollup policy 側にあります。主要な問題
1. 現行設計は「marker 検証失敗」と「非ブロッキング skip」を混同している
preparation.mdは marker 検証に失敗した場合、silent fallback は禁じていますが、その後の選択肢としてdeferredで scope rollup をスキップして Step 3 へ進む経路を許しています。これは #841 の問題そのものです。marker が無い、壊れている、別 invocation のものである、sha が合わない、という事象は「scope rollup の結果が空」ではなく「control-plane の証跡が壊れた」です。修正方針は、
runner_unavailableとmarker_missingを分けることです。runner_unavailableは runner が 有効な marker として 返した状態です。一方、marker 欠落は runner の終了契約そのものが破れている状態なので、deferredではなくhuman_review_requiredに固定すべきです。2.
human_judgmentという AC 表現が既存の termination schema とズレている#841 の AC1 は「
human_judgmentとして停止」としていますが、impl-review-loopの termination reason はhuman_escalationを使っています。既存のLOOP_STATEでも termination reason はnull | approved | max_iterations | human_escalation | intake_gate_failedです。したがって #841 は次のように書き換えるべきです。
「human_judgment」は人間が読む説明語としてはよいですが、machine-readable state では既存 enum に合わせるべきです。
3. 既存の
ISSUE_SCOPE_ROLLUP_DECISION_V2にmarker_missingが存在しない現行 schema の
runner_result.statusはok | runner_unavailable | rejected、reject_reasonは repo / issue / invocation / stale / script sha / result sha mismatch などに限定されています。marker 欠落、marker 重複、marker malformed、raw plan 不正パス、result file 不在が表現できません。追加すべき enum は最低限これです。
decisionは既存のhuman_review_requiredを使えば足ります。scope rollup policy は、統合実施・未実施にかかわらずISSUE_SCOPE_ROLLUP_DECISION_V2を常時記録する要求を持っています。4. 「runner 自身に必ず marker を返させる」は単独では不十分
scope-rollup-runner.mdは、確かにISSUE_SCOPE_ROLLUP_RUN_RESULT_V1を stdout に返す専用 SubAgent と定義し、OUTPUT_BUDGET_V1でも routing-critical field を削らないとしています。しかし Claude Code の subagent は独立 context で動き、最終的にメインへ返すのは要約です。これは「LLM が marker を必ず出す」ことの保証ではありません。公式 docs でも subagent は独自 context / system prompt / tool access を持ち、結果を返す構造です。(Claude API Docs)
したがって、プロンプト強化だけではなく、orchestrator 側の deterministic parser または SubagentStop hook で検査する必要があります。Claude Code hooks には
SubagentStopがあり、subagent 終了時のlast_assistant_messageとagent_typeを受け取れます。(Claude API Docs)5. raw JSON fallback は明示禁止すべき
#841 の背景では、marker 欠落後に raw JSON ファイルを直接読む fallback が発生しています。これは危険です。
ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1の役割は、raw_plan_locationとresult_sha256とinvocation_idを結び、現在の run の結果であることを証明することです。現行preparation.mdも marker の repo / issue / invocation / timestamp / script sha / result sha を検証対象にしています。修正後は、次を rule として明文化してください。
6.
.toml参照が間違っている#841 の参考には
.claude/agents/scope-rollup-runner.tomlとありますが、実際に repo で見つかる定義は.claude/agents/scope-rollup-runner.mdです。Issue 本文の参照は修正してください。推奨実装
A. parser script を追加する
preparation.mdに自然言語で「marker を確認する」と書くだけでは弱いです。次のような script を追加してください。入力:
出力:
既存の
verify_scope_rollup_result.pyは JSON result の self-validation、schema、payload hash、script hash を検証する良い土台です。特に duplicate key、non-object、schema mismatch、sha mismatch を分けて fail する設計は #841 側でも踏襲すべきです。B. marker は YAML prose ではなく fenced block としてだけ認める
CONTRACT_REVIEW_RESULT_V1側では、単に marker 文字列を含むだけでは採用せず、valid fenced YAML block と必須 field を要求しています。同じ思想を scope rollup にも適用してください。ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1という文字列が散文中に出てきただけで pass にしてはいけません。可能なら YAML より JSON marker へ寄せる方が安全です。Python 標準ライブラリで strict JSON parsing と duplicate-key detection を実装できるためです。YAML を維持するなら、PyYAML / ruamel.yaml などの依存を明示し、正規表現だけで nested YAML を読まないでください。
C. SubagentStop hook で二重化する
Claude Code hooks は lifecycle event の JSON input を受け取り、exit code / stdout で結果を返せます。SubagentStop では subagent の
last_assistant_messageを検査できます。(Claude API Docs) (Claude API Docs)設計案:
ただし hook だけに依存せず、
preparation.mdの routing logic でも同じ parser を呼ぶべきです。hook は早期検知、orchestrator parser は canonical 判定、という分担がよいです。D. 「structured output / schema 強制」は現在の Claude Code SubAgent には直接の解ではない
OpenAI API の Structured Outputs は、JSON mode と異なり schema adherence を保証する仕組みですが、これは API 側の
strict: trueschema enforcement の話です。Claude Code の project subagent 最終応答にそのまま適用できるとは限りません。(OpenAI Platform)したがって #841 の実装方針はこう分けるべきです。
経路 | 採用可否 -- | -- Claude Code SubAgent prompt に「必ず marker」と書く | 補助策に留める deterministic parser で final response を検査 | 必須 SubagentStop hook で last_assistant_message を検査 | 推奨 OpenAI Structured Outputs による schema 強制 | 将来 API runner 化する場合のみ有効#841 の AC 改訂案
scope-rollup-runnerの最終応答に valid fencedISSUE_SCOPE_ROLLUP_RUN_RESULT_V1block が存在しない場合、impl-review-loop orchestrator は Step 3 へ進まず、LOOP_STATE.termination_reason: human_escalationとtermination_cause: scope_rollup_marker_missingを記録して停止する。LOOP_STATE.scope_rollup_decision.runner_result.statusとreject_reasonにmarker_missing | marker_malformed | marker_ambiguous | result_sha_mismatch | raw_plan_location_invalidのいずれかを構造化保存する。result.raw_plan_locationを読んではならない。marker 欠落時の raw JSON fallback は禁止する。runner_unavailableは valid marker として返された場合のみ runner failure として扱う。marker 欠落とは別 enum にする。[ ] AC7:
.claude/agents/scope-rollup-runner.toml参照を実在する.claude/agents/scope-rollup-runner.mdに修正する。最終コメント案
#841 は実装する価値があります。ただし、現行の Issue 契約のままだと「runner prompt を強化するだけ」の PR が通る余地があります。それでは再発します。
実装の核は、
## 判定: REQUEST_CHANGESscope-rollup-runnerの出力を信頼することではなく、impl-review-looporchestrator が marker 欠落を構造化された control-plane failure として検出し、Step 3 前に停止すること です。特にdeferredは削るか、少なくとも validrunner_unavailablemarker の場合だけに限定してください。marker 欠落、malformed、ambiguous、sha mismatch はすべてhuman_review_requiredです。#841 の方向性は正しいです。
scope-rollup-runnerの marker 欠落をdeferredにして Step 3 へ進める現在設計は、scope collision 検出を「失敗しても進める」扱いにしており、オーケストレーターの control-plane として危険です。#841 は、marker 欠落を fail-closed / human escalation に変える Issue として実装すべきです。#841 自体にコメントはなく、議論の根拠は #824、PR #837、scope-rollup-runner/preparation.md/ scope rollup policy 側にあります。主要な問題
1. 現行設計は「marker 検証失敗」と「非ブロッキング skip」を混同している
preparation.mdは marker 検証に失敗した場合、silent fallback は禁じていますが、その後の選択肢としてdeferredで scope rollup をスキップして Step 3 へ進む経路を許しています。これは #841 の問題そのものです。marker が無い、壊れている、別 invocation のものである、sha が合わない、という事象は「scope rollup の結果が空」ではなく「control-plane の証跡が壊れた」です。修正方針は、
runner_unavailableとmarker_missingを分けることです。runner_unavailableは runner が 有効な marker として 返した状態です。一方、marker 欠落は runner の終了契約そのものが破れている状態なので、deferredではなくhuman_review_requiredに固定すべきです。2.
human_judgmentという AC 表現が既存の termination schema とズレている#841 の AC1 は「
human_judgmentとして停止」としていますが、impl-review-loopの termination reason はhuman_escalationを使っています。既存のLOOP_STATEでも termination reason はnull | approved | max_iterations | human_escalation | intake_gate_failedです。したがって #841 は次のように書き換えるべきです。
「human_judgment」は人間が読む説明語としてはよいですが、machine-readable state では既存 enum に合わせるべきです。
3. 既存の
ISSUE_SCOPE_ROLLUP_DECISION_V2にmarker_missingが存在しない現行 schema の
runner_result.statusはok | runner_unavailable | rejected、reject_reasonは repo / issue / invocation / stale / script sha / result sha mismatch などに限定されています。marker 欠落、marker 重複、marker malformed、raw plan 不正パス、result file 不在が表現できません。追加すべき enum は最低限これです。
decisionは既存のhuman_review_requiredを使えば足ります。scope rollup policy は、統合実施・未実施にかかわらずISSUE_SCOPE_ROLLUP_DECISION_V2を常時記録する要求を持っています。4. 「runner 自身に必ず marker を返させる」は単独では不十分
scope-rollup-runner.mdは、確かにISSUE_SCOPE_ROLLUP_RUN_RESULT_V1を stdout に返す専用 SubAgent と定義し、OUTPUT_BUDGET_V1でも routing-critical field を削らないとしています。しかし Claude Code の subagent は独立 context で動き、最終的にメインへ返すのは要約です。これは「LLM が marker を必ず出す」ことの保証ではありません。公式 docs でも subagent は独自 context / system prompt / tool access を持ち、結果を返す構造です。([Claude API Docs]1)
したがって、プロンプト強化だけではなく、orchestrator 側の deterministic parser または SubagentStop hook で検査する必要があります。Claude Code hooks には
SubagentStopがあり、subagent 終了時のlast_assistant_messageとagent_typeを受け取れます。([Claude API Docs]2)5. raw JSON fallback は明示禁止すべき
#841 の背景では、marker 欠落後に raw JSON ファイルを直接読む fallback が発生しています。これは危険です。
ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1の役割は、raw_plan_locationとresult_sha256とinvocation_idを結び、現在の run の結果であることを証明することです。現行preparation.mdも marker の repo / issue / invocation / timestamp / script sha / result sha を検証対象にしています。修正後は、次を rule として明文化してください。
6.
.toml参照が間違っている#841 の参考には
.claude/agents/scope-rollup-runner.tomlとありますが、実際に repo で見つかる定義は.claude/agents/scope-rollup-runner.mdです。Issue 本文の参照は修正してください。推奨実装
A. parser script を追加する
preparation.mdに自然言語で「marker を確認する」と書くだけでは弱いです。次のような script を追加してください。入力:
出力:
既存の
verify_scope_rollup_result.pyは JSON result の self-validation、schema、payload hash、script hash を検証する良い土台です。特に duplicate key、non-object、schema mismatch、sha mismatch を分けて fail する設計は #841 側でも踏襲すべきです。B. marker は YAML prose ではなく fenced block としてだけ認める
CONTRACT_REVIEW_RESULT_V1側では、単に marker 文字列を含むだけでは採用せず、valid fenced YAML block と必須 field を要求しています。同じ思想を scope rollup にも適用してください。ISSUE_SCOPE_ROLLUP_RUN_RESULT_V1という文字列が散文中に出てきただけで pass にしてはいけません。可能なら YAML より JSON marker へ寄せる方が安全です。Python 標準ライブラリで strict JSON parsing と duplicate-key detection を実装できるためです。YAML を維持するなら、PyYAML / ruamel.yaml などの依存を明示し、正規表現だけで nested YAML を読まないでください。
C. SubagentStop hook で二重化する
Claude Code hooks は lifecycle event の JSON input を受け取り、exit code / stdout で結果を返せます。SubagentStop では subagent の
last_assistant_messageを検査できます。([Claude API Docs]2) ([Claude API Docs]2)設計案:
ただし hook だけに依存せず、
preparation.mdの routing logic でも同じ parser を呼ぶべきです。hook は早期検知、orchestrator parser は canonical 判定、という分担がよいです。D. 「structured output / schema 強制」は現在の Claude Code SubAgent には直接の解ではない
OpenAI API の Structured Outputs は、JSON mode と異なり schema adherence を保証する仕組みですが、これは API 側の
strict: trueschema enforcement の話です。Claude Code の project subagent 最終応答にそのまま適用できるとは限りません。([OpenAI Platform]3)したがって #841 の実装方針はこう分けるべきです。
SubagentStophook でlast_assistant_messageを検査#841 の AC 改訂案
最終コメント案
#841 は実装する価値があります。ただし、現行の Issue 契約のままだと「runner prompt を強化するだけ」の PR が通る余地があります。それでは再発します。
実装の核は、
scope-rollup-runnerの出力を信頼することではなく、impl-review-looporchestrator が marker 欠落を構造化された control-plane failure として検出し、Step 3 前に停止すること です。特にdeferredは削るか、少なくとも validrunner_unavailablemarker の場合だけに限定してください。marker 欠落、malformed、ambiguous、sha mismatch はすべてhuman_review_requiredです。squne121 commentedon Jun 13, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 13, 2026
実装の進捗を共有します。#841 の対象範囲に限定して、既存差分の不足精査・最小修正・検証まで完了しました。
実装概要
scope-rollup-runnerのISSUE_SCOPE_ROLLUP_RUN_RESULT_V1検証を parser 化し、fenced YAML 以外は受け付けないようにしました。marker_missing/marker_malformed/marker_ambiguous/rejectedとして fail-closed で扱い、rawresult.raw_plan_locationの直接読込は禁止へ統一。runner_unavailable/failedは valid marker として分離し、fail-closed と混同しない。preparation.mdStep 2.5 の判断フローに parser 呼び出しと raw fallback 禁止・記録ルールを反映。verify_scope_rollup_result.pyを委譲して result の self-validation を流用。変更ファイル
.claude/skills/impl-review-loop/steps/preparation.md.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py.claude/skills/impl-review-loop/scripts/verify_scope_rollup_result.py.claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.pyAC / VC 対応
runner_unavailableは valid marker として独立扱い.toml参照の混入は対象差分から除去済み(scope-rollup-runner.md統一)実行テスト
uv run python3 -m pytest .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py -q=>9 passeduv run python3 -m pytest .claude/skills/impl-review-loop/tests -q=>193 passed, 4 xfailed人間が見るべき点(merge前)
SCOPE_ROLLUP_MARKER_PARSE_RESULT_V1.statusのmarker_ambiguousとrunner_result.statusenum の実運用吸収方針(仕様上の同値化は必要なら追加調整)scope_rollup_plan_refの実データ連携は実行時の context 側で正常に採用されるかfix(#841): fail closed on missing scope rollup marker
squne121 commentedon Jun 13, 2026
実装再開報告(#841)
レビューコメント #4698316409 の主指摘(1〜3点)を先に対応しました。
実装概要
marker_missing / marker_malformed / marker_ambiguous / rejected / failed / runner_unavailableを分離し、failed/runner_unavailableを marker_missing と混同しない。failedはstatus: failed(routing_action: stop_human)。runner_unavailableはstatus: runner_unavailable(routing_action: deferred)。requested_atを CLI 引数と照合し、不一致はrequested_at_mismatchで拒否。raw_plan_locationは/tmp配下・絶対パス・..禁止・symlink 禁止・invocation_id同一性を確認する検証へ更新。marker_malformed扱い。preparation.mdの Step2.5 をrunner_unavailableとfailedの取扱、marker_ambiguous・requested_at_mismatchを含む enum 更新。変更ファイル
.claude/skills/impl-review-loop/scripts/parse_scope_rollup_run_result.py.claude/skills/impl-review-loop/steps/preparation.md.claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py実行テスト
uv run python3 -m pytest .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py -q=>12 passeduv run python3 -m pytest .claude/skills/impl-review-loop/tests -q=>196 passed, 4 xfailed反映 PR/コミット
957a7acmerge 前の注視点
squne121 commentedon Jun 13, 2026
impl-review-loop 実行結果(2026-06-13T00:00:00Z 想定)
.claude/skills/impl-review-loop/steps/preparation.mdの scope-rollup marker fail-closed 方針に沿った更新反映CLEAN/MERGEABLE検証
uv run python3 -m pytest .claude/skills/impl-review-loop/tests/test_parse_scope_rollup_run_result.py -q(12 passed)uv run python3 -m pytest .claude/skills/impl-review-loop/tests -q(196 passed, 4 xfailed)補足
impl-review-loopとpr-review-judge経路での再マージ阻害要因は未検出。fix(#841): fail closed on missing scope rollup marker (#869)