Skip to content

実装: fix(issue-refinement-loop): anchor_comment schema を docs の Required flow と一致させる #1010

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "anchor_comment の schema 正規化と preflight 正規化を一致させ、docs が要求する metadata を deterministic に enforcement できる状態にする"
change_kind: code

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: anchor-comment-handling.md が要求する LOOP_STATE.anchor_comment の required metadata と preflight 入力境界を repo reality に一致させる
  • Desired Destination: loop_state.schema.json と run_refinement_preflight.py が normalized anchor_comment state を共有し、schema-invalid anchor state を preflight で blocked にできる

Current Validated Scope

  • .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json で anchor_comment の正本 shape を definitions.anchor_comment に固定し、properties.anchor_comment から $ref 参照する
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py で GitHub issue comment API response から required metadata を正規化し、schema-invalid anchor state を blocked にする
  • .claude/skills/issue-refinement-loop/references/anchor-comment-handling.md を現行実装 shape と一致させる
  • .claude/skills/issue-refinement-loop/tests/ に anchor_comment.required / scope_impact null / 複数 --anchor-comment-url / anchor_comment_feedback boundary の regression を追加する

Remaining Parent Gaps

  • trusted anchor scope amendment を planner known_context に渡す routing 変更は #1008
  • CONTEXT_PROVENANCE_V1 による origin/actionability 分離は #1011
  • preflight 直後の phase gate は #1013
  • anchor reframe comment schema / template の運用面は #920

Background

現行の anchor-comment-handling.md は、LOOP_STATE.anchor_comment に url / id / issue_number / html_url / api_url / user_login / author_association / snapshot / timestamps / classification / scope_impact / requires_fact_check を保持することを要求している。

一方で live repo の loop_state.schema.json は anchor_comment を inline properties だけで持ち、definitions.anchor_comment も required もない。run_refinement_preflight.py も anchor URL の構造検証と issue_url 一致確認までは行うが、docs が要求する full metadata を schema-valid な normalized state として組み立てていない。

この不一致のため、schema enforcement を期待する Issue なのに AC / VC が現行 repo reality と食い違い、実装者が classification / fact_check_status のような別名 field を追加したり、scope_impact の null を文字列として実装したり、raw snapshot と normalized feedback の境界を曖昧にしたりする余地が残っている。

Outcome

loop_state.schema.json が definitions.anchor_comment を正本として docs required fields を schema enforcement し、run_refinement_preflight.py が GitHub issue comment API response から同 shape の normalized anchor_comment state を生成する。required field 欠落・enum 外値・複数 anchor URL・raw snapshot 境界違反は preflight / pytest で fail-closed に検出でき、routing 変更は #1008 / #1011 / #1013 に波及しない。

