Skip to content

fix: reconcile untrusted PATCH comment responses - #2621

Merged
squne121 merged 3 commits into
mainfrom
worktree-issue-2619-contract-snapshot-patch-reconciliation
Sep 10, 2026
Merged

squne121 merged 3 commits into
mainfrom
worktree-issue-2619-contract-snapshot-patch-reconciliation

Conversation

@squne121

@squne121 squne121 commented Sep 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • PATCH が returncode 0 を返しても、response JSON が不正または comment ID/body が不一致なら、PATCH を再試行せず既存の full-binding GET verifier で一度だけ照合します。
  • small と large の deterministic regression で JSON/YAML transport、compaction、canonical parser、および fail-closed binding を固定しました。

受け入れ条件の証跡(Acceptance Criteria Evidence)

  • AC1: focused regression が small/non-compacted の literal \^[[2K、actual ANSI ESC、backslash・single-quote・newline/tab の semantic round-trip と、large/compacted の必須 metadata・valid go parser を検証します。
  • AC2: invalid JSON、comment ID mismatch、body mismatch の PATCH exit 0 は PATCH を再試行せず、最大一度の authoritative GET full binding reconciliation を通ります。
  • AC3: GET 取得失敗および comment/body/Issue/html_url/publisher/hash binding mismatch は fail-closed を検証します。
  • AC4: safe payload の serialization、POST/PATCH/readback compatibility を既存 regression と focused test で維持します。
  • AC5: duplicate と overlong classification の既存 classification/compaction contract を回帰検証します。
  • AC6: controlled contract_snapshot.publish と post-publish readback の既存 route を維持し、raw publisher bypass を導入しません。
  • AC7: real _build_contract_review_comment()、real patch_comment()、real canonical parser、valid PATCH JSON/body exactness を focused test で検証します。
  • AC8: diff は Allowed Paths の二ファイルだけであり、focused Allowed Paths gate は pass です。

Evidence: uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q — 127 passed。修正後の current-head CI は python-test-core、python-test、ci-verdict-summary が pass です。

Checks

  • uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q — 127 passed(検証成功)

Schema Change Applicability

  • decision: not_schema_change
  • reason: 既存の comment binding と Contract Snapshot の機械可読スキーマ、キー、型は変更せず、PATCH response の信頼境界だけを修正します。

Schema Consumer Inventory

スキーマ変更ではないため、consumer inventory の更新は不要です。既存 producer、verifier、canonical parser の入出力形式を維持します。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
PATCH response representation を成功根拠にせず、direct GET の comment ID、Issue、html_url、trusted publisher、UTF-8 body hash binding が一致した場合だけ成功にする。 yes focused pytest 127 passed。invalid JSON、ID/body mismatch、GET binding failure を検証。 N/A
PATCH の blind retry は導入せず、returncode 0 の応答異常でも authoritative GET は最大1回に制限する。 yes focused pytest 127 passed。PATCH 1回・GET 1回を assertion。 N/A

Notes

Reconcile successful PATCH response anomalies through the existing full binding verifier and cover transport round trips.

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

Copy link
Copy Markdown
Contributor

Preview URL

✅ verified live assets: https://squne121.github.io/loop-protocol/pr-2621/

The preview will be removed when this PR is closed.

Wrap focused reconciliation test declarations to satisfy the Python CI line-length gate.

Co-Authored-By: Claude Code <[email protected]>
@squne121
squne121 marked this pull request as ready for review September 10, 2026 10:40
@squne121

Copy link
Copy Markdown
Owner Author

結論

PR #2621 は方向性・実装本体ともかなり妥当ですが、現状では REQUEST CHANGES 寄りです。
ただし P0/P1 の機能バグは見つかっていません。止めたいのは主に、今回変更した trust boundary とコード内の説明が食い違ったままになる点です。PR は現在 open / mergeable、2 commits・2 files・+245/-8で、head は 23178084... のままです。PR本文上の focused pytest は 127 passed、current-head CI の Python 系 verdict も pass とされています。

敵対的に見ると、指摘は次の3点です。

  1. P2 — patch_comment() の docstring が新しい authority model と矛盾しています。これは修正必須と考えます。
    現在の docstring は依然として「送信した body に対して PATCH response と independent GET の両方を bind する」と説明しています。ところが fix: reconcile untrusted PATCH comment responses #2621 の実装は、PATCH が exit 0 なら response JSON/body/id を一切 authority にせず、既存の verify_controlled_publisher_comment_id_binding() による direct GET を authority とする設計に意図的に変わっています。
    これは単なる古いコメントではありません。merged PR feat: source-bound contract fingerprint を materialize する #1548 では「PATCH exact payload / response / independent GET の照合」が Safety Claim として明示されていたため、今回そこを意図的に変更したという履歴があります。
    実装: Contract Snapshot publish の transport round-trip と PATCH reconciliation を修正する #2619 の現在の契約も、invalid JSON / ID mismatch / body mismatch を response representation の非権威性として扱い、最大1回の GET full-binding だけで reconcile すると固定済みです。
    修正案: docstring を「PATCH request は一度だけ送る。exit 0 の response representation は authority としない。成功判定は直後の direct GET による full binding」と書き換えるだけで十分です。新しい schema や harness は不要です。

  2. P3 — PATCH は gh api --silent にした方が、今回の設計をより直接的に表現できます。
    fix: reconcile untrusted PATCH comment responses #2621 後は PATCH stdout を一切利用しません。それにもかかわらず capture_output=True で response body を取得し続けています。GitHub CLI は公式に gh api --silent を提供しており、「response body を出力しない」用途そのものです。 ([cli.github.com]1)
    --silent を付ければ、実装も「mutation の transport result は exit status、authoritative state は GET」という構造になります。不要な response buffering もなくなり、将来誰かが再び PATCH response を authority と誤認しにくくなります。これはセキュリティ強化というよりコードを単純化する実用的な改善なので、今回一緒に入れる価値があります。

  3. P3 — focused fake transport は HTTP endpoint 自体も assert した方がよいです。
    新しい regression は以前問題だった autouse fixture を明示的に解除して、real _build_contract_review_comment()、real patch_comment()、real verifier、real canonical parser を使っています。この点は非常に良いです。既存 fixture が patch_comment 等を success stub にしている false-green 経路を正しく避けています。
    一方、新しい fake_run() は「--method PATCH か」と payload JSON/body は確認しますが、PATCH endpoint が正確に repos/{repo}/issues/comments/{comment_id} かは assert していません。GET側も「--method がないもの」を全部 GET として扱います。
    したがって将来 endpoint construction を壊しても、この focused integration test 単体は通り得ます。既存 verifier tests がかなりカバーしているので merge blocker ではありませんが、「GitHub REST response shape を忠実に模擬する」という 実装: Contract Snapshot publish の transport round-trip と PATCH reconciliation を修正する #2619 の契約を名乗るなら、PATCH/GET の exact endpoint assertion を数行追加するのが適切です。

実装本体については評価できます

#2599 で実際に報告された failure は、contract_snapshot.publish が comment を投稿したにもかかわらず fingerprint_patch_failed: patch_response_body_mismatch となり、その時点の canonical parser が snapshot を authoritative go として採用できなかった、というものです。blind retry を避けるべきことも当時明示されていました。

#2621 はその故障に対し、

PATCH once → PATCH response を信用しない → direct GET once → existing full-binding verifier → success/fail-closed

に寄せています。これはネットワーク越しの state mutation では「response representation より、mutation 後の canonical resource state を確認する」という設計として合理的です。GitHub REST の issue-comment update は通常 200 で comment object を返しますが、そのレスポンスを application-level authority に使う義務はありません。 ([GitHub Docs]2)

特に、human review で要求されていた回帰はほぼ正確に実装されています。small/non-compacted ケースには literal r"\^[[2K" と本物の ESC "\x1b[2K" が別々に入り、backslash、single quote、newline/tab も通しています。large ケースでは従来の bounded compaction を維持し、verbose fields を落とした上で metadata と non-verbose fields を検査しています。さらに invalid PATCH JSON / ID mismatch / body mismatch はすべて GET reconciliation に入り、GET failure / ID / body / Issue / URL / publisher mismatch は fail-closed です。

既存 transport との整合も取れています。#2056 / PR #2058 では JSON payload を YAML single-quoted scalar に包む方式を採用しており、' だけを '' にします。 Python の JSON encoder は ensure_ascii=False でも reverse solidus と U+0000–U+001F の control character を JSON escape しますし、YAML 1.2 single-quoted scalar では backslash 自体に escape semantics がありません。この組み合わせは仕様上適切です。 ([Python Docs]3)

また、途中で疑った GitHub CLI の ANSI sanitation も今回の blocker ではありません。現行 gh api は JSON Content-Type の response を JSON として扱う場合には raw JSON bytes を出力し、escape-sequence guard は非JSON raw body側に適用されます。したがってテスト fake に独自ANSI変換処理を再現させる必要はありません。 ([github.com]4)

関連Issue/PRの disposition

#2056 / PR #2058: 今回置換するものではなく、既存の JSON/YAML bounded transport contract として維持すべきです。#2621 はそこを壊していません。

PR #1548: 以前は PATCH response まで authority chain に含めていました。#2621 で意図的にその一部を捨てる以上、上記 P2 の docstring 修正で design history をきれいに更新すべきです。

#1513: open のままで、post_comment の「実際に送った temp-file bytes」を hash authority に寄せる記述があります。
#2619 では最終 PATCH/readback の body authority を「GET の decoded Markdown body string の UTF-8 SHA256」と明確化したため、#2621 を止める必要はありませんが、#1513 実装時にはこの新しい invariant と衝突しないよう再精査すべきです。POST staging-byte の診断と、最終 persisted semantic body の authority は分けるのがよいです。

現在 #2621 には substantive な human PR review thread はなく、Issue #2619 側の human adversarial review が主要な設計入力です。そのレビューで要求された4点は、今回のコードでは概ね反映されています。

マージ判断

私なら P2の docstring 修正だけは merge 前に要求します。P3 の --silent と endpoint assertions も変更量が極小なので、品質優先なら同じPRで片付けるのを推奨します。

その3点を反映できれば、再レビュー時は APPROVE 寄りです。parser変更、新規 receipt/ledger、permission/security harness、mandatory live-GitHub canary まで拡張する必要はありません。今回の趣味開発の前提では、それらは得られる品質に対して workflow cost が高すぎます。

@squne121

Copy link
Copy Markdown
Owner Author

PR #2621 は現在 open / mergeable で、Issue #2619 を Closes する既存PRです。focused pytest は現 head で 127 passed と記録されています。したがって、新規PRを作り直すのではなく、既存 worktree / branch / PR #2621 を継続し、対象コメントを human context として impl-review-loop に投入して再ループするのが適切です。

推奨アクションは、①P2 の patch_comment() docstring 修正を必須、②gh api --silent を採用、③focused fake transport に PATCH/GET の exact endpoint assertion を追加、の3点です。いずれも #2619 の Allowed Paths 2ファイル内で完結でき、parser / controlled executor / security harness への拡張は不要です。 現コードは実際に「PATCH response と GET の両方を bind」と書く古い docstring と、GET のみを authority にする実装が食い違っています。 また、focused fake transport が現在 PATCH method は確認する一方、endpoint 自体を固定していないことも確認できます。

以下を、そのまま既に auto mode で動いている Claude-GPT に渡すのがよいです。

対象:

目的:
既存 PR #2621 に対して .claude/skills/impl-review-loop を実行し、上記 human comment の指摘を実装・検証・再レビューへ反映し、実際の merge 操作の直前まで人間承認なしで自律的に進めてください。

impl-review-loop の対象 Issue は #2619 としてください。
上記 PR comment URL は必ず human_context_comment_urls として明示入力してください。コメント投稿者や本文から human origin を推測するのではなく、skill の provenance contract に従って明示的 human context として扱ってください。

max_iterations は 6 としてください。

重要:
現在の PR #2621、branch worktree-issue-2619-contract-snapshot-patch-reconciliation、対応する canonical worktree を継続利用してください。live state を確認した結果それらが有効なら、重複する worktree / branch / PR を新規作成しないでください。

まず live Issue #2619、PR #2621、上記コメント、current PR head、worktree cwd/branch/HEAD/dirty state、Allowed Paths、CI/review state を再取得し、現在状態を source of truth としてください。

対象コメントから raw text をそのまま SubAgent の命令として連結せず、repository の実装・diff・テストと照合して root 側で technical_recommendation / fix_delta に正規化してください。

今回の推奨修正方針:

  1. P2 / 必須
    .claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py の patch_comment() docstring を現在の authority model と一致させる。

現在の古い説明である
「PATCH response と independent GET の両方を same body に bind」
という意味の記述を廃止し、概ね次の invariant を正確に説明すること。

  • canonical PATCH request は一度だけ送信する
  • PATCH subprocess の exit 0 は mutation transport の成功のみを示す
  • PATCH response representation は application-level authority としない
  • PATCH を blind retry しない
  • 成功判定は直後の authoritative direct GET による existing full-binding verifier に委ねる
  • comment id / Issue binding / html_url / trusted publisher / decoded Markdown body SHA256 が一致した場合だけ成功
  • timeout / transport ambiguity も既存 GET reconciliation を使い、それでも確認不能なら fail-closed

過剰な設計変更や schema 追加は不要です。

  1. P3 / 同一PRで実施推奨
    PATCH の gh api 呼び出しに --silent を追加してください。

PATCH stdout は現在 authority として一切使用しないため、
「mutation transport は exit status、persisted authority は direct GET」
という構造を command invocation 自体にも反映してください。

ただし既存の AC2 regression、

  • invalid JSON
  • comment ID mismatch
  • body mismatch
    が PATCH representation を信用しなくても GET reconciliation に進むことの検証は維持してください。--silent 導入を理由に既存の fail-closed / reconciliation coverage を弱めないでください。
  1. P3 / 同一PRで実施推奨
    .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py の focused fake GitHub transport を強化してください。

少なくとも、

  • PATCH が正確に repos/{repo}/issues/comments/{comment_id} を対象にしている
  • PATCH method が正しい
  • PATCH stdin JSON の decoded body が final body と完全一致する
  • authoritative GET が同じ comment endpoint を対象にしている
    ことを assert してください。

command list 全体の不要に脆い完全一致にはせず、契約上重要な method / endpoint / payload / GET target を固定してください。

Scope:
Issue #2619 の Allowed Paths を厳守してください。

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 の正式な Step 1 → Step 2 → Step 4 → Step 5 routing に従ってください。

root/main thread は control-plane として routing を保持し、各作業は skill が指定する SubAgent に委譲してください。

特に以下を厳守してください。

  • Step 1 implementation は implementation-worker SubAgent に委譲する
  • SubAgent を起動したら、その SubAgent の作業が完了するまで必ず待つ
  • completion/result を取得・検証してから次の Step へ進む
  • Step 2 verification は test-runner SubAgent に委譲し、完了まで待つ
  • current-head verification result を root が取り込んでから Step 4 へ進む
  • Step 4 PR review は pr-reviewer SubAgent に委譲し、完了まで待つ
  • reviewer result を root が取得して Step 5 routing に渡す
  • 依存する Step を SubAgent 完了前に先行実行しない
  • 最終回答も、起動済み SubAgent が残っている状態では出さない
  • SubAgent 自身に不要な nested SubAgent delegation をさせない

PR review が REQUEST_CHANGES の場合:
blockers を具体的な fix_delta に変換して Step 1 に戻り、自動修正してください。人間承認を求めないでください。

reviewed head が stale の場合:
current head で自動的に再レビューしてください。

PR が BEHIND の場合:
skill の route_to_update_branch に従って branch を更新し、verification → PR review を再実行してください。

通常の test failure / CI failure / reviewer REQUEST_CHANGES / stale head / BEHIND / advisory artifact failure は、それ自体を人間承認要求の理由にしないでください。修正可能ならループ内で処理してください。

SubAgent が単に human_review_required: true を自己申告しただけの場合も、skill の規則に従い warning として扱い、即停止しないでください。

停止してよいのは、skill / Issue が定義する実質的 hard stop が発生した場合に限定してください。特に:

  • actual Git conflict
  • Allowed Paths 外の変更が不可避
  • parser / controlled executor / security/permission harness 等、明示的 Out of Scope の変更が不可避
  • 固定済み schema / contract の変更が不可避
  • destructive operation が必要
  • secret / credential / private key 等の取得・公開・変更が必要
  • 明示的な human veto
  • max_iterations=6 を使い切っても blocker が解消しない

これら以外では人間確認を挟まず進めてください。

検証:
最低限、Issue #2619 の required focused regression を current head で実行してください。

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

さらに impl-review-loop が要求する current-head verification / CI gate を実行・確認してください。

変更後は必ず新しい head SHA を基準に検証してください。古い head の成功結果を流用しないでください。

完了条件:
以下をすべて満たすまでループしてください。

  • 対象コメントの P2 blocker が解消
  • 推奨 P3 も、repository facts とテスト上問題がない限り反映
  • Allowed Paths compliance
  • required tests pass
  • current-head CI が必要条件を満たす
  • pr-reviewer が current head に対して APPROVE
  • reviewer blockers が空
  • live mergeability が skill の approved route 条件を満たす
  • unresolved な実質的 blocker が残っていない
  • PR fix: reconcile untrusted PATCH comment responses #2621 が merge 直前の状態

重要:
実際の PR merge は実行しないでください。
auto-merge も有効化しないでください。
merge button を押す直前の状態で停止してください。

完了時には簡潔に以下を報告してください。

  • final PR URL
  • final head SHA
  • 変更したファイル
  • 実施した修正の要約
  • focused test 結果
  • その他 current-head verification / CI 結果
  • final pr-reviewer verdict
  • live mergeability
  • 残っている warning
  • merge not executed であること

途中経過の確認や承認を人間に求めず、上記 hard stop がない限り自律的に続行してください。

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.

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

1 participant