Skip to content

実装: issue-refinement-loop の derived design note stale contract を修正しテストで常時検出する #1012

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: derived design note を runtime で読まない方針を維持しつつ、canonical sources との齟齬を常時検知する
change_kind: mixed

Parent Issue

none(単独改善)

Parent Goal Ref

  • Goal: issue-refinement-loop の design note が SKILL と drift し続けると、AI が stale assertion を再利用して誤運用する問題を解消する
  • Desired Destination: derived design note が SKILL の実装 runtime の主要な契約点を機械可読に宣言し、pytest で再発を検出できる状態にする

Current Validated Scope

  • docs/dev/workflows/issue-refinement-loop-design.md の Invocation Contract を SKILL の現行値に合わせる
  • docs/dev/workflows/issue-refinement-loop-design.md に DERIVED_RUNTIME_CLAIMS_V1 を追加し、主要契約点を明文化する
  • .claude/skills/issue-refinement-loop/tests/test_design_note_contract.py を新設し、以下を検出する:
    • max_iterations=1
    • needs_second_pass
    • canonical source からの長文コピー

Remaining Parent Gaps

なし

Outcome

docs/dev/workflows/issue-refinement-loop-design.md が .claude/skills/issue-refinement-loop/SKILL.md と drift しない設計ノートになり、.claude/skills/issue-refinement-loop/tests/test_design_note_contract.py の回帰テストで stale contract が自動検知できる状態。

In Scope

  • max_iterations の既定値(SKILL は default 3)と termination semantics(needs-fix は上限まで自動継続、超過時は human_escalation)を design note に反映
  • REVIEW_ISSUE_RESULT_COMPACT_V1 と decide_next_loop_action.py の routing 参照を design note に同期
  • LOOP_STATE と scope_signal_guard の実体参照先を references/loop-state.md / references/termination-policy.md へ明示
  • .claude/skills/issue-refinement-loop/tests/test_design_note_contract.py で以下を検出する:
    • 派生 claim と SKILL 実体の乖離
    • max_iterations: 1 / needs_second_pass スタイルの再退行
    • canonical source から 12 行以上または 600 文字以上の長文コピー(空行・見出し・短い path 除外)
  • docs/dev/workflows/issue-refinement-loop-design.md の not_loaded_when 条件(normal loop execution (runtime) / routine issue refinement / any SubAgent execution within the loop itself)を明確化

Out of Scope

  • SKILL 本文の直接編集(Allowed Paths 外)
  • .claude/agents/*.md の直接編集
  • issue-refinement-loop の runtime ロジック変更(既存実装)
  • 外部サービス調査

Acceptance Criteria

  • AC1: max_iterations と iteration stop semantics が SKILL.md の実装値(既定 3 / human_escalation)と一致する。
  • AC2: reviewer contract 名が ISSUE_REVIEW_RESULT_COMPACT_V1 へ統一されている。
  • AC3: LOOP_STATE 参照先が loop-state 実体参照として design note 内に明記される。
  • AC4: DERIVED_RUNTIME_CLAIMS_V1 を追加し、max_iterations / termination_reason / review_result_contract / loop_state_reference の4項目を YAML で宣言する。
  • AC5: docs/dev/workflows/issue-refinement-loop-design.md は max_iterations が 3、iteration + 1 >= max_iterations -> human_escalation を含む。
  • AC6: .claude/skills/issue-refinement-loop/tests/test_design_note_contract.py を新設し、max_iterations=1 / needs_second_pass / 長文コピー fixture を含めた再発検知テストが PASS する。
  • AC7: design note の not_loaded_when に normal loop execution (runtime) が含まれ、routine refinement / SubAgent 実行で読み込まれないことが明記される。

Verification Commands

# AC1
$ rg -n "max_iterations[:=][[:space:]]*3" docs/dev/workflows/issue-refinement-loop-design.md
# AC2
$ rg -n "ISSUE_REVIEW_RESULT_COMPACT_V1" docs/dev/workflows/issue-refinement-loop-design.md
# AC3
$ rg -n "references/loop-state.md" docs/dev/workflows/issue-refinement-loop-design.md
# AC4
$ rg -n "DERIVED_RUNTIME_CLAIMS_V1|max_iterations_default|iteration_limit_termination|review_result_contract|loop_state_reference" docs/dev/workflows/issue-refinement-loop-design.md
# AC5
$ rg -n "iteration \+ 1 >= max_iterations -> human_escalation|max_iterations\s*[:=][[:space:]]*3" docs/dev/workflows/issue-refinement-loop-design.md
# AC6
$ uv run pytest .claude/skills/issue-refinement-loop/tests/test_design_note_contract.py -q -x
# baseline-expect: pass
# AC7
$ rg -n "not_loaded_when:|normal loop execution \(runtime\)|routine issue refinement|any SubAgent execution within the loop itself" docs/dev/workflows/issue-refinement-loop-design.md

Allowed Paths

  • docs/dev/workflows/issue-refinement-loop-design.md
  • .claude/skills/issue-refinement-loop/tests/**
  • .claude/skills/issue-refinement-loop/SKILL.md

Runtime Verification Applicability

decision: not_applicable
deferred_verification_condition: N/A

Stop Conditions

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

Required Skills

なし

Scope Delta(任意)

N/A

Activity

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

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #1012 の問題意識は正しいです。現行 issue-refinement-loop-design.md は max_iterations を「既定 1」と書いており、現行 SKILL.md は max_iterations 既定 3 / default_max_iterations: 3 です。これは明確な stale contract です。

    ただし、この Issue contract のまま実装すると「数値 1→3 だけ直して PASS」になり、派生 design note に残っている古い routing semantics までは検出できません。#1012 には現時点でコメントがないため、本文契約以外の anchor decision もありません。

    Blockers

    B1. stale 対象が max_iterations だけに狭すぎる

    design note は max_iterations=1 の根拠として「1周で十分」「超過時は needs_second_pass」と説明していますが、現行 SKILL.md は iteration + 1 >= max_iterations で human_escalation に停止する設計です。つまり直すべき stale contract は数値だけではなく、termination semantics も含みます。

    さらに design note の SubAgent Contract Matrix は REVIEW_ISSUE_RESULT_V1 を前提にしていますが、現行 SKILL.md は ISSUE_REVIEW_RESULT_COMPACT_V1 を consumer contract としています。PR #805 でも issue-reviewer / issue-author の compact contract 化が明記されています。

    修正要求: AC1/AC2 を「主要 runtime constants」ではなく、最低限以下まで明示してください。

    • max_iterations default
    • needs-fix 時の continuation 条件
    • iteration limit 到達時の termination_reason
    • review result contract 名
    • LOOP_STATE 定義の実体参照先

    B2. canonical_sources 整合テストの仕様が曖昧

    frontmatter には canonical_sources と conflict_rule: canonical_sources_win が存在しますが、#1012 は「何を canonical source から抽出し、design note のどの主張と照合するか」を定義していません。

    regex で本文を雑に探す実装だと、表現変更に弱く、逆に本質的な stale claim を見逃します。design note に小さな機械可読ブロックを追加して、そこだけをテスト対象にする方が堅いです。YAML を読むなら arbitrary object construction を避けるため safe_load 系を使うべきです。PyYAML docs でも safe_load は標準タグだけを扱う API と説明されています。

    推奨:

    <!-- DERIVED_RUNTIME_CLAIMS_V1 -->
    ```yaml
    claims:
      max_iterations_default:
        canonical_source: .claude/skills/issue-refinement-loop/SKILL.md
        canonical_selector: loop_policy.default_max_iterations
        expected_value: 3
      iteration_limit_termination:
        canonical_source: .claude/skills/issue-refinement-loop/SKILL.md
        expected_value: human_escalation
      review_result_contract:
        canonical_source: .claude/skills/issue-refinement-loop/SKILL.md
        expected_value: ISSUE_REVIEW_RESULT_COMPACT_V1
    
    ### B3. AC4「長文ブロック重複コピー」の検出条件が未定義
    
    AC4 は正しい方向ですが、「長文ブロック」の閾値がないため、実装者が `SequenceMatcher` の類似度 0.8 などで雑に実装しても通ってしまいます。Python `difflib.SequenceMatcher` は最小 edit sequence を返すものではなく、`autojunk` heuristic もあるため、契約検査の唯一の判定器にするのは弱いです。:contentReference[oaicite:10]{index=10}
    
    **修正要求:** 以下のような決定論的条件にしてください。
    
    - canonical source から正規化済み連続 N 行、例: 12 行以上、または 600 文字以上、が design note に出現したら fail
    - 空行・見出し・短い path 参照は除外
    - fenced code block は `DERIVED_RUNTIME_CLAIMS_V1` のような短い宣言ブロックのみ whitelist
    - negative fixture で「SKILL.md から 15 行コピーした design note」が fail することを確認
    
    ### B4. Verification Commands がまだ grep 中心で、回帰検出になっていない
    
    #1012 の VC は `rg` と pytest 実行だけで、pytest が何を検出すべきかが不足しています。#460 のレビューコメントでも、grep 中心の VC では state machine を保証できないことが blocker とされ、pytest による iteration routing テストが要求されていました。
    
    **追加すべきテスト名:**
    
    ```bash
    uv run pytest .claude/skills/issue-refinement-loop/tests/test_design_note_contract.py -q -x
    

    中身は最低限これです。

    test_design_note_frontmatter_declares_derived_note_contract
    test_design_note_max_iterations_matches_skill_loop_policy
    test_design_note_iteration_limit_termination_matches_skill
    test_design_note_review_contract_matches_skill_compact_contract
    test_design_note_not_loaded_during_runtime
    test_design_note_rejects_long_copied_blocks_from_canonical_sources
    test_negative_fixture_with_default_1_fails
    test_negative_fixture_with_needs_second_pass_fails
    

    uv run は project environment を同期・利用してコマンドを実行する用途なので、VC としては妥当です。([Astral Docs]1)
    fixture は repo 実体を書き換えず tmp_path に置いて検査するのが安全です。pytest docs でも tmp_path は各 test function 固有の一時ディレクトリを提供します。([pytestドキュメント]2)

    B5. Allowed Paths に docs/dev/agent-skill-boundaries.md が入っているが、変更目的が未定義

    docs/dev/agent-skill-boundaries.md は「SKILL.md / SubAgent 定義に書くとコンテクスト汚染になるため、本ドキュメントを正本とする」と明記された境界ドキュメントです。ここを Allowed Paths に入れるなら、何を変更するのか AC に落とす必要があります。

    現状の #1012 では design note と tests だけで達成可能に見えます。agent-skill-boundaries.md を変更しないなら Allowed Paths から外すべきです。変更するなら、「derived design note の runtime 非ロード方針をどの loading tier / ssot-discovery ルールに接続するか」を明示してください。loading tier は同ドキュメントに定義済みです。

    B6. #467 / #460 の履歴を contract に反映していない

    max_iterations=3 は単なる現在値ではなく、Issue #460 / PR #467 で「1→3」「permission mode とは別概念」「needs-fix は上限まで自動継続」という policy change として入っています。PR #467 は SKILL.md の既定値変更、loop policy 追加、termination-policy 更新、planner/golden fixture 更新まで含んでいました。

    そのため #1012 は「SKILL.md の値と一致」だけでなく、「#467 後の loop policy を design note が再び 1 / needs_second_pass に戻して説明しない」ことを検出対象にすべきです。

    修正版 Issue 方針

    #1012 は次のように直すと実装可能です。

    ## Outcome
    
    `issue-refinement-loop-design.md` が現行 canonical sources と一致し、以下の stale contract を pytest で常時検出できる。
    
    - max_iterations default は `.claude/skills/issue-refinement-loop/SKILL.md` の `loop_policy.default_max_iterations` と一致する
    - iteration limit 到達時の termination は現行 SKILL.md の routing と一致する
    - review result contract 名は現行 compact contract と一致する
    - design note は normal runtime / routine refinement / SubAgent execution で loaded されない
    - SKILL.md / SubAgent 定義の長文コピーを含まない

    投稿コメント案

    ## Verdict: REQUEST_CHANGES
    
    #1012 の方向性は妥当です。現行 `issue-refinement-loop-design.md` は `max_iterations` を既定 1 と書いており、現行 `SKILL.md` は既定 3 なので、stale contract は実在します。
    
    ただし、この Issue contract は狭すぎます。数値だけを 1→3 に直しても、design note 側には `needs_second_pass` 前提、古い review result contract、古い LOOP_STATE 参照が残り得ます。#467 後の canonical behavior は「既定3」「上限到達時 human_escalation」「compact result contract」です。
    
    ### Required changes
    
    1. AC1/AC2 を `max_iterations` だけでなく、termination semantics / review result contract / LOOP_STATE 実体参照まで含める。
    2. design note に `DERIVED_RUNTIME_CLAIMS_V1` のような小さな機械可読 claim block を追加し、pytest はその block と canonical sources を照合する。
    3. AC4 の「長文コピー」検出を閾値付きで定義する。例: 正規化済み連続12行以上、または600文字以上の canonical source コピーを fail。
    4. negative fixtures を追加する:
       - `max_iterations: 1` に戻した fixture は fail
       - `needs_second_pass` に戻した fixture は fail
       - SKILL.md から長文コピーした fixture は fail
    5. `docs/dev/agent-skill-boundaries.md` を変更しないなら Allowed Paths から外す。変更するなら具体 AC/VC を追加する。
    
    このままでは、今回の既知 drift は直せても、次の stale design note を自動検出できる契約にはなりません。

    現状の #1012 は「良いバグ報告」ですが、「再発防止 Issue」としてはまだ弱いです。テスト対象を数値一致から derived design note の機械可読 claim と canonical source の差分検出 に上げるべきです。

  3. squne121 commented on Jun 19, 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

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-06-20T00:01:09Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1012
      body_sha256: "sha256:5421160fb9bbd7213908d220fa1a2e4313c7d106745468240b04501620a284d8"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  5. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-06-20T00:16:00Z)

    • iteration: 2
    • verdict: APPROVE
    • merge_ready: true
    • required_auto_actions: []
    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      termination_reason: approved
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1017"
      head_sha: "67da7713203a9d7e322c2533c94ed88656726f14"
      issue_number: 1012
      iteration: 2
      required_auto_actions: []

    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
    schema_version: 1
    materialized_by: impl-review-loop
    follow_up_issues: []

  6. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-06-20T00:37:24Z)

    • iteration: 2
    • verdict: APPROVE
    • merge_ready: true
    • required_auto_actions: []
  7. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (${NOW})

    • iteration: 2
    • verdict: APPROVE
    • merge_ready: true
    • required_auto_actions: []
    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      termination_reason: approved
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1017"
      head_sha: "37f5298db1577dd2090401c1023e82c100494b81"
      issue_number: 1012
      iteration: 2
      required_auto_actions: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations: []
  8. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-06-20T00:37:46Z)

    • iteration: 2
    • verdict: APPROVE
    • merge_ready: true
    • required_auto_actions: []
    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      termination_reason: approved
      merge_ready: true
      pr_url: "https://github.com/squne121/loop-protocol/pull/1017"
      head_sha: "37f5298db1577dd2090401c1023e82c100494b81"
      issue_number: 1012
      iteration: 2
      required_auto_actions: []
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations: []
  9. squne121 commented on Jun 20, 2026

    @squne121
    OwnerAuthor

    PR #1017 で解決済みのため close します。post-merge-cleanup により関連 worktree/branch も整理済みです。

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