Repository navigation
Description
Machine-Readable Contract
contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "ensure_contract_snapshot.py の binding_body_hash_mismatch 診断情報の欠如と check-only の existence classification 粒度不足を、current main(PR #2629/#2621 マージ後)の実装に整合した形で解消する"
change_kind: codeParent Issue
none
Parent Goal Ref
- Goal: N/A(単独改善)
- Desired Destination: N/A(単独改善)
Current Validated Scope
.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.pyのverify_controlled_publisher_comment_id_binding()がbinding_body_hash_mismatchを返す際の bounded diagnostics 追加- 同ファイルの
materialize_contract_review_snapshot()(post_comment()/patch_comment()呼び出し直後の binding 再照合箇所。expected body 本文を呼び出し元スコープが保持している call site 限定)での diagnostics 供給 - 同ファイルの check-only 分岐(
run_ensure_contract_snapshot()内、mode == "check-only" and result["contract_snapshot_url"] is None判定部)の 3-way classification 化
Remaining Parent Gaps
なし
Outcome
ensure_contract_snapshot.py が binding_body_hash_mismatch を検出した際、expected body 本文を呼び出し元が保持している call path に限り、UTF-8 バイト長・先頭差分オフセット・両者の sha256 を含む bounded diagnostics を errors に記録する状態。expected_body_sha256 のみが渡される call path(呼び出し元が expected body 本文を保持していない場合)では、ダミー値を合成せず既存の reason code のみを返す状態を維持する。check-only モードでは「候補が本当に存在しない」「既存 go の base-binding drift」「go-like candidate は存在するが trusted publisher / fingerprint readiness 条件を満たさず採用不能」の 3 区分を診断上区別できる状態。回帰テストが追加され PASS している。
Runtime Verification Applicability
- decision: not_applicable
- reason: 静的検証(pytest による決定論的な関数呼び出し・戻り値検証)のみで完結するため。GitHub 実 API への書き込みや外部サービスの実行時挙動を新規に伴わない
In Scope
verify_controlled_publisher_comment_id_binding()がbinding_body_hash_mismatchを返す分岐に、UTF-8 バイト列基準の bounded diagnostics(expected_byte_len/actual_byte_len/first_diff_byte_offset/expected_sha/actual_sha)を追加する。ただし、この関数は現在expected_body_sha256(ハッシュ値のみ)しか受け取らないため、関数内部だけでは expected body の byte 内容や diff offset を算出できない。呼び出し元(materialize_contract_review_snapshot()内のpost_comment()/patch_comment()直後の binding 再照合箇所)が expected body 本文をスコープ内に保持している call site に限り、呼び出し元側で actual body(GET readback 済み)との比較を行い diagnostics をerrorsへ付加するexpected_body_sha256のみが渡され expected body 本文自体を呼び出し元が保持していない call path では、expected_byte_len/first_diff_byte_offsetのダミー値を合成しない。この場合は従来通りbinding_body_hash_mismatchの reason code のみを返す- check-only モードの existence 判定(
no_existing_go_comment系エラー)を、以下の 3 区分に分離する:no_existing_go_comment(現状維持): trusted かつ fingerprint-ready な go candidate が一件も存在しないexisting_go_base_binding_drift(現状維持): trusted かつ fingerprint-ready な go candidate は存在するが base ref/sha が現在の default branch tip と乖離- 新規区分(reason code
go_like_candidate_authority_unmet):find_latest_result()は候補を検出するが、find_latest_go(trusted_only=True, fingerprint_ready_only=True)が trusted publisher 判定または fingerprint readiness 判定のいずれかで候補を除外している(= go-like な comment は存在するが current authority 条件を満たさず採用不能)
- 新規区分の追加は、既存の
no_existing_go_comment/existing_go_base_binding_driftの判定条件・reason code 文字列・戻り値スキーマを変更しない(additive のみ) - 上記変更を検証する回帰テストの追加(既存
TestControlledPublisherCommentIdBindingクラスへの diagnostics テスト追加、既存TestCheckOnlyModeクラスへの 3-way classification テスト追加)
Out of Scope
tempfile.NamedTemporaryFileの導入・復活(current main は既に不使用。導入しない)--field body=@filetransport の導入・復活(current main は既に不使用)- 一時ファイル読み戻し(tempfile readback)を authority とする設計
post_comment()の transport 再設計(canonical JSON stdin transport で確定済み。staging 用途のみ)patch_comment()の transport 再設計(canonical JSON stdin transport で確定済み)- final PATCH persisted-body authority の再実装(PR fix: reconcile untrusted PATCH comment responses #2621 の direct-GET SHA256 binding を変更しない)
- PR fix: reconcile untrusted PATCH comment responses #2621 が確立した PATCH → direct-GET binding パターンの再実装
verify_controlled_publisher_comment_id_binding()の trusted author 判定ロジック自体(is_trusted_snapshot_author())の変更is_fingerprint_ready_go()の fingerprint readiness 判定ロジック自体の変更run_contract_review_once.py側の readiness / VC preflight / product spec check ロジックの変更- 専用
test_ensure_contract_snapshot_body_hash_roundtrip.pyの新設(既存 test class への追加を優先する。必須契約にしない) - Issue fix: post_comment() を canonical JSON stdin transport に統一し staging/final authority を分離する #2629 の production-orchestration regression gap(別 follow-up Issue 実装: ensure_contract_snapshot() の real orchestration を通す staging/final digest 取り違えregression testを追加する #2635 の責務。本 Issue には含めない)
- Issue 実装: M4 Upgrade Loop の E2E / preview evidence を追加する #1283 本体(本 Issue の起票理由となった観測事象。実装: M4 Upgrade Loop の E2E / preview evidence を追加する #1283 自体は go コメント URL を手動確認して対応済み)
Acceptance Criteria
- AC1:
verify_controlled_publisher_comment_id_binding()の呼び出し元で expected body 本文を保持している call site(materialize_contract_review_snapshot()内の binding 再照合箇所)において、binding_body_hash_mismatch検出時にexpected_byte_len/actual_byte_len/first_diff_byte_offset/expected_sha/actual_shaを含む bounded diagnostics がresult["errors"]に記録される - AC2:
expected_body_sha256のみが渡される(expected body 本文を呼び出し元が保持していない)call path では、expected_byte_len/first_diff_byte_offsetのダミー値が生成されないことをテストで確認する - AC3: check-only モードにおいて、go-like candidate(trusted でない、または fingerprint-ready でない)が存在する場合、
no_existing_go_commentとは異なる新規 reason codego_like_candidate_authority_unmetがresult["errors"]に記録される - AC4: 上記 AC3 の追加後も、候補が一件も存在しない場合は引き続き
no_existing_go_commentが返る(既存挙動の非破壊) - AC5: 上記 AC3 の追加後も、
existing_go_base_binding_driftの既存判定・reason code 文字列は変更されない(既存挙動の非破壊) - AC6: 既存
.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.pyのTestCheckOnlyMode/TestControlledPublisherCommentIdBindingを含む全件が regression なく PASS する - AC7: 既存
.claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.pyのTestControlledPublisherCommentIdBindingを含む全件が regression なく PASS する - AC8:
pnpm typecheckが PASS する - AC9:
pnpm lintが PASS する - AC10:
pnpm testが PASS する - AC11:
pnpm buildが PASS する
Verification Commands
# AC1
$ rg -n "expected_byte_len" .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
$ rg -n "actual_byte_len" .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
$ rg -n "first_diff_byte_offset" .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
# AC2
# baseline-expect: pass
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -k "hash_mismatch" -v
# AC3
$ rg -n "go_like_candidate_authority_unmet" .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
# AC4
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py::TestCheckOnlyMode -v
# AC5
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py::TestCheckOnlyMode -v
# AC6
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -v
# AC7
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py -v
# AC8
$ pnpm typecheck
# AC9
$ pnpm lint
# AC10
$ pnpm test
# AC11
$ pnpm buildAllowed Paths
- .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
- .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py
- .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py
Stop Conditions
- Allowed Paths 外の変更が必要と判明した場合
- In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
- 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
- 後続 Phase / 別スコープへの波及が判明した場合
- nested SubAgent delegation が必要になった場合
- 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
is_trusted_snapshot_author()/is_fingerprint_ready_go()の判定ロジック自体、またはpost_comment()/patch_comment()の transport 方式の変更が必要と判明した場合
Required Skills
- Python
Required Design References
- Issue 調査: #1513 を #2627 マージ後の current main に合わせて再スコープする #2633(squne121/loop-protocol)— 本 Issue の縮小再定義(reframe)の根拠となった上流調査・disposition
- Issue fix: post_comment() を canonical JSON stdin transport に統一し staging/final authority を分離する #2629(squne121/loop-protocol)—
post_comment()の canonical JSON stdin transport 確立(現状把握の前提) - Issue fix: reconcile untrusted PATCH comment responses #2621(squne121/loop-protocol)— final PATCH persisted-body authority(direct-GET SHA256 binding)確立(現状把握の前提)
.claude/skills/impl-review-loop/SKILL.md—ensure_contract_snapshot.pyの位置付けと呼び出し契約
Delivery Rule
- 1 Issue = 1 PR
- 専用 worktree を使う
- PR 本文に、
binding_body_hash_mismatchdiagnostics の実際の出力例(テストで生成された errors 配列の値)と、check-only 3-way classification の新旧比較を記録する
Notes for Reviewer
本 Issue は Issue #2633(調査: #1513 を #2627 マージ後の current main に合わせて再スコープする)の issue-refinement-loop が approved で終了した際の確定済み disposition(OWNER anchor comment #2633 (comment) の REQUEST_CHANGES — reframe_in_place 判定、および approved report https://github.com/squne121/loop-protocol/issues/2633#issuecomment-5679410187)に基づき、旧本文(tempfile readback 前提の AC2/AC5 等)を縮小再定義したものである。詳細な disposition context は #1513 の以下のコメントにも記録済み: #1513 (comment)
Scope Delta(任意)
N/A
Activity
squne121 commentedon Sep 15, 2026
Upstream Disposition Handoff(#2633 より)
本 Issue(#1513)は、Issue #2633(
調査: #1513 を #2627 マージ後の current main に合わせて再スコープする)の issue-refinement-loop がapprovedで終了した際の確定済み disposition に基づき、縮小再定義(reframe)する。close ではなく update を採用する。Disposition(#2633 確定内容の要約)
判断: #1513 は close せず、残存責務のみを持つ小さな implementation Issue として縮小再定義する。
current main(
.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py)は PR #2629 マージによりpost_comment()が canonical JSON stdin transport に統一され、tempfile.NamedTemporaryFile/--field body=@fileは既に削除済み。#1513 の現行本文(AC2: 一時ファイル読み戻しベースのexpected_body_sha256、AC5: 一時ファイル読み戻しベースの sha256 計算を検証する新規テスト)は current main の実装と不整合であり、これらは Out of Scope として除去する。残存責務(Residual Scope、#1513 の新 AC の基礎とする)
binding_body_hash_mismatch(verify_controlled_publisher_comment_id_binding())の bounded diagnostics 化expected_byte_len/actual_byte_len/first_diff_byte_offset)expected_byte_len/actual_byte_len/first_diff_byte_offset/expected_sha/actual_sha程度の bounded evidence を返す。expected_body_sha256のみ渡される call path では expected body や byte diff のダミー値を合成しないno_existing_go_comment)」「existing go comment の base-binding drift(existing_go_base_binding_drift)」に加え、「go-like candidate は存在するが current authority 条件(trusted publisher / fingerprint readiness / binding 検証)を満たさず採用不能」という第三の診断区分を追加する。candidate が存在するだけで success 扱いにはしないOut of Scope(除去対象。current main で既に確立済み、または PR #2629/#2621 が扱った領域)
tempfile.NamedTemporaryFile--field body=@filepost_comment()は canonical JSON stdin transport で確定済み、staging 用途に限定)patch_comment()は canonical JSON stdin transport で確定済み)テスト構成方針
test_ensure_contract_snapshot_body_hash_roundtrip.pyの新設は必須契約にしない.claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py(binding_body_hash_mismatchdiagnostics / check-only 3-way classification).claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py(binding 検証まわりの focused regression)pnpm typecheck/lint/test/buildは repository-wide merge gate として別途要求する(Issue 固有 AC と混同しない)#2629 production-orchestration regression gap(#1513 には含めない)
#2629 の「staging→final 誤配線防止 regression」が current main でも未完成という finding は、#1513 の責務には追加しない。issue-refinement-loop の
follow_up_materializationにより別 Issue #2635(https://github.com/squne121/loop-protocol/issues/2635)として既に分離済み。本コメントは、#2633 の approved disposition を #1513 側の human-context anchor として結線するために投稿する(
preflight.run.with_human_contextの same-target anchor binding 要件を満たすため)。#1513 本文はこのコメントを含む live 本文の reframe を経て、上記残存責務のみを対象とする new AC / Allowed Paths / Verification Commands に更新される。squne121 commentedon Sep 15, 2026
issue-refinement-loop 終了報告
Termination cause:
approved(canonical Step 2 review:verdict: approve/next_action: proceed、Step 2.5 semantic review:semantic_review_applicable: falseのため skip、blocking_issues なし)Anchor: https://github.com/squne121/loop-protocol/issues/1513#issuecomment-5679589849(#2633 の disposition を #1513 に結線した same-target human-context anchor)
Iteration サマリ
canonical_step2_route: step_4(needs-fix / request_changes)。VCP_UNEXPECTED_PASSblocker 1件(AC3 の VC が既存文字列no_existing_go_commentを参照しており baseline で unexpected pass)。issue-editorにより AC2 に# baseline-expect: passを付与し、AC3 の VC を新規 reason code リテラルgo_like_candidate_authority_unmetへ変更。canonical_step2_route: step_2_5(deterministic approve, blocking_issues: [])。semantic_review_trigger.pyはsemantic_review_applicable: falseを返したため Step 2.5 をスキップし Step 4.5 へ。実行 SubAgent と completion status
issue-editor(1回目、本文全面書き換え): completed(final result 消費済み、list_agentsで terminal completed 確認済み)issue-editor(2回目、VC hygiene fix): completed(同上)#1513 の判断
update(縮小再定義)を採用。close はしない。 #2633 の disposition(Residual Scope / Out of Scope / テスト配置方針)を保持したまま、旧 tempfile readback 前提の AC/VC を全面置換した。
Step 5 termination dependency gate(Issue #2435 P0)
本サイクルでは trusted human context / trusted anchor / controlled reframe による hard dependency(native
blockedBy)確定はなし。dependency_materializer.py gateはdecision: proceed,reason: no_hard_dependencies_confirmed_this_cycleを返した。human intervention
不要。canonical terminal route
approvedに到達し、loop は正常終了した。squne121 commentedon Sep 15, 2026
root-owned entry router audit
route: invoke_impl_review_loop
reason: fresh_review_go_live_equality
squne121 commentedon Sep 15, 2026
implement-issue: 実装完了 (2026-09-15T12:07:12Z)
.claude/worktrees/issue-1513-ensure-contract-snapshot-py-go-binding-gworktree-issue-1513-ensure-contract-snapshot-py-go-binding-gsqune121 commentedon Sep 15, 2026
impl-review-loop: 完了 (2026-09-15T12:35:00Z)
squne121 commentedon Sep 15, 2026
live mergeability 最終更新
直前の終了報告投稿時点では
merge_state_status: BLOCKED(CI settle 待ち)だったが、その後の再確認でmerge_state_status: CLEAN/mergeable: MERGEABLEに到達した(head:bd0f7231e24e6c763fa1cab3392f0327bc455cb3、変更なし)。PR は引き続き Draft のまま残す(人間の Ready-for-review 変換・レビュー・マージ判断を待つ)。
fix: binding_body_hash_mismatch 診断情報と check-only existence 3-way clas…