Skip to content

実装: ensure_contract_snapshot.py の go コメント binding 検証が実際に投稿済みの go コメントを恒久的に検出できないバグを修正する #1513

Closed

Description

@squne121

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: code

Parent 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 区分に分離する:
    1. no_existing_go_comment(現状維持): trusted かつ fingerprint-ready な go candidate が一件も存在しない
    2. existing_go_base_binding_drift(現状維持): trusted かつ fingerprint-ready な go candidate は存在するが base ref/sha が現在の default branch tip と乖離
    3. 新規区分(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

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 code go_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 build

Allowed 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

Delivery Rule

  • 1 Issue = 1 PR
  • 専用 worktree を使う
  • PR 本文に、binding_body_hash_mismatch diagnostics の実際の出力例(テストで生成された 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

  1. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    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 化
    • UTF-8 bytes 基準の diagnostics(expected_byte_len / actual_byte_len / first_diff_byte_offset)
    • expected body 自体を caller が保持している publish/readback path に限り、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 のダミー値を合成しない
    • check-only モードで「候補が本当に存在しない(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 扱いにはしない
    • trusted publisher・fingerprint readiness・product-spec check・live/base binding といった current authority model は弱めない

    Out of Scope(除去対象。current main で既に確立済み、または PR #2629/#2621 が扱った領域)

    • tempfile.NamedTemporaryFile
    • --field body=@file
    • tempfile readback を authority とする設計
    • POST transport の再設計(post_comment() は canonical JSON stdin transport で確定済み、staging 用途に限定)
    • PATCH transport の再設計(patch_comment() は 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 の再実装

    テスト構成方針

    • 専用 test_ensure_contract_snapshot_body_hash_roundtrip.py の新設は必須契約にしない
    • 既存の自然な test class に focused regression を追加することを原則とする:
      • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py(binding_body_hash_mismatch diagnostics / check-only 3-way classification)
      • .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py(binding 検証まわりの focused regression)
    • Issue 固有 correctness evidence は focused pytest を中心にし、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 に更新される。

  2. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    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 サマリ

    • Iteration 1(review only): canonical_step2_route: step_4(needs-fix / request_changes)。VCP_UNEXPECTED_PASS blocker 1件(AC3 の VC が既存文字列 no_existing_go_comment を参照しており baseline で unexpected pass)。
    • Iteration 2(rewrite → review): 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 は正常終了した。

    LOOP_HANDOFF_RESULT_V1:
      status: impl_ready
      routing_action: run_impl_review_loop
      contract_review:
        status: go
        gate_result: fresh_go
        latest_comment_url: "https://github.com/squne121/loop-protocol/issues/1513#issuecomment-5679589849"
        generated_at: "2026-09-15T11:52:37Z"
        body_sha256: "sha256:ff995ef15aff21d35cc4665ea0ca693d63a031655df89f234ed102fd0f8a5c34"
      metadata:
        title_prefix_ready: true
      label_sync_observation:
        kind: presentation_sync
        result: noop
        detail: "no label mutation attempted this cycle"
      auto_fixes:
        result: auto_fixed
        required:
          - kind: known_marker_fix
            executor: implementation-worker
            result: applied
            evidence:
              before: "VC AC3 referenced pre-existing string no_existing_go_comment (baseline unexpected_pass)"
              after: "VC AC3 references new reason-code literal go_like_candidate_authority_unmet; AC2 annotated # baseline-expect: pass"
              comment_url: "https://github.com/squne121/loop-protocol/issues/1513#issuecomment-5679589849"
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-09-15T11:55:00Z"
      checked_body_sha256: "sha256:ff995ef15aff21d35cc4665ea0ca693d63a031655df89f234ed102fd0f8a5c34"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
  3. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    root-owned entry router audit

    route: invoke_impl_review_loop
    reason: fresh_review_go_live_equality

  4. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    implement-issue: 実装完了 (2026-09-15T12:07:12Z)

  5. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    impl-review-loop: 完了 (2026-09-15T12:35:00Z)

    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      pr_url: "https://github.com/squne121/loop-protocol/pull/2637"
      head_sha: "bd0f7231e24e6c763fa1cab3392f0327bc455cb3"
      issue_number: 1513
      termination_reason: approved
      merge_ready: false
      iteration: 2
    
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: impl-review-loop
      follow_up_issues: []
      note_only_observations: []
  6. squne121 commented on Sep 15, 2026

    @squne121
    OwnerAuthor

    live mergeability 最終更新

    直前の終了報告投稿時点では merge_state_status: BLOCKED(CI settle 待ち)だったが、その後の再確認で merge_state_status: CLEAN / mergeable: MERGEABLE に到達した(head: bd0f7231e24e6c763fa1cab3392f0327bc455cb3、変更なし)。

    IMPL_REVIEW_LOOP_RESULT_V1:
      schema_version: 1
      status: draft_pr_ready
      pr_url: "https://github.com/squne121/loop-protocol/pull/2637"
      head_sha: "bd0f7231e24e6c763fa1cab3392f0327bc455cb3"
      issue_number: 1513
      termination_reason: approved
      merge_ready: true
      iteration: 2

    PR は引き続き Draft のまま残す(人間の Ready-for-review 変換・レビュー・マージ判断を待つ)。

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions