Repository navigation
Closed
Labels
area/ai-opsAI operations and agent tooling areaenhancementNew feature or requestworkflowWorkflow / skill automation changes
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
goal_ref: "#1038 merge 後に残った issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget gap を閉じる"
change_kind: improvement
risk_class: agent_ops_guard
affected_runtimes:
- claude_code
non_goals:
- "Issue template の種類追加"
- "product spec policy の変更"
- "#1038 で解消済みの forwarding 導入をやり直すこと"Parent Issue
なし(standalone 実装 Issue)
Parent Goal Ref
#1023 は #1014 の準備中に観測された fail_closed 改善から始まったが、現在の live scope は #1038 merge 後に残った follow-up gap の解消である。#1014 本体の branch guard 実装は直接の親スコープではない。
Current Validated Scope
.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py.claude/skills/issue-refinement-loop/scripts/route_after_rewrite.py.claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py.claude/skills/issue-refinement-loop/tests/.claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json.claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json.claude/skills/issue-refinement-loop/references/refinement-loop-plan-output.md.claude/skills/issue-refinement-loop/references/termination-policy.md.claude/agents/issue-author.md.claude/skills/edit-issue/SKILL.md
Remaining Parent Gaps
Machine-Readable Contractsection 欠落時の reason semantics がmissing_required_contract_keyに寄ってしまう境界を解消する。- malformed YAML / parse error と missing key を混線させず、downstream consumer が誤修復しない fail_closed contract にする。
- issue-author / rewrite consumer 側で同一 reason + 同一 constraints の二重 rewrite 防止と format-only repair の iteration budget 非消費を証跡付きで閉じる。
Outcome
issue-refinement-loop の fail_closed rewrite contract が current repo reality に一致し、Machine-Readable Contract section 欠落・YAML parse error・missing key・payload invalid・consumer rewrite budget の境界が決定論的に区別される。
In Scope
plan_refinement_loop.pyの fail_closed reason semantics 修正- malformed contract / parse error / missing key の判定境界の明確化
run_refinement_preflight.pyの payload 自己整合性検証と invalid payload の environment failure routing 修正- strict JSON (
allow_nan=False) を含む compact stdout / serializability 契約の強化 - issue-author / rewrite consumer の reason-history または同等の no-progress 判定を追加し、同一 reason + 同一 constraints の二重 rewrite を拒否する実装
- format-only repair が max_iterations を消費しないことの実装とテスト追加
- false-positive fail_closed を防ぐ valid fixture / 回帰テストの追加または復元
- consumer rewrite budget を反映する
issue-author/edit-issue/ termination policy 契約の同期
Out of Scope
- Issue template の種類追加
- product spec policy の変更
#1038で導入済みのrequired_sections/required_contract_keys/rewrite_constraintsforwarding の再実装- unrelated runtime / permission / workflow change
Background
初期の #1023 は preflight で不足セクションと contract key を全件提示し、issue-author に lossless に渡すことを目的としていた。この forwarding gap 自体は #1037 / PR #1038 で大きく改善された。一方、anchor comment では、現在の repo reality に対してなお次の gap が残ると指摘されている。
Machine-Readable Contractsection 欠落時にmissing_required_contract_keyを出してしまい、section 欠落と key 欠落の意味論が混線する。- YAML parse error / malformed contract と missing key が downstream repair 観点で区別し切れていない。
- wrapper schema は存在必須を担保するが、top-level / nested rewrite payload の自己整合性までは十分に検証していない。
- strict JSON 契約として
allow_nan=Falseが不足している。 - consumer 側の iteration budget 制御と no-progress 証跡が 改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる #1023 の元 AC4/AC5 に対してまだ弱い。
Acceptance Criteria
- AC1:
Machine-Readable Contractsection 欠落時はrequired_sectionsにMachine-Readable Contractを出し、reason code はmissing_required_section系で表現する。missing_required_contract_keyを混在させない。 - AC2: Contract YAML parse error / malformed contract は missing key と別経路で扱い、
required_contract_keysは parsed mapping のときだけ出す。 - AC3:
run_refinement_preflight.pyはrequired_sections/required_contract_keysと nestedmust_add_*の一致を custom invariant で検証し、不整合 payload を deterministic に fail-close する。 - AC4: compact stdout と serializability check は strict JSON として
allow_nan=Falseを用い、NaN / Infinity 系 payload を environment failure として扱う。 - AC5: planner / wrapper 間の non-string または non-JSON payload は Issue 本文修正 blocker ではなく environment failure / fix_environment routing へ送る。
- AC6: issue-author / rewrite consumer は artifact field を source of truth として読み、同一 reason + 同一 constraints の二重 rewrite を拒否する。
- AC7: format-only repair は max_iterations を消費せず、reason-history または同等の state で no-progress 判定を機械的に再現できる。
- AC8: false-positive fail_closed を検出できる valid canonical fixture または既存 good fixture 検証を復元し、期待しない fail_closed を回帰テストで捕捉する。
Verification Commands
# AC1
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py -q
# AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -q
# AC3
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -q
# AC4
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -q
# AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_fail_closed_override_rewrite.py -q
# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_route_after_rewrite.py -q
# AC7
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_rewrite_router.py -q
# AC8
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_fail_closed_override_rewrite.py -q
# schema shape
$ uv run python3 -m json.tool .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.jsonAllowed Paths
.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py.claude/skills/issue-refinement-loop/scripts/route_after_rewrite.py.claude/skills/issue-refinement-loop/scripts/decide_rewrite_route.py.claude/skills/issue-refinement-loop/tests/.claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json.claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json.claude/skills/issue-refinement-loop/references/refinement-loop-plan-output.md.claude/skills/issue-refinement-loop/references/termination-policy.md.claude/agents/issue-author.md.claude/skills/edit-issue/SKILL.md
Runtime Verification Applicability
decision: not_applicable
reason: "script / schema / consumer contract 修正で完結し、interactive runtime 証跡を成功条件に含まない"Stop Conditions
実装中にこれらの状況が発生したら直ちに作業を停止し、Issue comment に状況を記録して人間の判断を待つ。
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
- fail_closed reason code の後方互換を壊さずに section 欠落と key 欠落を分離できない場合
- artifact field を issue-author / rewrite consumer が source of truth として読めない場合
- format-only repair を iteration budget 外へ分離する state 設計が既存 router と両立しない場合
issue-author/edit-issue/ termination policy を更新せずに AC6-AC7 を満たせないと判明した場合- false-positive fail_closed を再現できる valid fixture を特定できない場合は、その時点で追加調査 issue に分離する
Required Skills
- Python scripting
- issue-refinement-loop SKILL.md 理解
- fail_closed rewrite contract と issue-author consumer 理解
Delivery Rule
1 Issue = 1 PRで完了する。- Draft PR を既定とする。
Metadata
Metadata
Assignees
Labels
area/ai-opsAI operations and agent tooling areaenhancementNew feature or requestworkflowWorkflow / skill automation changes
Activity
squne121 commentedon Jun 20, 2026
判定: 実装前に Issue 本文を修正すべきです
#1023 の狙い自体は妥当です。
missing_required_section/missing_required_contract_keyを最初の preflight で全件出し、issue-author に lossless に渡す、という目的は token 浪費の原因に直接効きます。#1023 自体にはコメントがなく、本文上の直接参照は #1014 です。ただし、このまま実装すると AC を満たしたように見えて、実際には downstream に constraints が届かない可能性が高いです。最大の理由は、Planner はすでに
FAIL_CLOSED_REWRITE_CONSTRAINTS_V1を返せる一方で、Wrapper 側のrefinement_preflight_result/v1がそれを保持・stdout 露出する契約になっていないためです。Blocker
B1.
Parent Goal Refが事実と合っていない#1023 は
Parent Goal Refに「#1014 refinement loop での required section 逐次発見」と書いていますが、実際の #1014 は「Claude Code / Codex CLI で local root checkout のブランチ変更をブロックする」Issue です。内容もlocal_main_branch_guard、Codex/Claude hooks、branch drift、worktree guard に関するものです。これは単なる表記ミスではありません。関連Issue/PR探索、スコープ判断、レビュー対象の根拠が汚染されます。修正するなら
Parent Issue: noneのままにし、Parent Goal Refは「#1014 の実装準備中に観測された refinement-loop failure mode」など、#1014 本体とは別の incident として明示してください。B2. #1023 の AC1/AC3 は現行
refinement_preflight_result/v1schema では素直に実装できないWrapper の compact stdout は現在
STATUS / NEXT_ACTION / MUST_READ / COMMANDS / BLOCKERS / ARTIFACTだけを出す設計です。 また、Wrapper result schema はadditionalProperties: falseで、許可される top-level field も固定されています。 JSON Schema ではadditionalProperties: falseは定義外プロパティを許可しない、という意味です。(JSON Schema)つまり
rewrite_constraintsやrequired_sectionsを artifact に lossless に追加するなら、schema 変更が必要です。しかし #1023 の Allowed Paths には schema ファイルが入っていません。これは実装前 blocker です。B3. Planner は「全 section 収集」を常に保証していない
既存 Planner は、
issue_kindが読めて template が解決できる場合、template の required labels から欠落 section を全件取得できます。 実際、implementation template 側ではMachine-Readable Contract、Parent Issue、Parent Goal Ref、Current Validated Scope、Remaining Parent Gaps、Outcome、In Scope、Out of Scope、Acceptance Criteria、Verification Commands、Allowed Paths、Stop Conditions、Required Skillsが required です。一方で、Machine-Readable Contract が無い場合、
_extract_missing_contract_keys()は空配列を返します。 さらにissue_kindが取れない場合はOutcomeだけに fallback します。 これでは #1023 の「最初の preflight で全件提示」は、最も壊れている入力ほど達成できません。B4. Wrapper が
rewrite_constraintsを捨てているPlanner の fail-closed output には
fail_closed.rewrite_constraintsが入ります。 しかしrun_refinement_preflight.pyはfail_closed.reason_codesをblockersに追加するだけで、rewrite_constraints.required_sections/required_contract_keysを result artifact や stdout に転送していません。#1023 の中核はここです。Planner を少し直すだけでは不十分です。Wrapper schema、artifact、compact stdout、issue-author input の受け渡し契約まで定義してください。
B5.
repair_issue_contract.pyとの関係が曖昧Wrapper は
repair_issue_contract.pyを dry-run で実行しますが、Planner には修復後 body ではなく元の Issue body を渡しています。 repair script は Machine-Readable Contract の escaped fence 修復などを持っています。そのため「決定的 repair なら issue_kind が読める」ケースでも、Planner は壊れた元 body だけを見て
Outcomefallback になる可能性があります。#1023 では、repair diagnostics と missing-section detection をどう合成するかを明記すべきです。修正方針
#1023 は次のように scope を拡張・明確化してください。
AC は次の形に直すのが安全です。
実装時の具体指示
plan_refinement_loop.pyではaccumulated_missing_sections = missingの代入ではなく、複数検査結果を merge/dedupe してください。required_contract_keys=[]で終わらせないでください。少なくともMachine-Readable Contractsection 欠落と canonical keys の要求を constraints に出す設計が必要です。run_refinement_preflight.pyでplan["fail_closed"]["rewrite_constraints"]を取り出し、schema-valid な result artifact に格納してください。BLOCKERSに JSON 文字列として埋めるのは避けるべきです。REWRITE_CONSTRAINTSまたはREQUIRED_SECTIONS/REQUIRED_CONTRACT_KEYSの短縮 projection を追加してください。shell=False/ argv array を維持してください。Python docs でも shell を暗黙起動しないことが shell metacharacter handling 上安全で、shell=Trueは呼び出し側が quoting 責任を負うと説明されています。([Python documentation]2)追加すべきテスト
最低限、以下を入れないと再発防止として弱いです。
最終コメント
#1023 は「Planner の missing section 収集バグ」ではなく、Planner → Wrapper → artifact/stdout → issue-author の contract forwarding バグとして扱うべきです。現行コードでは Planner 側に rewrite constraints の土台はありますが、Wrapper schema が閉じており、転送経路がありません。まず Issue 本文で schema 変更と downstream consumer を scope に入れてから実装するのが妥当です。
squne121 commentedon Jun 20, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 20, 2026
改善ループ移管
プロジェクトルール外変更を避けるため、#1023 の実装分は新規 worktree へ分離しました。
必要なら 1023 本体にも差分を追従するための follow-up 参照として使用してください。
squne121 commentedon Jun 20, 2026
判定
REQUEST_CHANGES 相当です。
#1038 はすでに merge 済みですが、#1023 の目的である「fail_closed の不足セクション・contract key を最初に全件提示し、issue-author に lossless に渡す」はかなり改善された一方、reason_code の意味論、malformed contract の扱い、consumer 側 AC4/AC5 の証跡がまだ弱いです。
#1023 本体は、preflight で
missing_required_section/missing_required_contract_keyを全件出し、FAIL_CLOSED_REWRITE_CONSTRAINTS_V1.required_sectionsとして issue-author に渡すこと、さらに同一 reason の二重 rewrite と format-only repair による iteration 浪費を防ぐことをACにしています。その後、コメントで #1037 / PR #1038 に実装が移管され、#1038 は 2026-06-20 03:03:42Z に merge 済みです。
良くなっている点
#1038 は、初期レビューで指摘された「Wrapper が
rewrite_constraintsを捨てる」「schema が閉じているため artifact に追加できない」「stdout が downstream parseable ではない」という中核問題に対して、少なくとも構造上の対策を入れています。refinement_preflight_result_v1.schema.jsonにはplanner_fail_closed_reason_codes、required_sections、required_contract_keys、rewrite_constraintsが追加され、planner_fail_closed=trueの場合にそれらを必須化するif/thenも入っています。Wrapper 側も、compact stdout に
REQUIRED_SECTIONS、REQUIRED_CONTRACT_KEYS、REWRITE_CONSTRAINTSを出すようになり、REWRITE_CONSTRAINTSはjson.dumps(..., sort_keys=True, separators=(",", ":"))で deterministic JSON として出力しています。Python subprocess 呼び出しも
shell=Falseの argv 実行を維持しており、この点は安全です。Python docs でも、shell を暗黙使用しない場合は shell metacharacter の解釈を避けられ、shell=Trueでは呼び出し側が quoting に責任を負うと説明されています。 ([Python documentation]1)Blocker 1: Machine-Readable Contract セクション欠落時の reason_code が不正確
現在の planner は
Machine-Readable Contractセクションがない場合、required_sectionsに"Machine-Readable Contract"を入れる一方で、reason_code にはmissing_required_contract_keyを追加しています。これは downstream consumer にとって危険です。セクションが存在しない状態は「key 欠落」ではなく「required section 欠落」です。にもかかわらず
missing_required_contract_keyとして扱うと、issue-author が「既存 contract に key を足す」方向へ誤誘導される可能性があります。さらに
OVERRIDE_POLICYではmissing_required_contract_keyが allowed reason に入っており、malformation 系や parse error 系より軽い扱いになります。修正するなら、セクション欠落時は次のどちらかに寄せるべきです。
現行テストは
required_contract_keys == []までは見ていますが、reason_codes にmissing_required_contract_keyが混入しないことを見ていません。Blocker 2: malformed YAML と missing key がまだ混線している
_check_malformed_contract()はかなり粗く、YAML block があり、かつcontract_schema_version:文字列がなければ malformed と判定するだけです。一方、
_extract_missing_contract_keys()は Machine-Readable Contract section が存在するが_extract_machine_contract()がNoneの場合、全 required key を返します。つまり、次のようなケースが危険です。
そして
required_contract_keysは parsed_mapping のときだけ出す。parse error はrequired_contract_keysに混ぜず、contract_parse_statusまたはcontract_schema_parse_errorとして返すべきです。Major 1: schema は存在必須を見ているが、payload の自己整合性までは見ていない
JSON Schema では、
propertiesに書いただけでは property は必須にならず、requiredが必要です。またadditionalProperties: falseは余計な property を拒否するだけで、存在必須や値同士の一致までは担保しません。([JSON Schema]2)今回の
if/then追加自体は正しい方向です。JSON Schema のif/thenは、ifが valid のときthenも valid でなければならない、という条件付けに使えます。(JSON Schema)ただし、現在の schema は以下の一致までは保証していません。
Wrapper が現在コピーしているので通常は揃いますが、fallback や将来変更でズレても schema だけでは検出しにくいです。
_validate_with_schema()の前後に custom invariant check を追加し、ズレたらRESULT_SCHEMA_INVALIDまたは専用 blocker にすべきです。Major 2:
allow_nan=Falseがないため、machine-readable JSON としてはまだ甘いREWRITE_CONSTRAINTSは deterministic JSON になりましたが、json.dumps()にallow_nan=Falseが指定されていません。Python のjson.dumpsは既定でNaN/Infinityを出力し得ますが、これは JSON 仕様準拠ではありません。([Python documentation]4)現在の
_ensure_json_serializable()と compact stdout のjson.dumps()はどちらもallow_nan=Falseを指定していません。修正案:
追加テスト:
Major 3: planner payload invalid を
blocked扱いにするのは誤誘導になり得るWrapper は planner の
reason_codesやrewrite_constraints.required_sectionsに非文字列が混ざると blocker を追加し、safe fallback payload に落とします。しかし exit mapping では、
GH_API_FAILUREとRESULT_SCHEMA_INVALID以外の blocker は原則blockedになります。これは人間・issue-author から見ると「Issue 本文を直せば進む blocked」に見えます。実際には planner-wrapper 間の内部契約違反なので、
environment_failureまたはRESULT_SCHEMA_INVALIDに近い扱いのほうが正確です。推奨:
少なくとも、Issue 本文修正ループに戻さないでください。ここを誤ると #1023 の目的である token 浪費削減に反します。
Major 4:
test_good_fixture_does_not_fail_closedが弱体化しているPR #1038 で
test_good_fixture_does_not_fail_closedは、以前のfail_closed.required is Falseとreason_codes == []の検証をやめ、現在は exit code と shape だけを見るテストになっています。これはテスト名と実態が一致していません。良性 fixture が fail_closed になっても検出できません。
もし
repo_path_in_outcomefixture が現行 template 契約ではもう valid ではないなら、テスト名を変えるべきです。そうでないなら assertion を戻すべきです。推奨:
#1023 は「fail_closed を正しく出す」だけでなく、「出すべきでない fail_closed を出さない」ことも重要です。
Major 5: #1023 AC4 / AC5 は #1038 だけでは閉じていない
#1023 のAC4は「同一 reason で2回以上 rewrite しない」、AC5は「max_iterations を format-only repair で浪費しない」です。
一方、#1038 の変更は主に planner / wrapper / schema / tests / fixtures で、reason-history や iteration state を持つ consumer 側の実装は見えていません。PR #1038 は45ファイル・+1525/-95の変更ですが、PR本文上の検証も
test_refinement_preflight.pyの単体実行に留まっています。初期レビューコメントでも、AC4/AC5 は consumer 側の reason-history / iteration state で検証すべき、と指摘されています。
したがって、#1023 を完了扱いにするなら、少なくとも次の follow-up が必要です。
Minor: repair pass は依然として planner 入力に反映されていない
Wrapper は
repair_issue_contract.pyを dry-run しますが、コメントで明示されている通り、planner は修復後 body ではなく元の Issue body を受け取ります。これは #1023 の背景にある「format-only repair で iteration を浪費する」問題と相性が悪いです。
安全にやるなら、planner に直接修復済み body を食わせるより、次のような明示的な sidecar を渡すのがよいです。
{ "repair_diagnostics": { "changed": true, "change_kind": "format_only", "repaired_body_sha256": "...", "safe_for_planner_detection": true } }そのうえで、format-only repair は rewrite iteration に数えない、という consumer 仕様に接続してください。
推奨する follow-up Issue 草案
Stop Conditions
[-]実装: issue-refinement-loop preflight で required sections を全件提示し、逐次発見を防ぐ[/-][+]改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる[/+]squne121 commentedon Jun 20, 2026
更新内容
改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じるに更新Current Validated Scope/In Scope/Stop Conditionsを consumer rewrite budget 反映版へ更新Guard 結果
check_vc_scope.py: PASSguard-issue-body.py: PASScontract_readiness_check.py: gosqune121 commentedon Jun 20, 2026
Close判断
#1038 の merge により本Issueの主要な forwarding / contract 透過は実装済みです。
未解消の残課題は本Issue上でも指摘されている reason semantics / consumer rewrite budget などの follow-up 領域に寄るため、#1023 自体はここで close します。
必要な追加修正は follow-up issue 側を正本として継続してください.
squne121 commentedon Jun 20, 2026
handoff 明確化
直前の close コメントで書いた
follow-up issueは、まず #1037(PR #1038 で実装されたissue-refinement-loop preflight の fail_closed 制約を issue-author へ安全透過)を指していました。一方で、live issue を見直すと、#1037 のスコープは主に forwarding / preflight wrapper 側であり、#1023 の最終版に残っていた
reason semantics/malformed contract と missing key の分離/consumer rewrite budgetまでを完全には包含していません。したがって、今回の close は次の意味です。
つまり、
follow-up issueという表現は少なくとも #1037 を指していましたが、#1023 の残課題すべてが #1037 に完全移管された、という意味ではありません。このコメントをもって handoff の指し先を明示します.squne121 commentedon Jun 20, 2026
canonical handoff 追記
#1023 close 後に未移管だった残課題は、#1067 を canonical destination として引き継ぎました。
#1037 / #1038 は forwarding / schema / compact stdout 透過の完了先、#1067 はその後も残っていた reason semantics / malformed contract 境界 / consumer rewrite budget gap の追跡先です。