In Scope

  • definitions.anchor_comment を追加し、properties.anchor_comment は $ref で参照する
  • anchor_comment.required を anchor-comment-handling.md の Required LOOP_STATE fields と一致させる
  • author_association を OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE の enum として定義する
  • scope_impact を type: [\"string\", \"null\"] かつ enum: [\"none\", \"amend\", \"replace\", \"ambiguous\", null] で定義し、文字列 \"null\" は許容しない
  • classification / fact_check_status は追加せず、既存の preliminary_classification / final_classification / requires_fact_check を使う
  • run_refinement_preflight.py で id / html_url / api_url / user.login / author_association / created_at / updated_at / issue_url / body を取得し、schema-valid な normalized anchor_comment state を生成する
  • raw comment body は artifact にのみ保存し、planner input / Step 4 writer request には normalized anchor_comment_feedback のみを渡す
  • 複数 --anchor-comment-url はこの Issue では unsupported とし、ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED 相当の blocked routing を追加する
  • .claude/skills/issue-refinement-loop/tests/ に schema-invalid fixture、複数 anchor URL fixture、artifact boundary fixture を追加する

Out of Scope

  • decide_next_loop_action.py の routing ロジック変更
  • trusted anchor scope amendment を planner known_context に渡す処理
  • CONTEXT_PROVENANCE_V1 導入
  • phase gate / hard_stop_eligible routing
  • anchor-comment-handling.md への新規フロー追加(既存 required flow との整合のみ)
  • loop_state.schema.json の anchor_comment 以外のフィールド変更

Acceptance Criteria

  • AC1: loop_state.schema.json に definitions.anchor_comment が追加され、properties.anchor_comment がその $ref を参照している
  • AC2: definitions.anchor_comment.required が anchor-comment-handling.md の Required LOOP_STATE fields と一致し、author_association / comment_created_at / comment_updated_at / fetched_at / scope_impact / requires_fact_check を必須化している
  • AC3: scope_impact は JSON null を許容し、文字列 \"null\" を許容しない
  • AC4: classification / fact_check_status は追加されず、classification 系は preliminary_classification / final_classification / classification_reason / requires_fact_check に統一されている
  • AC5: run_refinement_preflight.py が GitHub issue comment API response から normalized anchor_comment state を生成し、required field 欠落・enum 外値・issue_url 不一致を preflight 段階で blocked にする
  • AC6: 複数 --anchor-comment-url はこの Issue のスコープでは blocked になり、単数 anchor 契約を fail-closed で守る
  • AC7: raw comment body は raw_issue_snapshot.json / raw anchor artifact にのみ保存され、planner_input.json と Step 4 writer request には normalized anchor_comment_feedback のみが含まれることを pytest で検証できる

Verification Commands

# AC1
# baseline-expect: fail
$ uv run pytest .claude/skills/issue-refinement-loop/tests -q -x -k "anchor_comment_ref or anchor_comment_schema_shape"

# AC2
# baseline-expect: fail
$ rg -n '"comment_created_at"' .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json

# AC3
# baseline-expect: fail
$ rg -n '"enum": \["none", "amend", "replace", "ambiguous", null\]' .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json

# AC4
# baseline-expect: fail
$ test -f .claude/skills/issue-refinement-loop/tests/fixtures/anchor_comment/classification_alias_rejected.json

# AC5
# baseline-expect: fail
$ rg -n 'author_association' .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py

# AC6
# baseline-expect: fail
$ rg -n 'ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED' .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py

# AC7
# baseline-expect: fail
$ test -f .claude/skills/issue-refinement-loop/tests/fixtures/anchor_comment_feedback/planner_input_boundary.json

Allowed Paths

  • .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json
  • .claude/skills/issue-refinement-loop/references/anchor-comment-handling.md
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/tests/**

Runtime Verification Applicability

decision: not_applicable

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合

Required Skills

  • JSON Schema(draft-07 / jsonschema validation)
  • Python / pytest
  • GitHub issue comment API response の正規化

Scope Delta(任意)

N/A

Activity

  1. added
    enhancement
    phase/implementation
    triage-required
    agent/implementer
    on Jun 19, 2026
  2. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    結論

    #1010 は方向性は正しいですが、このまま実装 Issue として渡すと失敗する可能性が高いです。理由は、docs と schema の不一致を直す Issue なのに、Issue 自体の AC / VC が現行 schema・既存 preflight 実装・関連 Issue の責務分割と矛盾しているためです。

    #1010 自体のコメントは空で、Closes #1010 検索でも明示的な関連作業は #1010 自身しか確認できませんでした。したがって、関連 Issue と現行ファイルを主証跡にしています。

    敵対的レビュー

    1. AC / VC が現行 loop_state.schema.json と噛み合っていない

    #1010 の Scope / Outcome は、loop_state.schema.json の anchor_comment を docs の Required flow と一致させ、preflight で schema-invalid anchor state を block することです。 しかし現行 schema の anchor_comment は properties 直下に inline 定義されており、definitions.anchor_comment は存在しません。現在あるのは url、preliminary_classification、final_classification、classification_reason、verified_claims、unresolved_claims、scope_impact、requires_fact_check 程度です。

    問題は、#1010 の検証コマンドが s['definitions']['anchor_comment'] を参照している点です。現行構造のまま実装すると VC は KeyError で落ちます。逆に VC に合わせて definitions.anchor_comment を追加するなら、properties.anchor_comment を $ref へ置き換える設計変更を AC に明記すべきです。

    修正案:
    definitions.anchor_comment を正本にし、properties.anchor_comment は $ref 参照にする。もしくは VC を s['properties']['anchor_comment'] 参照に直す。個人的には再利用性とテスト容易性のため、definitions.anchor_comment 化を推奨します。


    1. required を入れない限り “schema enforcement” にならない

    現行 schema の top-level required に anchor_comment は含まれていません。 さらに anchor_comment 内にも required がありません。JSON Schema draft-07 では、required は配列で指定された property の存在を要求し、省略時は空配列と同等です。つまり、properties に field を追加するだけでは必須化されません。

    #1010 は「必須フィールドを追加」と書いていますが、実装者が properties だけ足して終えるリスクが高いです。これはレビューで必ず落とすべきです。

    修正案:
    anchor_comment が存在する場合は以下を required に入れるべきです。

    [
    "url",
    "id",
    "issue_number",
    "html_url",
    "api_url",
    "user_login",
    "author_association",
    "snapshot",
    "captured_at",
    "fetched_at",
    "comment_created_at",
    "comment_updated_at",
    "preliminary_classification",
    "final_classification",
    "classification_reason",
    "verified_claims",
    "unresolved_claims",
    "scope_impact",
    "requires_fact_check"
    ]

    これは anchor-comment-handling.md の Required LOOP_STATE fields と一致します。


    1. scope_impact の null が壊れている

    #1010 の AC3 / VC は scope_impact enum を none | amend | replace | ambiguous | null としつつ、検証コマンドでは文字列 'null' を期待しています。これは危険です。

    JSON Schema の type における "null" は型名ですが、enum の要素として null を許可する場合は JSON の null 値そのものを入れます。draft-07 でも enum の要素は任意の値を取れ、null も含められると定義されています。

    NG:

    "enum": ["none", "amend", "replace", "ambiguous", "null"]

    推奨:

    "type": ["string", "null"],
    "enum": ["none", "amend", "replace", "ambiguous", null]

    VC も Python 側では None を期待する形に直すべきです。


    1. classification / fact_check_status が docs と衝突している

    #1010 の AC1 は classification / fact_check_status を追加対象にしています。しかし現行 docs は preliminary_classification、final_classification、requires_fact_check、verified_claims、unresolved_claims を要求しています。 現行 schema も preliminary_classification / final_classification / requires_fact_check を持っています。

    ここで classification や fact_check_status を新規追加すると、同じ意味の状態が二重化します。additionalProperties: false の schema では、曖昧な別名追加は将来の migration と test fixture を壊します。

    修正案:
    #1010 の AC1 から classification / fact_check_status を削除し、既存 docs に合わせて以下に統一する。

    preliminary_classification

    final_classification

    requires_fact_check

    verified_claims

    unresolved_claims


    1. preflight は anchor metadata を取得しているように見えて、実際は routing に使える state を作っていない

    GitHub REST の issue comment API は id、API url、html_url、body、user.login、created_at、updated_at、issue_url、author_association を返します。つまり #1010 が必要とするデータは API から取れます。

    しかし現行 run_refinement_preflight.py の anchor validation は、URL 構造・repo/issue 一致・comment existence・issue_url 一致を見るだけです。 実際の実装でも issue_url を検証した後、author_association、created_at、updated_at、body、html_url、user.login を正規化して LOOP_STATE.anchor_comment に落としていません。

    そのため、schema だけ増やしても #1008 の問題、つまり trusted anchor scope amendment を known_context.anchor_reframe: true として planner に渡せない問題は解消しません。#1008 はまさに、author_association / scope_impact が実装されず、scope_signal_guard が trusted human request と AI scope creep を区別できないことを問題にしています。

    修正案:
    #1010 の実装には最低限 _build_anchor_comment_state() を追加する必要があります。

    処理順は以下。

    1. URL parse

    2. gh api repos/{repo}/issues/comments/{comment_id} で comment fetch

    3. issue_url が対象 issue と一致することを検証

    4. API response から anchor_comment 正規化

    5. loop_state.schema.json の definitions.anchor_comment で validate

    6. invalid なら ANCHOR_COMMENT_SCHEMA_INVALID で blocked

    7. raw body は artifact のみに保存し、planner / writer には normalized feedback のみ渡す


    1. 複数 anchor URL 対応と単数 anchor_comment schema が矛盾している

    現行 CLI は --anchor-comment-url を複数受け取れます。_validate_anchor_comments_batch() も複数 URL を stable sort / dedupe します。 しかし schema/docs は LOOP_STATE.anchor_comment 単数です。

    このまま実装すると、複数 anchor が指定されたときに以下が未定義です。

    最初の 1 件だけ採用するのか

    複数を block するのか

    anchor_comments[] に schema を変えるのか

    trusted と untrusted が混ざった場合の判定はどうするのか

    修正案:
    #1010 は単数契約に閉じるべきです。active_anchor_urls が 2 件以上なら ANCHOR_COMMENT_MULTIPLE_UNSUPPORTED で blocked にする。複数 anchor を正式サポートするなら別 Issue です。


    1. feat: issue-refinement-loop に anchor scope reframe comment schema を追加する #920 / 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 / 実装: issue-refinement-loop に phase gate を追加し preflight 直後の誤った human_escalation を防ぐ #1013 との責務境界が曖昧

    #920 は、人間が anchor comment で scope 拡張を許可できる schema / template を追加する Issue です。背景には、OWNER が anchor comment を書いても excluded_by_anchor_reframe=false になり、loop が停止した問題があります。

    #1008 は、その trusted anchor comment を known_context.anchor_reframe: true として planner に渡す Issue です。

    #1011 は、anchor comment 由来の REQUEST_CHANGES を origin: trusted_anchor_comment / actionability: requirement、AI が自発的に追加した scope を origin: agent_inferred / actionability: hypothesis として分離する Issue です。

    #1013 は、scope_signal_guard.triggered を phase-sensitive に扱い、preflight 直後の誤った human_escalation を防ぐための phase gate Issue です。

    #1010 はこの中で schema / preflight 正規化の下位基盤 に限定すべきです。routing ロジックや phase gate まで触ると #1008 / #1011 / #1013 と衝突します。

    修正案:
    #1010 の Outcome を次のように狭めるべきです。

    anchor_comment の API snapshot を schema-valid な normalized state に変換し、invalid / untrusted / stale 判定に必要な metadata を artifact / known_context に渡せる状態にする。routing の最終判断変更は #1008 / #1011 / #1013 に委譲する。


    1. AC6 の検証が弱すぎる

    #1010 の AC6 は「Step 4 writer へは正規化済み feedback のみを渡す」ですが、VC は normalized_feedback / anchor_comment_feedback / raw_snapshot という文字列がソースに存在するかを見るだけです。これは実質的に無検証です。

    現行 preflight は raw issue snapshot、planner input、preflight result を artifact として書き出します。 また compact stdout は raw issue body / raw comments を出さない設計です。 この境界は良いので、AC6 は grep ではなく artifact / planner input の負例テストにするべきです。

    修正案:
    pytest で以下を検証する。

    raw_issue_snapshot.json には raw comment body がある

    planner_input.json には raw snapshot がない

    planner_input.json には anchor_comment_feedback だけがある

    Step 4 writer request fixture に anchor_comment.snapshot / raw body が混入しない


    実装を高品質化する具体案

    Schema 形状

    loop_state.schema.json は draft-07 なので、以下の方向が堅いです。

    {
    "definitions": {
    "anchor_comment": {
    "type": "object",
    "additionalProperties": false,
    "required": [
    "url",
    "id",
    "issue_number",
    "html_url",
    "api_url",
    "user_login",
    "author_association",
    "snapshot",
    "captured_at",
    "fetched_at",
    "comment_created_at",
    "comment_updated_at",
    "preliminary_classification",
    "final_classification",
    "classification_reason",
    "verified_claims",
    "unresolved_claims",
    "scope_impact",
    "requires_fact_check"
    ],
    "properties": {
    "url": { "type": "string", "minLength": 1 },
    "id": { "type": ["integer", "string"] },
    "issue_number": { "type": "integer", "minimum": 1 },
    "html_url": { "type": "string", "minLength": 1 },
    "api_url": { "type": "string", "minLength": 1 },
    "user_login": { "type": "string", "minLength": 1 },
    "author_association": {
    "type": "string",
    "enum": ["OWNER", "MEMBER", "COLLABORATOR", "CONTRIBUTOR", "NONE"]
    },
    "snapshot": { "type": "string" },
    "captured_at": { "type": "string", "format": "date-time" },
    "fetched_at": { "type": "string", "format": "date-time" },
    "comment_created_at": { "type": "string", "format": "date-time" },
    "comment_updated_at": { "type": "string", "format": "date-time" },
    "preliminary_classification": {
    "type": "string",
    "enum": [
    "superseded_by_decision",
    "reframe_in_place",
    "feedback_update_required",
    "human_escalation"
    ]
    },
    "final_classification": {
    "type": ["string", "null"],
    "enum": [
    "superseded_by_decision",
    "reframe_in_place",
    "feedback_update_required",
    "human_escalation",
    null
    ]
    },
    "classification_reason": { "type": ["string", "null"] },
    "verified_claims": { "type": "array", "items": { "type": "string" } },
    "unresolved_claims": { "type": "array", "items": { "type": "string" } },
    "scope_impact": {
    "type": ["string", "null"],
    "enum": ["none", "amend", "replace", "ambiguous", null]
    },
    "requires_fact_check": { "type": "boolean" }
    }
    }
    }
    }

    注意点は、format: date-time は draft-07 では実装依存です。JSON Schema 仕様上、format を validation assertion として実装するかは実装依存なので、厳密に日付検証したいなら Python 側で datetime.fromisoformat 相当の検証も追加すべきです。

    preflight artifact 境界

    配布物としては、次の 4 層に分けるのが安全です。

    raw_issue_snapshot.json: raw issue / comments

    anchor_comment_snapshot_v1.json: GitHub comment API response の raw subset

    planner_input.json: raw snapshot を含めず、normalized anchor_comment_feedback / known_context のみ

    refinement_preflight_result_v1.json: status / blockers / artifact paths のみ

    GitHub comment API は raw markdown body を body として返せるため、raw body は artifact に閉じ込め、planner / writer には要約済み feedback だけを渡す設計にできます。

    #1010 に入れるべき追加 AC

    この Issue は、最低限以下を追加しないとレビューで落とすべきです。

    • AC7: definitions.anchor_comment を追加し、properties.anchor_comment は $ref で参照する。VC は実 schema 形状と一致する。
    • AC8: anchor_comment.required に docs Required LOOP_STATE fields の全 field が含まれる。
    • AC9: scope_impact の enum は JSON null を許容し、文字列 "null" を許容しない。
    • AC10: classification / fact_check_status という別名 field は追加せず、preliminary_classification / final_classification / requires_fact_check に統一する。
    • AC11: 複数 --anchor-comment-url が指定された場合の挙動を定義する。この Issue では単数のみ許可し、複数は blocked にする。
    • AC12: fixture で author_association 欠落、enum 外値、comment_updated_at 欠落、scope_impact: "null" を schema-invalid として block する。
    • AC13: raw comment body は artifact にのみ保存され、planner input / Step 4 writer request には anchor_comment_feedback のみが渡る。

    実装プロンプトに落とすなら

    以下の方針で指示するのが安全です。

    Issue #1010 はそのまま実装せず、まず Issue body の AC/VC を現行 schema と docs に整合させる修正 PR を作ること。

    必須修正:

    1. loop_state.schema.json は definitions.anchor_comment を正本化し、properties.anchor_comment から $ref する。
    2. anchor_comment.required に anchor-comment-handling.md の Required LOOP_STATE fields を全件入れる。
    3. scope_impact enum は JSON null を使い、文字列 "null" を許容しない。
    4. classification/fact_check_status は追加せず、既存 docs の preliminary_classification/final_classification/requires_fact_check に統一する。
    5. run_refinement_preflight.py は GitHub issue comment API response から id/url/html_url/body/user.login/author_association/created_at/updated_at/issue_url を取り、schema-valid な normalized anchor_comment を生成する。
    6. 複数 anchor URL はこの Issue では unsupported として blocked にする。
    7. raw snapshot は artifact のみに保存し、planner/Step4 writer へは normalized anchor_comment_feedback のみ渡ることを pytest で検証する。
    8. routing ロジック変更、CONTEXT_PROVENANCE_V1、phase gate は 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008/実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011/実装: issue-refinement-loop に phase gate を追加し preflight 直後の誤った human_escalation を防ぐ #1013 の責務として触らない。

    停止条件:

    現時点の判定は 修正条件付き GO です。schema の field 追加だけで閉じる実装なら reject でよいです。

  3. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop を指定 comment 起点で実施し、Issue 本文を live rewrite しました。

    今回の更新点:

    • anchor_comment の責務を schema enforcement + preflight 正規化 + artifact boundary に狭め、routing 変更は #1008 / #1011 / #1013 / #920 へ明示的に分離
    • definitions.anchor_comment 正本化、required 必須化、scope_impact の JSON null、classification 語彙の既存 docs への統一を AC/Outcome/In Scope に反映
    • Verification Commands を $ ... 形式へ修正し、## Runtime Verification Applicability を decision: not_applicable で追加
    • 複数 --anchor-comment-url はこの Issue では unsupported / blocked として fail-closed 方針を明記
    • raw snapshot は artifact のみに保持し、planner_input / Step 4 writer には normalized anchor_comment_feedback のみを渡す境界を AC7 に格上げ

    ローカル検証:

    • check_issue_contract.py --file /tmp/issue1010_rewrite.md → verdict: approve
    • contract_readiness_check.py --mode preflight-static --body-file /tmp/issue1010_rewrite.md → status: go
  4. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-20T13:03:13Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1010
      body_sha256: "sha256:2051d94a9a29f837dc4ff8ed03748d0e7780ab59e9bc3897b02d749ba22deba4"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. added a commit that references this issue on Jun 20, 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

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions