Repository navigation
Closed
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "#1023 の未移管残課題を implementation issue として明示し、reason semantics / consumer rewrite budget gap を閉じる"
change_kind: workflowParent Issue
none
Parent Goal Ref
- Goal: 改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる #1023 最終版で未移管だった reason semantics / malformed contract 境界 / consumer rewrite budget gap を、再開可能な implementation issue として明示する。
- Desired Destination: issue-refinement-loop fail_closed contract の残課題を 1 Issue = 1 PR で閉じる。
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
なし(本 Issue を #1023 未移管分の canonical destination とする)
Outcome
issue-refinement-loop の fail_closed rewrite contract に残っている reason semantics / malformed contract 境界 / consumer rewrite budget gap が、validator と consumer 契約を含めて deterministic に閉じた状態になる。
Contract Semantics Matrix
section 欠落・malformed・key 欠落の 3 ケースは以下のように分離する。
| ケース | reason_codes | required_sections | required_contract_keys |
|---|---|---|---|
Machine-Readable Contract section なし |
missing_required_section |
["Machine-Readable Contract"] |
[] |
| section はあるが YAML block なし / malformed / parse error | malformed_machine_readable_contract または contract_schema_parse_error |
[] |
[] |
| YAML parse 成功だが required key 欠落 | missing_required_contract_key |
[] |
欠落 key のみ |
- section 欠落時に
missing_required_contract_keyを 出してはならない。 - parse error 時に
required_contract_keysを出力しては ならない(parsed mapping のときだけ許可)。 contract_parse_statusフィールドで"missing_yaml_block"/"parse_error"を明示することを推奨する。
In Scope
Machine-Readable Contractsection 欠落時の reason semantics をmissing_required_contract_keyから分離する修正- malformed YAML / parse error / missing key の判定境界を
plan_refinement_loop.pyと preflight consumer で明確化する修正 run_refinement_preflight.pyによる top-level / nested rewrite payload の自己整合性検証追加- compact stdout / serializability check の strict JSON 化(
allow_nan=False) - non-string / non-JSON planner payload を environment failure / fix_environment routing に送る修正
- issue-author / rewrite consumer 側の同一 reason + 同一 constraints 二重 rewrite 防止
- format-only repair が max_iterations を消費しない state / route / test の追加
- false-positive fail_closed を検出する valid fixture / 回帰テストの追加または復元
- router state schema の更新(
last_mutation_kind/budget_debit/rewrite_request_fingerprintフィールド追加) route_after_rewrite.py/decide_rewrite_route.pyの artifact source-of-truth 読み取りへの移行
Out of Scope
#1038で完了済みの forwarding / schema / compact stdout 透過の再実装- Issue template 種別の追加や product spec policy の変更
- unrelated runtime / permission / workflow change
issue-refinement-loop以外の別ワークフロー全面改修
Acceptance Criteria
- AC1:
Machine-Readable Contractsection 欠落時はrequired_sectionsにMachine-Readable Contractを出し、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: planner output / wrapper result / compact stdout / artifact hash / schema validation のすべての JSON シリアライズで
allow_nan=Falseを使い、NaN / Infinity 系 payload を environment failure として扱う。 - AC5: JSON parsing の machine payload 読み取りが NaN / Infinity / -Infinity を reject する(読み込み側も strict)。
- AC6:
REWRITE_CONSTRAINTS_NON_STRING_PAYLOAD/REWRITE_CONSTRAINTS_NOT_JSON_SERIALIZABLE/planner_fail_closed_payload_invalidがenv_blockersに含まれ、next_action: fix_environmentへ routing される。Issue 本文修正 blocker に見えない形で出力される。 - AC7: wrapper の custom invariant が
required_sections == rewrite_constraints.rewrite_constraints.must_add_sectionsとrequired_contract_keys == rewrite_constraints.rewrite_constraints.must_add_contract_keysを検証し、不一致をREWRITE_CONSTRAINTS_INVARIANT_VIOLATIONとしてenvironment_failureへ送る。 - AC8:
route_after_rewrite.pyが checker prose / stdout からmissing_sectionsを regex で復元せず、refinement_preflight_result_v1artifact または同等の machine field を source of truth として読む。artifact path が無い / 読めない / schema invalid の場合はenvironment_failure / fix_environment。 - AC9: router state が
reason_codes + rewrite_constraintsの strict-JSON fingerprint を保持し、同一 fingerprint の再出現をhuman_judgment_requiredまたはno_progress_routeに送る。 - AC10: router state が
last_mutation_kind: semantic_rewrite | format_only_repair | no_changeとbudget_debit: 0 | 1を区別し、format-only repair はbudget_debit=0でmax_iterationsを消費しない。 - AC11: false-positive fail_closed を検出できる valid canonical fixture または good fixture 検証が回帰テストで担保される。
Verification Commands
# AC1, AC2
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py -q
# AC3, AC6, AC7
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_refinement_preflight.py -q
# AC4, AC5
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_fail_closed_override_rewrite.py -q
# AC8, AC11
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_route_after_rewrite.py -q
# AC9, AC10
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_rewrite_router.py -q
# AC3
$ 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
Stop Conditions
- 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 を更新せずに AC を満たせないと判明した場合(→ Stop Condition の観点でも当該ファイルは Allowed Paths に含まれているので問題なし)- false-positive fail_closed を再現できる valid fixture を特定できない場合
Runtime Verification Applicability
decision: deferred
deferred_verification_condition: "テストファイル実装完了後(実装 PR マージ時)にすべての pytest が pass する。VC baseline は exit 4(file not found)が期待値。"Required Skills
- Python scripting
- issue-refinement-loop fail_closed contract 理解
- issue-author consumer 契約理解
Delivery Rule
1 Issue = 1 PRで完了する。- Draft PR を既定とする。
- 改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる #1023 の close 後に残った未移管分の canonical destination として扱う。
Metadata
Metadata
Assignees
Labels
agent/implementerAI implementer agentenhancementNew feature or requestphase/implementationImplementation phasetriage-requiredNeeds owner triage for priority decision
Activity
squne121 commentedon Jun 20, 2026
判定
#1067 は 必要な implementation issue です。ただし、このまま実装に入ると「ACを満たしたように見えるが、consumer 側ではまだ誤 rewrite / budget 誤消費が残る」可能性が高いです。#1067 自体にコメントはなく、根拠は本文・#1023・#1037・PR #1038・現行 main の該当コードです。
#1023 は完了扱いですが、残課題として「Machine-Readable Contract section 欠落時の reason semantics」「malformed YAML / parse error と missing key の分離」「consumer rewrite budget」が明示されており、#1067 はその未移管分の受け皿として妥当です。
一方、#1037 はまだ open で、Planner の
rewrite_constraints/required_sections/required_contract_keysを Wrapper 経由で issue-author に渡す断絶を扱っています。#1038 はその一部を merge した PR ですが、現行コードを見る限り #1067 の主張する残バグは実在します。Blocker 1: section 欠落時の reason code がまだ間違っている
現行
plan_refinement_loop.pyはMachine-Readable Contractsection が存在しない場合に、required_sectionsへMachine-Readable Contractを追加しつつ、reason code はFAIL_CLOSED_REASON_MISSING_CONTRACT_KEYを追加しています。これは #1067 / #1023 の AC と正面衝突します。section が無い状態は key 欠落ではありません。さらに
_extract_missing_contract_keys()は、section が無い場合は空配列を返す一方、section はあるが YAML を parse できない場合に required key 全件を返します。#1067 の AC2 は「required_contract_keysは parsed mapping のときだけ出す」としているため、malformed YAML で required key 全件を返す現仕様も直す必要があります。実装方針は明確に分けるべきです。
新 reason code を増やすなら schema enum / override policy / tests まで同時更新が必要です。後方互換を壊せないなら、少なくとも section 欠落は既存
missing_required_sectionに寄せるべきです。Blocker 2: strict JSON 化が不完全
#1067 は
allow_nan=Falseを要求していますが、現行run_refinement_preflight.pyの_canonical_json()と_ensure_json_serializable()はjson.dumps(..., allow_nan=False)を使っていません。compact stdout のREWRITE_CONSTRAINTSもsort_keys=Trueは使っていますが、allow_nan=Falseがありません。これは仕様上の瑕疵です。Python の
json.dumpsは既定ではNaN/Infinity/-Infinityを出力し得ますが、標準JSONではこれらは許可されません。Python docs でもallow_nan=Falseにすると非有限数でValueErrorになると説明されていますし、RFC 8259 でもInfinityやNaNは許可されないとされています。([Python documentation]1)共通関数を作って全箇所に強制するのが安全です。
また、読み込み側も
json.loads()のparse_constantでNaN/Infinityを reject しないと「出力だけ strict、入力は permissive」という片手落ちになります。Blocker 3: invalid planner payload が environment_failure に落ちない
#1067 の AC5 は、planner / wrapper 間の non-string / non-JSON payload を Issue 本文修正 blocker ではなく
environment_failure / fix_environmentへ送ることを要求しています。しかし現行_apply_exit_code_mapping()のenv_blockersはGH_FAILUREとRESULT_SCHEMA_INVALIDだけです。REWRITE_CONSTRAINTS_NON_STRING_PAYLOADやplanner_fail_closed_payload_invalidは env 扱いされず、通常のblocked → human_judgment_requiredへ流れます。payload invalid の検出自体はあります。
required_sections/required_contract_keysの非 string を検出し、planner_fail_closed_payload_invalidを blocker に追加しています。問題は、その後の routing が AC と一致していない点です。修正は
env_blockersに以下を入れるだけでは足りません。next_actionもfix_environmentへ落ちること、artifact / stdout 上で Issue 修正要求に見えないことをテストで固定してください。Major 1: schema だけでは top-level / nested の一致を保証できない
現行 schema は
planner_fail_closed=trueのときにplanner_fail_closed_reason_codes/required_sections/required_contract_keys/rewrite_constraintsを必須化しています。これは #1038 のレビュー指摘に対する前進です。ただし、schema は
required_sectionsとrewrite_constraints.rewrite_constraints.must_add_sectionsが同一であることを保証していません。required_contract_keysとmust_add_contract_keysも同様です。schema 上は両方とも list[string] であれば通ります。JSON Schema では、
propertiesに書いた property は自動的に required にならず、requiredが必要です。またadditionalProperties:falseは余計な property を拒否するだけで、値同士の同一性までは表現しません。条件分岐にはif/then/elseを使えますが、配列同士の完全一致は標準 JSON Schema だけで扱いづらいため、custom invariant が妥当です。(JSON Schema)追加すべき invariant は最低限これです。
不一致は
RESULT_SCHEMA_INVALIDではなく、明示的にREWRITE_CONSTRAINTS_INVARIANT_VIOLATIONのような blocker にしてenvironment_failureへ送るべきです。Major 2: consumer が artifact を source of truth にしていない
#1067 は「issue-author / rewrite consumer が artifact field を source of truth として読む」ことを要求しています。しかし現行
route_after_rewrite.pyは checker のblocking_issues文字列を regex で解析してmissing_sections/missing_contract_keysを復元しています。これは artifact source-of-truth ではなく、自然文 / 日本語エラーメッセージ依存です。issue-author.mdにはFAIL_CLOSED_REWRITE_CONSTRAINTS_V1の契約はありますが、実際の入力としてrefinement_preflight_result_v1artifact path を受け取り、そこからrewrite_constraintsを読む、という手順は弱いです。edit-issue/SKILL.mdの Inputs もreadiness_forwarding_payloadは定義していますが、fail_closed rewrite constraints artifact を source-of-truth とする入力は明示されていません。ここは #1067 の AC を強化してください。
Major 3: duplicate rewrite 防止が fix_category 粒度で粗すぎる
現行 router state は
rewrite_historyにfix_categoryを積み、occurrence_countで同カテゴリ再発を見ています。decide_rewrite_route.pyの state も missing section/key、hash、fix_category、occurrence_count は持っていますが、reason_codes + rewrite_constraintsの fingerprint は持っていません。これでは「同じ reason + 同じ constraints で二重 rewrite」を機械的に拒否するには粗いです。body hash が変わっても constraints が同一なら、実質的に同じ修正要求を繰り返している可能性があります。missing set の strict decrease はありますが、consumer rewrite payload の同一性そのものは見ていません。
追加すべき state はこれです。
同一 fingerprint が再出現した場合は
human_judgment_requiredまたはno_progress_routeに落とすべきです。fix_categoryの再発は category-wide remediation に使えますが、同一 payload の二重 rewrite 防止には不十分です。Major 4: format-only repair の budget 非消費が現在の state では証明できない
issue-author.mdにはissue_contract_hygiene_autofix.pyによる format hygiene repair があり、contract_hygiene_repair_appliedを結果に含める契約があります。しかし
route_after_rewrite.pyは previous state がある場合にrewrite_attempt_count + 1しています。format-only repair を budget 外にするためのattempt_kind/budget_debit/contract_hygiene_repair_appliedの入力はありません。#1067 の AC7 を満たすには、router state schema の変更が必要です。
そして increment はこうするべきです。
これは allowed paths 内の
decide_rewrite_route.py/ schema / tests に収まりますが、Issue 本文に「router state schema 更新を許可」と明記した方が実装者が Stop Condition に誤って入らずに済みます。Major 5: repair diagnostics と planner input の関係がまだ曖昧
run_refinement_preflight.pyはrepair_issue_contract.pyを dry-run しますが、修復後 body は planner に渡さず、planner は常に元の Issue body を受け取る、とコメントされています。この仕様のままだと、format-only repair が可能な入力でも planner は壊れた本文を見て fail_closed し続ける可能性があります。#1023 の anchor comment でもここは曖昧さとして指摘されていました。
#1067 では次のどちらかを固定するべきです。
どちらでも構いませんが、未定義のまま実装すると budget 非消費と fail_closed reason semantics が再び混線します。
追加すべきテスト
現状の #1067 AC に加えて、以下は必須です。
#1067 本文への修正提案
#1067 は実装 Issue として維持してよいですが、以下を追記した方が安全です。
最終評価
#1067 は 採用すべき です。ただし、現状の Issue 本文のままだと「planner の reason 修正」「wrapper の JSON strict 化」「consumer の budget 制御」が横並びに書かれているだけで、実装者が route / state / artifact source-of-truth を弱く実装しても AC を満たしたように見えてしまいます。
実装前に上記の semantics matrix、strict JSON 方針、environment_failure routing、rewrite fingerprint、format-only budget debit を本文に追加してください。そこまで固定すれば、#1038 の残りを閉じる implementation issue として十分に高品質です。
squne121 commentedon Jun 20, 2026
Refinement Loop: Approved
The issue has been approved and is ready for implementation.
approvedsqune121 commentedon Jun 21, 2026
CONTRACT_REVIEW_RESULT_V1
squne121 commentedon Jun 21, 2026
IMPLEMENT_RESULT_V1
fix(#1067): B1/B2 ブロッカー修正 — schema revert + fingerprint duplicate rou…
fix(#1067): route_after_rewrite.py の AC9/AC10 フィールドを schema から除外
fix(#1067): B1-B5/Major 1-3 バグ修正 + AC8-11 テスト追加 (iteration 2)
fix(#1067): issue-refinement-loop reason semantics と consumer rewrite…
squne121 commentedon Jun 21, 2026
PR #1071 がマージされました。AC1-AC11 全通過・bot APPROVE (iteration 2) を確認。クローズします。