Skip to content

改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる #1023

Closed

Description

@squne121

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 Contract section 欠落時の 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_constraints forwarding の再実装
  • 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 Contract section 欠落時に 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 Contract section 欠落時は 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 と nested must_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.json

Allowed 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 を既定とする。

Activity

  1. added
    enhancement
    workflow
    area/ai-ops
    on Jun 20, 2026
  2. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    判定: 実装前に 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/v1 schema では素直に実装できない

    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 だけを見て Outcome fallback になる可能性があります。#1023 では、repair diagnostics と missing-section detection をどう合成するかを明記すべきです。

    修正方針

    #1023 は次のように scope を拡張・明確化してください。

    ## Allowed Paths に追加
    
    - `.claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json`
    - `.claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json`(必要な場合のみ)
    - issue-author / rewrite consumer の実体ファイル(未特定なら Stop Condition ではなく事前調査対象にする)

    AC は次の形に直すのが安全です。

    - [ ] AC1: planner fail_closed が `missing_required_section` を含む場合、template-derived required labels の欠落分を stable sorted / deduped で `FAIL_CLOSED_REWRITE_CONSTRAINTS_V1.required_sections` に全件入れる。
    - [ ] AC2: `missing_required_contract_key` がある場合、欠落 key を `required_contract_keys` に全件入れる。Machine-Readable Contract section 自体が無い場合も、section 欠落と canonical key 欠落を downstream が区別できる構造にする。
    - [ ] AC3: `run_refinement_preflight.py` の artifact と compact stdout が、schema-valid な形で `required_sections` / `required_contract_keys` を lossless に露出する。
    - [ ] AC4: issue-author は stdout 文字列パースではなく artifact/schema field から同一 payload を受け取る。
    - [ ] AC5: 「同一 reason で 2 回以上 rewrite しない」「max_iterations を format-only repair で浪費しない」は reason-history / iteration state を持つ consumer 側で検証する。consumer が本Issueの Allowed Paths 外なら、本IssueのACから外す。

    実装時の具体指示

    1. plan_refinement_loop.py では accumulated_missing_sections = missing の代入ではなく、複数検査結果を merge/dedupe してください。
    2. Machine-Readable Contract section 欠落時に required_contract_keys=[] で終わらせないでください。少なくとも Machine-Readable Contract section 欠落と canonical keys の要求を constraints に出す設計が必要です。
    3. run_refinement_preflight.py で plan["fail_closed"]["rewrite_constraints"] を取り出し、schema-valid な result artifact に格納してください。BLOCKERS に JSON 文字列として埋めるのは避けるべきです。
    4. compact stdout には、raw body/comments を出さない既存方針を維持しつつ、REWRITE_CONSTRAINTS または REQUIRED_SECTIONS / REQUIRED_CONTRACT_KEYS の短縮 projection を追加してください。
    5. Python subprocess 呼び出しは現状どおり shell=False / argv array を維持してください。Python docs でも shell を暗黙起動しないことが shell metacharacter handling 上安全で、shell=True は呼び出し側が quoting 責任を負うと説明されています。([Python documentation]2)

    追加すべきテスト

    最低限、以下を入れないと再発防止として弱いです。

    1. implementation template の複数 required sections が同時欠落する fixture
       - Parent Issue
       - Parent Goal Ref
       - Current Validated Scope
       - Remaining Parent Gaps
       - In Scope
       - Out of Scope
       - Stop Conditions
       - Required Skills
    
    2. Machine-Readable Contract は存在するが `contract_schema_version` または `issue_kind` が欠落する fixture
    
    3. Machine-Readable Contract section 自体が無い fixture
    
    4. Planner output:
       - reason_codes は重複しない
       - rewrite_constraints.required_sections は全件・stable sorted
       - required_contract_keys は全件
    
    5. Wrapper output:
       - artifact が result schema に通る
       - compact stdout に required_sections / required_contract_keys が出る
       - raw issue body / comments は stdout に出ない
    
    6. consumer 側:
       - 同一 reason の二重 rewrite を拒否する
       - format-only repair で max_iterations を消費しない
    

    最終コメント

    #1023 は「Planner の missing section 収集バグ」ではなく、Planner → Wrapper → artifact/stdout → issue-author の contract forwarding バグとして扱うべきです。現行コードでは Planner 側に rewrite constraints の土台はありますが、Wrapper schema が閉じており、転送経路がありません。まず Issue 本文で schema 変更と downstream consumer を scope に入れてから実装するのが妥当です。

  3. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Approved

    The issue has been approved and is ready for implementation.

  4. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    改善ループ移管

    プロジェクトルール外変更を避けるため、#1023 の実装分は新規 worktree へ分離しました。

    必要なら 1023 本体にも差分を追従するための follow-up 参照として使用してください。

  5. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    判定

    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 系より軽い扱いになります。
    修正するなら、セクション欠落時は次のどちらかに寄せるべきです。

    案A: 既存 reason を使う
    - required_sections: ["Machine-Readable Contract"]
    - required_contract_keys: []
    - reason_codes: ["missing_required_section"]
    
    案B: 新 reason を追加する
    - reason_codes: ["missing_required_contract_section"]
    - override_policy 上の扱いを明示する
    

    現行テストは 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 を返します。

    つまり、次のようなケースが危険です。

    ## Machine-Readable Contract
    
    ```yaml
    contract_schema_version: v1
    issue_kind: [broken
    
    この場合は本質的に **contract_schema_parse_error / malformed_machine_readable_contract** であり、`required_contract_keys` の補完問題ではありません。現行コードでは parse 不能を「全 key 欠落」として downstream に流す経路が残っています。
    
    既に `contract_schema_parse_error` reason_code は定義されています。  
    したがって、`_extract_machine_contract()` を単純な `dict | None` ではなく、次のような状態付き戻り値に変えるべきです。
    
    ```python
    ContractParseStatus = Literal[
        "section_absent",
        "yaml_block_absent",
        "yaml_parse_error",
        "parsed_mapping",
        "parsed_non_mapping",
    ]
    

    そして 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 は以下の一致までは保証していません。

    top-level required_sections
    == rewrite_constraints.required_sections
    == rewrite_constraints.rewrite_constraints.must_add_sections
    
    top-level required_contract_keys
    == rewrite_constraints.required_contract_keys
    == rewrite_constraints.rewrite_constraints.must_add_contract_keys
    

    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 を指定していません。

    修正案:

    json.dumps(
        value,
        ensure_ascii=False,
        sort_keys=True,
        separators=(",", ":"),
        allow_nan=False,
    )

    追加テスト:

    - rewrite_constraints に float("nan") が混入したら blocked / environment_failure
    - float("inf") / -float("inf") も拒否
    - compact stdout の REWRITE_CONSTRAINTS は strict JSON parser で round-trip できる
    

    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 に近い扱いのほうが正確です。

    推奨:

    REWRITE_CONSTRAINTS_NON_STRING_PAYLOAD
    REWRITE_CONSTRAINTS_NOT_JSON_SERIALIZABLE
    planner_fail_closed_payload_invalid
    
    => human_judgment_required ではなく fix_environment
    => exit 3
    

    少なくとも、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_outcome fixture が現行 template 契約ではもう valid ではないなら、テスト名を変えるべきです。そうでないなら assertion を戻すべきです。

    推奨:

    def test_canonical_valid_fixture_does_not_fail_closed():
        output, exit_code = run_planner(valid_canonical_input)
        assert exit_code == 0
        assert output["fail_closed"]["required"] is False
        assert output["fail_closed"]["reason_codes"] == []

    #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 が必要です。

    - issue-author / rewrite consumer が artifact の rewrite_constraints を読む
    - stdout 文字列 parse ではなく artifact/schema field を source of truth にする
    - previous_reason_codes / previous_required_sections / previous_required_contract_keys を保存する
    - 同一 reason + 同一 constraints で2回目の rewrite を拒否する
    - repair_issue_contract.py の format-only repair は iteration budget に含めない
    

    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 草案

    ## Title
    
    修正: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる
    
    ## 背景
    
    #1023 / #1038 により `required_sections` / `required_contract_keys` / `rewrite_constraints` の artifact/stdout forwarding は導入されたが、以下が未完了:
    
    - Machine-Readable Contract section 欠落時に `missing_required_contract_key` reason が出る
    - YAML parse error / malformed contract と missing key が混線し得る
    - `rewrite_constraints` top-level / nested payload の自己整合性が custom invariant で検証されていない
    - `json.dumps(..., allow_nan=False)` が未指定で strict JSON 契約として弱い
    - issue-author / rewrite consumer 側で AC4/AC5 が検証されていない
    
    ## Acceptance Criteria
    
    - [ ] Machine-Readable Contract section 欠落時は `required_sections=["Machine-Readable Contract"]` を出し、`missing_required_contract_key` は出さない。
    - [ ] Contract YAML parse error は `contract_schema_parse_error` または `malformed_machine_readable_contract` として扱い、`required_contract_keys` に混ぜない。
    - [ ] Wrapper が `required_sections` / `required_contract_keys` / nested `must_add_*` の一致を custom invariant で検証する。
    - [ ] `REWRITE_CONSTRAINTS` stdout と serializability check は `allow_nan=False` を使う。
    - [ ] non-string / non-JSON planner payload は Issue rewrite ではなく environment failure として扱う。
    - [ ] issue-author / rewrite consumer が artifact field を読み、同一 reason + 同一 constraints の二重 rewrite を拒否する。
    - [ ] format-only repair は max_iterations を消費しない。
    - [ ] `test_good_fixture_does_not_fail_closed` を復元するか、valid canonical fixture を追加して false-positive fail_closed を検出する。
    
    ## Verification Commands
    
    ```bash
    uv run pytest .claude/skills/issue-refinement-loop/tests/ -q
    python -m json.tool .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json

    Stop Conditions

    • issue-author / rewrite consumer の実体が特定できない場合
    • artifact schema field を consumer が読めない場合
    • 既存 fail_closed reason code の後方互換を壊す場合
    
    ## 最終評価
    
    #1038 は「Planner → Wrapper → artifact/stdout」までは大きく前進しています。  
    ただし、#1023 の本質は **issue-author が誤らず一回で直せる constraints contract** です。現在は `Machine-Readable Contract` 欠落・YAML parse error・key 欠落の境界がまだ曖昧で、payload invalid も人間修正可能な blocked に見えます。
    
    したがって、#1023 を完全完了にするには、**reason semantics の修正 + strict JSON 化 + consumer 側 iteration budget 制御**を follow-up で閉じるべきです。
    
  6. changed the title [-]実装: issue-refinement-loop preflight で required sections を全件提示し、逐次発見を防ぐ[/-] [+]改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる[/+] on Jun 20, 2026
  7. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    更新内容

    • title を 改善: issue-refinement-loop fail_closed constraints の reason semantics と consumer rewrite budget を閉じる に更新
    • body を最終版に差し替え
    • Current Validated Scope / In Scope / Stop Conditions を consumer rewrite budget 反映版へ更新

    Guard 結果

    • check_vc_scope.py: PASS
    • guard-issue-body.py: PASS
    • contract_readiness_check.py: go
  8. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    Close判断

    #1038 の merge により本Issueの主要な forwarding / contract 透過は実装済みです。

    未解消の残課題は本Issue上でも指摘されている reason semantics / consumer rewrite budget などの follow-up 領域に寄るため、#1023 自体はここで close します。

    必要な追加修正は follow-up issue 側を正本として継続してください.

  9. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    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 の指し先を明示します.

  10. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    canonical handoff 追記

    #1023 close 後に未移管だった残課題は、#1067 を canonical destination として引き継ぎました。

    #1037 / #1038 は forwarding / schema / compact stdout 透過の完了先、#1067 はその後も残っていた reason semantics / malformed contract 境界 / consumer rewrite budget gap の追跡先です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/ai-opsenhancementworkflow

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions