Skip to content

feat: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する - #2469

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-2431-known-scalars-wiring
Sep 1, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-2431-known-scalars-wiring

Conversation

@squne121

@squne121 squne121 commented Aug 31, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • run_refinement_preflight.py の Step 0f が build_structural_repair_bundle() を known_scalars / source_spans 未指定のまま呼んでいたため、derivation 可能な missing section が不要に human_judgment_required へ落ちていた(実装: Claude-GPT を既存 Latitude project に接続し Native Claude Code と runtime source を識別可能にする #2426 で発現)。本 PR で known_scalars / source_spans の実抽出関数を配線する。
  • parent_issue スカラーを Machine-Readable Contract のキー / ## Parent Issue heading / (人間ラベル付き trusted anchor comment のみ)から解決し、parent-issue と machine-readable-contract.parent_issue の両方の consumer field-id へ供給する(_resolve_parent_issue_known_scalar)。
  • ## Proposed Allowed Paths -> ## Allowed Paths の closed / one-way / exact heading alias から same-body source_span_exact を生成する(_resolve_current_issue_heading_alias_source_spans)。source_revision は sha256(body) を束縛し、alias 複数出現・canonical heading 既存・空内容のいずれでも発火しない。
  • repair_issue_contract.py の _SOURCE_SPAN_AUTHORITY_KINDS に same-body 専用の additive extension current_issue を追加し、両 schema(repair_issue_contract_result_v1.schema.json / refinement_preflight_result_v1.schema.json)の enum も同期した。新規 derivation 種別・新規 structural schema model は追加していない。
  • agent-authored / unlabeled anchor comment は既存の _resolve_scope_delta_source_kind() lane classifier をそのまま再利用し、新規の trust 判定ロジックは追加していない(引き続き fail-closed で human review へ落ちる)。
  • fix_delta iteration 3(human adversarial REQUEST_CHANGES、comment)で解消した P1 blocker 2件:
    • _resolve_current_issue_heading_alias_source_spans() の line_start/line_end が、heading 直後の行を content 開始位置と誤って仮定していたため、heading → blank line → bullets という通常の Markdown 構造(この Issue テンプレート自体が使っている構造)で body.splitlines()[line_start-1:line_end] != span["text"] になっていた。repair_issue_contract.py の _section_line_bounds()(_apply_insertion_decision() が使っているのと同じ helper)を再利用し、raw content の実際の開始/終了行を計算するよう修正した。byte-exact reconstruction を正常系(単一行)・複数行content系の2パターンで regression test 化した。
    • current_issue authority_kind の「same issue / same repo / body digest 一致」という narrow precondition が assembler(run_refinement_preflight.py)側にしか実装されておらず、repair_issue_contract.py の generic provenance validator(_validate_source_span_provenance())は forged な current_issue span(例: source_object_kind: issue_comment を騙る span)を拒否できなかった。build_structural_repair_bundle() の generic producer boundary(assembler 固有ロジックではない箇所)に _validate_current_issue_source_span_authority() / _reject_forged_current_issue_source_spans() を追加し、precondition を満たさない current_issue span は auto_apply_safe/source_span_exact に昇格させず human_review_required のまま fail-closed とする。forged provenance negative test を追加した。
  • 上記2件の fix_delta を受け、Issue 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 本文も human reviewer 自身の推奨(選択肢1)に沿って、実装が実際に行っている「current-body + parent scalar assembly」の範囲に narrow 済み(AC1 の記述を現在の実装範囲に一致させ、AC5 の「exact」の定義を実装が使っている casefold ベースの CommonMark heading normalization 後 case-insensitive exact match に一致させた。実装側の変更は行っていない)。

Checks

  • pnpm typecheck
  • pnpm lint
  • pnpm test
  • pnpm build
  • 上記コマンドをすべてローカルで実行し、成功したことを確認してからチェックしてください

本 PR は .claude/skills/issue-refinement-loop/ 配下の Python スクリプト(issue-refinement-loop skill 自体のツール実装)のみを変更しており、フロントエンドアプリ(pnpm 対象)には影響しないため、上記 4 コマンドは対象外(N/A)。代わりに Issue #2431 の Verification Commands(下記)をローカルで実行し、すべて PASS を確認済み。

$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py -v
# 19 passed

$ uv run --locked rg -n -e DERIVATION_TEMPLATE_VALUE_EXACT -e DERIVATION_SOURCE_SPAN_EXACT -e DERIVATION_DERIVED_SCALAR_EXACT .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
# 既存3種のみ存在(baseline-expect: pass)

advisory broad regression check(PR review 時、merge 基準は main baseline との差分で new failure = 0):

$ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q
# 1953 passed, 3 failed in 328.52s
# 3 failed はいずれも test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch
# 系(本 PR のスコープと無関係な pre-existing failure。Issue #2431 の Notes for Reviewer に記載済みの
# 既知3件と一致。1953 = 旧 1949 + fix_delta iteration 3 で追加した新規 test 4本。new failure = 0)

uv run ruff check は変更した3スクリプト/テストファイルで clean。

受け入れ条件の達成状況

  • AC1: run_refinement_preflight.py に known_scalars / source_spans を assemble する新規関数(_resolve_parent_issue_known_scalar / _resolve_current_issue_heading_alias_source_spans)を追加し、build_structural_repair_bundle() 呼び出しへ配線した(source_spans は current-body の heading alias relocation のみ、known_scalars/parent_issue は current body MRC / current body ## Parent Issue heading / trusted anchor comment から解決 -- narrow 済み Issue 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 AC1 と一致)。根拠: test_known_scalars_and_source_spans_reach_build_structural_repair_bundle_kwargs PASS(production 経路で kwargs を観測)
  • AC2: parent_issue の解決値が known_scalars の parent-issue と machine-readable-contract.parent_issue の両方の consumer field-id へ供給される。根拠: test_parent_issue_scalar_cross_populates_both_consumer_field_ids / test_parent_issue_via_mrc_cross_populates_missing_heading_field_via_real_preflight PASS
  • AC3: source_span_exact.authority_kind に current_issue を追加し、Python _SOURCE_SPAN_AUTHORITY_KINDS と両 schema(repair_issue_contract_result_v1.schema.json / refinement_preflight_result_v1.schema.json)の enum が一致。根拠: test_current_issue_authority_kind_enum_consistent_across_python_and_schemas PASS
  • AC4: current_issue authority は全条件(same issue / body digest 一致 / closed alias exact match / alias exactly once / canonical heading missing / byte-exact copy / 複数候補時 conflict)を満たす場合のみ有効。fix_delta iteration 3 で追加: (a) line_start/line_end が body.splitlines()[line_start-1:line_end] == text を byte-exact に満たすことの regression test、(b) forged provenance(source_object_kind/source_repo/source_object_id/source_revision の不一致)が build_structural_repair_bundle() の generic producer boundary で拒否されることの negative test。根拠: test_current_issue_source_span_only_emitted_when_every_precondition_holds / test_current_issue_source_span_digest_binds_to_original_body_sha256 / test_current_issue_source_span_line_range_reconstructs_text_single_line / test_current_issue_source_span_line_range_reconstructs_text_multi_line / test_forged_current_issue_source_span_rejected_at_generic_producer_boundary / test_current_issue_source_span_authority_validator_rejects_each_forgeable_field PASS
  • AC5: heading alias は Proposed Allowed Paths -> Allowed Paths の closed / one-way / exact string マッピングのみで fuzzy/substring/semantic matching を行わない(CommonMark heading normalization 後の case-insensitive exact match。実装の既存 casefold() 挙動を変更せず、narrow 済み Issue 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 AC5 の定義と一致)。根拠: test_heading_alias_table_is_closed_one_way_exact_match_only PASS
  • AC6: parent_issue 存在 + heading alias 経由 semantic source + trusted current-owner reframe があるが canonical heading 一部欠落のケースで auto_apply_safe/source_span_exact に分類される。根拠: test_combined_positive_fixture_classifies_auto_apply_safe_via_real_preflight PASS
  • AC7: source authority なし / 複数競合(distinct bytes) / agent-only anchor / unlabeled anchor / malformed Machine-Readable Contract のいずれも fail-closed のまま human_judgment_required を維持。根拠: TestNegativeFixturesStayFailClosed 配下 5 テスト全 PASS(test_no_source_authority_stays_human_review_required / test_multiple_distinct_byte_candidates_conflict_to_none / test_agent_only_anchor_never_backs_auto_apply_safe / test_unlabeled_anchor_never_backs_auto_apply_safe / test_malformed_machine_readable_contract_stays_fail_closed)
  • AC8: unknown issue_kind / template resolution error / checker internal error / authority conflict は引き続き block として扱われる(既存 negative fixture の回帰なし)。根拠: test_regression_unknown_issue_kind_still_leaves_structural_repair_action_absent PASS、既存 test_template_section_repair.py も全件 PASS
  • AC9: repair_issue_contract.py に新規 derivation 種別・新規 structural schema model を追加していない(current_issue additive extension を除く)。fix_delta iteration 3 で追加した _validate_current_issue_source_span_authority() / _reject_forged_current_issue_source_spans() は既存 3 derivation mode / current_issue authority_kind の枠組み内での provenance 検証強化のみで、新規 derivation mode・新規 structural schema model は追加していない。根拠: test_no_new_derivation_mode_added PASS。独立再検証として rg -n -e DERIVATION_TEMPLATE_VALUE_EXACT -e DERIVATION_SOURCE_SPAN_EXACT -e DERIVATION_DERIVED_SCALAR_EXACT の結果、既存3種(DERIVATION_TEMPLATE_VALUE_EXACT / DERIVATION_SOURCE_SPAN_EXACT / DERIVATION_DERIVED_SCALAR_EXACT)以外の新規追加は無し
  • AC10: 本 Issue で新規追加した positive/negative regression test(test_structural_repair_known_scalars_wiring.py)が PASS する。根拠: 独立再実行で 19 passed(下記 検証コマンド結果 参照。fix_delta iteration 3 で 15 -> 19 に4本追加)

検証コマンド結果

Issue #2431 の Verification Commands 3件を worktree(head 0942672a049c361d32a44b433e469fec47a2de08、fix_delta iteration 3 反映後)で独立再実行した結果:

  • VC1(AC1-AC10 focused test):

    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py -v

    結果: 19 passed in 1.58s(19/19 全件 PASS。fix_delta iteration 3 で追加した4本の regression/negative test を含む)

  • VC2(AC9 regression invariant grep、baseline-expect: pass):

    $ uv run --locked rg -n -e DERIVATION_TEMPLATE_VALUE_EXACT -e DERIVATION_SOURCE_SPAN_EXACT -e DERIVATION_DERIVED_SCALAR_EXACT .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py

    結果: exit 0、既存3種の定義・使用箇所(1009-1015行目付近および各 _classify_* 関数内)が全て一致(新規 derivation 種別なし)

  • VC3(.claude/skills/issue-refinement-loop/tests/ 全 suite advisory broad regression check、preflight-scope: pr_review_only):

    $ uv run --locked pytest .claude/skills/issue-refinement-loop/tests/ -q

    結果: 1953 passed, 3 failed in 328.52s。3 failed はいずれも test_command_registry.py::TestAuthorityTransportPrivilegedExecutorRealSubprocessDispatch 系(本 PR のスコープと無関係な main baseline 既存 failure。Issue 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 Notes for Reviewer 記載の既知3件と一致)。merge 基準「main baseline との差分で new failure = 0」を満たす

Allowed Paths 遵守

本 PR の diff は Issue #2431(narrow 済み)の Allowed Paths に列挙された以下 5 パスのみを変更しており、それ以外のファイルへのスコープ拡張は無い(git diff --name-only main...HEAD で確認済み)。fix_delta iteration 3 での追加変更もこの範囲内(新規ファイル追加なし、既存3ファイルの追加編集のみ):

  • .claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py
  • .claude/skills/issue-refinement-loop/scripts/repair_issue_contract.py
  • .claude/skills/issue-refinement-loop/schemas/repair_issue_contract_result_v1.schema.json
  • .claude/skills/issue-refinement-loop/schemas/refinement_preflight_result_v1.schema.json
  • .claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py(Allowed Paths の .claude/skills/issue-refinement-loop/tests/ ディレクトリ配下)

Schema Change Applicability

  • decision: schema_change
  • reason: repair_issue_contract_result_v1.schema.json / refinement_preflight_result_v1.schema.json の source_span_exact.authority_kind enum に current_issue を additive extension として追加した(fix_delta iteration 3 での変更はこの schema 自体には影響しない。Python 側の provenance 検証強化のみ)。互換性の非対称性については下記 Compatibility Decision を参照。

Schema Consumer Inventory

変更対象 schema: repair_issue_contract_result_v1.schema.json / refinement_preflight_result_v1.schema.json(.../source_span_exact.authority_kind.enum)

before/after 差分:

# before
authority_kind:
  enum: [parent_issue, owner_anchor, design_reference, null]

# after
authority_kind:
  enum: [parent_issue, owner_anchor, design_reference, current_issue, null]

Consumer 列挙(rg コマンド例と結果):

$ rg -l '_load_schema\("repair_issue_contract_result_v1\.schema\.json"\)|_load_schema\("refinement_preflight_result_v1\.schema\.json"\)' .claude/skills/issue-refinement-loop
.claude/skills/issue-refinement-loop/tests/test_structural_repair_known_scalars_wiring.py
.claude/skills/issue-refinement-loop/tests/test_template_section_repair.py
.claude/skills/issue-refinement-loop/scripts/run_refinement_preflight.py

$ rg -l "repair_issue_contract_result_v1.schema.json|refinement_preflight_result_v1.schema.json" .
./docs/dev/workflow.md

Consumer 更新状況:

Consumer ファイル 更新有無 備考
run_refinement_preflight.py(refinement_preflight_result_v1.schema.json を自己検証) 更新済み current_issue を発火させる同ファイル内の producer 変更と同時に schema を更新。_validate_against_result_schema()(新規テスト)で緑を確認済み
test_template_section_repair.py 不要(追加のみで既存 enum 値は変更していないため既存アサーションは影響を受けない) 全件 PASS を確認
test_structural_repair_known_scalars_wiring.py(本 PR で新規追加) 更新済み(新規) AC3 として Python _SOURCE_SPAN_AUTHORITY_KINDS と両 schema enum の一致を機械検証
docs/dev/workflow.md 未対応(理由: schema ファイル名への言及のみで、authority_kind の値集合そのものへの参照ではない) —

Compatibility Decision(互換性判定)

  • change_type: additive
  • compatibility: backward_compatible(下記の方向限定の注記を参照)
  • migration_required: no
  • migration_or_followup: N/A
  • reason: 既存 3 値(parent_issue / owner_anchor / design_reference / null)は変更せず、新規値 current_issue を追加しただけの enum 拡張。非対称性の明記(PR feat: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2469 fix_delta iteration 3, P2、human adversarial review 指摘): 「backward_compatible」は「既存 payload(current_issue を含まない)→ 新 schema」の方向にのみ成立する(既存 producer/consumer は current_issue を出力しない限りこれまで通り動作する)。逆方向、すなわち「新しい current_issue を含む payload → 旧 schema/current_issue を認識しない旧 consumer ロジック」は forward-compatible ではない(旧 schema の enum に current_issue が無いため旧 schema でのバリデーションは失敗し、current_issue を想定しない旧 consumer ロジックは未知の値として扱う)。この非対称性は additive enum extension 一般に共通する性質であり、本 PR 固有の欠陥ではない。上記 Consumer Inventory のとおりリポジトリ内の direct consumer は限定的(run_refinement_preflight.py 自身と本 PR で追加したテストのみ)で、いずれも本 PR と同時に更新済みのため、実務上の migration は不要(migration_required: no は維持する)。

Visual Impact Declaration(視覚影響申告)

UI(DOM/CSS)変更を含まないため省略。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
current_issue authority の source_span_exact は AC4 の全条件(alias exactly once / canonical heading missing / 非空 / same-body digest 束縛)を満たす場合のみ生成される yes test_current_issue_source_span_only_emitted_when_every_precondition_holds / test_current_issue_source_span_digest_binds_to_original_body_sha256(PASS) N/A
current_issue source_span の line_start/line_end は body.splitlines()[line_start-1:line_end] が text を byte-exact に再構成する範囲を指す(fix_delta iteration 3 で修正) yes test_current_issue_source_span_line_range_reconstructs_text_single_line / test_current_issue_source_span_line_range_reconstructs_text_multi_line(新規テスト、PASS) N/A
forged な current_issue provenance(source_object_kind/source_repo/source_object_id/source_revision の不一致)は build_structural_repair_bundle() の generic producer boundary で拒否され、auto_apply_safe/source_span_exact に昇格しない(fix_delta iteration 3 で追加) yes test_forged_current_issue_source_span_rejected_at_generic_producer_boundary / test_current_issue_source_span_authority_validator_rejects_each_forgeable_field(新規テスト、PASS) N/A
agent-authored / unlabeled anchor comment の内容は parent_issue known_scalars 解決に使われない(fail-closed のまま human review) yes test_agent_only_anchor_never_backs_auto_apply_safe / test_unlabeled_anchor_never_backs_auto_apply_safe(PASS) N/A
distinct 値を持つ複数候補(MRC vs. trusted anchor)は conflict として None に解決され、いずれの値も採用しない yes test_multiple_distinct_byte_candidates_conflict_to_none(PASS) N/A
_resolve_parent_issue_known_scalar / _resolve_current_issue_heading_alias_source_spans はいずれも body: str(と repo/issue_number の静的値)のみを引数に取り、gh / GitHub REST を一切呼ばない yes diff で確認(両関数のシグネチャに gh / API クライアント引数が存在しない) N/A

記載ルール確認: Not controlled は空であり、すべての claim を yes(完全実装)としている。「safe」「read-only」等の無限定 claim は使用していない。

Notes

…ars/source_spans の実抽出を配線する (#2431)

run_refinement_preflight.py の Step 0f が build_structural_repair_bundle() を
known_scalars/source_spans 未指定のまま呼んでいたため、derivation 可能な
missing section が不要に human_judgment_required へ落ちていた(#2426)。

- parent_issue スカラーを MRC / `## Parent Issue` heading / (人間ラベル付き
  trusted anchor comment のみ) から解決し、parent-issue と
  machine-readable-contract.parent_issue の両方へ供給する
  (_resolve_parent_issue_known_scalar)
- `## Proposed Allowed Paths` -> `## Allowed Paths` の closed / one-way /
  exact heading alias から same-body source_span_exact を生成する
  (_resolve_current_issue_heading_alias_source_spans)。source_revision は
  sha256(body) を束縛し、alias 複数出現・canonical 既存・空内容では
  発火しない
- repair_issue_contract.py の _SOURCE_SPAN_AUTHORITY_KINDS に
  same-body 専用の additive extension `current_issue` を追加
  (両 schema の enum も同期)
- 新規 derivation 種別・新規 structural schema model は追加していない
- agent-authored / unlabeled anchor は既存の
  _resolve_scope_delta_source_kind() lane classifier を再利用し、
  引き続き fail-closed のまま人間レビューへ落ちる

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #2469 closed).

@squne121

Copy link
Copy Markdown
Owner Author

pr-review-judge 判定 (iteration 0)

Mergeability: mergeable=MERGEABLE, merge_state_status=BEHIND(実 conflict ではない)
CI: required checks 全て green(python-test / test / build / validate-generated-artifact / typecheck / lint)
Evidence Check: 独立 test-runner 検証済み。focused test 15/15 PASS(独立再実行でも再現)、AC9 regression grep 一致、Allowed Paths gate status: ok(全5変更ファイルが Allowed Paths 内)、diff スコープは宣言された5ファイルのみ。

Blockers:

  • PR 本文に必須セクション ## 受け入れ条件の達成状況(AC1-AC10 個別の [x]/[ ] + 根拠)が存在しない
  • PR 本文に必須セクション ## 検証コマンド結果 が存在しない
  • PR 本文に必須セクション ## Allowed Paths 遵守 の明示的申告が存在しない

Non-blockers:

  • 技術的実装・CI・Allowed Paths・テスト証拠は独立検証済みで問題なし。missing sections は本文フォーマットの不備であり、実装内容自体への疑義ではない。
verdict: REQUEST_CHANGES
reviewed_head_sha: "2f61fadefa70891a114783aabb7d9815802495ef"
blockers:
  - "PR 本文に必須セクション `## 受け入れ条件の達成状況`(AC1-AC10 個別の [x]/[ ] + 根拠)が存在しない"
  - "PR 本文に必須セクション `## 検証コマンド結果` が存在しない"
  - "PR 本文に必須セクション `## Allowed Paths 遵守` の明示的申告が存在しない"
warnings:
  - "技術的実装・CI・Allowed Paths・テスト証拠は独立検証済みで問題なし。missing sections は本文フォーマットの不備であり、実装内容自体への疑義ではない"

@squne121

Copy link
Copy Markdown
Owner Author

pr-review-judge 判定 (iteration 1, head a737bd6)

Mergeability: mergeable=MERGEABLE, merge_state_status=BEHIND(実 conflict ではない。main がさらに先行したため control-plane が再度 update_branch を実行)
CI: required checks 全て green(build / lint / test / typecheck / validate-generated-artifact)
Evidence Check: 独立 test-runner 再検証済み(focused test 15/15 PASS, AC9 regression grep 一致, full suite 1949 passed/3 pre-existing unrelated failures)。Allowed Paths gate status: ok。PR本文の3必須セクション健在。

Blockers: なし

verdict: APPROVE
reviewed_head_sha: "a737bd64610049d4c088601b0fd42c9513df6f67"
blockers: []
warnings:
  - "merge_state_status=BEHIND at review time; control-plane will re-run mechanical update_branch"
  - "PR is Draft; not a reviewer blocker per policy"
  - "Advisory full regression run reports 3 pre-existing failures, unrelated to this PR"

@squne121

Copy link
Copy Markdown
Owner Author

pr-review-judge 判定 (iteration 2, head 91f9a9b)

Mergeability: mergeable=MERGEABLE, merge_state_status=CLEAN
CI: required checks 全て green(build / lint / test / typecheck / validate-generated-artifact、20/20 checks passed)
Allowed Paths gate: status: ok。5変更ファイルが Allowed Paths 内。
Evidence Check: 独立 test-runner 再検証済み(focused test 15/15 PASS, AC9 regression grep 一致, full suite 1949 passed/3 pre-existing unrelated failures)。PR本文の3必須セクション健在。

Blockers: なし

Warnings:

  • PR本文の ## 検証コマンド結果 セクションのテキストが古い head (2f61fad...) を引用したままだが、本レビューで exact-head-bound の独立再検証により実質的に上書き済み。次の substantive push 時に本文を更新することが望ましい(non-blocking)。
verdict: APPROVE
reviewed_head_sha: "91f9a9b4a6a00472d5a3513557e30843810930ee"
blockers: []
warnings:
  - "PR body's 検証コマンド結果 section text still cites the prior head; substantively superseded by exact-head-bound independent re-verification, non-blocking"

live mergeability: mergeable=MERGEABLE, merge_state_status=CLEAN → route_loop_verdict_v2() の判定は route: approved。

@squne121

Copy link
Copy Markdown
Owner Author

判定: REQUEST_CHANGES

PR #2469 の方向性自体は妥当です。#2426 で表面化した「known_scalars / source_spans が production Step 0f に配線されていない」という gap に対し、新しい derivation model を増やさず、既存 producer を活かす設計になっています。現在の head 91f9a9b... では reviewer 再検証も通り、CI も clean と報告されています。

ただし、敵対的に見ると merge 前に直したい correctness / contract 問題が3件あります。新しい権限機構や大掛かりな harness を追加する必要はありません。

優先度 | Finding | 判定 -- | -- | -- P1 | current_issue の source_span 行範囲が通常の Markdown で本文と一致しない | 修正推奨・merge blocker P1 | current_issue の厳しい意味制約が assembler にしかなく、generic producer は偽の current_issue を auto_apply_safe にできる | 修正推奨・merge blocker P1 | Issue #2431 が要求する source assembly より実装が狭い | 実装するか Issue 契約を狭める必要あり P2 | 「exact heading」なのに実装は casefold() で case-insensitive | 契約か実装のどちらかを合わせる P2 | enum 追加を単純に backward_compatible としている | 表現修正で十分

P1 — source_span.line_start/line_end が実際の text を指していません

ここが一番具体的なバグです。

既存 _parse_h2_sections() は section content を最後に .strip() しています。つまり、

## Proposed Allowed Paths
  • src/foo.py

なら、返る content は - src/foo.py です。先頭の空行は除去されます。

一方、今回追加された assembler は、

line_start = alias_matches[0]["start_line"] + 1
line_end = line_start + ...

としているため、line_start は 見出し直後の空行を指します。しかし text は strip 後の - src/foo.py です。

したがって正常な Markdown ですでに、

source_span[line_start:line_end] != source_span["text"]

になります。

現 consumer はこの provenance を厳格に再構成していないので今すぐ mutation が壊れるとは限りませんが、source_span_exact と名乗る evidence としては不正確です。

最小修正は parser から strip 後 content の実際の content_start_line / content_end_line を返すことです。あるいは assembler 内で content_lines の leading/trailing blank を考慮して offset を計算するだけでも構いません。

追加テストは1本で十分です。

actual = "\n".join(body.splitlines()[line_start - 1:line_end])
assert actual == span["text"]

通常の「heading → blank line → bullets」と、複数行 content の2ケースを通せば十分です。新しい provenance harness は不要です。


P1 — current_issue が producer/schema 上では広すぎます

Issue #2431 の owner review で要求された current_issue は、「same-body heading relocation 専用」です。source object は target Issue の body、digest は同じ body、closed alias からの byte-exact copy、という限定でした。

今回の assembler はかなり忠実にそれを守っています。問題は 制約を assembler だけが持っていることです。

repair_issue_contract.py 側では current_issue を enum に追加しただけで、コメントにも「狭い precondition は caller が責任を持つ」と明記されています。

generic provenance validator が確認しているのは、

  • authority が enum 内

  • object kind が issue_body | issue_comment | git_blob

  • required fields が非空

  • line range が妥当

までです。

そして _classify_missing_field() はこの generic validation が通れば source_span_exact → auto_apply_safe にします。

つまり別 caller が理論上、

{
"authority_kind": "current_issue",
"source_object_kind": "issue_comment",
"source_object_id": "999999",
"source_repo": "other/repo",
...
}

のような provenance を渡しても、generic classifier 自体は「current issue ではない」と拒否できません。

これはセキュリティ問題というより 型/契約の表現力不足です。しかも build_structural_repair_bundle() 自身は body, repo, issue_number と original_body_sha256 をすでに持っています。

したがって追加 infrastructure は不要です。build_structural_repair_bundle() / detect_missing_template_sections() の境界で current_issue の場合だけ、

source_object_kind == issue_body
source_repo == repo
source_object_id == str(issue_number)
source_revision == original_body_sha256

を確認してください。さらに alias relation は assembler のままでも構いません。

JSON Schema 側にも最低限、

authority_kind == current_issue
→ source_object_kind == issue_body

という conditional を入れれば、schema 自体が嘘をつかなくなります。

direct producer test で forged current_issue を1件拒否できれば十分です。


P1 — PR は Issue #2431 の AC1 を完全には実装していません

これは実害とは別の、scope/claim の不一致です。

#2431 は known_scalars / source_spans を、

parent Issue body / current Issue body / trusted anchor comment

から assemble することを In Scope / AC1 にしています。また複数 source candidate は bytes で exact dedup し、distinct content のみ conflict にする契約です。 Owner review でも同値 candidate を assembler 側で dedup することが明記されています。

しかし今回の実装は実質、

  • parent_issue scalar:

    • current body MRC

    • current body ## Parent Issue

    • trusted anchor の ## Parent Issue

  • source_spans:

    • current body の Proposed Allowed Paths のみ

です。

parent Issue body を source として assemble していませんし、trusted anchor から一般的な source span を作ってもいません。source-span candidate の exact dedup machinery もありません。

ここは個人開発前提なら、実装を広げるより Issue #2431 の契約を狭める方を推します。

実インシデント #2426 を閉じるために必要なのが、

current Issue の Proposed Allowed Paths
→ missing Allowed Paths

だけなら、parent Issue の追加 fetch や多元 source resolution を今作る費用対効果は低いです。#2206 で producer、#2400 で single-mutation / stale guard / fresh validation を含む consumer はすでに成立しています。

したがって二択です。

  1. 推奨: 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 の AC1 / Outcome / In Scope を、今回本当に実装する current-body + parent scalar assembly に狭める。

  2. 契約を維持するなら、parent body / anchor source span collection と exact dedup を実装する。

後者のために新しい GitHub provenance framework を作る必要はありません。


P2 — 「exact heading」ではなく case-insensitive matching です

alias table 自体は、

{"Proposed Allowed Paths": "Allowed Paths"}

という closed mapping ですが、lookup は双方に .casefold() をかけています。したがって、

## proposed allowed paths

PROPOSED ALLOWED PATHS

もマッチします。

テストは Suggested Allowed Paths のような near-match は検証していますが、case variant は検証していません。

CommonMark の ATX heading は heading raw content の前後 whitespace を strip しますが、大文字小文字を同一視する仕様ではありません。(CommonMark仕様)

一方、このリポジトリの既存 required-heading 検出も casefold() を使っています。

なので私は実装を変えるより、AC5 の「exact」を、

CommonMark heading normalization 後の case-insensitive exact match

など、実装に合う定義へ修正する方を選びます。これなら workflow を悪化させません。


P2 — current_issue enum 追加は「完全な backward compatibility」ではありません

PR本文は schema change を additive / backward_compatible / migration_required: no としています。既存 payload が新 schema で引き続き valid、という意味なら正しいです。

ただし JSON Schema の enum は「列挙された値だけが valid」という closed validation です。(JSON Schema)

したがって旧 schema snapshot、

["parent_issue", "owner_anchor", "design_reference", null]

を持つ consumer は、新 producer が出す "current_issue" を reject します。

つまり正確には、

existing payloads → new schema は backward-compatible。
new current_issue payload → stale schema/consumer は forward-compatible ではない。

です。

リポジトリ内検索上、authority_kind の direct consumer はかなり限定されているので、実務上 migration は不要でよいと思います。ここは PR 本文の Compatibility Decision の表現だけ直せば十分です。


最小修正セット

私なら merge 前の変更を次の4点だけに絞ります。

  1. source_span の line range を実際の stripped text と一致させ、slice == text の regression test を追加する。

  2. generic producer 境界で current_issue の issue_body / repo / issue_number / digest を検証し、forged span の negative test を1本追加する。

  3. 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 の source scope を今回の実装に合わせて狭める。parent-Issue fetch / multi-source machinery は、実際に必要な incident が出るまで作らない。

  4. AC5 の case sensitivity と Schema Compatibility の文言だけ実装実態に合わせる。

この修正なら、新しい permission gate、署名、ledger、history fetch、mutation harness、CI 全suite zero-failure gateは一切不要です。既存 #2400 の controlled consumer をそのまま利用できます。

総評としては、実装の中心部分は良く、#2426 の実用上の gap を閉じるところまではほぼできています。ただし今のまま APPROVE すると、source_span_exact の provenance が実際の行を指していない点と、current_issue の schema/producer 契約が assembler より広い点を後で負債として拾うことになります。そこだけ狭く直してから merge が適切です。

## 判定: `REQUEST_CHANGES`

PR #2469 の方向性自体は妥当です。#2426 で表面化した「known_scalars / source_spans が production Step 0f に配線されていない」という gap に対し、新しい derivation model を増やさず、既存 producer を活かす設計になっています。現在の head 91f9a9b... では reviewer 再検証も通り、CI も clean と報告されています。

ただし、敵対的に見ると merge 前に直したい correctness / contract 問題が3件あります。新しい権限機構や大掛かりな harness を追加する必要はありません。

優先度 Finding 判定
P1 current_issue の source_span 行範囲が通常の Markdown で本文と一致しない 修正推奨・merge blocker
P1 current_issue の厳しい意味制約が assembler にしかなく、generic producer は偽の current_issue を auto_apply_safe にできる 修正推奨・merge blocker
P1 Issue #2431 が要求する source assembly より実装が狭い 実装するか Issue 契約を狭める必要あり
P2 「exact heading」なのに実装は casefold() で case-insensitive 契約か実装のどちらかを合わせる
P2 enum 追加を単純に backward_compatible としている 表現修正で十分

P1 — source_span.line_start/line_end が実際の text を指していません

ここが一番具体的なバグです。

既存 _parse_h2_sections() は section content を最後に .strip() しています。つまり、

## Proposed Allowed Paths

- src/foo.py

なら、返る content は - src/foo.py です。先頭の空行は除去されます。

一方、今回追加された assembler は、

line_start = alias_matches[0]["start_line"] + 1
line_end = line_start + ...

としているため、line_start は 見出し直後の空行を指します。しかし text は strip 後の - src/foo.py です。

したがって正常な Markdown ですでに、

source_span[line_start:line_end] != source_span["text"]

になります。

現 consumer はこの provenance を厳格に再構成していないので今すぐ mutation が壊れるとは限りませんが、source_span_exact と名乗る evidence としては不正確です。

最小修正は parser から strip 後 content の実際の content_start_line / content_end_line を返すことです。あるいは assembler 内で content_lines の leading/trailing blank を考慮して offset を計算するだけでも構いません。

追加テストは1本で十分です。

actual = "\n".join(body.splitlines()[line_start - 1:line_end])
assert actual == span["text"]

通常の「heading → blank line → bullets」と、複数行 content の2ケースを通せば十分です。新しい provenance harness は不要です。


P1 — current_issue が producer/schema 上では広すぎます

Issue #2431 の owner review で要求された current_issue は、「same-body heading relocation 専用」です。source object は target Issue の body、digest は同じ body、closed alias からの byte-exact copy、という限定でした。

今回の assembler はかなり忠実にそれを守っています。問題は 制約を assembler だけが持っていることです。

repair_issue_contract.py 側では current_issue を enum に追加しただけで、コメントにも「狭い precondition は caller が責任を持つ」と明記されています。

generic provenance validator が確認しているのは、

  • authority が enum 内
  • object kind が issue_body | issue_comment | git_blob
  • required fields が非空
  • line range が妥当

までです。

そして _classify_missing_field() はこの generic validation が通れば source_span_exact → auto_apply_safe にします。

つまり別 caller が理論上、

{
    "authority_kind": "current_issue",
    "source_object_kind": "issue_comment",
    "source_object_id": "999999",
    "source_repo": "other/repo",
    ...
}

のような provenance を渡しても、generic classifier 自体は「current issue ではない」と拒否できません。

これはセキュリティ問題というより 型/契約の表現力不足です。しかも build_structural_repair_bundle() 自身は body, repo, issue_number と original_body_sha256 をすでに持っています。

したがって追加 infrastructure は不要です。build_structural_repair_bundle() / detect_missing_template_sections() の境界で current_issue の場合だけ、

source_object_kind == issue_body
source_repo == repo
source_object_id == str(issue_number)
source_revision == original_body_sha256

を確認してください。さらに alias relation は assembler のままでも構いません。

JSON Schema 側にも最低限、

authority_kind == current_issue
→ source_object_kind == issue_body

という conditional を入れれば、schema 自体が嘘をつかなくなります。

direct producer test で forged current_issue を1件拒否できれば十分です。


P1 — PR は Issue #2431 の AC1 を完全には実装していません

これは実害とは別の、scope/claim の不一致です。

#2431 は known_scalars / source_spans を、

parent Issue body / current Issue body / trusted anchor comment

から assemble することを In Scope / AC1 にしています。また複数 source candidate は bytes で exact dedup し、distinct content のみ conflict にする契約です。 Owner review でも同値 candidate を assembler 側で dedup することが明記されています。

しかし今回の実装は実質、

  • parent_issue scalar:

    • current body MRC
    • current body ## Parent Issue
    • trusted anchor の ## Parent Issue
  • source_spans:

    • current body の Proposed Allowed Paths のみ

です。

parent Issue body を source として assemble していませんし、trusted anchor から一般的な source span を作ってもいません。source-span candidate の exact dedup machinery もありません。

ここは個人開発前提なら、実装を広げるより Issue #2431 の契約を狭める方を推します。

実インシデント #2426 を閉じるために必要なのが、

current Issue の Proposed Allowed Paths
→ missing Allowed Paths

だけなら、parent Issue の追加 fetch や多元 source resolution を今作る費用対効果は低いです。#2206 で producer、#2400 で single-mutation / stale guard / fresh validation を含む consumer はすでに成立しています。

したがって二択です。

  1. 推奨: 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 の AC1 / Outcome / In Scope を、今回本当に実装する current-body + parent scalar assembly に狭める。
  2. 契約を維持するなら、parent body / anchor source span collection と exact dedup を実装する。

後者のために新しい GitHub provenance framework を作る必要はありません。


P2 — 「exact heading」ではなく case-insensitive matching です

alias table 自体は、

{"Proposed Allowed Paths": "Allowed Paths"}

という closed mapping ですが、lookup は双方に .casefold() をかけています。したがって、

## proposed allowed paths
## PROPOSED ALLOWED PATHS

もマッチします。

テストは Suggested Allowed Paths のような near-match は検証していますが、case variant は検証していません。

CommonMark の ATX heading は heading raw content の前後 whitespace を strip しますが、大文字小文字を同一視する仕様ではありません。([CommonMark仕様]1)

一方、このリポジトリの既存 required-heading 検出も casefold() を使っています。

なので私は実装を変えるより、AC5 の「exact」を、

CommonMark heading normalization 後の case-insensitive exact match

など、実装に合う定義へ修正する方を選びます。これなら workflow を悪化させません。


P2 — current_issue enum 追加は「完全な backward compatibility」ではありません

PR本文は schema change を additive / backward_compatible / migration_required: no としています。既存 payload が新 schema で引き続き valid、という意味なら正しいです。

ただし JSON Schema の enum は「列挙された値だけが valid」という closed validation です。([JSON Schema]2)

したがって旧 schema snapshot、

["parent_issue", "owner_anchor", "design_reference", null]

を持つ consumer は、新 producer が出す "current_issue" を reject します。

つまり正確には、

existing payloads → new schema は backward-compatible。
new current_issue payload → stale schema/consumer は forward-compatible ではない。

です。

リポジトリ内検索上、authority_kind の direct consumer はかなり限定されているので、実務上 migration は不要でよいと思います。ここは PR 本文の Compatibility Decision の表現だけ直せば十分です。


最小修正セット

私なら merge 前の変更を次の4点だけに絞ります。

  1. source_span の line range を実際の stripped text と一致させ、slice == text の regression test を追加する。
  2. generic producer 境界で current_issue の issue_body / repo / issue_number / digest を検証し、forged span の negative test を1本追加する。
  3. 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 の source scope を今回の実装に合わせて狭める。parent-Issue fetch / multi-source machinery は、実際に必要な incident が出るまで作らない。
  4. AC5 の case sensitivity と Schema Compatibility の文言だけ実装実態に合わせる。

この修正なら、新しい permission gate、署名、ledger、history fetch、mutation harness、CI 全suite zero-failure gateは一切不要です。既存 #2400 の controlled consumer をそのまま利用できます。

総評としては、実装の中心部分は良く、#2426 の実用上の gap を閉じるところまではほぼできています。ただし今のまま APPROVE すると、source_span_exact の provenance が実際の行を指していない点と、current_issue の schema/producer 契約が assembler より広い点を後で負債として拾うことになります。そこだけ狭く直してから merge が適切です。

@squne121 squne121 self-assigned this Aug 31, 2026
…#2431 fix_delta iteration 3)

human adversarial review (PR #2469 REQUEST_CHANGES) の P1 blocker 2件を解消する:

- `_resolve_current_issue_heading_alias_source_spans()` の line_start/line_end
  が heading 直後の行を content 開始位置と誤って仮定していたため、heading ->
  blank line -> bullets という通常の Markdown 構造で
  `body.splitlines()[line_start-1:line_end] != span["text"]` になっていた。
  `_section_line_bounds()` を再利用して raw content の実際の開始/終了行を
  計算するよう修正し、byte-exact reconstruction を regression test で検証する。
- `current_issue` authority_kind の same-issue/same-repo/body-digest 一致という
  narrow precondition が assembler 側にしか無く、`repair_issue_contract.py`
  の generic provenance validator は forged な current_issue span
  (例: source_object_kind: issue_comment)を拒否できなかった。
  `build_structural_repair_bundle()` の generic producer boundary に
  `_validate_current_issue_source_span_authority()` /
  `_reject_forged_current_issue_source_spans()` を追加し、precondition を
  満たさない current_issue span は auto_apply_safe/source_span_exact に
  昇格させず human_review_required のまま fail-closed とする。

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squne121

Copy link
Copy Markdown
Owner Author

pr-review-judge 判定 (iteration 3, head 0942672)

人間オーナーの敵対的 REQUEST_CHANGES(https://github.com/squne121/loop-protocol/pull/2469#issuecomment-5485342004)に対する fix_delta 対応の再レビュー。

対応内容の独立検証:

  • P1(line-range bug): _section_line_bounds() 再利用 + fail-closed reconstruction guard 追加を確認。新規2テスト(single/multi-line)が実際に slice==text を検証していることをコード読解で確認。
  • P1(forged provenance): _validate_current_issue_source_span_authority() / _reject_forged_current_issue_source_spans() が build_structural_repair_bundle() の generic boundary で呼ばれていることを確認。新規2テスト(production API経由 + 直接unit test)を確認。
  • P1(scope narrowing): live Issue 実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する #2431 本文の AC1/Outcome/In Scope が current-body-only に縮小されていることを再取得で確認。
  • P2(AC5 reword): live AC5 が casefold() 実装と整合する文言に修正済みを確認。
  • P2(PR本文 compatibility wording): 非対称性の明記を確認。

CI: 全 required checks green(head 0942672a...)
Allowed Paths gate: status: ok、5変更ファイルが Allowed Paths 内
AC coverage: AC1-10 全て根拠付きで確認、focused test 15→19(+4)全PASS、full suite 1953 passed/3 pre-existing unrelated failures

Blockers: なし

verdict: APPROVE
reviewed_head_sha: "0942672a049c361d32a44b433e469fec47a2de08"
blockers: []
warnings: []

live mergeability: mergeable=MERGEABLE, merge_state_status=CLEAN → route_loop_verdict_v2() の判定は route: approved。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

実装: issue-refinement-loop の structural repair producer に known_scalars/source_spans の実抽出を配線する

1 participant