Skip to content

実装: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする #1323

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "issue-refinement-loop の scope guard が人間レビュー由来の明示的な契約更新要求を scope_delta_authority で分類し、不要な human_escalation を避けつつ実装続行と契約更新を分離できるようにする。加えて #1008 / #1011 を supersede し、trusted anchor 判定に基づく provenance 分離と scope amendment routing を単一の拡張ポイントへ統合する"
change_kind: workflow

Parent Issue

なし(単独改善。ただし #1008 / #1011 を supersede する統合 Issue)

Parent Goal Ref

  • Goal: issue-refinement-loop の scope guard が「誰が・どの権限で・何を変更しようとしているか」を区別できるようにし、人間レビュー由来の明示的な契約更新要求を過剰に human_escalation しないようにする
  • Desired Destination: N/A(単独改善 Issue のため)

Current Validated Scope

  • .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py に scope_delta_authority 分類ロジックを追加する
  • .claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.py が scope_delta_authority を scope_signal_guard_decision_v2 の additive フィールドとして出力できるようにする(既存 schemas/refinement_loop_plan_v1.json のトップレベル契約は変更しない)
  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py に anchor comment / issue comment metadata から scope_delta_authority_evidence_v1 を生成するロジックを追加する
  • .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py に scope_signal_guard_decision_v2.route == contract_update_required を消費する非破壊的 next_action 分岐を追加する(既存 termination_reason enum は変更しない)
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md に scope_delta_authority 契約、scope_delta_authority_evidence_v1、contract_patch_plan_v1 を明文化する
  • .claude/skills/issue-refinement-loop/schemas/ に scope_delta_authority / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 の JSON Schema を追加する
  • .claude/skills/issue-refinement-loop/tests/ に AC 対応の回帰テストを追加する

Remaining Parent Gaps

なし(単独改善 Issue のため)

Background

現行 issue-refinement-loop の scope guard(.claude/skills/issue-refinement-loop/references/scope-signal-guard.md)は、Issue 本文の In Scope / Acceptance Criteria / Allowed Paths / Stop Conditions を超える変更要求を検出すると scope_signal_guard_triggered / reason_code:new_in_scope_area で無条件に human_escalation する。

この安全設計自体は妥当だが、人間レビューコメントが明示的に Issue 契約の更新を要求している場合まで、AI が独自に推定した未承認スコープ拡張と同一の扱いで停止してしまう。

実例(Issue #1270): 人間レビューコメントが provider_auto_policy_v1、retry budget schema、AGY failure classifier、idempotency guard、#1274 前提条件、Revised Acceptance Criteria を具体的に提示していたにもかかわらず、Refinement Loop は new_in_scope_area として iteration 0 で human_escalation した(コメント: https://github.com/squne121/loop-protocol/issues/1270#issuecomment-4881521790)。安全側ではあるが運用上は過剰停止であり、人間からの明示的な指摘は「未承認のスコープ拡張」ではなく「契約更新の入力」として扱うべきである。

Supersede 宣言(OWNER 判断、2026-07-04)

本 Issue は以下 2 件を supersede する。本 Issue マージ後、両 Issue は「Closed as superseded by #1323」として close する。

ただし、#1090(PR #1294, マージ済み)が既に実装した ANCHOR_SCOPE_REFRAME_V1(構造化テンプレートによる trusted anchor scope 拡張承認)と SCOPE_SIGNAL_GUARD_DECISION_V2(raw_signal / scope_context / scope_delta_approval / security_sensitive / route の分解 shape、additive-only 拡張ポイント)は再実装しない。本 Issue はこれらの上に築く Phase 2 的拡張であり、scope_signal_guard_decision_v2 の下に scope_delta_authority を additive フィールドとして追加することで、#1008 / #1011 が残していた「自由記述の人間レビュー指摘の扱い」というギャップを埋める。

Problem

現在の scope guard は scope delta の発生源と権限レベルを区別していない。以下が同一扱いになっている。

  1. AI が独自判断で新しい AC / path / dependency を提案した
  2. 人間レビューコメントが明示的に AC / path / dependency の追加を要求した
  3. 親 Issue / 関連 Issue の既存コメントが既に revised AC を提示していた
  4. 実装中に初めて別スコープが必要だと判明した

この結果、人間がすでに承認・要求している契約更新であっても、Refinement Loop が実行せずに停止する。

加えて、この問題を解決しようとする既存 OPEN Issue(#1008 の trusted anchor 判定、#1011 の provenance 分離)が並行して存在し、#1090 で既に merged された SCOPE_SIGNAL_GUARD_DECISION_V2 / ANCHOR_SCOPE_REFRAME_V1 とは異なる別の権限モデル(ANCHOR_SCOPE_AMENDMENT_V1、CONTEXT_PROVENANCE_V1)を導入しようとしていたため、正本が分散し agent が誤読するリスクがあった。本 Issue はこれを一本化する。

Goal

Refinement Loop / scope guard に、scope delta の発生源と処理方針を分類する scope_delta_authority を、既存 scope_signal_guard_decision_v2 の additive 拡張として導入する。人間レビュー由来の明示的な契約変更要求は、危険・矛盾・権限昇格・別 Issue 分割の懸念がない限り、Issue 本文への契約更新案として処理できるようにする(ただし契約更新と実装続行は分離し、契約更新のみでは実装フェーズへ進まない)。同時に #1008 / #1011 が残した trusted anchor 判定と provenance 分離のギャップを本 Issue の中で完結させる。

Non-Goal

  • Issue 契約を更新せずに拡張スコープの実装へ直接進むこと
  • AI が独自提案した新スコープを無条件で採用すること
  • 危険な権限昇格、外部サービス利用、Allowed Paths 大幅拡張を自動承認すること
  • 人間コメントが曖昧または矛盾している場合の自動判断
  • 既存の scope guard 自体を撤廃すること
  • REFINEMENT_LOOP_PLAN_V1 トップレベル schema や LOOP_STATE_V1.termination_reason enum の破壊的変更(additionalProperties:false を緩和したり新しい top-level V2 schema を導入したりしない)
  • Issue 本文への実際の書き込み(direct_github_write)を本 Issue のスコープに含めること(contract_patch_plan_v1 は生成のみ)

Outcome

.claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py、plan_refinement_loop.py、run_refinement_preflight.py、decide_next_loop_action.py に scope_delta_authority / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 のロジックが追加され、references/scope-signal-guard.md に判定契約が明文化され、schemas/ に対応する JSON Schema が追加され、AC1からAC20(#1008/#1011 統合分含む)に対応する pytest 回帰テストが全て PASS している状態。#1008 / #1011 は本 Issue のマージ後に superseded として close されている状態。

Proposed Behavior

1. scope delta の authority を分解された shape で分類する

単一 enum ではなく、#1090 の scope_signal_guard_decision_v2 と同じ分解パターンを踏襲する。

scope_delta_authority:
  schema_version: SCOPE_DELTA_AUTHORITY_V1
  authority_category: ai_inferred | human_review_directive | existing_parent_contract | related_issue_dependency
  provenance:
    source_kind: issue_comment | pr_review | parent_issue | related_issue | generated_by_agent
    source_ref: "<url or artifact ref>"
    body_sha256: "<sha256|null>"
    author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
  directive:
    confidence: explicit | ambiguous | conflicting | inferred
    extracted_markers: []
  boundary_flags:
    expands_allowed_paths: false
    changes_permission_boundary: false
    changes_external_service_boundary: false
    destructive_or_non_idempotent_operation: false
    requires_issue_split: false
  route:
    action: contract_update_required | human_escalation | not_triggered
    reason_code: explicit_human_contract_directive | ambiguous_human_directive | conflicting_human_directives | safety_or_permission_boundary
    implementation_allowed: false
    next_step: rerun_refinement_after_contract_update

このフィールドは scope_signal_guard_decision_v2 の下に additive に格納する(新しい top-level schema V2 は導入しない)。known_context.scope_signal_delta_input が与えられた場合にのみ生成される opt-in ガードは #1090 の既存方針を踏襲する。

2. run_refinement_preflight.py が normalized evidence を生成する(#1008 統合)

raw anchor comment body / raw issue comment body を planner に直接渡さず、run_refinement_preflight.py が GitHub comment metadata(author、author_association、comment_url、issue_url、created_at)を構造検証した上で以下の evidence を生成する。

scope_delta_authority_evidence_v1:
  source_kind: issue_comment | pull_request_review | parent_issue | related_issue | agent_inferred
  source_ref: "<stable url or artifact ref>"
  source_issue_number: <int>
  comment_id: <int|null>
  comment_url: "<url|null>"
  issue_url: "<url|null>"
  body_sha256: "<sha256>"
  author_login: "<login>"
  author_type: User | Bot | Organization | unknown
  author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
  captured_at: "<ISO-8601>"
  directive_markers: []
  extracted_directives: []
  ambiguity_flags: []
  boundary_flags: []

author_association が OWNER / MEMBER / COLLABORATOR 以外(CONTRIBUTOR / NONE / bot user / 欠落)の場合は fail-closed とし、authority_category: ai_inferred 相当(human_review_directive への昇格なし)として扱う。

3. 人間レビュー由来なら Issue 契約更新へ進む

以下をすべて満たす場合、human_escalation せず contract_update_required として処理する。

  • scope_delta_authority_evidence_v1.author_association が OWNER / MEMBER / COLLABORATOR
  • コメントが明示的な修正要求(Revised Acceptance Criteria / 前提条件 / Stop Condition 等)を含む(directive.confidence: explicit)
  • 変更が対象 Issue の goal_ref と矛盾しない
  • 実装ではなく Issue 契約の更新に留まる
  • 外部サービス利用、権限昇格、破壊的変更を要求していない(boundary_flags が全て false)

4. contract_update_required の消費点(Blocker 3 の解決)

contract_update_required は scope_signal_guard_decision_v2.route の新しい enum 値としてのみ追加する。REFINEMENT_LOOP_PLAN_V1 トップレベル schema と LOOP_STATE_V1.termination_reason(approved / human_escalation / superseded_by_decision / null)の enum は変更しない。

decide_next_loop_action.py はこの route 値を見て、既存の human_escalation 分岐とは別に NEXT_ACTION: proceed_with_contract_update を返す(termination_reason は設定せず、loop を継続させたまま Step 4 相当の契約更新へ進める非破壊的分岐)。

5. 契約更新と実装続行を分離する

human_review_directive と分類された場合も、Issue 本文(In Scope / Out of Scope / Acceptance Criteria / Stop Conditions / Verification Commands)を更新し、Refinement Loop を再実行するまで実装フェーズへ進まない(implementation_allowed: false を維持)。

6. contract_patch_plan_v1(Blocker 7 の解決)

Issue 本文への実際の書き込みは行わず、patch plan の生成のみを本 Issue のスコープとする。

contract_patch_plan_v1:
  target_issue_number: <int>
  base_issue_body_sha256: "<sha256>"
  source_evidence:
    - source_ref: "<comment url>"
      source_body_sha256: "<sha256>"
      author_association: OWNER
      start_line: <int>
      end_line: <int>
  operations:
    - section: Acceptance Criteria
      op: append
      text: "- [ ] ACx: ..."
      rationale: "Revised AC from trusted review comment"
      source_evidence_index: 0
  forbidden:
    - direct_github_write
    - implementation_phase_transition
  required_next_step: rerun_refinement_after_contract_update

forbidden に列挙された操作(Issue 本文への直接書き込み、実装フェーズへの遷移)は本 Issue のコードパスから実行できない設計にする。実際の適用は既存の issue-author / edit-issue skill 経由でのみ行う。

7. escalation を維持する条件(reason_code を具体化する)

以下に該当する場合は従来どおり human_escalation するが、reason_code を new_in_scope_area のような汎用値ではなく以下のいずれかに具体化する。

  • ambiguous_human_directive(指摘が曖昧)
  • conflicting_human_directives(reviewer 間で要求が衝突)
  • requires_issue_split(Issue 分割が必要な規模)
  • expands_allowed_paths(Allowed Paths を大幅に拡張する)
  • changes_permission_boundary(権限昇格を要求する)
  • changes_external_service_boundary(外部サービス利用を要求する)
  • destructive_or_non_idempotent_operation(破壊的操作を要求する)

In Scope

Out of Scope

  • scope guard の撤廃
  • 人間コメントを無条件で実装承認とみなすこと
  • 実装フェーズの Allowed Paths 自動拡張
  • GitHub への destructive write operation の自動実行(Issue 本文への direct_github_write を含む)
  • reviewer 権限モデルの大規模実装
  • 複数 Issue への自動分割・自動起票(Issue 案生成は可、実起票は human decision 経由)
  • REFINEMENT_LOOP_PLAN_V1 トップレベル schema の破壊的変更・新規 top-level V2 schema の導入
  • LOOP_STATE_V1.termination_reason enum への値追加

Acceptance Criteria

  • AC1: scope delta 検出時に scope_delta_authority.authority_category が ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency のいずれかに分類される
  • AC2: 人間レビューコメントが明示的な Revised Acceptance Criteria または修正要求を含む場合、new_in_scope_area だけで即時 human_escalation せず、contract_update_required として処理される
  • AC3: human_review_directive の場合、Issue 本文の In Scope / Out of Scope / Acceptance Criteria / Stop Conditions / Verification Commands への反映案(contract_patch_plan_v1)が生成される
  • AC4: human_review_directive であっても、Issue 本文更新前に実装フェーズへ進まない(implementation_allowed:false が出力される)
  • AC5: AI が独自に推定した scope delta は従来どおり human_escalation される(regression)
  • AC6: 人間コメントが曖昧・矛盾・権限昇格・外部サービス利用・Allowed Paths 大幅拡張・destructive operation を含む場合は human_escalation される(regression)
  • AC7: new_in_scope_area のような汎用 reason_code だけでなく、ambiguous_human_directive 等の具体的な reason_code が出力される
  • AC8: Issue 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 相当のケース(人間レビューコメントが Revised AC を明示している)で、human_escalation ではなく contract_update_required への分岐を検証する回帰テストが追加されている
  • AC9: human_review_directive による契約更新後の次アクションとして next_step:rerun_refinement_after_contract_update が出力される
  • AC10: 既存の scope_signal_guard 回帰テスト(scope_signal_guard_termination)が regression しない
  • AC11: trusted anchor comment(author_association: OWNER/MEMBER/COLLABORATOR)が REQUEST_CHANGES で AC / Allowed Paths / VC 追加を明示している fixture では authority_category: human_review_directive に分類される(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC1 相当)
  • AC12: 同じ Allowed Paths 拡張でも、anchor comment 由来ではなく AI が自発的に作った変更では authority_category: ai_inferred のまま human_escalation する(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC2 相当、regression)
  • AC13: untrusted author(CONTRIBUTOR / NONE / bot user / author_association 欠落)は fail-closed で human_escalation する(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC3 / Blocker 4 追加テスト相当)
  • AC14: issue-author へ raw comment body を直接渡さず、正規化済み scope_delta_authority_evidence_v1 のみを渡す(実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 AC4 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 AC5 相当)
  • AC15: scope_delta_authority.provenance に origin 相当の分類(source_kind: issue_comment 等、author_association)が含まれ、trusted_anchor_comment 由来と agent_inferred 由来が区別される(実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 AC1/AC2/AC3 相当)
  • AC16: PR review comment URL と issue comment URL を混同せず、issue comment URL と issue_url が対象 Issue と不一致な場合は invalid として fail-closed になる
  • AC17: 複数 reviewer の要求が衝突する場合は conflicting_human_directives に分類される
  • AC18: changes_permission_boundary / changes_external_service_boundary / destructive_or_non_idempotent_operation のいずれかが true の場合、trusted anchor による承認があっても contract_update_required に進まず human_escalation する
  • AC19: 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 の実コメント fixture から contract_patch_plan_v1 が生成され、forbidden に direct_github_write と implementation_phase_transition が含まれる
  • AC20: decide_next_loop_action.py が scope_signal_guard_decision_v2.route == contract_update_required を受け取ると NEXT_ACTION: proceed_with_contract_update を返し、termination_reason enum には新しい値を追加しないことを end-to-end で検証する(回帰テストは新規ファイル test_decide_next_loop_action_contract_update.py に追加する)

Verification Commands

# AC1
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_scope_delta_authority_classifies_into_four_categories"
# AC2
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_human_review_directive_yields_contract_update_required"
# AC3
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_human_review_directive_generates_contract_patch_plan"
# AC4
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_contract_update_required_sets_implementation_allowed_false"
# AC5
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_ai_inferred_scope_delta_still_escalates"
# AC6
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_ambiguous_conflicting_or_permission_boundary_still_escalates"
# AC7
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_reason_code_is_specific_not_generic_new_in_scope_area"
# AC8
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_1270_human_review_decision_fixture_yields_contract_update_required"
# AC9
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_contract_update_required_next_step_is_rerun_refinement"
# AC10
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_signal_guard_termination.py
# AC11
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_trusted_anchor_request_changes_classified_as_human_review_directive"
# AC12
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_agent_inferred_allowed_path_expansion_still_escalates"
# AC13
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_untrusted_or_missing_author_association_fails_closed"
# AC14
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_raw_comment_body_not_forwarded_to_issue_author"
# AC15
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_provenance_distinguishes_trusted_anchor_from_agent_inferred"
# AC16
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_comment_url_mismatch_or_pr_review_url_confusion_is_invalid"
# AC17
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_conflicting_reviewer_directives_classified_as_conflicting_human_directives"
# AC18
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_boundary_flags_block_contract_update_even_with_trusted_approval"
# AC19
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py -k "test_issue_1270_fixture_generates_contract_patch_plan_with_forbidden_operations"
# AC20
$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.py

Allowed Paths

  • .claude/skills/issue-refinement-loop/scripts/scope_signal_delta.py
  • .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/decide_next_loop_action.py
  • .claude/skills/issue-refinement-loop/references/scope-signal-guard.md
  • .claude/skills/issue-refinement-loop/references/anchor-comment-handling.md
  • .claude/skills/issue-refinement-loop/schemas/
  • .claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py
  • .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action.py
  • .claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.py
  • .claude/skills/issue-refinement-loop/tests/fixtures/

Stop Conditions

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

Required Skills

  • Python / pytest
  • YAML / JSON Schema 設計
  • GitHub REST API(author_association / comment metadata 取得)

Scope Delta(任意)

N/A

Delivery Rule

Runtime Verification Applicability

  • decision: not_applicable
  • reason: 本 Issue は issue-refinement-loop skill 内の静的なロジック変更(Python)であり、pytest による決定論的検証で完結する。ゲームランタイム/ブラウザ実行を伴わない。

Notes for Reviewer

今回の改善目的は scope guard を弱めることではなく、「誰が、どの権限で、何を変更しようとしているか」を区別できるようにすることである。参考実例: Issue #1270(コメント #1270 (comment) の Human Review Decision)。

OWNER 判断(2026-07-04): #1323 は #1008 / #1011 を supersede する(anchor comment #1323 (comment) への回答)。既存 #1090(PR #1294, マージ済み)の SCOPE_SIGNAL_GUARD_DECISION_V2 / ANCHOR_SCOPE_REFRAME_V1 は再実装せず、その additive 拡張ポイント(scope_signal_guard_decision_v2 配下)に scope_delta_authority を追加する形で統合する。contract_update_required は route の新しい enum 値としてのみ追加し、REFINEMENT_LOOP_PLAN_V1 トップレベル schema と LOOP_STATE_V1.termination_reason enum は変更しない。scope_delta_authority_evidence_v1 は raw comment body を含まない正規化済み evidence とし、contract_patch_plan_v1 は Issue 本文への実際の書き込み(direct_github_write)を実行しない生成専用の shape とする。

本改訂で #1008 / #1011 の Outcome / AC を吸収したため、両 Issue は本 Issue マージ後に superseded として close する。

Activity

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

    @squne121
    OwnerAuthor

    判定: REQUEST_CHANGES

    #1323 の問題意識は妥当です。#1270 のように、人間レビューが Revised AC や前提条件を明示しているのに new_in_scope_area で即 human_escalation するのは過剰停止です。ただし、現契約のまま実装すると 既存の ANCHOR_SCOPE_REFRAME_V1 / SCOPE_SIGNAL_GUARD_DECISION_V2 と並行する別権限モデルを増やすだけになり、schema-invalid、router 未接続、または自由記述コメントによる権限注入のいずれかに落ちます。

    #1323 自体にはコメントはありません。本文は #1008 / #1011 との概念重複を認識しつつ、#1090 で実装済みの構造化 anchor approval とは別に「自由記述の人間レビュー指摘」を扱う Issue と位置づけています。

    Blocker 1: #1008 / #1011 / #1090 との統合方針が未決定

    #1008 は trusted human anchor comment を AI scope creep と分離し、run_refinement_preflight.py から planner の known_context へ渡すことを目的にしています。#1011 は CONTEXT_PROVENANCE_V1 で human-requested / agent-inferred / repo-evidence を分離する設計です。#1323 の scope_delta_authority はこの2件の中核と重複します。

    さらに #1090 / PR #1294 では、SCOPE_SIGNAL_GUARD_DECISION_V2、trusted anchor approval、proceed_with_notes、security-sensitive fail-closed が既に merged されています。PR #1294 は既存 decisions.scope_signal_guard を変えず、known_context.scope_signal_delta_input がある場合だけ additive に v2 artifact を出す設計です。

    修正要求: #1323 は単独実装ではなく、次のどちらかに寄せるべきです。

    この整理なしに実装すると、ANCHOR_SCOPE_REFRAME_V1、ANCHOR_SCOPE_AMENDMENT_V1、CONTEXT_PROVENANCE_V1、scope_delta_authority が併存し、エージェントが正本を誤読します。

    Blocker 2: scope_signal_delta.py だけでは authority 分類に必要な入力がない

    #1323 は scope_signal_delta.py に scope_delta_authority 分類を追加するとしていますが、現行 scope_signal_delta_input は before_body / current_body / after_body / source_refs だけです。compute_scope_signal_delta() も本文差分から Allowed Paths / In Scope / AC の delta を出すだけで、author、author_association、comment_url、issue_url、PR review metadata、parent/related issue snapshot を受け取りません。

    さらに _validate_input() は未知フィールドを拒否します。つまり、現在の入力契約のままでは human_review_directive、existing_parent_contract、related_issue_dependency を deterministic に分類できません。

    修正要求: Allowed Paths に少なくとも以下を入れるか、#1323 を planner-only の diagnostic 拡張に縮退してください。

    • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
    • .claude/skills/issue-refinement-loop/schemas/
    • 必要なら .claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.py
    • 必要なら .claude/skills/issue-refinement-loop/schemas/loop_state.schema.json

    Blocker 3: contract_update_required が schema / router / loop_state に存在しない

    #1323 は status: contract_update_required、implementation_allowed:false、next_step:rerun_refinement_after_contract_update を出す設計ですが、現行 refinement_loop_plan_v1.json は top-level additionalProperties:false で、decisions も additionalProperties:false です。

    また、現行 decisions.scope_delta_decision.status の enum は approved_by_trusted_anchor / fail_closed / not_applicable のみで、contract_update_required はありません。

    LOOP_STATE_V1.termination_reason も approved / human_escalation / superseded_by_decision / null だけです。router は scope_signal_guard.triggered を見ると STATUS: human_escalation / NEXT_ACTION: human_escalation / TERMINATION_CAUSE: human_judgment_required を返す実装です。

    修正要求: contract_update_required の置き場を明確にしてください。

    • planner artifact だけなのか
    • preflight status なのか
    • router next_action なのか
    • loop_state termination_reason なのか

    実際の停止挙動を変えるなら schema/router/loop_state まで変更対象です。変えないなら AC2/AC4/AC9 は「出力するだけ」で運用効果がありません。

    Blocker 4: 「自由記述の人間レビュー指摘」は安全境界を下げる

    既存 docs は、raw anchor comment body を planner や delta helper に直接流してはならず、normalized decision / hash / provenance のみを渡す、と明記しています。

    現行の anchor approval は、top-level fenced YAML の ANCHOR_SCOPE_REFRAME_V1 を要求し、GitHub author_association が OWNER / MEMBER / COLLABORATOR であること、target repo/issue 一致、schema validity などを fail-closed で確認します。

    GitHub の Issue Comments REST response には issue_url と author_association が含まれるため、同一 Issue コメントか、信頼できる関係者か、という構造検証は可能です。ただし GitHub Docs も issue comments と pull request review comments を別エンドポイントとして扱っており、自由記述コメントの意味解釈はリポジトリ側の独自ロジックです。([GitHub Docs]1) (GitHub Docs)

    修正要求: 「テンプレート形式を問わない」は残してもよいですが、planner に渡すのは raw body ではなく、preflight が生成する normalized evidence に限定してください。

    最低限の normalized shape:

    scope_delta_authority_evidence_v1:
      source_kind: issue_comment | pull_request_review | parent_issue | related_issue | agent_inferred
      source_ref: "<stable url or artifact ref>"
      source_issue_number: 1270
      comment_id: 4881420705
      comment_url: "https://github.com/...#issuecomment-..."
      issue_url: "https://api.github.com/repos/.../issues/1270"
      body_sha256: "<sha256>"
      author_login: "<login>"
      author_type: User | Bot | Organization | unknown
      author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
      captured_at: "<ISO-8601>"
      directive_markers:
        - Revised Acceptance Criteria
        - 修正要求
        - 前提条件
      extracted_directives:
        - section: Acceptance Criteria
          text_sha256: "<sha256>"
          confidence: explicit
      ambiguity_flags: []
      boundary_flags: []

    Blocker 5: additionalProperties:false と additive-only 方針の相性が悪い

    PR #1294 では、v2 field を schema 外に置き、テストも plan_refinement_loop() 直呼びで schema validation を避けています。テストファイル自身が「新フィールドは intentionally kept out of schemas/refinement_loop_plan_v1.json」と説明しています。

    これは #1090 では暫定的に成立しても、#1323 のように router/status/contract patch plan に影響するフィールドでは危険です。JSON Schema でも、additionalProperties は同じ subschema 内で宣言された property だけを認識するため、closed schema を後から allOf 等で拡張しようとすると失敗しやすいです。新しい draft では unevaluatedProperties でこの問題を緩和できます。([JSON Schema]2)

    修正要求: 次のいずれかにしてください。

    • REFINEMENT_LOOP_PLAN_V2 を導入する。
    • REFINEMENT_LOOP_PLAN_V1 に明示的な extensions / artifacts slot を追加する。
    • scope_signal_guard_decision_v2 を拡張し、scope_delta_authority をその配下に入れる。

    Blocker 6: authority / safety / route / reason_code が混ざっている

    #1323 の分類は ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency / ambiguous_or_conflicting / safety_or_permission_boundary ですが、これは同じ軸ではありません。

    • authority: 誰が要求したか
    • provenance: どこに書かれていたか
    • confidence: 明示か曖昧か
    • boundary: permission / external service / destructive operation か
    • route: contract update か human escalation か
    • reason_code: なぜ止めたか

    これを1つの enum に押し込むと、後続 consumer が分岐条件を誤ります。#1090 の v2 は既に raw_signal / scope_context / scope_delta_approval / security_sensitive / route に分けています。#1323 も同じ分解に寄せるべきです。

    推奨 shape:

    scope_delta_authority:
      schema_version: SCOPE_DELTA_AUTHORITY_V1
      authority_category: ai_inferred | human_review_directive | existing_parent_contract | related_issue_dependency
      provenance:
        source_kind: issue_comment | pr_review | parent_issue | related_issue | generated_by_agent
        source_ref: "<url or artifact ref>"
        body_sha256: "<sha256|null>"
        author_association: OWNER | MEMBER | COLLABORATOR | CONTRIBUTOR | NONE | null
      directive:
        confidence: explicit | ambiguous | conflicting | inferred
        extracted_markers: []
      boundary_flags:
        expands_allowed_paths: false
        changes_permission_boundary: false
        changes_external_service_boundary: false
        destructive_or_non_idempotent_operation: false
        requires_issue_split: false
      route:
        action: contract_update_required | human_escalation | not_triggered
        reason_code: explicit_human_contract_directive | ambiguous_human_directive | conflicting_human_directives | safety_or_permission_boundary
        implementation_allowed: false
        next_step: rerun_refinement_after_contract_update

    Blocker 7: patch plan が未定義で、Issue 本文の危険な半自動編集になり得る

    #1323 は In Scope / Out of Scope / AC / Stop Conditions / Verification Commands への patch plan 生成を求めていますが、patch の形式、source evidence、staleness check、競合時の扱い、適用主体が未定義です。

    修正要求: contract_patch_plan_v1 を明文化してください。

    contract_patch_plan_v1:
      target_issue_number: 1323
      base_issue_body_sha256: "<sha256>"
      source_evidence:
        - source_ref: "<comment url>"
          source_body_sha256: "<sha256>"
          author_association: OWNER
          start_line: 10
          end_line: 40
      operations:
        - section: Acceptance Criteria
          op: append
          text: "- [ ] ACx: ..."
          rationale: "Revised AC from trusted review comment"
          source_evidence_index: 0
      forbidden:
        - direct_github_write
        - implementation_phase_transition
      required_next_step: rerun_refinement_after_contract_update

    Python artifact 出力では json.dumps(..., allow_nan=False) を維持してください。Python の JSON encoder は既定だと NaN / Infinity を出力し得るため、strict JSON にするなら allow_nan=False が必要です。([Python documentation]3)

    追加すべきテスト

    現 AC1〜AC10 だけでは不足です。最低限、以下を追加してください。

    1. scope_signal_delta_input だけでは human_review_directive を分類できず、normalized evidence 不在なら fail-closed。
    2. author_association 欠落、CONTRIBUTOR、NONE、bot user は fail-closed。
    3. issue comment URL と issue_url が対象 Issue と一致しない場合は invalid。
    4. PR review comment URL と issue comment URL を混同しない。
    5. raw comment body が planner input に入らない。
    6. 自由記述コメントで「検討してほしい」「可能なら」など曖昧表現は ambiguous_human_directive。
    7. 複数 reviewer の要求が衝突したら conflicting_human_directives。
    8. changes_permission_boundary / changes_external_service_boundary / destructive_or_non_idempotent_operation は approval があっても contract update に進まない。
    9. 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 の実コメント fixture から contract_patch_plan_v1 が生成される。
    10. contract_update_required が schema validation / preflight / router / loop_state のどこで消費されるかを end-to-end で検証する。

    結論

    #1323 は 実装着手前に契約修正必須です。特に直すべきは次の3点です。

    1. 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 をどう扱うかを明示する。
    2. scope_signal_delta.py 単体ではなく、preflight provenance → planner artifact → router/loop_state までの責務境界を再定義する。
    3. 自由記述コメントを authority として直接扱わず、GitHub構造検証済みの normalized evidence に変換してから判定する。

    貼り付け用のレビューコメント案です。

    判定

    REQUEST_CHANGES。

    #1323 の方向性は妥当です。#1270 のように、人間レビューが Revised Acceptance Criteria / 前提条件 / Stop Condition を明示しているにもかかわらず、Refinement Loop が new_in_scope_area として即 human_escalation する挙動は過剰停止です。

    ただし、現契約のまま実装すると、既存の ANCHOR_SCOPE_REFRAME_V1 / SCOPE_SIGNAL_GUARD_DECISION_V2 / #1008 / #1011 と衝突します。

    Blockers

    1. 実装: run_refinement_preflight が trusted anchor scope amendment を planner known_context に渡せるようにする #1008 / 実装: CONTEXT_PROVENANCE_V1 を導入し human-requested / agent-inferred / repo-evidence を分離する #1011 / 実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 との統合方針が未定義

    2. scope_signal_delta.py 単体では human_review_directive を分類できない

      • 現行 scope_signal_delta_input は before_body / current_body / after_body / source_refs だけで、author、author_association、comment_url、issue_url、parent/related issue snapshot を持ちません。
      • _validate_input() は unknown field を拒否するため、現在の入力契約のまま authority 分類を足すのは無理があります。
      • run_refinement_preflight.py で GitHub comment metadata を検証し、normalized evidence を planner に渡す設計にしてください。
    3. contract_update_required が schema / router / loop_state に存在しない

      • REFINEMENT_LOOP_PLAN_V1 は top-level / decisions ともに closed schema です。
      • scope_delta_decision.status enum に contract_update_required はありません。
      • LOOP_STATE_V1.termination_reason と decide_next_loop_action.py も contract_update_required を消費しません。
      • 実際の挙動を変えるなら schema/router/loop_state まで Allowed Paths に含める必要があります。
    4. 自由記述コメントを authority として扱う設計は危険

      • 既存契約は raw anchor comment body を planner / delta helper に直接流さず、normalized decision / hash / provenance のみ渡す方針です。
      • 「テンプレート形式を問わない自由記述」を採用する場合でも、preflight が scope_delta_authority_evidence_v1 のような構造化 evidence に変換し、planner はそれだけを読むべきです。
    5. authority / provenance / boundary / route / reason_code が混ざっている

      • human_review_directive と safety_or_permission_boundary は同じ分類軸ではありません。
      • authority_category、provenance、directive.confidence、boundary_flags、route.action、reason_code に分解してください。

    Required Contract Changes

    この修正なしで実装すると、過剰停止の解消ではなく、既存 guard の外側に未検証の authority bypass を追加するリスクが高いです。

  3. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "scope_signal_guard_triggered (reason_code: new_in_scope_area)"
    
    "Anchor comment (OWNER, REQUEST_CHANGES, https://github.com/squne121/loop-protocol/issues/1323#issuecomment-4881639904) は自由記述の human_review_directive であり、機械可読な ANCHOR_SCOPE_REFRAME_V1 payload を含まないため scope_delta_decision は fail_closed(reason: no_anchor_scope_reframe_v1_payload)"
    
    "Blocker1: #1323 の scope_delta_authority は #1008 / #1011 と概念重複しており、既存 #1090 (SCOPE_SIGNAL_GUARD_DECISION_V2) との統合方針(supersede か Phase2拡張か)が未決定"
    
    "Blocker2: 現行 scope_signal_delta_input には author/author_association/comment_url/issue_url/PR review metadata 等がなく、Allowed Paths を run_refinement_preflight.py / schemas/ / decide_next_loop_action.py / loop_state.schema.json まで拡張するか、planner-only diagnostic へスコープ縮退するかの判断が必要"
    
    "Blocker3: contract_update_required という新しい termination status を schema (refinement_loop_plan_v1.json) / router / loop_state.schema.json のどこに実装対象として組み込むか未定義"
    
    "Blocker5: additionalProperties:false の既存 schema に対し REFINEMENT_LOOP_PLAN_V2 導入・extensions slot 追加・scope_signal_guard_decision_v2 拡張のいずれを取るか未決定"
    
    "Blocker6: authority/provenance/confidence/boundary/route/reason_code を単一 enum に混在させており、#1090 のような分解された shape (raw_signal/scope_context/scope_delta_approval/security_sensitive/route) への re-design が必要"
    
    "これらは Issue 本文の機械的な文言修正では解決できず、複数 OPEN Issue (#1008/#1011/#1090) との統合方針という product/architecture 判断が必要なため human escalation する"
    
  4. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Refinement Loop: Human Escalation Required

    The loop has terminated and requires human review. Cause: human judgment required

    Blockers

    "scope_signal_guard_triggered"
    
    "scope_signal_guard_reason_code:new_in_scope_area"
    
  5. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-07-04T11:41:08Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/1323
      body_sha256: "sha256:32c0b2994f024cf706c5dae561993a07248c33b32be730a8960e0e17b8174fd5"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        vc_preflight: pass
      source: ensure_contract_snapshot_auto
  6. squne121 commented on Jul 4, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-07-04)

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