Skip to content

実装: plan_refinement_loop FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 スキーマを schemas/ に追加する(#661 follow-up) #663

Closed

Description

@squne121

Machine-Readable Contract

スキーマ定義 + テスト再有効化の実装 Issue。

contract_schema_version: v1
issue_kind: implementation
parent_issue: "#647"
goal_ref: "FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を JSON Schema で固定し、PR #661 で skip されたスキーマ検証テストを再有効化する"
change_kind: mixed

Parent Issue

#647 — fail-closed override 基盤整備を担う親 Issue。本 Issue はそのスコープ内のフォローアップ。

Parent Goal Ref

  • Goal: plan_refinement_loop.py が出力する FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 契約を JSON Schema で機械的に固定する
  • Desired Destination: fail_closed.rewrite_constraints が schema-valid として検証され、plan_refinement_loop.py のすべての fail-closed reason code が schema の enum に反映されている状態

Current Validated Scope

本 Issue の実装スコープ(write-capable scope)は以下の2ファイルに限定する。

  • .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json に definitions.FailClosedRewriteConstraintsV1 を追加し、fail_closed.properties.rewrite_constraints から $ref で参照する
  • .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py の pytest.skip を削除し、schema self-validation test と negative tests を追加する

Remaining Parent Gaps

本 Issue で塞がない親 Issue の未解決 gap は以下の通り。

Outcome

.claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json に FailClosedRewriteConstraintsV1 definition が追加され、PR #661 で skip された test_schema_validation_all_fixtures / test_fail_closed_is_schema_valid が PASS し、negative tests が invalid instance を reject する状態。

In Scope

本 Issue の対象スコープは以下の通り。

  • schemas/refinement_loop_plan_v1.json への definitions.FailClosedRewriteConstraintsV1 追加
  • fail_closed.properties.rewrite_constraints の optional $ref 追加
  • fail_closed.reason_codes.items.enum への PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 追加 reason code の同期
  • tests/test_plan_refinement_loop.py の pytest.skip 削除
  • schema self-validation test の追加
  • negative tests の追加(未知キー・invalid const 値・unknown reason code)

Out of Scope

本 Issue のスコープ外は以下の通り。

Acceptance Criteria

以下の受け入れ条件をすべて満たすこと。

  • AC1: .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json の fail_closed.properties に optional な rewrite_constraints が追加され、"$ref": "#/definitions/FailClosedRewriteConstraintsV1" で参照されている。fail_closed.required には追加しない
  • AC2: definitions.FailClosedRewriteConstraintsV1 が追加され、PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 の planner 出力 shape(schema_version, required_sections, required_contract_keys, rewrite_constraints, override_policy, max_rewrite_attempts, no_progress_route)と一致している
  • AC3: schema_version、freeform_rewrite_forbidden、max_rewrite_attempts、no_progress_route が const で固定されている(それぞれ "FAIL_CLOSED_REWRITE_CONSTRAINTS_V1"、true、2、"human_judgment_required")
  • AC4: override_policy.allowed_reason_codes / never_override_reason_codes / overridable_in_current_result / non_overridable_in_current_result が配列として schema 化されている
  • AC5: fail_closed.reason_codes.items.enum が plan_refinement_loop.py(PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 マージ後)が出力し得るすべての fail-closed reason code を含む(missing_required_contract_key、unknown_issue_kind、issue_kind_policy_load_error、contract_schema_parse_error、template_resolution_error、checker_internal_error、missing_required_parent_section、template_required_sections_unavailable を含む)
  • AC6: FailClosedRewriteConstraintsV1 とその nested object(rewrite_constraints、override_policy)はすべて additionalProperties: false である
  • AC7: Draft202012Validator.check_schema(schema) を実行する schema self-validation test が test_plan_refinement_loop.py に追加されている
  • AC8: PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 で追加された pytest.skip が test_schema_validation_all_fixtures と test_fail_closed_is_schema_valid から削除されており、skip 条件が残っていない
  • AC9: negative tests が追加されており、以下の invalid instance を reject する:rewrite_constraints 内の未知キー、freeform_rewrite_forbidden: false、schema_version の typo、unknown reason code、max_rewrite_attempts: 3

Verification Commands

以下のコマンドで各 AC を検証する。

# AC1
# AC2
# AC3
# AC4
# AC5
# AC6
# AC7
# AC8
# AC9
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py -v

$ uv run pytest .claude/skills/issue-refinement-loop/tests/ -v
$ pnpm typecheck
$ pnpm lint
$ pnpm test
$ pnpm build

Allowed Paths

変更対象ファイルは .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json と .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py の2ファイルに限定する。

Stop Conditions

以下のいずれかが発生した場合は即時作業を停止し、Issue コメントに状況を記録して人間の判断を待つ。

Runtime Verification Applicability

本 Issue はスキーマ定義(JSON ファイル)とテストコードの変更のみであり、ブラウザ・ゲームループ・外部 API などのランタイム動作を変更しない。

  • decision: not_applicable
  • reason: schema + test のみの変更であり、runtime 挙動の変化なし

Required Skills

実装に必要な技術領域は以下の通り。

  • JSON Schema Draft 2020-12 の definitions / $ref / const / additionalProperties キーワードを使ったスキーマ型定義
  • Python jsonschema ライブラリの Draft202012Validator.check_schema によるスキーマ自己検証

Scope Delta

なし。Allowed Paths と実作業の乖離はない。

Activity

  1. added
    enhancement
    phase/implementation
    area/ai-ops
    on Jun 4, 2026
  2. squne121 commented on Jun 4, 2026

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #663 は方向性として妥当ですが、現状の Issue 定義は実装指示として不十分です。単に fail_closed.rewrite_constraints を schema に追加して skip を外すだけでは、#661 が導入した fail-closed 契約全体を schema が受け止められない可能性が高いです。#663 自体は「#661 follow-up」として、schema 未更新のため test_schema_validation_all_fixtures と test_fail_closed_is_schema_valid が skip されている問題を解く Issue です。([GitHub]1)

    #647 の本来スコープは、required_sections / required_contract_keys / rewrite_constraints / override_policy / FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を planner・issue-author・checker・router の契約として通すことです。つまり #663 は「schema にフィールドを1個足す」ではなく、「#661 でコード・fixture・agent contract に現れた構造化契約を JSON Schema とテストで固定する」Issue として扱うべきです。([GitHub]2)

    致命的な不足

    1. 対象パスが曖昧

    #663 の本文では実体として .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json が問題だと書かれていますが、AC では schemas/refinement_loop_plan_v1.json と短縮されています。リポジトリ上の schema は .claude/skills/issue-refinement-loop/schemas/ 配下に存在するため、AC はフルパスで固定すべきです。([GitHub]1)

    修正要求:
    AC1 を次のように具体化してください。

    .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json の fail_closed.properties に optional な rewrite_constraints を追加する。


    2. rewrite_constraints の shape が未定義

    #661 の planner 実装は fail_closed.rewrite_constraints に、schema_version, required_sections, required_contract_keys, rewrite_constraints.must_add_sections, rewrite_constraints.must_add_contract_keys, freeform_rewrite_forbidden, override_policy, max_rewrite_attempts, no_progress_route を含む構造を返す設計です。これを schema 側で曖昧な type: object として受けると、契約化ではなく穴になります。([GitHub]3)

    JSON Schema の additionalProperties は、properties / patternProperties に載っていないプロパティへ適用されます。既存 schema の fail_closed は additionalProperties: false なので、rewrite_constraints を明示的に properties へ追加しない限り、#661 の出力は invalid になります。([GitHub]4)

    修正要求:
    definitions.FailClosedRewriteConstraintsV1 を追加し、最低限これを固定してください。

    {
      "schema_version": { "const": "FAIL_CLOSED_REWRITE_CONSTRAINTS_V1" },
      "freeform_rewrite_forbidden": { "const": true },
      "max_rewrite_attempts": { "const": 2 },
      "no_progress_route": { "const": "human_judgment_required" }
    }

    max_rewrite_attempts や no_progress_route を単なる integer / string にすると、#647 の「止め方」の契約を schema が守れません。([GitHub]2)


    3. reason_codes enum 更新が AC にない

    既存 schema の fail_closed.reason_codes enum は古い値だけを許容しています。一方 #661 側では missing_required_contract_key, unknown_issue_kind, issue_kind_policy_load_error, contract_schema_parse_error, template_resolution_error, checker_internal_error などの fail-closed reason が実装・文書化されています。([GitHub]4)

    #663 が rewrite_constraints だけを足すと、skip を外した後に reason_codes enum mismatch で落ちる可能性があります。JSON Schema の enum は列挙配列のいずれかと完全一致することを要求するため、コードが出す値は schema enum に全て反映されている必要があります。([JSON Schema]5)

    修正要求:
    AC にこれを追加してください。

    fail_closed.reason_codes.items.enum は plan_refinement_loop.py が実際に出力し得る fail-closed reason code をすべて含む。

    さらにテストで「planner が生成した fail-closed fixture が schema validation を通る」ことを確認すべきです。


    4. definitions / $defs の扱いを誤る危険がある

    Draft 2020-12 では reusable schema の標準キーワードは $defs ですが、現行 schema は definitions と #/definitions/... で統一されています。#661 の skip guard も schema["definitions"]["FailClosedRewriteConstraintsV1"] の存在を見ています。([JSON Schema]6)

    ここで実装者が「Draft 2020-12 だから $defs に追加する」と判断すると、既存テストの skip guard が解除されない、または参照様式が混在します。

    修正要求:
    #663 では既存様式に合わせて definitions.FailClosedRewriteConstraintsV1 を追加してください。$defs への移行は別 Issue に切り出すべきです。


    5. additionalProperties の方針が曖昧

    #663 の AC4 は「additionalProperties が existing schema policy と consistent」と書いていますが、これは実装者に解釈余地を残しすぎです。現行 schema は root や fail_closed で additionalProperties: false を使っており、契約外フィールドを拒否する方向です。([GitHub]4)

    修正要求:
    AC4 は次のように明文化してください。

    FailClosedRewriteConstraintsV1 とその nested object はすべて additionalProperties: false とする。
    fail_closed.rewrite_constraints 自体は backward compatibility のため optional とし、fail_closed.required には追加しない。


    6. schema 自体の妥当性検査がない

    #663 の Verification は instance validation だけに寄っています。Python jsonschema では Draft202012Validator.check_schema(schema) により schema 自体の妥当性を検査できます。invalid schema は validation 結果を信頼不能にするため、schema 契約を追加する PR では必須です。([jsonschema]7)

    修正要求:
    VC に追加してください。

    uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py -q

    加えて、テスト内に以下を追加。

    Draft202012Validator.check_schema(schema)

    追加すべき Acceptance Criteria

    #663 は以下の形に修正した方が安全です。

    1. .claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json の fail_closed.properties.rewrite_constraints に optional $ref を追加する。

    2. definitions.FailClosedRewriteConstraintsV1 を追加し、feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 の planner 出力 shape と一致させる。

    3. schema_version, freeform_rewrite_forbidden, max_rewrite_attempts, no_progress_route は const で固定する。

    4. override_policy.allowed_reason_codes / never_override_reason_codes / overridable_in_current_result / non_overridable_in_current_result は配列として schema 化し、reason code enum と整合させる。

    5. fail_closed.reason_codes.items.enum は plan_refinement_loop.py が出力し得る全 reason code を含む。

    6. test_schema_validation_all_fixtures と test_fail_closed_is_schema_valid の skip を削除し、skip 条件を残さない。

    7. Draft202012Validator.check_schema(schema) を実行する schema self-validation test を追加する。

    8. negative test を追加する。

      • rewrite_constraints 内の未知キーは fail
      • freeform_rewrite_forbidden: false は fail
      • schema_version の typo は fail
      • unknown reason code は fail
      • max_rewrite_attempts: 3 は fail
    9. outer fail_closed.rewrite_constraints は optional のままにし、既存 fixture との backward compatibility を維持する。

    GitHub に貼るレビューコメント案

    REQUEST_CHANGES
    
    #663 は #661 follow-up として必要だが、現状の Issue 定義では実装範囲が狭すぎる。
    
    この Issue は単なる `fail_closed.rewrite_constraints` フィールド追加ではなく、#661 で `plan_refinement_loop.py` / fixtures / issue-author contract に導入された `FAIL_CLOSED_REWRITE_CONSTRAINTS_V1` を JSON Schema で固定し、skip されている schema validation tests を再有効化する作業として定義すべき。
    
    Blockers:
    
    1. 対象ファイルは `schemas/refinement_loop_plan_v1.json` ではなく `.claude/skills/issue-refinement-loop/schemas/refinement_loop_plan_v1.json` と明記すること。
    2. `fail_closed.properties.rewrite_constraints` を optional `$ref` として追加すること。`fail_closed.required` には追加しない。
    3. `definitions.FailClosedRewriteConstraintsV1` を追加し、`schema_version`, `freeform_rewrite_forbidden`, `max_rewrite_attempts`, `no_progress_route`, `override_policy`, nested `rewrite_constraints` を厳密に schema 化すること。
    4. `fail_closed.reason_codes.items.enum` を #661 の planner が実際に出力し得る reason code と同期すること。
    5. `additionalProperties: false` を nested object まで維持すること。
    6. `Draft202012Validator.check_schema(schema)` を追加し、schema 自体の invalid を検出すること。
    7. skip guard を削除し、`test_schema_validation_all_fixtures` / `test_fail_closed_is_schema_valid` が通常実行で PASS すること。
    8. negative tests を追加し、unknown key / unknown reason code / `freeform_rewrite_forbidden: false` / wrong schema_version / wrong max_rewrite_attempts を reject すること。
    
    この修正なしに merge すると、「skip は外したが schema が fail-closed 契約を過小検証している」状態になり、#647 の目的である fail-closed override の安全な機械契約化を満たさない。

    結論

    #663 は作るべきですが、現状のままでは Issue が弱いです。特に reason_codes enum、definitions.FailClosedRewriteConstraintsV1、const 固定、schema self-validation、negative tests が抜けています。ここを入れないと、#661 の follow-up ではなく「skip を消すための最小パッチ」になり、fail-closed 契約の品質保証として不十分です。

  3. squne121 commented on Jun 4, 2026

    @squne121
    OwnerAuthor

    Issue #663 の refinement loop が完了しました。アンカーコメントのフィードバックをすべて反映し、check_issue_contract.py の全チェック PASS・contract_review_status: go を確認しています。

    LOOP_HANDOFF_RESULT_V1:
      schema_version: 1
      termination_reason: approved
      issue_number: 663
      iterations_completed: 1
      final_verdict: approve
      contract_review_status: go
      handoff_state: implementation_ready
      loop_summary: |
        アンカーコメント(#issuecomment-4626457929)の REQUEST_CHANGES フィードバックを受け、
        Issue 本文を Japanese 見出し形式から標準 Implementation Issue contract 形式に完全リフォームした。
        AC を4項目から9項目(FailClosedRewriteConstraintsV1 definition・const 固定・reason_codes enum 更新・
        additionalProperties: false・schema self-validation・negative tests)に拡張。
        checker の全チェック PASS・日本語 prose guard の delta check PASS・status: go を確認した。
      blockers_resolved:
        - "AC パスが短縮形 → フルパス修正"
        - "rewrite_constraints の shape 未定義 → definitions.FailClosedRewriteConstraintsV1 追加 AC"
        - "reason_codes enum 更新が AC になかった → AC5 として追加"
        - "definitions vs $defs の扱い → definitions 固定を AC2 に明記"
        - "additionalProperties の方針が曖昧 → AC6 に additionalProperties: false 明記"
        - "schema 自体の妥当性検査なし → AC7 に Draft202012Validator.check_schema 追加"
      next_action: impl_review_loop_handoff
      prerequisite_note: "PR #661 マージ後に着手すること"
  4. squne121 commented on Jun 4, 2026

    @squne121
    OwnerAuthor

    契約スナップショット(issue-contract-review 完了・2026-06-05)

    issue-contract-review による事前検査が完了しました。全チェック PASS、status: go です。

    • 成果物: refinement_loop_plan_v1.json に FailClosedRewriteConstraintsV1 定義を追加し、PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661 でスキップされていたスキーマ検証テスト・ネガティブテストを有効化する
    • 対象 AC: AC1〜AC9(スキーマ定義・const 固定・reason_codes enum 同期・additionalProperties・スキーマ自己検証・スキップ削除・ネガティブテスト)
    • 許可パス: schemas/refinement_loop_plan_v1.json および tests/test_plan_refinement_loop.py(各 issue-refinement-loop skill 配下)
    • ワークツリー: .claude/worktrees/issue-663-plan-refinement-loop-fail-closed-rewrite
    • ブランチ: worktree-issue-663-plan-refinement-loop-fail-closed-rewrite
    • VC preflight: baseline fail = 0(期待通り)、想定外 pass = 0、実行不可 = 0、regression_gate pass = 6
    • PR feat(#647): fail_closed override 後に FAIL_CLOSED_REWRITE_CONSTRAINTS_V1 を返す #661: マージ済み(2026-06-04T22:47:03Z)。AC8 の pytest.skip 削除は安全に着手可能
    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-05T00:00:00Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/663
      checks:
        template_compliance: pass
        state_label: ok
        allowed_paths_present: pass
        vc_present: pass
        stop_conditions_complete: pass
        vc_preflight:
          passed: true
          vc_failed_as_expected: 0
          vc_passed_unexpectedly: 0
          vc_unrunnable: 0
          vc_expected_pass: 6
          vc_skipped: 0
          classifications:
            - ac: "AC1-AC9"
              command: "uv run pytest .claude/skills/issue-refinement-loop/tests/test_plan_refinement_loop.py -v"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
            - ac: "AC1-AC9"
              command: "uv run pytest .claude/skills/issue-refinement-loop/tests/ -v"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
            - ac: "AC9"
              command: "pnpm typecheck"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
            - ac: "AC9"
              command: "pnpm lint"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
            - ac: "AC9"
              command: "pnpm test"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
            - ac: "AC9"
              command: "pnpm build"
              exit_code: 0
              category: regression_gate
              scope_class: regression_gate
              classification: expected_pass
              confidence: low
              decision: go
        ac_verifiability: pass
        product_spec_check:
          applicability: not_applicable
          decision: pass
          triggers:
            docs_product_allowed_paths: false
            tasks_md_mentioned: false
            specify_artifact_mentioned: false
            generated_task_mentioned: false
            product_spec_context_present: false
          blocked_reasons: []
        worktree_branch_collision: clear
      next_action: implement_issue
      blocked_reasons: []
      warnings:
        - "PR #661 マージ確認済み(2026-06-04T22:47:03Z)。AC8 の pytest.skip 削除は安全に着手可能"
        - "全 VC が regression_gate(baseline pass)。実装後も同じコマンドで PASS を確認する設計"
  5. squne121 commented on Jun 5, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-06-05T00:02:22Z)

    実装が完了し Draft PR を作成しました。

    • PR: feat(#663): add FailClosedRewriteConstraintsV1 to refinement_loop_plan_v1.json schema #670
    • Worktree: .claude/worktrees/issue-663-plan-refinement-loop-fail-closed-rewrite
    • Branch: worktree-issue-663-plan-refinement-loop-fail-closed-rewrite
    • 検証結果: 6 コマンド全 PASS(pytest 38 passed、tests/ ディレクトリ全体 209 passed、typecheck / lint / test / build)
    • 後続: PR レビュー(pr-review-judge)→ マージ → post-merge-cleanup
  6. added 2 commits that reference this issue on Jun 5, 2026
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-opsenhancementphase/implementation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions