Repository navigation
feat: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする (#1323) - #1332
Conversation
) 人間レビュー由来の明示的な契約更新要求を scope_delta_authority で分類し、 new_in_scope_area のような汎用 reason_code で無条件に human_escalation する 過剰停止(Issue #1270 相当のケース)を解消する。#1090 の scope_signal_guard_decision_v2 の additive 拡張点として実装し、#1008 (trusted anchor 判定)と #1011(provenance 分離)を統合・supersede する。 - scope_signal_delta.py: authority_category(ai_inferred / human_review_directive / existing_parent_contract / related_issue_dependency)と provenance / directive / boundary_flags / route の分解 shape を classify_scope_delta_authority() として実装。 boundary_flags(permission / external_service / destructive / issue_split)は trusted anchor 承認があっても route を human_escalation へ固定する(AC18)。contract_patch_plan_v1 の生成もここに実装し、 forbidden: [direct_github_write, implementation_phase_transition] を 常に含める(Issue 本文への実書き込みは行わない)。 - run_refinement_preflight.py: _build_scope_delta_authority_evidence() が freeform な human review コメント(構造化 ANCHOR_SCOPE_REFRAME_V1 yaml を 含まない Revised Acceptance Criteria 提示等)から scope_delta_authority_evidence_v1 を生成する。raw body は決して known_context へ渡さず、抽出済み marker / directive / sha256 のみ渡す (AC14)。anchor URL が対象 Issue の issue comment として構造的に無効な 場合は fail-closed で evidence を生成しない(AC16)。 - plan_refinement_loop.py: known_context.scope_delta_authority_evidence が 与えられた場合のみ scope_signal_guard_decision_v2.scope_delta_authority を additive に出力する(opt-in、既存 golden fixture 非破壊)。 - decide_next_loop_action.py: scope_signal_guard_decision_v2 を --scope-signal-guard-decision-v2-file/-json という loop_state とは別の sidecar 引数として受け取り、route == contract_update_required のとき NEXT_ACTION: proceed_with_contract_update を返す(termination_reason は 変更しない非破壊分岐)。loop_state.schema.json のトップレベル契約・ LOOP_STATE_V1.termination_reason enum は変更しない。 - schemas/: scope_delta_authority_v1 / scope_delta_authority_evidence_v1 / contract_patch_plan_v1 の JSON Schema を追加。 - references/scope-signal-guard.md, anchor-comment-handling.md: 新契約を 明文化。 - tests/test_scope_delta_authority.py(AC1-AC19, 19 tests)、 tests/test_decide_next_loop_action_contract_update.py(AC20, 7 tests) を新規追加。既存 issue-refinement-loop 回帰テスト 1176 件全て pass。 Closes #1323 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Preview URLPreview removed (PR #1332 closed). |
squne121
left a comment
There was a problem hiding this comment.
レビュー結果(issue-contract-review / impl-review-loop 相当)
Issue #1323 の Acceptance Criteria(AC1〜AC20)は全て個別 Verification Command で pass していることを確認しました。test_scope_delta_authority.py(19 tests、AC1〜AC9・AC11〜AC19)と test_decide_next_loop_action_contract_update.py(7 tests、AC20)に加え、AC10 の regression として test_scope_signal_guard_termination.py(17 tests)も pass しています。CI は全 required job が green、変更ファイルは Issue #1323 の Allowed Paths と完全一致しています。
LOOP_VERDICT_V2:
verdict: APPROVE
reviewed_head_sha: "d7752d7bc8b36f2215fab0ed4982b3f18b29170b"
merge_ready: false
merge_ready_note: "このコメント投稿後に update_branch と update_pr_body_hygiene の mechanical action を実施して解消予定"
blockers: []
required_auto_actions:
- kind: update_branch
reason: "PR branch が main から BEHIND"
- kind: update_pr_body_hygiene
reason: "PR本文に「## 受け入れ条件の達成状況」(AC1〜AC20 毎の [x]/[ ] + 根拠)と「## Allowed Paths 遵守」の正式見出しが不足"
allowed_paths_gate:
status: ok
violations: []
reason: "All 10 changed files match Issue #1323 Allowed Paths exactly"確認事項
- Issue #1323 の AC1〜AC20 は全てテストで裏付けられている(
test_scope_delta_authority.py19件 +test_decide_next_loop_action_contract_update.py7件、AC20 は non-destructive regression チェック込み)。 - CI は全 required job(typecheck / lint / test / build / e2e / python-test / node-backed-hook-tests / actionlint 等)が green。
- Allowed Paths は Issue #1323 記載と完全一致(scripts 4 + schemas 3 + references 2 + tests 2 = 変更ファイル一致確認済み)。
…efinement-loop-scope-guard
結論REQUEST_CHANGES。現状マージ不可。 重大指摘P0: producer と router の
|
…修正する OWNER レビュー (issuecomment-4882361027) の P0/P1 指摘に対応する: - decide_next_loop_action.py がトップレベル scope_signal_guard_decision_v2.route ではなく、classify_scope_delta_authority() が実際に出力するネストされた scope_delta_authority.route.action を読むように修正 (P0) - test_decide_next_loop_action_contract_update.py からトップレベル route 手動注入への依存を排除し、plan_refinement_loop() の実出力を sidecar として router に渡す producer→router E2E テストを追加 (P0) - Issue #1270 の実コメント fixture を issuecomment-4881420705(実際の OWNER レビューコメント)に差し替え、issuecomment-4881521790 という誤った ID を修正 (P0) - classify_scope_delta_authority() に expected_repo を必須化し、同一 issue 番号でも別 repo からの evidence を fail-closed で拒否。pull_request_review evidence は構造検証手段が未実装のため常に fail-closed 拒否に変更 (P0/P1) - scope_delta_authority_evidence_v1.schema.json を additionalProperties:false にし、raw body 系フィールドを schema レベルで拒否 (P1) - contract_patch_plan_v1 で base_issue_body_sha256 を必須・non-null化し、 source_evidence に source_comment_id / extracted_text_sha256 / captured_at / start_line / end_line を追加 (P1) Co-Authored-By: Claude Sonnet 5 <[email protected]>
squne121
left a comment
There was a problem hiding this comment.
LOOP_VERDICT_V2
verdict: APPROVE
reviewed_head_sha: "d4e4da356123944baa6bbd4aa031869f4d0fa88f"
merge_ready: true
mergeability:
mergeable: "MERGEABLE"
merge_state_status: "CLEAN"
blockers: []
required_auto_actions: []
auto_fix_applied: []
follow_up_issue_requests: []
allowed_paths_gate:
producer_role: review_subagent
worker_report_used_as_canonical: false
status: ok
changed_files_source: git_diff_name_status_find_renames_z
diff_base_sha: "fb241c60be0775f873b3cde8a16c634ef74039de"
audited_paths_count: 11
violations: []
OWNER REQUEST_CHANGES (issuecomment-4882361027) 再検証結果
コードを実際に読み・pytest を実行して独立検証した(自己申告は使用していない)。6項目すべて解消を確認。
- P0 producer/router 経路不一致 — 解消。
decide_next_loop_action.py:319-329がscope_signal_guard_decision_v2.get("scope_delta_authority").get("route", {}).get("action")を読み、plan_refinement_loop.py:1936が同じネストされたscope_signal_guard_decision_v2["scope_delta_authority"]にclassify_scope_delta_authority()の出力を書き込んでいる。producer/consumer が同一パスで結線されていることをコードで確認した。 - P0 AC20 が fixture 手動注入のみ — 解消。
test_decide_next_loop_action_contract_update.pyに新規 E2E テストtest_producer_to_router_e2e_yields_proceed_with_contract_update/test_producer_to_router_e2e_without_evidence_regresses_to_human_escalationが追加され、plan_refinement_loop.plan_refinement_loop()を実際に呼び出しその戻り値のscope_signal_guard_decision_v2をそのままdecide_next_loop_action.pyの CLI にサイドカーとして渡している(手動 route 注入なし)。worktree で該当11テスト実行し全 PASS を確認済み。 - P0 #1270 fixture ID誤り — 解消。
test_scope_delta_authority.pyの fixture はissuecomment-4881420705を参照しており、gh api repos/squne121/loop-protocol/issues/comments/4881420705で実在コメント(OWNER, squne121, created_at 2026-07-04T09:11:40Z)と突合。body の sha256(35f0c1fa52e29f0f6d6cc2ffb7b83f7781bae29992e512166d442035d1bf6cb6)が fixture 定数ISSUE_1270_ACTUAL_COMMENT_4881420705_BODY_SHA256と完全一致することを独立に再計算して確認した。誤IDissuecomment-4881521790への言及はコメントとして残っているのみで、実データとしては使われていない。 - P0/P1 expected_repo 未配線・pull_request_review 検証不足 — 解消。
plan_refinement_loop.py:1936-1941がexpected_repo=_expected_repo_for_issue(issue, known_context)をclassify_scope_delta_authority()に渡している。scope_signal_delta.py:validate_scope_delta_authority_evidence_url()はexpected_repo欠落時に fail-closed(return False)、pull_request_reviewevidence は検証手段が未実装であるため無条件 fail-closed reject(return False)に変更されている。 - P1 schema additionalProperties: true — 解消。
scope_delta_authority_evidence_v1.schema.jsonのadditionalPropertiesはfalseになっている(python で読み込み再確認済み)。 - P1 base_issue_body_sha256 nullable — 解消。
contract_patch_plan_v1.schema.jsonでbase_issue_body_sha256がrequiredに含まれminLength: 1の非null文字列必須になっている。加えて producer 側build_contract_patch_plan_v1()が空/None時にContractPatchPlanBaseShaMissingErrorを raise する fail-closed ガードを追加している。
追加検証
uv run --locked pytest .claude/skills/issue-refinement-loop/tests/を fetch した head SHA の worktree で実行し、1194 tests 全て PASS(回帰なし)。ci_verdict_summary.py --pr 1332の結果はstatus: all_pass、expected_head_sha/head_sha一致、failed_checks: []。git diff --name-statusで merge-base から head までの変更ファイル 11 件を独立算出し、Issue #1323 の Allowed Paths(scripts 4件・references 2件・schemas/ ディレクトリ・tests 2件)と完全一致、Allowed Paths 外の混入なし。
Draft 状態について
Draft はそれ自体 blocker ではない。merge_ready: true はマージ可否の終端条件であり、Ready 化は人間判断に委ねる。
…と不整合になるバグを修正 (#1342) * fix: run_refinement_preflight.py の関数定義順序と check_issue_contract.py の body_sha256 不整合を修正する run_refinement_preflight.py は _build_scope_delta_authority_evidence が `if __name__ == "__main__": main()` より後に定義されており、直接実行すると NameError で全ての issue-refinement-loop 起動が失敗していた(#1323/#1332 由来)。 check_issue_contract.py は gh --jq の raw string 出力に付与される末尾改行を `.strip()` で誤魔化しており、body_sha256 が contract_readiness_check.py / run_refinement_preflight.py の canonical raw-body hash と常に不一致になり reviewer_claim_replay.py が body_sha_mismatch で fail-closed していた。 --json 直接パースに置き換えて解消する。 Co-Authored-By: Claude Sonnet 5 <[email protected]> * revert: run_refinement_preflight.py の関数順序修正を取り下げる(#1334/PR #1339 と重複) Issue #1334 / PR #1339 で同一バグが既に修正対応中のため重複作業を解消する。 本 PR には check_issue_contract.py の body_sha256 不整合修正のみを残す。 Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix: PR #1342 レビュー指摘に対応する(regression test 追加・payload型検証) pr-review-judge の REQUEST_CHANGES を受けて以下を追加する。 - fetch_issue_body() の gh --json 出力 parse / raw body hash parity を 固定する regression test を追加する(Blocker 2) - json.loads() 後に payload が dict でない場合・labels が list でない場合を fail-closed で exit 2 にする(P1) Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
…r verifies manifest repo (P1 partial) OWNER PR review fix_delta iteration 2 (P1, schema/security boundary): the router (decide_next_loop_action.py) previously did not even accept a `repo` argument, and the controlled consumer never checked manifest["repo"] == repo -- a same-issue-number, cross-repo spoofed manifest could pass through unnoticed (the exact boundary PR #1332 had previously added for evidence classification, dropped again here). - generate_router_receipt() and the decide_next_loop_action.py CLI (--repo) now accept an expected repo and fail closed to reason_code: wrong_repo when the manifest's own repo field disagrees. - consume_authority_transport() now independently checks manifest["repo"] == repo, alongside its existing issue_number / git_head_sha / invocation_id checks. - command_registry.py's canonical decide.run entry carries an optional `repo` placeholder through to the router. Note: full JSON-Schema enforcement via _validate_with_schema() for the transport/receipt payloads (the other half of this P1 blocker) is not yet wired in -- see PR body follow-up note.
…o-end and expose routing telemetry (#2068) * fix(issue-refinement-loop): bind freeform OWNER scope authority end-to-end and expose routing telemetry (#2053) - Add SCOPE_DELTA_AUTHORITY_TRANSPORT_V1 / SCOPE_DELTA_ROUTER_RECEIPT_V1 / SCOPE_DELTA_CONSUMPTION_RECEIPT_V1 schemas, binding producer, router (decide_next_loop_action.py via command_registry.py decide.run), and controlled consumer (run_refinement_preflight.py) to the same canonical payload digest (loop-protocol-json-c14n-v1). - run_refinement_preflight.py: generate_authority_transport_manifest() / consume_authority_transport() write immutable per-invocation artifacts (flush -> fsync -> os.replace -> readback), so a stale previous-invocation artifact can never be silently reused, and the consumer refuses to mutate a second time for the same invocation_id. - decide_next_loop_action.py: generate_router_receipt() fails closed to environment_failure (never a legacy-route downgrade) when authority_expected=true and the sidecar is missing/malformed/digest- or source-mismatched. - command_registry.py: decide.run.with_authority_transport, authority_transport.produce, authority_transport.consume registry entries so the producer/router/consumer chain runs via registry-rendered argv. - scope_signal_delta.py: classify_scope_delta_authority() always rejects cross_target_direct_mutation and separates it from primary_target_exact_delta + non-mutating follow_up_candidates (AC6). - run_refinement_preflight.py: a structured ANCHOR_SCOPE_REFRAME_V1 payload that is present but invalid/wrong-target no longer downgrades to freeform authority evidence from the same comment body (AC2). Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(issue-refinement-loop): wrap allowed_write_roots to satisfy Ruff E501 pr-review-judge REQUEST_CHANGES (PR #2068 iteration 1, blocker 1): required CI python-test-core failed with Ruff E501 (line too long, 127>120) at command_registry.py:440 and :473. Reformat the allowed_write_roots single-element list across multiple lines without changing the string value. * fix(issue-refinement-loop): wire authority transport into canonical decide.run (P0-1) OWNER PR review fix_delta iteration 2 (P0, AC7): the previous implementation added a parallel "decide.run.with_authority_transport" sibling command ID instead of carrying the authority transport manifest through the actual production "decide.run" invocation path. Merge the authority-transport routing directly into decide.run via optional placeholders (authority_transport_manifest_path, authority_expected, invocation_id, git_head_sha, issue_number). render_command() now supports optional_flag_pair / bool_flag placeholder semantics so callers that omit these params get byte-identical argv to decide.run's original shape. * fix(issue-refinement-loop): fresh-rerun is a real fail-closed gate (P0-2 partial) OWNER PR review fix_delta iteration 2 (P0, AC9): consume_authority_transport() discarded the return value of classify_scope_delta_authority() during its "fresh rerun" step and always reported fresh_rerun_performed=true / status: ok regardless of drift or exception. Now the fresh classification's route.action is honored: only contract_update_required counts as a successful fresh rerun; any other route (human_escalation, drift) or an exception fails the consumption closed (environment_failure, fresh_rerun_route_drift / fresh_rerun_error), never silently ok. Note: full wiring of the controlled consumer to the existing controlled- mutation lane (consume_trusted_anchor_contract_patch_plan() / edit_issue_txn.py) is NOT done here -- edit_issue_txn.py is outside Issue #2053's Allowed Paths and this fix stays within them. See PR body for the explicit Allowed Paths escalation note. * fix(issue-refinement-loop): confine authority-transport artifact paths, narrow canonicalization_id (P1, P2) OWNER PR review fix_delta iteration 2: - P1 (no artifact path confinement / symlink defense): consume_authority_ transport() now resolves router_receipt_path / transport_manifest_path and confines them under <repo_root>/.claude/artifacts/, rejecting symlinks and non-regular files before ever reading them (_confine_artifact_path). Two existing fault-injection tests that used tmp_path fixtures outside the artifact root were relocated into the confined artifact directory so they keep exercising their intended fault (malformed_json / digest_mismatch) instead of being masked by the new confinement check. - P2 (rfc8785-jcs allowed but never implemented): narrowed scope_delta_authority_transport_v1.schema.json's canonicalization_id to a const of the one ID actually implemented (loop-protocol-json-c14n-v1); rfc8785-jcs removed until a real RFC 8785 dispatch (with its number/sorting semantics) exists. Adds 2 new regression tests (symlink rejection, outside-artifact-root rejection). * fix(issue-refinement-loop): real AC10 termination telemetry projection (P0-3) OWNER PR review fix_delta iteration 2 (P0, AC10): the only prior AC10 evidence was test_stale_previous_invocation_sidecar_is_never_reused, which only proves non-reuse of a stale sidecar -- not an actual canonical termination telemetry projection. consume_authority_transport()'s SCOPE_DELTA_CONSUMPTION_RECEIPT_V1 (the canonical termination point of the producer -> router -> consumer chain) now records generated_artifact / received_artifact / consumed_artifact, each an independently confirmed {relative_path, sha256} of the producer manifest, router receipt, and consumed payload respectively -- populated progressively as each artifact is verified to exist on disk, present in every terminal receipt (success or fail-closed). Adds a new regression test (test_termination_telemetry_records_generated_received_consumed_by_relpath_and_sha256) that independently recomputes each artifact's sha256 from the actual on-disk file and cross-checks it against the receipt. * fix(issue-refinement-loop): router accepts and enforces repo, consumer verifies manifest repo (P1 partial) OWNER PR review fix_delta iteration 2 (P1, schema/security boundary): the router (decide_next_loop_action.py) previously did not even accept a `repo` argument, and the controlled consumer never checked manifest["repo"] == repo -- a same-issue-number, cross-repo spoofed manifest could pass through unnoticed (the exact boundary PR #1332 had previously added for evidence classification, dropped again here). - generate_router_receipt() and the decide_next_loop_action.py CLI (--repo) now accept an expected repo and fail closed to reason_code: wrong_repo when the manifest's own repo field disagrees. - consume_authority_transport() now independently checks manifest["repo"] == repo, alongside its existing issue_number / git_head_sha / invocation_id checks. - command_registry.py's canonical decide.run entry carries an optional `repo` placeholder through to the router. Note: full JSON-Schema enforcement via _validate_with_schema() for the transport/receipt payloads (the other half of this P1 blocker) is not yet wired in -- see PR body follow-up note. * fix(issue-refinement-loop): refuse to overwrite existing authority-transport artifacts (P1) OWNER PR review fix_delta iteration 2 (P1, immutability/exactly-once): per-invocation-directory naming alone is not immutability -- os.replace() happily replaces an existing destination file. Two concrete gaps closed: - generate_authority_transport_manifest() now refuses to overwrite an existing manifest for the same invocation_id (manifest_already_exists), forcing callers to mint a fresh invocation_id for a fresh manifest. - consume_authority_transport() now binds its idempotency state BEFORE mutation: if a consumed_authority_payload_v1.json already exists for this invocation_id (a crash between the mutation write and the receipt publish), it refuses to re-mutate (stale_previous_invocation) instead of relying solely on post-mutation receipt presence. Adds 2 regression tests covering both refusal paths. * fix(issue-refinement-loop): wire AC9 mutation to real controlled-mutation lane, enforce schema validation, add stale anchor rejection (P0/P1/P2) #2053 fix-delta (iteration 3, owner PR review, unblocked by Allowed Paths expansion): - P0: consume_authority_transport()'s mutation step now delegates to the existing consume_trusted_anchor_contract_patch_plan() -> edit_issue_txn.py controlled-mutation lane when a CONTRACT_PATCH_PLAN_V1 + anchor_context are supplied, instead of only writing consumed_authority_payload_v1.json as a standalone artifact. mutation_applied now reflects that lane's real, independently-projected outcome (mutation_lane / contract_update_status on the receipt). Registered decide.run / authority_transport.produce / authority_transport.consume in skill_runtime_command_policy.py's eligible_command_ids so the privileged runtime policy recognizes them. - P1: producer (generate_authority_transport_manifest), router (generate_router_receipt), and consumer (consume_authority_transport) now call _validate_with_schema() against their respective schemas before persisting/returning "ok", not just manual field checks. - P2: _classify_anchor_scope_reframe() rejects a structured anchor whose comment was edited after posting (created_at != updated_at) with a new "stale:" reason, distinct from schema_invalid/wrong-target. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(issue-refinement-loop): wire authority_transport.consume placeholders, fail-closed schema/write races (fresh review iteration 4) Fresh review blockers on PR #2068 (#2053): - P0-A: add --contract-patch-plan-file/--anchor-context-file placeholders to authority_transport.consume so registry-rendered subprocess argv can actually reach consume_trusted_anchor_contract_patch_plan(); fix network_effect misclassification (local_only -> github_mutation). - P0-B: investigate skill_runtime_exec.py privileged dispatcher reachability for decide.run/authority_transport.produce/authority_transport.consume; add real-subprocess regression pinning the current (documented) rejection. Full fix requires scripts/agent-guards/skill_runtime_exec.py, which is outside Issue #2053's Allowed Paths -- recorded as a Stop Condition. - P1-A: _validate_with_schema() now fails closed when jsonschema is unavailable; producer/consumer fail closed when the schema file itself cannot be loaded, instead of silently skipping validation. - P1-C: _atomic_write_json_with_readback() uses os.link() exclusive-create instead of exists()-check-then-os.replace(), closing the TOCTOU race between concurrent producer writers for the same artifact path. Co-Authored-By: Claude Sonnet 5 <[email protected]> * fix(issue-refinement-loop): P0-B pinned regression must not depend on a real branch name CI checks out the PR head in detached HEAD (pull_request merge-ref), so `git branch --show-current` is empty there. The P0-B privileged-executor rejection is driven purely by parse_exact_skill_runtime_command()'s execution_class check, which runs before any cwd/branch check -- drop the unnecessary branch-name assertion/env override so the test passes in both a real local worktree checkout and CI's detached-HEAD checkout. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Summary
Refinement Loop の scope guard に
scope_delta_authorityを追加し、人間レビュー由来の明示的な契約更新要求をnew_in_scope_areaのような汎用 reason_code で無条件にhuman_escalationする過剰停止を解消する。Issue #1270 相当のケース(人間レビューコメントが Revised Acceptance Criteria を明示している)で、human_escalationではなくcontract_update_requiredへ分岐できるようにする。本 PR は #1090 で merge 済みの
SCOPE_SIGNAL_GUARD_DECISION_V2/ANCHOR_SCOPE_REFRAME_V1を再実装せず、その additive 拡張点(scope_signal_guard_decision_v2.scope_delta_authority)に統合する。また #1008(trusted anchor scope amendment)と #1011(CONTEXT_PROVENANCE_V1)を supersede する(本 PR マージ後、両 Issue を「Closed as superseded by #1323」として close する)。Closes #1323(本 Issue を解決する)
変更内容
.claude/skills/issue-refinement-loop/scripts/scope_signal_delta.pyclassify_scope_delta_authority()— 4 分類(ai_inferred/human_review_directive/existing_parent_contract/related_issue_dependency)とprovenance/directive/boundary_flags/routeの分解 shapebuild_contract_patch_plan_v1()/derive_contract_patch_operations()— Issue 本文への実書き込み(direct_github_write)は行わない生成専用の patch planparse_issue_comment_url()/validate_scope_delta_authority_evidence_url()— issue comment URL と PR review URL の混同を fail-closed で拒否(AC16).claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py_build_scope_delta_authority_evidence()— 構造化ANCHOR_SCOPE_REFRAME_V1を持たない freeform な人間レビューコメント(Issue 実装: クォータ管理と provider fallback policy を明文化・実装する #1270 相当)からもscope_delta_authority_evidence_v1を生成。raw comment body は決してknown_contextに渡さない(AC14).claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.pyknown_context.scope_delta_authority_evidenceが与えられた場合にのみscope_signal_guard_decision_v2.scope_delta_authorityを additive に出力(opt-in、既存 golden fixture 非破壊).claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.pyscope_signal_guard_decision_v2を--scope-signal-guard-decision-v2-file/--scope-signal-guard-decision-v2-jsonというloop_stateとは別の sidecar 引数として受け取る(loop_state.schema.jsonのトップレベル契約は変更しない)route == contract_update_requiredのときNEXT_ACTION: proceed_with_contract_updateを返す非破壊分岐(termination_reasonは変更しない).claude/skills/issue-refinement-loop/schemas/—scope_delta_authority_v1/scope_delta_authority_evidence_v1/contract_patch_plan_v1の JSON Schema.claude/skills/issue-refinement-loop/references/scope-signal-guard.md,anchor-comment-handling.md— 新契約の明文化.claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py(AC1〜AC19、19 tests).claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.py(AC20、7 tests、新規ファイル)Non-Goals(変更していないもの)
REFINEMENT_LOOP_PLAN_V1トップレベル schemaLOOP_STATE_V1.termination_reasonenumscope_signal_guard_decision_v2shape(raw_signal/scope_context/scope_delta_approval/security_sensitive/route)contract_patch_plan_v1は生成のみ)OWNER レビュー修正(iteration 1, PR #1332 head d4e4da3)
OWNER レビュー(issuecomment-4882361027)の
REQUEST_CHANGES を受け、以下を修正した。
decide_next_loop_action.pyはこれまでトップレベルのscope_signal_guard_decision_v2["route"](実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 由来の既存 enum。contract_update_requiredという値は取らない)を参照していたが、
plan_refinement_loop.pyはclassify_scope_delta_authority()の戻り値をネストされた
scope_signal_guard_decision_v2["scope_delta_authority"]["route"]["action"]に格納するだけだった。router を「ネストされた
scope_delta_authority.route.actionを読む」方針(review 提案の方針A)に統一し、references/scope-signal-guard.md/ docstring / tests を同期した。test_decide_next_loop_action_contract_update.pyはfixture 内で
decision_v2["route"] = "contract_update_required"を手動注入して router のみを検証しており、producer 出力そのものを経由していなかった。
plan_refinement_loop()を実際に呼び出し、その実出力scope_signal_guard_decision_v2を sidecar としてdecide_next_loop_action.pyの CLI に渡しNEXT_ACTION: proceed_with_contract_updateになることを検証するtest_producer_to_router_e2e_yields_proceed_with_contract_update/test_producer_to_router_e2e_without_evidence_regresses_to_human_escalationを追加した。加えて、トップレベル
routeだけをcontract_update_requiredに手動書き換えてもproceed_with_contract_updateにならないことを保証する回帰テストtest_top_level_route_alone_does_not_trigger_contract_update_regression_guardを追加した。AC20 はこれにより、top-level route 手注入ではなく実 producer 出力で検証済みである。
issuecomment-4881521790は Issue 実装: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする #1323 自体がどう提案されたかを示す ChatGPT 対話ログの comment であり、Issue 実装: Refinement Loop の scope guard を人間レビュー由来の契約更新として自動反映できるようにする #1323 の Background が言及する
「Revised Acceptance Criteria を明示した OWNER レビューコメント」の実体は
issuecomment-4881420705(
gh api repos/squne121/loop-protocol/issues/comments/4881420705、created_at 2026-07-04T09:11:40Z,author_association: OWNER)だった。fixture をこの実コメントのスナップショットから計算した
body_sha256(
scope_signal_delta.extract_directive_markers()/extract_directive_items()の実出力)に差し替え、テスト名も
test_issue_1270_actual_comment_4881420705_*に固定した。classify_scope_delta_authority()にexpected_repo引数を追加し、
plan_refinement_loop.pyの呼び出し元は既存の_expected_repo_for_issue()ヘルパー(実装: scope_signal_guard の escalation lane を分割し scope delta approval を契約化する #1090 の
scope_delta_approval検証と同一ソース)から値を渡すようにした。issue_commentevidence はexpected_repoなしでは fail-closed で拒否する(同一 issue 番号でも別 repo の URL によるなりすましを防ぐ)。pull_request_reviewevidence はSCOPE_DELTA_AUTHORITY_EVIDENCE_V1がpull_request_url/_links.pull_requestのような PR 紐付けフィールドをまだ持たず構造検証できないため、常に fail-closed で拒否するよう変更した(review 提案の「まだ扱えないなら fail-closed にする」を採用)。
cross-repo spoof 拒否テスト・
pull_request_review拒否テストを追加した。additionalProperties: falseに変更。scope_delta_authority_evidence_v1.schema.jsonが
body/body_text/body_html/raw_body/snapshotのような raw payload フィールドを schemaレベルで reject することをテストで担保した(AC14 の「raw body 非流入」を schema でも保証)。
contract_patch_plan_v1の適用安全性を強化。contract_update_requiredの場合はbase_issue_body_sha256を必須・non-null にし(未解決の場合はbuild_contract_patch_plan_v1()がContractPatchPlanBaseShaMissingErrorを送出し、呼び出し元はhuman_escalation(
reason_code: missing_base_issue_body_sha256)にフォールバックする)、source_evidenceにsource_comment_id/extracted_text_sha256/captured_at/start_line/end_lineを追加した。修正後、
.claude/skills/issue-refinement-loop/tests/全体(1194 tests)と.claude/skills/gemini-cli-headless-delegation/tests/test_model_routing.py(21 tests)、pnpm typecheck/pnpm lint/pnpm test(1399 tests)/pnpm buildが全て green であることを確認済み。Checks
全 AC1〜AC20 の Verification Command を個別に実行し、全て pass。
pytest tests/test_scope_delta_authority.py -k "<各AC名>"— 各 1 passed(iteration 1 で fixture/expected_repo/base_issue_body_sha256 対応の新規テストを含め 32 passed)pytest tests/test_scope_signal_guard_termination.py— 17 passed(regression なし)pytest tests/test_decide_next_loop_action_contract_update.py— 13 passed(producer→router E2E 2件を含む)既存回帰:
.claude/skills/issue-refinement-loop/tests/全体で 1194 passed(iteration 1 修正後、新規テスト含む)。ruff check .claude/skills/issue-refinement-loop/は新規/変更ファイルに新規エラーなし(既存 9 件の E402 は本 PR と無関係な既存ファイルで、CI Ruff gate は--ignore E402済み)。pnpm typecheck / lint / test / build は本 Issue が Python/pytest のみのスコープ(TypeScript/フロントエンド変更なし)のため元来非該当だが、iteration 1 の修正後に念のため全て実行し green を確認した(typecheck: pass, lint: pass, test: 1399 passed, build: pass)。
受け入れ条件の達成状況
classify_scope_delta_authority()がai_inferred/human_review_directive/existing_parent_contract/related_issue_dependencyの4分類を返す(test_scope_delta_authority_classifies_into_four_categories)contract_update_requiredに分岐する(test_human_review_directive_yields_contract_update_required)contract_patch_plan_v1が生成される(test_human_review_directive_generates_contract_patch_plan)contract_update_requiredはimplementation_allowed:falseを伴う(test_contract_update_required_sets_implementation_allowed_false)test_ai_inferred_scope_delta_still_escalates)test_ambiguous_conflicting_or_permission_boundary_still_escalates)new_in_scope_areaのような汎用値でなく具体値になる(test_reason_code_is_specific_not_generic_new_in_scope_area)issuecomment-4881420705, OWNER, iteration 1 で ID 修正済み)fixture がcontract_update_requiredに分岐する回帰テストが存在する(test_issue_1270_actual_comment_4881420705_yields_contract_update_required)contract_update_required後のnext_step:rerun_refinement_after_contract_updateが出力される(test_contract_update_required_next_step_is_rerun_refinement)test_scope_signal_guard_termination.py17 tests)が regression しないhuman_review_directiveに分類される(test_trusted_anchor_request_changes_classified_as_human_review_directive)ai_inferredのまま human_escalation する regression(test_agent_inferred_allowed_path_expansion_still_escalates)test_untrusted_or_missing_author_association_fails_closed)test_raw_comment_body_not_forwarded_to_issue_author)provenanceが trusted anchor 由来と agent_inferred 由来を区別する(test_provenance_distinguishes_trusted_anchor_from_agent_inferred)test_issue_comment_url_mismatch_or_pr_review_url_confusion_is_invalid)conflicting_human_directivesに分類される(test_conflicting_reviewer_directives_classified_as_conflicting_human_directives)boundary_flagsが true の場合は trusted anchor 承認があっても human_escalation する(test_boundary_flags_block_contract_update_even_with_trusted_approval)issuecomment-4881420705)fixture からcontract_patch_plan_v1が生成されforbiddenにdirect_github_write/implementation_phase_transitionが含まれ、base_issue_body_sha256必須化・source_evidenceのsource_comment_id/extracted_text_sha256/captured_at拡張後も pass する(test_issue_1270_actual_comment_4881420705_generates_contract_patch_plan_with_forbidden_operations)decide_next_loop_action.pyが、plan_refinement_loop()の実出力であるscope_signal_guard_decision_v2.scope_delta_authority.route.action == contract_update_requiredを受け取るとNEXT_ACTION: proceed_with_contract_updateを返し、termination_reasonenum は変更しないことを producer→router E2E で検証する(test_decide_next_loop_action_contract_update.py13 tests)。トップレベルscope_signal_guard_decision_v2["route"]の手動注入には一切依存しない(test_top_level_route_alone_does_not_trigger_contract_update_regression_guardで明示的に regression guard 済み)。Runtime Verification Applicability
decision: not_applicable(Issue 本文記載どおり)。issue-refinement-loop skill 内の静的な Python ロジック変更であり、pytest による決定論的検証で完結する。ゲームランタイム/ブラウザ実行を伴わない。CI_TEST_PERFORMANCE_DECISION_V1
Schema Change Applicability
.claude/skills/issue-refinement-loop/schemas/に新規 JSON Schema ファイル 3 件(scope_delta_authority_v1/scope_delta_authority_evidence_v1/contract_patch_plan_v1)を追加するため。既存 schema(refinement_loop_plan_v1/loop_state)の破壊的変更は行わない。Schema Consumer Inventory
before
新規追加のため before 相当の schema は存在しない(
scope_delta_authority_v1/scope_delta_authority_evidence_v1/contract_patch_plan_v1はいずれも本 PR で新規追加)。after
scope_delta_authority_v1:scope_signal_guard_decision_v2.scope_delta_authorityに additive フィールドとして格納される、authority_category/provenance/directive/boundary_flags/routeの分解 shapescope_delta_authority_evidence_v1:run_refinement_preflight.pyが生成する正規化済み evidence(raw comment body は含まない)contract_patch_plan_v1: Issue 本文への実書き込みを含まない生成専用の patch plan shape.claude/skills/issue-refinement-loop/scripts/plan_refinement_loop.pyknown_context.scope_delta_authority_evidenceを受け取り additive に出力する producer.claude/skills/issue-refinement-loop/scripts/decide_next_loop_action.pyroute == contract_update_requiredを消費する consumer.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.pyscope_delta_authority_evidence_v1の producer.claude/skills/issue-refinement-loop/scripts/scope_signal_delta.pycontract_patch_plan_v1の producerscope_signal_guard_decision_v2既存 consumer(他 skill)Safety Claim Matrix
LOOP_STATE_V1.termination_reasonenum とREFINEMENT_LOOP_PLAN_V1トップレベル schema は変更しないtest_decide_next_loop_action_contract_update.py7 tests pass(AC20)known_contextへ転送されず、正規化済み evidence のみが渡るtest_raw_comment_body_not_forwarded_to_issue_authorpass(AC14)test_untrusted_or_missing_author_association_fails_closedpass(AC13)boundary_flagsが true の場合、trusted anchor 承認があってもcontract_update_requiredへ進まず human_escalation するtest_boundary_flags_block_contract_update_even_with_trusted_approvalpass(AC18)test_issue_comment_url_mismatch_or_pr_review_url_confusion_is_invalidpass(AC16)Allowed Paths 遵守
Issue #1323 の Allowed Paths 内でのみ変更(変更ファイル一覧が Allowed Paths と完全一致していることを
git diff --name-onlyで確認済み、11 ファイル。iteration 1 の修正も同じ 11 ファイル内で完結し、新規ファイルは追加していない)。以下が変更ファイル一覧である。.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/contract_patch_plan_v1.schema.json.claude/skills/issue-refinement-loop/schemas/scope_delta_authority_evidence_v1.schema.json.claude/skills/issue-refinement-loop/schemas/scope_delta_authority_v1.schema.json.claude/skills/issue-refinement-loop/tests/test_scope_delta_authority.py.claude/skills/issue-refinement-loop/tests/test_decide_next_loop_action_contract_update.pyAllowed Paths 外の変更は含まれない(Issue 本文の Allowed Paths 一覧との完全一致を独立に再確認済み)。
Notes