Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "issue-refinement-loop が approved 終了時に references/termination-policy.md 準拠の LOOP_HANDOFF_RESULT_V1 marker を終了コメントに実際に出力する"
change_kind: codeParent Issue
none(単独改善)
Parent Goal Ref
- Goal: issue-refinement-loop の
approved終了レポートにLOOP_HANDOFF_RESULT_V1marker(<!-- LOOP_HANDOFF_RESULT_V1 -->HTML comment + fenced YAML)を実際に出力させる - Desired Destination:
.claude/skills/issue-refinement-loop/scripts/render_termination_report.py/publish_termination_report.pyがreferences/termination-policy.mdの契約を満たす状態
Current Validated Scope
render_termination_report.pyにloop_handoff入力(省略可)を追加し、termination_reason == "approved"かつloop_handoff提供時にLOOP_HANDOFF_RESULT_V1marker を本文へ組み込むpublish_termination_report.pyの入力受け口(stdin JSON パース箇所)にloop_handoffフィールドの受け渡し配線を追加する- 上記に対応する pytest テストの追加・更新
Remaining Parent Gaps
- orchestrator(
issue-refinement-loopSKILL.md の Step 手順)側でcontract_review/metadata/auto_fixes/blockers/permissionsの実データを収集しpublish_termination_report.pyへ渡す配線は本 Issue のスコープ外(follow-up issue 化を検討)
Outcome
render_termination_report.py が termination_reason == "approved" かつ loop_handoff 入力を受け取ったとき、schemas/loop_handoff_result_v1.json に準拠する LOOP_HANDOFF_RESULT_V1 YAML block(<!-- LOOP_HANDOFF_RESULT_V1 --> HTML comment 付き)を本文末尾へ追記し、publish_termination_report.py が同フィールドを stdin から受け取って render に渡せる状態。対応する pytest が全件 PASS している状態。
In Scope
render_termination_report.py:TERMINATION_REPORT_INPUT_V1に任意フィールドloop_handoff(schemas/loop_handoff_result_v1.jsonのLOOP_HANDOFF_RESULT_V1相当オブジェクトの構成要素、またはstatus/routing_actionを導出するための最小フィールド)を追加し、termination_reason == "approved"かつ本フィールドが与えられた場合にのみ<!-- LOOP_HANDOFF_RESULT_V1 -->+ fenced YAML block を本文へ追記するロジックを実装するstatus/routing_actionの導出はreferences/termination-policy.mdの「Routing Rules」表(impl_ready/run_impl_review_loop、blocked/blocked、human_judgment_required/ask_human等)に従うpublish_termination_report.py: stdin/--input-fileJSON からloop_handoffフィールドを読み取り、render_termination_report呼び出しへそのまま配線する- 生成された YAML block が
schemas/loop_handoff_result_v1.jsonに対して valid であることをテストで固定する termination_reason != "approved"(human_escalation/superseded_by_decision)のときはloop_handoffが提供されても marker を出力しない(policy が「approved 終了時」限定であることを明示的に固定する)loop_handoffが省略された場合は既存の後方互換動作(marker なし、例外なし)を維持するtest_render_termination_report.py/test_publish_termination_report.pyへのテスト追加・更新
Out of Scope
- orchestrator 側(
SKILL.mdの Step 手順)でcontract_review/metadata/auto_fixes/blockers/permissionsの実データを収集するロジック自体の実装 schemas/loop_handoff_result_v1.jsonの変更(既存スキーマのまま使用する)issue_kind/change_kind(research か implementation か)による出力有無の分岐。今回の調査結論としてreferences/termination-policy.mdは「issue-refinement-loopがapproved終了するとき」に marker 出力を要求しており、issue の種別による区別を規定していない。よって本 Issue では種別分岐ロジックを追加しない(曖昧な両論併記を避けるための明示的スコープ確定)decide_rewrite_route.py/ rewrite loop runtime router 側の変更
Acceptance Criteria
- AC1:
render_termination_report.pyはtermination_reason == "approved"かつloop_handoff入力が与えられたとき、出力 body に<!-- LOOP_HANDOFF_RESULT_V1 -->marker と fenced YAML block を含める - AC2:
loop_handoff入力が省略されたとき(後方互換)、termination_reason == "approved"でも marker を出力せず、既存の例外なし動作を維持する - AC3:
publish_termination_report.pyは stdin/--input-fileJSON のloop_handoffフィールドを読み取りrender_termination_reportの入力へ配線する - AC4: AC1 で生成された YAML block(fenced block 内の YAML)は
schemas/loop_handoff_result_v1.jsonに対して valid である - AC5:
status/routing_actionの導出はreferences/termination-policy.mdの Routing Rules 表に従う(少なくともimpl_ready/run_impl_review_loopとblocked/blockedの 2 パターンをテストで固定する) - AC6:
termination_reasonがhuman_escalationまたはsuperseded_by_decisionのとき、loop_handoffが提供されても marker を出力しない
Verification Commands
# AC1
# preflight-scope: pr_review_only
$ uv run python3 -m pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -k test_render_termination_report_approved_with_loop_handoff_emits_marker
# AC2
# preflight-scope: pr_review_only
$ uv run python3 -m pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -k test_render_termination_report_approved_without_loop_handoff_omits_marker
# AC3
$ rg -c "loop_handoff" .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
# AC4
# preflight-scope: pr_review_only
$ uv run python3 -m pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -k test_render_termination_report_loop_handoff_schema_valid
# AC5
# preflight-scope: pr_review_only
$ uv run python3 -m pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -k test_render_termination_report_routing_rules_matrix
# AC6
# preflight-scope: pr_review_only
$ uv run python3 -m pytest .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py -k test_render_termination_report_non_approved_omits_marker_even_with_loop_handoffRuntime Verification Applicability
- decision: not_applicable
- reason: 本 Issue の変更対象は
render_termination_report.py/publish_termination_report.pyへの純粋関数ロジック追加とスキーマ検証であり、AC1〜AC6 の VC はすべてpytestによるユニットテストとrgによるテキスト検索のみで完結する。プロセス起動・外部通信・ネットワーク I/O・GitHub API 呼び出し等の動作検証は不要なため、静的検証(typecheck / lint / unit test / build)のみで判定可能。
Allowed Paths
以下のファイルのみを変更対象とする:
- .claude/skills/issue-refinement-loop/scripts/render_termination_report.py
- .claude/skills/issue-refinement-loop/scripts/publish_termination_report.py
- .claude/skills/issue-refinement-loop/tests/test_render_termination_report.py
- .claude/skills/issue-refinement-loop/tests/test_publish_termination_report.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- orchestrator 側(SKILL.md Step 手順)でのデータ収集配線が必要と判明した場合は、本 Issue のスコープに含めず follow-up issue とする
Scope Delta(該当時のみ記載)
N/A
Required Skills
なし
Delivery Rule(配信規則)
1 Issue = 1 PR- isolation worktree で作業する
- Draft PR を既定とする
Background
Issue #246(squne121/loop-protocol, research issue)に対して issue-refinement-loop を実行し、iteration 3 で VERDICT: approve となったため publish_termination_report.py(内部で render_termination_report.py を使用)で終了コメントを投稿した。
しかし .claude/skills/issue-refinement-loop/SKILL.md は「approved 終了時は LOOP_HANDOFF_RESULT_V1 marker を終了コメントに出力する(references/termination-policy.md#LOOP_HANDOFF_RESULT_V1 参照)。出力は <!-- LOOP_HANDOFF_RESULT_V1 --> HTML comment と fenced YAML block の 2 要素」と定めているのに対し、実際に投稿されたコメント(https://github.com/squne121/loop-protocol/issues/246#issuecomment-4878550611)にはこの marker が含まれていなかった。
worktree 内で以下を確認済み:
render_termination_report.py/publish_termination_report.pyの両方にLOOP_HANDOFF_RESULT_V1という文字列が存在しない(rg -cで 0 件、grep 結果確認済み)- schema 定義自体は
.claude/skills/issue-refinement-loop/schemas/loop_handoff_result_v1.jsonに存在する references/termination-policy.mdのLOOP_HANDOFF_RESULT_V1セクションが仕様の正本であり、「issue-refinement-loopがapproved終了するとき」に marker 出力を要求している。同ファイルの Routing Rules 表・impl_ready定義・Hygiene Delegation Contract を確認したが、issue_kind/change_kind(research か implementation か)で出力有無を分ける記述は存在しない- したがって research/pilot: AI 駆動 session 記録 pilot smoke test (manifest 整合性 / Kill Switch 動作 / Secret 漏れ検査) #246 が research-only issue であることは marker 省略の正当化根拠にならず、これは仕様どおりの実装が欠落している実装ギャップである(
## Out of Scopeに決定を明記)
Notes for Reviewer(レビュアー向け注記)
TERMINATION_REPORT_INPUT_V1は現状termination_reason/termination_cause/issue_number/iteration/blockers_summaryのみを受け取り、contract_review等LOOP_HANDOFF_RESULT_V1を構成するために必要な情報を一切保持していない。本 Issue では render/publish の受け口(loop_handoff任意フィールド)を実装するところまでをスコープとし、orchestrator からの実データ供給配線は Out of Scope とした(Allowed Paths を 2 スクリプト + テストのみに限定するため)- 実装者は
loop_handoffフィールドの内部構造(必須キー最小セット)を、schemas/loop_handoff_result_v1.jsonのrequired配列を満たす形で設計してよい。ただし additionalProperties: false であるため、キー名は schema と完全一致させること
Activity
squne121 commentedon Jul 4, 2026
敵対的レビュー結論
#1311 は必要な実装Issueです。ただし、このまま実装者に渡すと
approvedなら機械的にimpl_readyを出す という危険な実装に寄りやすいです。正しい到達点は「loop_handoffが caller から提供され、schema/policy-valid な場合だけ、approved終了コメントにLOOP_HANDOFF_RESULT_V1marker を埋め込める renderer/publisher 受け口を追加する」です。orchestrator から実データを収集して渡す部分は #1311 の Out of Scope なので、#1311 だけでは「全 approved 終了で必ず marker が出る」状態にはなりません。これは明示しておくべきです。対象Issue自体のコメントは0件でした。追加制約はIssue本文、関連Issue/PR、repo内仕様ファイルから読む形になります。
確認した実装ギャップ
現在の
render_termination_report.pyは、入力としてtermination_reason/termination_cause/issue_number/iteration/blockers_summary程度しかテンプレートへ反映しておらず、approved時も headline と status line を出すだけでloop_handoff/LOOP_HANDOFF_RESULT_V1を扱う経路がありません。入力検証も現在は termination reason/cause、issue_number、iteration、blockers_summary を検査するだけで、
loop_handoffの schema validation や routing policy validation は存在しません。publish_termination_report.pyは stdin/--input-fileから読んだ JSON をnormalize_input()に通して renderer subprocess に渡す構造なので、renderer 側がloop_handoffを正規化・検証できれば publisher 側の実装は pass-through のテスト固定が中心になります。repo検索でも
LOOP_HANDOFF_RESULT_V1は schema / SKILL.md / termination-policy / tests には存在しますが、render/publish scripts 側の実装資産としては出てきませんでした。つまり #1311 の「実装欠落」主張は妥当です。Blocker 1:
impl_readyの導出を renderer に持たせすぎると仕様違反になるtermination-policy は、reviewer の approve だけでは
implementation_readyにしてはならず、最新のCONTRACT_REVIEW_RESULT_V1.status == "go"と freshness を確認することを要求しています。さらに
impl_readyを出せる条件は、fresh go、後続 request_changes/blocked で無効化されていないこと、metadata/auto-fix、blockers、permissions、routing_action まで含む7条件です。したがって、renderer が
termination_reason == "approved"だけを見てstatus: impl_ready/routing_action: run_impl_review_loopを生成する実装は不可です。#1311 では orchestrator 側のcontract_review/metadata/auto_fixes/blockers/permissionsの実データ収集が Out of Scope なので、renderer は 完全なloop_handoffpayload を受け取り、検証して出すだけ に限定するべきです。Blocker 2: JSON Schema だけでは Routing Rules の全行を固定できない
schemas/loop_handoff_result_v1.jsonは wrapperLOOP_HANDOFF_RESULT_V1を required にし、内側でstatus/routing_action/contract_review/metadata/auto_fixes/blockers/permissions/generated_atを必須にしています。ただし schema の
allOfは主にstatus == impl_readyの場合の制約を固定しており、missing_go/stale_goはblocked/blocked、semantic change はhuman_judgment_required/ask_humanといった Routing Rules 全体を完全には表現していません。termination-policy の Routing Rules は schema より広い契約なので、実装では schema validation に加えて、少なくとも AC5 が要求する
impl_ready/run_impl_review_loopとblocked/blockedの行を policy-level validator で固定すべきです。推奨は以下です。
Blocker 3: fallback template で marker が消える設計は不可
現在の renderer は attempt 1 で normal template、guard fail 時に attempt 2 で fallback minimal template を返す構造です。
LOOP_HANDOFF_RESULT_V1marker を normal template にだけ追加すると、guard fail 時に fallback minimal template が marker なしで publishable=true になり、AC1を破ります。正しい設計は、normal/fallback のどちらでも base body に marker を付与した状態で guard を走らせる ことです。marker付き本文が両方 guard fail するなら、markerを落として成功扱いにするのではなくpublishable=falseに倒すべきです。Blocker 4: YAML は手書きではなく
safe_dump+ round-trip validation にするPyYAML の
safe_dumpは標準YAMLタグだけを生成する API で、任意のPythonオブジェクト表現を出さない用途に向きます。yaml.dumpや手書き文字列連結ではなく、safe_dump(..., sort_keys=False, allow_unicode=True, default_flow_style=False)を使うべきです。テストでは fenced block 内の YAML を
yaml.safe_load()で戻し、schemas/loop_handoff_result_v1.jsonに対して[jsonschema](https://python-jsonschema.readthedocs.io/en/stable/validate/)で検証してください。jsonschemaはformatを自動では強制しないため、generated_atなどの"format": "date-time"を本当に検査したいならDraft7Validator(schema, format_checker=FormatChecker())を使うべきです。(jsonschema)依存関係として
pyyaml>=6.0とjsonschema>=4.0は既にpyproject.tomlにあります。追加依存なしで実装できます。Blocker 5: fence injection / marker injection の回帰テストが不足している
GFM の fenced code block は3個以上の backtick または tilde で開始し、closing fence は同じ文字で同数以上が必要です。現在 renderer には backtick 列の最大長+1で fence を作る
_make_dynamic_fence()があり、blockers_summary 向けの防御は既にテストされています。([GitHub Pages]2)しかし #1311 で追加される
loop_handoffYAML block は新しい攻撃面です。既存テストは blocker 内の<!-- LOOP_HANDOFF_RESULT_V1 -->注入を見ているだけで、実際に生成される handoff YAML block の中に backtick、tilde、HTML comment、shell-looking text が入った場合の構造保持を検査していません。追加すべきテストは、
loop_handoff.blockers[].descriptionやauto_fixes.required[].evidence.afterに以下を入れても、marker が1回だけ出ること、YAMLが parse できること、guard が通ることです。loop_handoffが無効な場合はInputValidationErrorで fail-closed にするべきです。非approved時にloop_handoffが提供された場合も、valid payload なら出力しない、invalid payload なら reject が安全です。無効な control-plane payload を silently ignore すると、caller側の壊れた配線を見逃します。追加すべきテスト
最低限、以下は必要です。
既存の
test_loop_handoff_result.pyには schema-valid な_base_impl_ready()と routing pattern tests があるため、同じ payload shape をtest_render_termination_report.py側に持ち込んで使うのがよいです。Allowed Paths にtest_loop_handoff_result.pyは含まれていないので、そのファイル自体は変更しない方が安全です。PRレビュー時の判定基準
このIssueの実装PRは、以下を満たすまで
REQUEST_CHANGES相当です。approved + valid loop_handoffで marker と fenced YAML が出る。loop_handoff_result_v1.jsonに対して valid。impl_readyを termination_reason だけから合成しない。--input-fileのloop_handoffを renderer に渡すことをテストで固定する。scope_signal_guard_decision_v2の既存投影を壊さない。PR feat(issue-refinement-loop): scope_signal_guard escalation lane split (#1090) #1294 で追加されたこの経路は直近の重要な回帰面です。実装タスクとしては妥当ですが、#1311 の完了条件は「render/publish が marker生成 capability を持つ」までに限定するべきです。「orchestrator が必ず実データを渡す」は follow-up Issue に分離してください。
squne121 commentedon Jul 4, 2026
Refinement Loop: Human Escalation Required
The loop has terminated and requires human review. Cause: human judgment required
human_escalationhuman_judgment_requiredBlockers
squne121 commentedon Jul 4, 2026
Contract Review Result
squne121 commentedon Jul 4, 2026
implement-issue: 実装完了
worktree-agent-add3c122adba19ce3(isolation worktree の自動命名。当初想定のworktree-issue-1311-issue-refinement-loop-termination-reportは既に別 worktree で使用中だったため代替。PR body にCloses #1311明記済み)AC / Verification Commands 実行結果
rg -c= 3)対象2テストファイル全体で131 passed(既存テスト回帰なし)。
標準検証:
pnpm typecheck/pnpm lint/pnpm test(1350 tests) /pnpm build/uv run pytest .claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(21 tests) すべて PASS。fix: loop_handoff routing rules を policy-level validator で厳格化する (#1311)
feat: issue-refinement-loop termination report に LOOP_HANDOFF_RESULT_…