Skip to content

実装: Contract Snapshot publish の transport round-trip と PATCH reconciliation を修正する #2619

Closed

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: none
goal_ref: "Contract Snapshot publish の shared serializer/transport round-trip と PATCH reconciliation を fail-closed のまま修正する"
change_kind: code
dedupe_key: "contract-snapshot-transport-round-trip-and-patch-reconciliation:v1"

Parent Issue

なし(単独改善)

Parent Goal Ref

  • Goal: 単独改善として Contract Snapshot publish の完全性を回復する。
  • Desired Destination: producer、PATCH/GET transport、canonical parser の間で同一の snapshot semantic を安全に保持する。

Current Validated Scope

  • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py の patch_comment は、PATCH が returncode 0 でも response representation が信用できない場合に、既存 full-binding verifier を用いる最大1回の authoritative GET reconciliation だけで fail-closed に判定するよう修正する。
  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py に real producer/patch/parser を通す focused deterministic integration regression を追加できる。
  • scripts/agent-guards/controlled_skill_mutation_exec.py は contract_snapshot.publish の controlled entrypoint と post-publish readback を既に持つため、本 Issue の変更対象に含めない。

Remaining Parent Gaps

なし(単独改善)。parser または controlled executor の変更が必要と判明した場合は、この Issue に混在させず follow-up とする。

Outcome

ensure_contract_snapshot.py と focused deterministic integration regression が、small/non-compacted と transport 上限超過 large/compacted の Contract Snapshot を、gh api subprocess contract と GitHub REST response shape を忠実に模擬した JSON→YAML→POST/PATCH→readback→canonical parser の境界で検証する状態。small は classification の semantic 値を完全一致させ、large は既存 bounded compaction semantics を維持する。PATCH exit 0 の信用できない response representation は blind retry せず authoritative direct GET を最大1回だけ行い、既存 full binding verifier が確認できる場合だけ成功、それ以外は fail-closed とする。

Runtime Verification Applicability

  • decision: not_applicable
  • reason: required gate は gh api subprocess contract と GitHub REST response shape を忠実に模擬する deterministic regression であり、外部 runtime service は不要なため。real disposable GitHub Issue の live test は不要で、既存 github_live suite は任意 canary のままとする。

Background

#2599 は historical evidence であり、serialized stdout_head の JSON として不正な literal backslash sequence \^ により PATCH が patch_response_body_mismatch となり canonical parser も snapshot を拒否した実障害である。修復・backfill・parent/child/dependency の対象ではない。#2056 で確立した bounded JSON/YAML transport、compaction、strict parser/fingerprint semantics は維持する。#1513 は body-hash diagnostics/check-only existence detection の境界であり、本 Issue との統合や native dependency 追加は行わない。Contract comment body SHA256 の authority は authoritative GET で得た decoded Markdown body string を UTF-8 encode した SHA256 であり、PATCH request JSON envelope 全体の bytes hash ではない。

In Scope

  • PATCH exit 0 でも response representation が信用できない invalid JSON、comment ID mismatch、body mismatch を同一 reconciliation class とし、blind retry を禁止して authoritative direct GET を最大1回だけ行う最小修正。
  • reconciliation の成功確認に既存 verify_controlled_publisher_comment_id_binding() を再利用し、comment ID、Issue binding、html_url、trusted publisher、final body SHA256 の full binding を全て満たす場合だけ成功、それ以外は fail-closed とする。
  • producer の JSON scalar/YAML serialization、POST/PATCH/readback、canonical parser semantic round-trip を同一 focused deterministic integration regression で固定する。
  • small/non-compacted fixture で 検証: M5 Workstream 2 current-main baseline playable-slice acceptance #2599 の literal r"\^[[2K" と actual ANSI ESC "\x1b[2K" を別々に必須化し、backslash stress (r"path\foo\bar", r"\q")、YAML single-quote stress ("runner's output")、newline/tab stress ("line1\nline2\tvalue") を含める。large fixture にこれらの文字列が存在するだけでは 検証: M5 Workstream 2 current-main baseline playable-slice acceptance #2599 regression の証明としない。
  • transport 上限超過 large fixture で既存 classification compaction semantics を regression 化する。
  • focused regression は real _build_contract_review_comment()、real patch_comment()、real canonical contract_review_result_parser.py を通す。mock/stub は subprocess.run による GitHub HTTP boundary と remote comment state のみに限定し、patch_comment() または parser の成功 stub による false-green を禁止する。PATCH stdin が valid JSON であり decoded body が final comment body と同一であることを検証する。

Out of Scope

Acceptance Criteria

  • AC1: 次の分離した round-trip 契約を満たす。
    • AC1a: small/non-compacted ANSI/control/backslash classification payload は、producer object→YAML transport→PATCH request JSON→readback→canonical parser の全境界を通り、stdout_head / stderr_head を含む classification の semantic 値が完全一致する。fixture は 検証: M5 Workstream 2 current-main baseline playable-slice acceptance #2599 の literal r"\^[[2K" と actual ANSI ESC "\x1b[2K" を別々に含み、必要な backslash/YAML stress case を含む。large fixture に当該文字列が存在するだけではこの AC を満たさない。
    • AC1b: transport 上限超過 large/compacted classification payload は既存 compaction contract を維持し、stdout_head / stderr_head 等の verbose fields の除去を許容する。一方で classification_count、original_payload_sha256、compact: true、truncated: true、non-verbose classification fields を保持し、canonical parser が valid go snapshot として parse する。
  • AC2: PATCH exit 0 でも response representation が信用できない invalid JSON、comment ID mismatch、body mismatch は同一 reconciliation class とする。blind retry は禁止し、authoritative direct GET は最大1回だけ行う。成功は既存 verify_controlled_publisher_comment_id_binding() を再利用して comment ID、Issue binding、html_url、trusted publisher、final body SHA256 の full binding を確認した場合だけとし、それ以外は fail-closed とする。body SHA authority は GET の decoded Markdown body string を UTF-8 encode した SHA256 であり、PATCH JSON envelope 全体の bytes hash ではない。
  • AC3: PATCH response mismatch または invalid JSON で、authoritative GET の full binding が不一致・欠落・取得不能の場合は fail-closed で成功にしない。
  • AC4: safe な既存 payload の serialization、POST/PATCH/readback 互換性を維持する。
  • AC5: duplicate および overlong classification の既存 classification/compaction の判定は不変である。
  • AC6: controlled contract_snapshot.publish を唯一の publish route とする既存 contract と post-publish readback を維持し、raw publisher bypass を導入しない。
  • AC7: focused deterministic integration regression は real _build_contract_review_comment()、real patch_comment()、real canonical contract_review_result_parser.py を通す。mock/stub は subprocess.run の GitHub HTTP boundary と remote comment state のみに限定し、patch_comment()/parser の成功 stub を用いる false-green を禁止する。PATCH stdin が valid JSON であり decoded body が final comment body と同一であることを検証する。
  • AC8: unrelated security/permission harness の変更を含めない。

Verification Commands

# Required focused deterministic gh-api-subprocess / GitHub REST-response-shape faithful regression.
# AC1
# Covers `AC1a` small/non-compacted exact semantic round-trip and #2599 literal/actual-ESC fixtures, and `AC1b` large/compacted metadata, non-verbose fields, and valid-go canonical parse.
# AC2
# Covers invalid JSON/comment-ID/body mismatch reconciliation, one-GET limit, and full binding.
# AC3
# Covers failed full binding/readback remaining fail-closed.
# AC4
# Covers safe payload and POST-PATCH-readback compatibility.
# AC5
# Covers duplicate and overlong classification compaction compatibility.
# AC6
# Covers controlled route and post-publish readback compatibility.
# AC7
# Covers real producer/patch/parser path and PATCH JSON/body binding.
# AC8
# Covers focused Allowed Paths-only regression coverage.
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q

Allowed Paths

  • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • canonical parser または controlled executor の変更が必要と判明した場合
  • trusted publisher validation、body-hash binding、既存 duplicate/overlong classification を弱めなければ解決できない場合

Required Skills

  • Python
  • pytest
  • JSON / YAML serialization

Required Design References

  • docs/dev/workflow.md
  • docs/dev/agent-skill-boundaries.md
  • docs/dev/secret-policy.md

Scope Delta(任意)

N/A

Delivery Rule

Notes for Reviewer

Activity

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

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-09-10T08:34:11Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/2619
      body_sha256: "sha256:c8f8a407fc9206b719d3ecfc0e07928baee76da4bd5ec3b2af0196388747521a"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        product_spec_check: {"schema":"product_spec_check/v1","applicability":"applicable","decision":"pass","triggers":{"docs_product_allowed_paths":false,"tasks_md_mentioned":false,"specify_artifact_mentioned":false,"generated_task_mentioned":false,"product_spec_context_present":false,"machine_readable_contract_present":true},"conditions":{"docs_product_requires_spec_evidence":{"status":"pass","evidence":[]},"tasks_md_not_direct_source":{"status":"pass","evidence":[]},"specify_not_canonical":{"status":"pass","evidence":[]},"diff_first_rationale_present":{"status":"pass","evidence":[]},"generated_task_trace_present":{"status":"pass","evidence":[]},"task_dependencies_materialized":{"status":"pass","evidence":[]}},"blocked_reasons":[],"body_sha256":"sha256:c8f8a407fc9206b719d3ecfc0e07928baee76da4bd5ec3b2af0196388747521a","source_provenance":{"source_type":"body_file","body_file":"/tmp/contract_review_once_body_4wwp1tsi.md"}}
        vc_preflight:
          decision: pass
          classifications: '[{"ac":"AC7","line":8,"raw_command":"uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q","command_hash":"sha256:847601667a9d9a65148d3296f1d44295772727dbfbbd802fb60565d6c87116fd","execution_key_hash":"sha256:7bca4bbc117d88b7bf8db1d512dacfd082b35a38684ca75490c2e78d38e9a4cc","runner":"exec","exit_code":0,"classification":"expected_pass","category":"regression_gate","decision":"go","scope_class":"regression_gate","confidence":"low","stdout_head":["........................................................................ [ 62%]","............................................                             [100%]","116 passed in 0.25s"],"stdout_truncated":false,"stdout_original_line_count":4,"stderr_head":[],"stderr_truncated":false,"stderr_original_line_count":1,"runner_env_delta":{},"duration_ms":441,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null,"timeout_provenance":{"timeout_seconds":150,"cleanup_tail_seconds":15,"source":"static_fallback","estimator_version":"v2","estimator_input_digest":"sha256:a8267734fadfa848bf0665715353d953f126dd038182e80bf25e0b2e904c8957"}}]'
          classifications_transport: {"schema":"vc_preflight_classifications_transport/v1","classification_count":1,"original_payload_sha256":"sha256:980899699286830d241bb89cb2aad453ce577858890974ce72d764ab916b4bb6","compact":false,"truncated":false}
        declared_path_overlap: '{"schema":"declared_path_overlap/v1","advisory":true,"blocking":false,"decision":"advisory_only","disjoint":true,"overlapping_prs":[],"inventory":{"schema":"OPEN_PR_INVENTORY_V1","repo":"squne121/loop-protocol","state":"open","base_ref":"main","base_sha":"b9f7e46c731690de6bba5293b79ec9537b8fdd44","draft_policy":"include_drafts","prs":[{"number":2578,"title":"feat: record phase-aware human history","base_ref_name":"main","head_ref_name":"worktree-issue-1908-human-history-phase-routing","head_ref_oid":"a7a1c5ebf2c1257f53b2f37ad5245090ec2a9ae5","is_draft":false,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2578","changed_files_count_graphql":12},{"number":2612,"title":"feat: agent-retrospective に session-window coverage / --since-last-retrospective を追加する","base_ref_name":"main","head_ref_name":"worktree-issue-2601-agent-retrospective-since-last-retrospec","head_ref_oid":"5e3133a057769d055b2d18608073f232275348a2","is_draft":false,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2612","changed_files_count_graphql":5},{"number":2614,"title":"feat: build_intake_capsule.pyのhuman-context-comment-url解決範囲をPRコメントに拡張する","base_ref_name":"main","head_ref_name":"worktree-issue-2606-pr-comment-resolution","head_ref_oid":"1431796b9152fd777ceb701c6d68d828192beb82","is_draft":false,"is_cross_repository":false,"head_repository_owner":"squne121","head_repository_name":"loop-protocol","url":"https://github.com/squne121/loop-protocol/pull/2614","changed_files_count_graphql":3}],"fetched_count":3,"totalCount":3,"has_next_page":false,"complete":true,"saturated":false,"limit":200,"page_count":1,"inventory_digest":"sha256:e5cc6dee0a7e5d72315779eac26cb5abf3430810b320a865a2837e9c4cf9af99","errors":[]},"inventory_digest_extended":"sha256:be2e14d0b2dd69a2521b2f1470d9ea2b043d972a31e5a078ebc60cf5750eaef4","errors":[],"note":"changed-file 名の単純な重なりのみを証明する advisory check。3-way merge・hunk 競合・rename/delete 競合は評価しない(実 Git merge 競合の判定は Issue #1792 の PAIRWISE_MERGE_OBSERVATION_V1 producer の責務)。単独では blocking にしない。disjoint は tri-state(true/false/null)— 観測が不完全な場合は null。"}'
      source: ensure_contract_snapshot_auto
      expected_contract_fingerprint: '{"issue_number":2619,"contract_source_kind":"issue_comment","contract_source_id":"5615637626","contract_body_sha256":"sha256:c8f8a407fc9206b719d3ecfc0e07928baee76da4bd5ec3b2af0196388747521a","allowed_paths_normalized_sha256":"d7dc5af215f87b6d4f60321a2175d7bdf3a68aefe0841d7f06330ccb9b202ffe","base_ref":"main","base_sha_at_snapshot":"b9f7e46c731690de6bba5293b79ec9537b8fdd44"}'
  3. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: approved

    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/2619#issuecomment-5615637626"
        generated_at: "2026-09-10T08:34:15Z"
        body_sha256: "sha256:c8f8a407fc9206b719d3ecfc0e07928baee76da4bd5ec3b2af0196388747521a"
      metadata:
        title_prefix_ready: true
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-09-10T08:34:15Z"
      checked_body_sha256: "sha256:c8f8a407fc9206b719d3ecfc0e07928baee76da4bd5ec3b2af0196388747521a"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues: []
      note_only_observations: []
  4. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    結論

    #2619 は方向性は妥当ですが、現状のままなら REQUEST CHANGES 相当です。
    issue-refinement-loop 自体は deterministic review=approve、semantic review=clear、Contract Snapshot=go で impl_ready まで到達しています。 ただし敵対的に読むと、今回直したい実障害をテストが通らずに迂回できる契約上の穴が2つあります。

    特に重要なのは、#2599 で実際に観測された障害が「ANSI」という抽象的な話ではなく、serialized stdout_head に JSON として不正な \^ が現れ、PATCH が patch_response_body_mismatch、canonical parser も snapshot を拒否したという具体的なものだった点です。

    敵対的レビュー

    優先度 | 指摘 | 判定 -- | -- | -- P1 | small / large payload の「semantic round-trip」と既存 compaction semantics が曖昧 | 修正必須 P1 | 元障害の \^ と「実 ANSI ESC」を区別しておらず、元障害を再現しないテストでも AC1 を満たせる | 修正必須 P1 | test_ensure_contract_snapshot.py の autouse fixture が patch_comment 等を成功 stub 化しており、integration test の作り方次第で false-green | ACに明記推奨 P2 | PATCH 200 の id/body mismatch だけ reconcile し、200 + invalid JSON response は対象外 | scope拡張推奨 P2 | AC2 が「ID + hash」だけ読め、既存 verifier の issue/html_url/publisher binding を弱める余地がある | 文言修正 P2 | Runtime Verification: not_applicable と「GitHub POST/PATCH → readback」という表現が少し不整合 | テスト境界を明記 P2 | open #1513 と transport/hash の authority 定義が近い | invariant を固定

    P1 — large payload の AC1 は現在の compaction 契約と分離すべき

    現在の compact_vc_preflight_classifications() は payload が上限を超えると、stdout_head、stderr_head、runner_env_delta、pnpm_gate_evidence を意図的に落とします。これは単なる実装詳細ではなく、現在の bounded transport 契約です。

    さらに current-main の回帰テストも、巨大な stdout_head を入れた場合には parser 復元後に stdout_head が消え、transport metadata が compact/truncated を示すことを検証する方向になっています。

    ところが #2619 は small と large の ANSI/control payload をまとめて「semantic round-trip」と表現しています。 これだと実装者が、

    • large payload でも元の stdout_head を完全復元しようとして compaction を壊す

    • 逆に small payload まで compaction してしまい、元障害を迂回する

    のどちらでも解釈できます。

    AC1 を2ケースに分けるべきです。

    AC1a — non-compacted payload
    small ANSI/control/backslash payload は、
    producer object → YAML transport → PATCH request JSON → readback →
    canonical parser の全境界を通り、stdout_head / stderr_head を含む
    classification semantic value が完全一致する。
    

    AC1b — compacted payload
    transport 上限を超える payload は既存 compaction contract に従い、
    stdout_head / stderr_head 等の verbose fields は除去される。
    classification_count / original_payload_sha256 /
    compact=true / truncated=true と非verbose classification fields が
    round-trip 後も一致し、snapshot は valid go として parse できる。

    これなら #2056/PR #2058 で既に確立した bounded transport を壊しません。PR #2058 はまさに JSON escape と YAML escape の衝突を single-quoted JSON transport で修正しており、既存 strictness を維持しています。

    P1 — 「ANSI/control」では元の ^ defect を再現したことにならない

    ここはかなり重要です。

    #2599 で壊れた文字列は ^ です。 一方、実際の ANSI clear-line sequence なら Python 上では例えば、

    "\x1b[2K"

    です。

    この2つは transport 上まったく別です。

    Python の json.dumps(..., ensure_ascii=False) でも、reverse solidus (</code>) と U+0000–U+001F の control character は必ず JSON escape されます。(Python Docs) RFC 8259 も JSON string 内の backslash と U+0000–U+001F を escape 必須としています。(RFC Editor)

    また YAML single-quoted scalar では backslash は escape character ではなく、そのまま保持されます。escape が必要なのは ' を '' にすることだけです。(YAML)

    したがって AC1 の fixture は最低でも以下を別々に持つべきです。

    # 元障害そのもの
    r"^[[2K"

    本物の ANSI ESC

    "\x1b[2K"

    backslash escape stress

    r"path\foo\bar"
    r"\q"

    YAML single quote stress

    "runner's output"

    newline / tab

    "line1\nline2\tvalue"

    特に r"^[[2K" は small/non-compacted payload に必須です。

    current-main には既に r"^[[2K" + huge payload のテストがありますが、巨大なので現在の compaction によって offending stdout_head 自体が final transport から除去され得ます。 したがって「似た fixture が既にある」だけでは #2599 の regression lock になりません。

    P1 — focused integration test が実 transport を通ることを固定する

    現在の test_ensure_contract_snapshot.py には autouse fixture があり、多くの既存テスト向けに、

    verify_controlled_publisher_comment_id_binding、capture_base_ref_and_sha、patch_comment、verify_snapshot_authority_postcondition

    を成功扱いに monkeypatch しています。

    #2619 の AC1 を単に「同ファイルに integration test を追加」としただけだと、新テストがこの fixture の影響を受け、肝心の PATCH serialization/reconciliation を一切実行せず PASS する実装が可能です。

    ACに次を追加するのがよいです。

    focused transport regression は _build_contract_review_comment()、patch_comment()、contract_review_result_parser.py の実実装を使用する。mock/stub は subprocess.run の GitHub HTTP 境界と remote comment state のみに限定し、patch_comment または canonical parser 自体を success stub に置換してはならない。

    fake GitHub は大規模 harness にする必要はありません。1つの stateful fake_run() で、

    PATCH stdin
    -> json.loads(stdin)
    -> remote_comment["body"] = payload["body"]
    -> configurable PATCH response

    GET
    -> remote_comment を返す

    だけで十分です。

    gh api --input - は stdin を request body として送る正式な使い方です。(GitHub CLI) なので、テスト内で PATCH stdin が valid JSON であり、json.loads(stdin)["body"] == final_comment_body まで assertion すると transport の責任境界がかなり明瞭になります。

    P2 — 200 OK なのに invalid JSON の場合も GET reconciliation 対象にした方が一貫する

    現在の patch_comment() は概ね、

    PATCH success
    response JSON invalid -> 即 fail
    response id mismatch -> 即 fail
    response body mismatch -> 即 fail
    exact match -> GET verification

    PATCH nonzero / timeout
    -> GET reconciliation

    です。

    #2619 は id/body mismatch を GET reconciliation に回そうとしています。これは妥当です。

    GitHub REST API では issue comment PATCH の成功は 200 OK で、default representation は raw Markdown の body を含みます。(GitHub Docs) したがって response mismatch は正常系ではありません。ただし、最終 authority を独立 GET に置くなら、200 + response JSON decode failure も同じ「PATCH result representation が信用できないが remote write は成功した可能性がある」クラスです。

    ここだけ即 fail のままなのは不自然です。

    推奨は、

    PATCH exit=0 だが

    • invalid JSON
    • id mismatch
    • body mismatch

    のいずれでも、blind retry はせず direct GET を最大1回行う。

    既存の full binding verifierが
    comment id / issue / html_url / trusted publisher / final body SHA256
    をすべて満たした場合のみ success。
    それ以外は従来どおり fail-closed。

    です。

    リトライ機構や backoff、receipt schema は不要です。GET 1回だけで趣味開発として十分な堅牢性と単純さのバランスになります。

    P2 — AC2 は既存 full binding verifier の再利用を明示した方がよい

    現在の verify_controlled_publisher_comment_id_binding() は body hash だけでなく、

    comment ID、Issue binding、html_url、trusted publisher identity、body hash

    まで確認しています。

    一方 #2619 の AC2 は「同じ comment id + final body SHA256」とだけ読むこともできます。実装者が専用の軽量 GET/hash check を追加すると、既存の強い verifier を迂回する余地があります。

    新しい security machinery は不要なので、むしろ、

    reconciliation は既存 verify_controlled_publisher_comment_id_binding() をそのまま使用する

    と固定するのが最小です。

    Runtime Verification は blocking にしなくてよい

    repository には既に、実 GitHub disposable Issue に対して real POST → PATCH → independent GET を行う github_live テストがあります。

    そのため理屈だけなら #2619 も immediate にできます。ただし、今回はそれを required gate にすることは推奨しません。

    理由は、今回の defect は transport serialization と reconciliation state machine を deterministic fake transport で完全に再現可能だからです。毎回 GitHub に disposable Issue を作ると、テスト速度・認証・ネットワーク依存・ゴミ Issue のコストが今回の価値を上回ります。

    #2619 の Runtime Verification: not_applicable は維持しつつ、Outcome/AC の表現を、

    real GitHub behavior を証明する

    ではなく、

    gh api subprocess contract と GitHub REST response shape を忠実に模擬した deterministic integration regression

    と限定するのが適切です。

    既存 github_live suite は任意の canary として残せば十分です。

    #1513 との境界だけは固定しておくべき

    open #1513 は、まさに ensure_contract_snapshot.py の body hash mismatch と「実際に送信した bytes を authority にする」問題を扱っています。

    #2619 と重複統合する必要はありませんが、authority invariant は明記した方が安全です。

    推奨 invariant:

    Contract comment body hash の意味は「GitHub GET で得られる decoded Markdown body string を UTF-8 encode した SHA256」であり、PATCH request JSON envelope 全体の byte hash ではない。

    つまり、

    {"body":"..."}

    全体ではなく、中の body semantic value が authority です。

    これを固定しておけば、#1513 が後から transport byte handling を変更しても #2619 の readback semantics と衝突しにくくなります。

    推奨する #2619 の修正量

    大規模な再設計は不要です。Issue body の修正は4点だけで十分です。

    1. AC1 を non-compacted exact round-trip と large compacted round-trip に分割する。

    2. small fixture に literal r"^[[2K" と actual "\x1b[2K" の両方を必須化する。

    3. AC2 の reconciliation 対象を invalid JSON / id mismatch / body mismatch とし、既存 full binding verifier + direct GET 1回だけに限定する。

    4. focused test は real producer + real patch_comment + real canonical parser を通し、mock は subprocess/GitHub state boundary だけ、と明記する。

    これを反映すれば、#2619 はかなり良い narrow tooling fix になります。parser変更、publish receipt、新規 permission/security harness、mandatory live GitHub test は追加しない方がよいです。#2056 で作った transport contract を再利用し、#2599 の実故障だけを end-to-end regression として固定するのが最小かつ有用です。

    ## 結論

    #2619 は方向性は妥当ですが、現状のままなら REQUEST CHANGES 相当です。
    issue-refinement-loop 自体は deterministic review=approve、semantic review=clear、Contract Snapshot=go で impl_ready まで到達しています。 ただし敵対的に読むと、今回直したい実障害をテストが通らずに迂回できる契約上の穴が2つあります。

    特に重要なのは、#2599 で実際に観測された障害が「ANSI」という抽象的な話ではなく、serialized stdout_head に JSON として不正な \^ が現れ、PATCH が patch_response_body_mismatch、canonical parser も snapshot を拒否したという具体的なものだった点です。

    敵対的レビュー

    優先度 指摘 判定
    P1 small / large payload の「semantic round-trip」と既存 compaction semantics が曖昧 修正必須
    P1 元障害の \^ と「実 ANSI ESC」を区別しておらず、元障害を再現しないテストでも AC1 を満たせる 修正必須
    P1 test_ensure_contract_snapshot.py の autouse fixture が patch_comment 等を成功 stub 化しており、integration test の作り方次第で false-green ACに明記推奨
    P2 PATCH 200 の id/body mismatch だけ reconcile し、200 + invalid JSON response は対象外 scope拡張推奨
    P2 AC2 が「ID + hash」だけ読め、既存 verifier の issue/html_url/publisher binding を弱める余地がある 文言修正
    P2 Runtime Verification: not_applicable と「GitHub POST/PATCH → readback」という表現が少し不整合 テスト境界を明記
    P2 open #1513 と transport/hash の authority 定義が近い invariant を固定

    P1 — large payload の AC1 は現在の compaction 契約と分離すべき

    現在の compact_vc_preflight_classifications() は payload が上限を超えると、stdout_head、stderr_head、runner_env_delta、pnpm_gate_evidence を意図的に落とします。これは単なる実装詳細ではなく、現在の bounded transport 契約です。

    さらに current-main の回帰テストも、巨大な stdout_head を入れた場合には parser 復元後に stdout_head が消え、transport metadata が compact/truncated を示すことを検証する方向になっています。

    ところが #2619 は small と large の ANSI/control payload をまとめて「semantic round-trip」と表現しています。 これだと実装者が、

    • large payload でも元の stdout_head を完全復元しようとして compaction を壊す
    • 逆に small payload まで compaction してしまい、元障害を迂回する

    のどちらでも解釈できます。

    AC1 を2ケースに分けるべきです。

    AC1a — non-compacted payload
    small ANSI/control/backslash payload は、
    producer object → YAML transport → PATCH request JSON → readback →
    canonical parser の全境界を通り、stdout_head / stderr_head を含む
    classification semantic value が完全一致する。
    
    AC1b — compacted payload
    transport 上限を超える payload は既存 compaction contract に従い、
    stdout_head / stderr_head 等の verbose fields は除去される。
    classification_count / original_payload_sha256 /
    compact=true / truncated=true と非verbose classification fields が
    round-trip 後も一致し、snapshot は valid go として parse できる。
    

    これなら #2056/PR #2058 で既に確立した bounded transport を壊しません。PR #2058 はまさに JSON escape と YAML escape の衝突を single-quoted JSON transport で修正しており、既存 strictness を維持しています。

    P1 — 「ANSI/control」では元の \^ defect を再現したことにならない

    ここはかなり重要です。

    #2599 で壊れた文字列は \^ です。 一方、実際の ANSI clear-line sequence なら Python 上では例えば、

    "\x1b[2K"

    です。

    この2つは transport 上まったく別です。

    Python の json.dumps(..., ensure_ascii=False) でも、reverse solidus (\) と U+0000–U+001F の control character は必ず JSON escape されます。([Python Docs]1) RFC 8259 も JSON string 内の backslash と U+0000–U+001F を escape 必須としています。([RFC Editor]2)

    また YAML single-quoted scalar では backslash は escape character ではなく、そのまま保持されます。escape が必要なのは ' を '' にすることだけです。([YAML]3)

    したがって AC1 の fixture は最低でも以下を別々に持つべきです。

    # 元障害そのもの
    r"\^[[2K"
    
    # 本物の ANSI ESC
    "\x1b[2K"
    
    # backslash escape stress
    r"path\foo\bar"
    r"\q"
    
    # YAML single quote stress
    "runner's output"
    
    # newline / tab
    "line1\nline2\tvalue"

    特に r"\^[[2K" は small/non-compacted payload に必須です。

    current-main には既に r"\^[[2K" + huge payload のテストがありますが、巨大なので現在の compaction によって offending stdout_head 自体が final transport から除去され得ます。 したがって「似た fixture が既にある」だけでは #2599 の regression lock になりません。

    P1 — focused integration test が実 transport を通ることを固定する

    現在の test_ensure_contract_snapshot.py には autouse fixture があり、多くの既存テスト向けに、

    verify_controlled_publisher_comment_id_binding、capture_base_ref_and_sha、patch_comment、verify_snapshot_authority_postcondition

    を成功扱いに monkeypatch しています。

    #2619 の AC1 を単に「同ファイルに integration test を追加」としただけだと、新テストがこの fixture の影響を受け、肝心の PATCH serialization/reconciliation を一切実行せず PASS する実装が可能です。

    ACに次を追加するのがよいです。

    focused transport regression は _build_contract_review_comment()、patch_comment()、contract_review_result_parser.py の実実装を使用する。mock/stub は subprocess.run の GitHub HTTP 境界と remote comment state のみに限定し、patch_comment または canonical parser 自体を success stub に置換してはならない。

    fake GitHub は大規模 harness にする必要はありません。1つの stateful fake_run() で、

    PATCH stdin
      -> json.loads(stdin)
      -> remote_comment["body"] = payload["body"]
      -> configurable PATCH response
    
    GET
      -> remote_comment を返す
    

    だけで十分です。

    gh api --input - は stdin を request body として送る正式な使い方です。([GitHub CLI]4) なので、テスト内で PATCH stdin が valid JSON であり、json.loads(stdin)["body"] == final_comment_body まで assertion すると transport の責任境界がかなり明瞭になります。

    P2 — 200 OK なのに invalid JSON の場合も GET reconciliation 対象にした方が一貫する

    現在の patch_comment() は概ね、

    PATCH success
      response JSON invalid       -> 即 fail
      response id mismatch        -> 即 fail
      response body mismatch      -> 即 fail
      exact match                 -> GET verification
    
    PATCH nonzero / timeout
      -> GET reconciliation
    

    です。

    #2619 は id/body mismatch を GET reconciliation に回そうとしています。これは妥当です。

    GitHub REST API では issue comment PATCH の成功は 200 OK で、default representation は raw Markdown の body を含みます。([GitHub Docs]5) したがって response mismatch は正常系ではありません。ただし、最終 authority を独立 GET に置くなら、200 + response JSON decode failure も同じ「PATCH result representation が信用できないが remote write は成功した可能性がある」クラスです。

    ここだけ即 fail のままなのは不自然です。

    推奨は、

    PATCH exit=0 だが
    - invalid JSON
    - id mismatch
    - body mismatch
    
    のいずれでも、blind retry はせず direct GET を最大1回行う。
    
    既存の full binding verifierが
    comment id / issue / html_url / trusted publisher / final body SHA256
    をすべて満たした場合のみ success。
    それ以外は従来どおり fail-closed。
    

    です。

    リトライ機構や backoff、receipt schema は不要です。GET 1回だけで趣味開発として十分な堅牢性と単純さのバランスになります。

    P2 — AC2 は既存 full binding verifier の再利用を明示した方がよい

    現在の verify_controlled_publisher_comment_id_binding() は body hash だけでなく、

    comment ID、Issue binding、html_url、trusted publisher identity、body hash

    まで確認しています。

    一方 #2619 の AC2 は「同じ comment id + final body SHA256」とだけ読むこともできます。実装者が専用の軽量 GET/hash check を追加すると、既存の強い verifier を迂回する余地があります。

    新しい security machinery は不要なので、むしろ、

    reconciliation は既存 verify_controlled_publisher_comment_id_binding() をそのまま使用する

    と固定するのが最小です。

    Runtime Verification は blocking にしなくてよい

    repository には既に、実 GitHub disposable Issue に対して real POST → PATCH → independent GET を行う github_live テストがあります。

    そのため理屈だけなら #2619 も immediate にできます。ただし、今回はそれを required gate にすることは推奨しません。

    理由は、今回の defect は transport serialization と reconciliation state machine を deterministic fake transport で完全に再現可能だからです。毎回 GitHub に disposable Issue を作ると、テスト速度・認証・ネットワーク依存・ゴミ Issue のコストが今回の価値を上回ります。

    #2619 の Runtime Verification: not_applicable は維持しつつ、Outcome/AC の表現を、

    real GitHub behavior を証明する

    ではなく、

    gh api subprocess contract と GitHub REST response shape を忠実に模擬した deterministic integration regression

    と限定するのが適切です。

    既存 github_live suite は任意の canary として残せば十分です。

    #1513 との境界だけは固定しておくべき

    open #1513 は、まさに ensure_contract_snapshot.py の body hash mismatch と「実際に送信した bytes を authority にする」問題を扱っています。

    #2619 と重複統合する必要はありませんが、authority invariant は明記した方が安全です。

    推奨 invariant:

    Contract comment body hash の意味は「GitHub GET で得られる decoded Markdown body string を UTF-8 encode した SHA256」であり、PATCH request JSON envelope 全体の byte hash ではない。

    つまり、

    {"body":"..."}
    

    全体ではなく、中の body semantic value が authority です。

    これを固定しておけば、#1513 が後から transport byte handling を変更しても #2619 の readback semantics と衝突しにくくなります。

    推奨する #2619 の修正量

    大規模な再設計は不要です。Issue body の修正は4点だけで十分です。

    1. AC1 を non-compacted exact round-trip と large compacted round-trip に分割する。
    2. small fixture に literal r"\^[[2K" と actual "\x1b[2K" の両方を必須化する。
    3. AC2 の reconciliation 対象を invalid JSON / id mismatch / body mismatch とし、既存 full binding verifier + direct GET 1回だけに限定する。
    4. focused test は real producer + real patch_comment + real canonical parser を通し、mock は subprocess/GitHub state boundary だけ、と明記する。

    これを反映すれば、#2619 はかなり良い narrow tooling fix になります。parser変更、publish receipt、新規 permission/security harness、mandatory live GitHub test は追加しない方がよいです。#2056 で作った transport contract を再利用し、#2599 の実故障だけを end-to-end regression として固定するのが最小かつ有用です。

  5. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    推奨アクションは、既存の impl_ready をそのまま実装へ渡さず、指定の OWNER コメントを direct human context として #2619 を再 refinement することです。コメントが明示した4点を今回の人間判断として確定し、Issue 本文を更新した後に deterministic review → semantic review → fresh Contract Snapshot まで再実行し、新しい impl_ready を作り直すのが適切です。指定コメントは、small/large の分離、\^[[2K と実 ESC の別 fixture、invalid JSON を含む GET reconciliation、実 patch_comment を通す regression を具体的に要求しています。

    また current-main では、対象テストファイルの autouse fixture が patch_comment などを success stub 化しており、実装側も id/body mismatch を reconciliation 前に即時失敗させています。このためコメントの指摘は抽象的な設計論ではなく、現状コードに直接対応しています。 issue-refinement-loop 自体も human-context 用 canonical lane を持ち、semantic review では sibling SubAgent の完了を待つ completion join barrier を要求しています。

    以下を、すでに auto mode で起動済みの対話的 Claude-GPT にそのまま渡すのを推奨します。

    GitHub Issue #2619 を、次の OWNER コメントを fresh human context / owner directive として .claude/skills/issue-refinement-loop で再 refinement してください。

    Issue:
    #2619

    今回の anchor comment:
    #2619 (comment)

    あなたは既に auto mode で起動済みです。この作業について、通常の refinement iteration、Issue 本文更新、再レビュー、fresh Contract Snapshot 作成の途中で人間承認を求めないでください。Claude の permission mode を変更したり、--dangerously-skip-permissions 等へ切り替えたりする必要はありません。リポジトリの canonical control-plane と .claude/skills/issue-refinement-loop の現行契約に従ってください。

    このプロンプト自体を、anchor comment に記載された改善方針を採用する direct interactive human instruction として扱ってください。特に、anchor の以下の判断は既に人間側で承認済みです。これらについて再度 human judgment を要求しないでください。

    1. AC1 を non-compacted exact round-trip と large/compacted round-trip に分離する。small/non-compacted では stdout_head / stderr_head 等の semantic value の完全一致を要求する。一方、transport 上限を超える large payload は既存 compaction contract を維持し、verbose fields が除去されても classification_count、original_payload_sha256、compact=true、truncated=true、非 verbose classification fields が保持され、valid go snapshot として parse できることを要求する。

    2. small/non-compacted regression fixture では、検証: M5 Workstream 2 current-main baseline playable-slice acceptance #2599 の実障害を再現する literal backslash sequence r"\^[[2K" と、本物の ANSI ESC sequence "\x1b[2K" を別々に必須化する。必要な backslash/YAML stress case も、anchor comment の意図を失わない範囲で含める。large fixture に同じ文字列が存在するだけでは 検証: M5 Workstream 2 current-main baseline playable-slice acceptance #2599 regression の証明とみなさない。

    3. PATCH が exit 0 でも response representation が信用できないケースとして、invalid JSON、comment id mismatch、body mismatch を同じ reconciliation class とすることを Issue contract に明記する。blind retry は導入せず、authoritative direct GET は最大1回とする。成功判定は新しい軽量 hash checkerを作らず、既存の verify_controlled_publisher_comment_id_binding() が持つ comment ID / Issue binding / html_url / trusted publisher / final body SHA256 の full binding を維持・再利用する。それ以外は fail-closed とする。

    4. focused transport regression は real _build_contract_review_comment() / real patch_comment() / real canonical contract_review_result_parser.py を実際に通すことを Acceptance Criteria に固定する。mock/stub は subprocess.run による GitHub HTTP 境界と remote comment state のみに限定し、patch_comment() や canonical parser 自体を success stub に置換した false-green を許可しない。PATCH stdin が valid JSON であり、decoded body が final comment body と一致するところまで検証対象にする。

    上記4点に伴う整合修正として、Outcome、In Scope、Acceptance Criteria、Verification、Notes/Reviewer guidance 等を必要な範囲で同期してください。ただし scope を膨張させないでください。

    Runtime Verification Applicability は not_applicable を維持してください。今回 required gate とするのは real GitHub disposable Issue への live test ではなく、gh api subprocess contract と GitHub REST response shape を忠実に模擬した deterministic integration regression です。既存 github_live suite がある場合は任意 canary のままとし、mandatory gate へ昇格させないでください。

    body-hash authority については #1513 との境界を曖昧にしないでください。今回の reconciliation が確認する body hash は「authoritative GET で得られた decoded Markdown body string を UTF-8 encode した SHA256」という semantic body の authority であり、PATCH request の JSON envelope 全体の byte hash ではありません。#1513 と #2619 を統合したり native dependency を追加したりする必要はありません。

    #2056 およびその関連実装で確立済みの bounded JSON/YAML transport、compaction、strict parser/fingerprint semantics は維持してください。#2599 は実故障の historical evidence として参照してください。parser、controlled executor、publisher route、permission/security harness の変更、新しい receipt/ledger/state schema、mandatory live-GitHub test は今回の refinement の解決策にしないでください。

    まず current main の最新状態を基準に Issue #2619、anchor comment、関連 Issue/PR、対象コードとテストを fresh に調査してください。過去の impl_ready や古い Contract Snapshot を今回の anchor より優先してはいけません。Issue body が更新されたら旧 body SHA に束縛された snapshot/handoff はそのまま再利用せず、fresh review/readback から新しい authority を生成してください。

    サブエージェントを必ず使用してください。main/root session を orchestrator とし、repository/code evidence の調査には sibling codebase-investigator を使ってください。また anchor が依存する JSON escaping、YAML single-quoted scalar、gh api --input -、GitHub issue-comment PATCH/GET semantics 等の外部 claim が planner 上 relevant/dispositive なら sibling web-researcher を使用し、可能な限り Python公式、RFC、YAML仕様、GitHub/GitHub CLI公式の一次資料で確認してください。semantic-design-review lane が適用される場合は canonical issue-design-reviewer SubAgent を fresh に起動してください。

    重要: すべての SubAgent は fire-and-forget にしないでください。各 SubAgent を起動したら、その SubAgent の作業完了を必ず待ち、completion join barrier を満たしてから結果を consume / record / 次工程へ進んでください。未完了の SubAgent の推測結果を使って rewrite、review、Contract Snapshot、handoff を進めてはいけません。Sibling SubAgent からさらに nested SubAgent を起動させないでください。

    anchor comment は URL だけから origin を推測する unlabeled lane ではなく、direct human context として canonical preflight.run.with_human_context 相当の経路で処理してください。trusted contract patch plan が生成された場合は、main/root control-plane から canonical contract_update.run.with_human_context 相当の controlled mutation route を使用してください。SubAgent や isolation worktree からこの privileged contract-update route を直接実行させないでください。

    issue-refinement-loop の planner/reviewer/decision scripts を prose で再実装せず、canonical registry/control-plane の結果を consume してください。needs-fix が出た場合は max_iterations の範囲で承認確認なしに rewrite → fresh investigation/review を継続してください。semantic finding 由来の rewrite constraints は再構築せず canonical payload をそのまま issue-editor lane に渡してください。

    今回の human authorization は anchor comment の上記判断、およびそれらを矛盾なく Issue contract に反映するための機械的な文言・AC番号・Verification対応の修正までを含みます。この既知判断だけを理由に human_judgment_required へ再エスカレーションしないでください。

    一方で、調査の結果、anchor で承認していない materially new なスコープ判断が本当に必要になった場合、たとえば Allowed Paths に parser/executor/security harness を追加しなければ成立しない、新規 Issue/依存関係を作らなければ成立しない、既存 strict binding/compaction を弱めなければ成立しない等の場合は、canonical fail-closed semantics を捏造して突破しないでください。その場合のみ根拠を明示して停止してください。単なる iteration 継続や既知4点の反映は停止理由ではありません。

    この実行は Issue refinement に限定してください。実装、implementation worktree 作成、impl-review-loop、PR 作成・merge は開始しないでください。

    完了条件は、anchor の substantive findings が Issue 本文へ反映され、deterministic review と applicable な semantic review が fresh body に対して収束し、static/readiness/contract review が fresh に通り、新しい authoritative Contract Snapshot/readback が valid go となり、LOOP_HANDOFF_RESULT_V1.status=impl_ready 相当まで到達することです。

    最後に、変更前後の Issue body SHA、実際に反映した anchor finding、実行した SubAgent と completion join の結果、deterministic/semantic review 結果、fresh Contract Snapshot URL、最終 handoff status、未解決 blocker の有無を簡潔に報告してください。

    この形なら、**「4点は既に人間が判断済み」**と明示することで同じ論点への無駄な再エスカレーションを抑えつつ、未知のスコープ拡張まで強制突破させない構成になります。特に今回は #1513 がまだ open なので、そこへ吸収・統合せず authority invariant だけ固定する指示を残すのが重要です。 #2056 は既に completed で、その bounded transport 契約を前提資産として扱えます。

  6. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    Contract Review Result

    CONTRACT_REVIEW_RESULT_V1:
      status: go
      generated_at: "2026-09-10T09:29:05Z"
      generated_by: issue-contract-review
      issue_url: https://github.com/squne121/loop-protocol/issues/2619
      body_sha256: "sha256:2a902ac6e52d39764f71bf65f97565da04010f559fb25b1fbc3b598ced674b8d"
      checks:
        readiness: go
        blockers: pass
        product_spec: pass
        product_spec_check: {"schema":"product_spec_check/v1","applicability":"applicable","decision":"pass","triggers":{"docs_product_allowed_paths":false,"tasks_md_mentioned":false,"specify_artifact_mentioned":false,"generated_task_mentioned":false,"product_spec_context_present":false,"machine_readable_contract_present":true},"conditions":{"docs_product_requires_spec_evidence":{"status":"pass","evidence":[]},"tasks_md_not_direct_source":{"status":"pass","evidence":[]},"specify_not_canonical":{"status":"pass","evidence":[]},"diff_first_rationale_present":{"status":"pass","evidence":[]},"generated_task_trace_present":{"status":"pass","evidence":[]},"task_dependencies_materialized":{"status":"pass","evidence":[]}},"blocked_reasons":[],"body_sha256":"sha256:2a902ac6e52d39764f71bf65f97565da04010f559fb25b1fbc3b598ced674b8d","source_provenance":{"source_type":"body_file","body_file":"/tmp/contract_review_once_body_p4uy9ltk.md"}}
        vc_preflight:
          decision: pass
          classifications: '[{"ac":"AC8","line":18,"raw_command":"uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q","command_hash":"sha256:847601667a9d9a65148d3296f1d44295772727dbfbbd802fb60565d6c87116fd","execution_key_hash":"sha256:7bca4bbc117d88b7bf8db1d512dacfd082b35a38684ca75490c2e78d38e9a4cc","runner":"exec","exit_code":0,"classification":"expected_pass","category":"regression_gate","decision":"go","scope_class":"regression_gate","confidence":"low","stdout_head":["........................................................................ [ 62%]","............................................                             [100%]","116 passed in 0.27s"],"stdout_truncated":false,"stdout_original_line_count":4,"stderr_head":[],"stderr_truncated":false,"stderr_original_line_count":1,"runner_env_delta":{},"duration_ms":495,"fix_hint":null,"certified_target_paths":null,"annotations":{"baseline_expect":null,"vc_role":null,"missing_baseline_expect":false},"annotation_source":{"line":null,"raw":null},"strict":null,"repair":null,"timeout_provenance":{"timeout_seconds":150,"cleanup_tail_seconds":15,"source":"static_fallback","estimator_version":"v2","estimator_input_digest":"sha256:a8267734fadfa848bf0665715353d953f126dd038182e80bf25e0b2e904c8957"}}]'
          classifications_transport: {"schema":"vc_preflight_classifications_transport/v1","classification_count":1,"original_payload_sha256":"sha256:0f7748c6df00937d7fcf57910945d2fdbd809944f40f1df6cbc80a499d5b9357","compact":false,"truncated":false}
        declared_path_overlap: '{"schema":"declared_path_overlap/v1","advisory":true,"blocking":false,"decision":"advisory_only","disjoint":true,"overlapping_prs":[],"inventory":{"schema":"OPEN_PR_INVENTORY_V1","repo":"squne121/loop-protocol","state":"open","base_ref":"main","base_sha":"f36f41a7ae20b81e380807a4ce9c4d9b1e95d652","draft_policy":"include_drafts","prs":[],"fetched_count":0,"totalCount":0,"has_next_page":false,"complete":true,"saturated":false,"limit":200,"page_count":1,"inventory_digest":"sha256:22dd9f7fb41b3e6d5fc8cb2f6e14b1ce7602f1f73afd271d1d09a9b10ffd41f8","errors":[]},"inventory_digest_extended":"sha256:b38221ebc1b3e88c32c065bab5a998652169d62550f0cd4ba9348d58dfa34046","errors":[],"note":"changed-file 名の単純な重なりのみを証明する advisory check。3-way merge・hunk 競合・rename/delete 競合は評価しない(実 Git merge 競合の判定は Issue #1792 の PAIRWISE_MERGE_OBSERVATION_V1 producer の責務)。単独では blocking にしない。disjoint は tri-state(true/false/null)— 観測が不完全な場合は null。"}'
      source: ensure_contract_snapshot_auto
      expected_contract_fingerprint: '{"issue_number":2619,"contract_source_kind":"issue_comment","contract_source_id":"5616343777","contract_body_sha256":"sha256:2a902ac6e52d39764f71bf65f97565da04010f559fb25b1fbc3b598ced674b8d","allowed_paths_normalized_sha256":"d7dc5af215f87b6d4f60321a2175d7bdf3a68aefe0841d7f06330ccb9b202ffe","base_ref":"main","base_sha_at_snapshot":"f36f41a7ae20b81e380807a4ce9c4d9b1e95d652"}'
  7. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    issue-refinement-loop: approved

    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/2619#issuecomment-5616343777"
        generated_at: "2026-09-10T09:28:58Z"
        body_sha256: "sha256:2a902ac6e52d39764f71bf65f97565da04010f559fb25b1fbc3b598ced674b8d"
      metadata:
        title_prefix_ready: true
      label_sync_observation:
        kind: presentation_sync
        result: noop
        detail: "labels are non-authoritative telemetry"
      auto_fixes:
        result: auto_fixed
        required: []
        skipped: []
      blockers: []
      permissions:
        unavailable: []
      generated_at: "2026-09-10T09:30:49Z"
      checked_body_sha256: "sha256:2a902ac6e52d39764f71bf65f97565da04010f559fb25b1fbc3b598ced674b8d"
      checker_exit_code: 0
      missing_sections: []
      missing_contract_keys: []
    FOLLOW_UP_MATERIALIZATION_RESULT_V1:
      schema_version: 1
      materialized_by: issue-refinement-loop
      follow_up_issues:
        - number: 2620
          url: "https://github.com/squne121/loop-protocol/issues/2620"
          disposition: created
          reason: "direct human-context substantive contract feedback requires a provenance-bound controlled rewrite route"
      note_only_observations: []
  8. self-assigned this
    on Sep 10, 2026
  9. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    推奨は、#2619 を再 refinement せず、そのまま impl-review-loop に投入です。最新 handoff は impl_ready / run_impl_review_loop、fresh Contract Snapshot は go で blocker なしです。triage-required ラベルは残っていますが、最新 handoff 自体が labels を non-authoritative telemetry として扱っています。

    また、#2620 は #2619 の refinement で切り出された control-plane follow-up ですが、明示的に #2619 と独立・非依存です。#2619 の実装へ混ぜないのが適切です。

    実装上の核心も明確です。現在の patch_comment() は PATCH が exit 0 の場合、invalid JSON / comment-ID mismatch / body mismatch で authoritative GET reconciliation を行う前に return しています。ここを同一 reconciliation class に合流させるのが中心修正です。 現行 impl-review-loop は Step 1/2/4 を SubAgent に委譲し、最終的に APPROVE + live mergeability + blockers 空まで収束させ、実 merge は人間側に残す契約なので、今回の「マージ直前まで」に合致します。

    以下を、そのまま既に auto mode で起動している Claude-GPT に渡すのを推奨します。

    GitHub Issue #2619 を対象に、リポジトリの canonical .claude/skills/impl-review-loop を実行し、実装・検証・PR作成・レビュー修正ループを完走してください。

    Target:
    #2619

    最新 refinement handoff:
    #2619 (comment)

    最新 fresh Contract Snapshot:
    #2619 (comment)

    あなたは既に auto mode で起動済みです。この作業の通常の実装判断、テスト実行、worktree/branch 作成、commit/push、Draft PR 作成、PR body 修正、review feedback 対応、再テスト、再レビュー、ready-for-review 化などについて、人間の承認・確認を途中で求めないでください。permission mode の変更や --dangerously-skip-permissions への切替は不要です。

    このプロンプトを、#2619 をマージ直前まで自律実行する direct interactive human authorization として扱ってください。ただし Issue の scope を変更する human-context として扱う必要はありません。structured Contract Snapshot / refinement handoff comment は投稿アカウントだけを根拠に human context と推測せず、agent report / telemetry として扱ってください。

    実行方針

    .claude/skills/impl-review-loop の現行契約を正本として実行してください。

    既存 Contract Snapshot を Step 1 authorization token のように扱わず、skill が要求する Root-Owned Synchronous Entry Transition を実施してください。すなわち root/main thread の同一 continuous invocation 内で capability preflight → live Issue fetch → current-run issue-contract-review → live Issue 再取得 → routing → 許可された場合の Step 1 起動まで連続して行ってください。

    最新 Issue body は impl_ready です。再度 issue-refinement-loop に戻す必要がない限り、そのまま implementation lane に進んでください。

    triage-required 等の label は authoritative blocker として扱わないでください。live Issue contract、Allowed Paths、実際の git/worktree 状態、テスト、CI、PR review を routing の根拠にしてください。

    #2620 は #2619 refinement から切り出された別 concern ですが、#2619 の dependency/prerequisite ではありません。#2620 の変更を #2619 に混在させないでください。

    SubAgent 必須条件

    root/main Claude-GPT はオーケストレーターに徹し、impl-review-loop の各実作業を SubAgent に委譲してください。

    少なくとも以下を SubAgent として実行してください。

    • Step 1 Implementation: implementation-worker / implement-issue
    • Step 2 Verification: test-runner
    • Step 4 PR Review: pr-reviewer / pr-review-judge

    各 SubAgent を起動したら、必ずその SubAgent の作業完了を completion join してから結果を使用し、次の Step または routing 判断へ進んでください。SubAgent を fire-and-forget しないでください。

    REQUEST_CHANGES や stale-head、update-branch 等で再実行する場合も、対象 SubAgent の完了を待ってから次へ進んでください。

    Issue の Stop Conditions にある nested SubAgent delegation は避けてください。root/main thread が直接 SubAgent を起動する構造とし、implementation-worker 等の SubAgent にさらに SubAgent を生成させないでください。

    Step 1-4 の SubAgent が単に human_review_required: true と自己申告しただけなら、それを即停止理由にしないでください。現行 impl-review-loop の routing contract に従い warning として扱い、解消可能な実装・検証・レビュー問題なら自律的にループを継続してください。

    #2619 の固定 scope

    変更可能なのは Issue の Allowed Paths のみです。

    • .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py
    • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py

    parser、controlled executor、publisher route、permission/security harness、別 Issue の資産は変更しないでください。

    実装開始時に current main を取得し、専用 worktree / branch を作成してください。既存 worktree/branch/PR が #2619 に既に存在する場合は重複作成せず、live state を確認して安全に resume してください。

    実装の主眼

    patch_comment() の PATCH exit code 0 の経路を修正してください。

    現在、PATCH response が以下の場合に authoritative GET reconciliation の前で fail しています。

    • invalid JSON
    • response comment ID mismatch
    • response body mismatch

    これらを同一の「PATCH 自体は成功した可能性があるが response representation を信用できない」reconciliation class として扱ってください。

    要件:

    1. blind PATCH retry はしない。
    2. authoritative direct GET は最大1回だけ。
    3. 既存 verify_controlled_publisher_comment_id_binding() を再利用する。
    4. comment ID、Issue binding、html_url、trusted publisher、final body SHA256 の full binding がすべて成立した場合だけ PATCH 成功として reconcile する。
    5. GET 取得不能、binding mismatch、body mismatch、publisher mismatch 等なら fail-closed。
    6. body SHA authority は authoritative GET で得た decoded Markdown body string の UTF-8 SHA256 とする。PATCH request JSON envelope 全体の hash にしない。
    7. returncode != 0 / timeout の既存 fail-closed reconciliation semantics を弱めない。
    8. trusted publisher validation、duplicate/overlong classification、bounded compaction semantics を弱めない。

    最小差分を優先し、不要な abstraction や新 schema は追加しないでください。

    必須 regression

    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py に focused deterministic integration regression を追加してください。

    mock/stub 可能なのは GitHub HTTP boundary を表す subprocess.run と remote comment state のみです。

    以下は real implementation を通してください。

    • real _build_contract_review_comment()
    • real patch_comment()
    • real canonical contract_review_result_parser.py

    patch_comment() 自体または parser の成功を stub して false-green にしないでください。

    small / non-compacted

    producer object → YAML transport → PATCH request JSON → authoritative readback → canonical parser を end-to-end で通し、classification の semantic value が完全一致することを検証してください。

    少なくとも別々の値として以下を含めてください。

    • literal backslash sequence r"\^[[2K"
    • actual ANSI ESC "\x1b[2K"
    • r"path\foo\bar"
    • r"\q"
    • "runner's output"
    • "line1\nline2\tvalue"

    特に #2599 regression は literal \^[[2K を small/non-compacted fixture で通したことで証明してください。large fixture に存在するだけでは不足です。

    PATCH stdin が valid JSON であること、その JSON の decoded body が final comment body と完全一致することも assert してください。

    large / compacted

    transport 上限を確実に超える payload を作り、既存 compaction contract を通してください。

    保持必須:

    • classification_count
    • original_payload_sha256
    • compact: true
    • truncated: true
    • non-verbose classification fields

    stdout_head / stderr_head 等の verbose field は compaction により消えて構いません。

    最終 comment を real canonical parser が valid go Contract Snapshot として parse できることを確認してください。

    PATCH reconciliation matrix

    少なくとも以下を固定してください。

    • PATCH exit 0 + invalid JSON + authoritative GET full-binding success → success
    • PATCH exit 0 + wrong comment ID + GET full-binding success → success
    • PATCH exit 0 + body mismatch + GET full-binding success → success
    • 上記各ケースで GET は最大1回
    • authoritative GET failure → fail-closed
    • GET comment/body/Issue/html_url/publisher/hash binding mismatch → fail-closed
    • blind PATCH retry が発生しない

    既存 safe payload、POST/PATCH/readback、duplicate/overlong classification の regression も維持してください。

    検証

    Issue に記載された required focused gate を必ず実行してください。

    uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q

    その後、impl-review-loop の Verification / PR-review contract に従い current HEAD に必要な検証を実施してください。

    live GitHub disposable Issue を使う mandatory test は追加しないでください。今回の Runtime Verification Applicability は not_applicable です。

    PR 上では current-head の required CI を確認し、失敗がコード起因なら人間へ確認せず修正→再検証→再レビューを継続してください。

    PR

    1 Issue = 1 PR を維持してください。

    PR body に closing keyword を明示してください。

    Closes #2619

    Draft PR を canonical flow に従って作成し、mark_ready_for_review が required auto action として必要なら、人間承認を求めず実行してください。

    pr-reviewer が REQUEST_CHANGES を返した場合、blockers を fix_delta として implementation-worker に渡し、修正 → verification → PR review を繰り返してください。

    BEHIND、stale reviewed head、body hygiene、closing keyword 等の機械的に解消可能な状態も、現行 impl-review-loop の routing に従って自律解消してください。

    完了境界

    実際の merge は絶対に実行しないでください。
    auto-merge も有効化しないでください。

    以下を満たすところまで進めてください。

    • implementation 完了
    • Allowed Paths gate pass
    • required verification pass
    • current-head required CI pass
    • unresolved actionable review blocker なし
    • pr-reviewer verdict APPROVE
    • reviewed_head_sha が current PR head と一致
    • live mergeability が canonical approved route を満たす
    • required auto actions が残っていない
    • IMPL_REVIEW_LOOP_RESULT_V1.status = draft_pr_ready
    • merge_ready = true / equivalent current canonical merge-ready state
    • termination_reason = approved

    この状態になったら merge せず停止してください。

    人間承認を要求しない範囲

    通常の実装判断、テスト、commit、push、PR作成、review feedback 修正、CI修正、update branch、stale-head re-review、ready-for-review 化について質問・確認を挟まないでください。

    一方、canonical contract 上の真正な hard stop を無理に突破しないでください。特に以下の場合は、承認待ちの対話状態にせず、証拠と停止理由を明記して fail-closed で終了してください。

    • secret / credential の取得・露出が必要
    • force push、履歴破壊等の破壊的操作が必要
    • actual Git conflict / mergeable == CONFLICTING / merge_state_status == DIRTY
    • Allowed Paths 外の変更が不可避
    • canonical parser / controlled executor / security harness の変更が不可避
    • 実装: Contract Snapshot publish の transport round-trip と PATCH reconciliation を修正する #2619 の固定 contract/schema を変更しなければ実装不能
    • 新しい別 scope / Issue が必要
    • formal pr-reviewer verdict HUMAN_REVIEW_REQUIRED
    • canonical bounded retry / iteration hard limit を使い切っても進展不能

    単なる telemetry/artifact/label の欠落や stale、通常の review blocker、CI failure、SubAgent の boolean human_review_required 自己申告だけで人間へ確認を求めないでください。

    最終報告

    完了時または hard-stop 時に、次だけを簡潔に報告してください。

    • Issue 実装: Contract Snapshot publish の transport round-trip と PATCH reconciliation を修正する #2619
    • worktree / branch
    • PR URL / PR number
    • final HEAD SHA
    • 変更ファイル
    • 実装内容の要約
    • SubAgent 一覧と、それぞれ completion join 済みであること
    • focused pytest 結果
    • required CI 結果
    • pr-reviewer 最終 verdict / reviewed_head_sha
    • live mergeability
    • loop iteration 数
    • unresolved blockers / warnings
    • IMPL_REVIEW_LOOP_RESULT_V1 の最終 status / termination_reason
    • merge を実行していないこと

    途中経過の人間承認は不要です。今すぐ canonical impl-review-loop を開始し、上記完了境界まで自律的に進めてください。

    補足すると、現在の main は f36f41a7... で、branch protection は typecheck / lint / test / build / python-test / validate-generated-artifact を要求しています。 また open-pr 側には Draft を mark_ready_for_review へ進める required auto action が既に存在するため、「Draft のまま止めず merge-ready まで」という指示も既存設計に沿っています。

  10. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    root-owned entry router audit

    route: invoke_impl_review_loop
    reason: fresh_review_go_live_equality

  11. squne121 commented on Sep 10, 2026

    @squne121
    OwnerAuthor

    root-owned entry router audit

    route: invoke_impl_review_loop
    reason: fresh_review_go_live_equality

  12. added a commit that references this issue on Sep 10, 2026
    6d89e2c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent/implementerenhancementphase/implementationtriage-required

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions