Skip to content

fix(issue-contract-review): fallback parserでcontract fingerprintのJSON flow mappingを保持する - #1929

Merged
squne121 merged 4 commits into
mainfrom
worktree-issue-1927-fallback-parser-contract-fingerprint
Aug 1, 2026
Merged

squne121 merged 4 commits into
mainfrom
worktree-issue-1927-fallback-parser-contract-fingerprint

Conversation

@squne121

@squne121 squne121 commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

Closes #1927(この実装 Issue を関連付ける)

#1153 の controlled contract snapshot(終了報告: https://github.com/squne121/loop-protocol/issues/1153#issuecomment-5150887495)では、producer が expected_contract_fingerprint を一行の JSON flow mapping として投稿していた一方、PyYAML が利用できない fallback parser がその値を文字列として保持しました。そのため authority postcondition が authority_comment_fingerprint_mismatch で fail-closed になりました。

本PRは generic contract snapshot parser の型保存修正です。Latitude / EntireCLI 固有の変更ではありません。#1153 の本文、既存 go コメント、snapshot は変更していません。

型契約と修正内容

境界 変更前 変更後
producer (_build_contract_review_comment) strict JSON object を YAML scalar として出力 変更なし
PyYAML parser dict 変更なし
fallback parser JSON flow mapping が str 先頭が { / [ の値だけ、サイズ・深さを制限した strict json.loads() により dict / list
authority comparator dict の完全一致を要求 変更なし

fallback は legacy の flat + 一段 mapping を維持し、任意深度の indentation mapping は受理しません。authority が必要とする producer の checks.vc_preflight だけは、既存 producer 出力に限定した二段互換経路として保持します。JSON flow collection は 16,384 文字・32 階層までの strict JSON のみで、malformed、巨大整数、過剰ネスト、NaN、Infinity、重複 key は候補を無効化して fail-closed にします。ast.literal_eval() は使用せず、Python dict literal、set、tuple、single-quote依存構文を collection として受理しません。文字列を comparator 側で辞書へ暗黙変換する変更もありません。

回帰テスト

  • 導入: EntireCLI + Latitude の観測データを agent_run_report に接続し、GitHub 経由の ChatGPT レトロ動線を確立する #1153 の body SHA sha256:2875f1a5982e327face1b5fdcd3b7d76a89cdd6459b21a1147d7a18d5b31323f と fingerprint 形状を、PyYAML import 強制失敗時に dict として保持する。
  • producer comment body → fallback parser → _validate_authority_postconditions() の実境界を通し、body SHA、product gate、base binding、fingerprint の完全一致を確認する(comparator は mock しない)。
  • fingerprint の1値変更、キー欠落、余分なキー、文字列型は、comment 本文そのものを変形しても拒否する。
  • malformed {...} / [...]、Python literal、非標準 JSON 定数、重複 key、入力サイズ・深さ超過を fail-closed にし、悪性コメントを skip して後続の trusted comment を継続解析する。
  • materialize_issue_scope_snapshot.py の contract-source consumer を PyYAML 強制不在で実行し、bounded fallback が dict fingerprint を渡すことを回帰する。

SubAgent 調査

  • snapshot_parser_investigator — gpt-5.3-codex-spark — completed: live OWNER go comment の JSON serialization、PyYAML/fallback の型差、producer→parser→comparator の最小修正境界を確認。
  • snapshot_parser_adversarial_tests — gpt-5.3-codex-spark — completed: PyYAML 不在の強制、malformed JSON、Python literal、strict comparator を通す negative/integration test を設計。

受け入れ条件の達成状況

  • AC1: PyYAML 無効時にも inline JSON object の fingerprint を dict として7 key・値を損失なく保持する parser regression を、parser pytest(63 passed)で確認した。
  • AC2: inline JSON array と既存 scalar / nested mapping の互換性を、同じ parser pytest(63 passed)で確認した。
  • AC3: malformed {...} / [...] を文字列成功へ降格せず parse failure とすることを、parser pytest(63 passed)で確認した。
  • AC4: Python literal、tuple、set、single quote 構文、曖昧 YAML tag を strict JSON として受理しないことを、parser pytest(63 passed)で確認した。
  • AC5: 値の途中に { を含む plain string を JSON flow collection と誤解析しないことを、parser pytest(63 passed)で確認した。
  • AC6: 導入: EntireCLI + Latitude の観測データを agent_run_report に接続し、GitHub 経由の ChatGPT レトロ動線を確立する #1153 の body SHA / fingerprint shape を使う networkless producer comment → fallback parser → authority postcondition の統合回帰を、snapshot pytest(137 passed、2 deselected)で確認した。
  • AC7: fingerprint の1値変更、string 型、key 欠落、余分な key を fail-closed に拒否することを、snapshot pytest(137 passed、2 deselected)で確認した。
  • AC8: body SHA、product gate fingerprint、base binding、trusted publisher binding の既存検証を、snapshot pytest(137 passed、2 deselected)、Ruff、git diff --check のすべてで回帰なしと確認した。

上記の証跡はすべて current code head 5d22213ac720996e7f4d5415da5c4114bd33ede2 で test-runner が独立実行した結果である。

検証コマンド結果

uv run --locked pytest .claude/skills/issue-contract-review/tests/test_contract_review_result_parser.py -q
# PASS: 63 passed

uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot_fingerprint_patch.py .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py -q
# PASS: 137 passed, 2 deselected

uv run --locked ruff check .claude/skills/issue-contract-review/scripts/contract_review_result_parser.py .claude/skills/issue-contract-review/tests/test_contract_review_result_parser.py .claude/skills/impl-review-loop/tests/test_contract_snapshot_author_binding.py
# PASS

git diff --check
# PASS

すべて test-runner が current code head 5d22213ac720996e7f4d5415da5c4114bd33ede2 で独立実行した。

Allowed Paths 遵守

Checks

テスト・lint・diff check の実行結果は上記「検証コマンド結果」に集約した。すべて current code head で独立実行済みである。

Schema Change Applicability

  • decision: not_schema_change
  • reason: 既存 producer output の parser 内部表現を復元するだけで、公開 schema・producer 契約・authority comparator 契約は変更しない。

Schema Consumer Inventory

この変更は schema_change ではないが、型契約の消費箇所を明示する。

Consumer ファイル 更新有無 備考
.claude/skills/impl-review-loop/scripts/ensure_contract_snapshot.py no dict の完全一致と authority_comment_fingerprint_mismatch を維持する。
.claude/skills/issue-contract-review/scripts/run_contract_review_once.py no 同じ parser 出力を受け取り、fallback の JSON 型保存を利用する。
scripts/agent-guards/materialize_issue_scope_snapshot.py no controlled contract-source consumer。Allowed Paths 内の authority-binding regression から forced fallback を実行する。

Safety Claim Matrix

Claim Implemented? Not controlled Evidence Follow-up
malformed flow collection を authority candidate として成功させない yes none fallback 強制 unit test と authority integration test none
comparator の fingerprint 完全一致・base binding を緩和しない yes none 1値変更、キー欠落、余分キーの reject test none
未信頼コメントの JSON 例外で parser 全体を停止させない yes none 巨大整数・PyYAML ValueError・後続 trusted comment の回帰 test none
fallback acceptance surface を任意 YAML へ拡大しない yes none arbitrary-depth mapping reject と producer-compatible checks.vc_preflight test none

Notes

#1153 との関係

この修正は optional な controlled materialization の正確性を改善します。default branch 反映後に fresh snapshot を試行する場合は、その dict 型・body SHA・product gate・base binding・fingerprint postcondition を telemetry として確認できます。

ただし、#1153 の review/refinement routing は live Issue、review verdict、実テスト等で継続可能です。snapshot の欠落・失敗・freshness 不一致は warning/telemetry であり、単独では impl_ready の拒否理由にしません。fresh snapshot 成功も単独では impl_ready を付与しません。

controlled commit authority(コミット権限)

このPRは Draft とし、auto merge は使用しない。

@github-actions

github-actions Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Preview URL

Preview removed (PR #1929 closed).

@squne121

squne121 commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

判定

REQUEST_CHANGES。現状のままではマージ非推奨です。

根本原因の特定と「producer/comparatorを緩めずparser境界で型を復元する」という方針自体は妥当です。しかし実装は、PRが主張する「strict JSONの最小修正」より広く、未信頼コメントからparserを例外終了させられる経路も追加しています。PRはDraftで、変更規模は3ファイル・追加312行・削除44行です。

指摘事項

1. P1 Blocker: 未信頼コメントからparser全体を例外終了できる

_parse_fallback_scalar() は json.loads() から発生する例外のうち、JSONDecodeError しか SimpleYamlParseError に変換していません。一方、外側のparse_contract_review_results()もSimpleYamlParseErrorしか捕捉しません。さらにauthor trust判定はYAML/JSONの解析後です。

例えば、次のような約5,000桁の整数を含むコメントを投稿すると、PyYAMLのsafe_load()がValueErrorになり、広いexcept Exceptionによってfallbackへ移り、そこでjson.loads()が再びValueErrorを送出します。

CONTRACT_REVIEW_RESULT_V1:
  bomb: [111111111111111111...約5000桁...]

手元のPython 3.13では、これは次の例外として再現します。

ValueError: Exceeds the limit (4300 digits) for integer string conversion

Python 3.11以降は巨大整数に変換長制限があり、標準ドキュメントも未信頼JSONのCPU・メモリ消費と入力サイズ制限を明示的に警告しています。([Python documentation]1)

PyYAMLはruntime dependencyとして宣言されていますが、現在のコードは「PyYAMLがない場合」だけでなく、PyYAMLが何らかの例外を出した場合すべてfallbackへ移ります。したがって通常環境でも成立する経路です。

必要な修正は以下です。

  • flow collectionに最大文字数を設定する。
  • ValueErrorとRecursionErrorをSimpleYamlParseErrorへ正規化する。
  • 巨大整数、過剰ネスト、未信頼コメントの後に有効なtrusted commentが続くケースを追加する。
  • 悪性ブロックをskipし、parser全体は処理を継続することを検証する。

2. P1 Major: scalar修正ではなく、多段YAML parserへの拡張になっている

Issue #1927は、変更対象を「fallback scalar parsing」に限定し、任意YAML parserの導入を明示的にOut of Scopeにしています。

しかし実装は、従来の限定的な一段mapping処理をparentsスタックへ置換し、任意深度のindentation mappingを構築します。これはJSON flow scalarの型保存とは独立した挙動変更です。

実際、materialize_issue_scope_snapshot.pyはこの共有parserを契約sourceのauthorizationに直接利用しています。また既存テストfixtureは、expected_contract_fingerprintをinline JSONではなく多段block mappingとして生成しています。新しいstack実装は、fallback時にこの形式まで新たに受理することになります。

一方、PR本文のconsumer inventoryは次の2件しか記載していません。

  • ensure_contract_snapshot.py
  • run_contract_review_once.py

少なくとも直接consumerのmaterialize_issue_scope_snapshot.pyと、そのcontrolled execution経路が欠落しています。

推奨は、従来parser構造を維持したまま、既存の値代入箇所だけを_parse_fallback_scalar()へ置換することです。stack実装を残すなら、これは「not_schema_change」ではなくfallback acceptance surfaceの変更として扱い、全consumer inventoryとforced-fallback回帰が必要です。

3. P2 Major: json.loads()の既定値は「strict JSON」ではない

PR本文とIssueは「strict JSONのみを受理する」と主張していますが、Python標準json.loads()の既定動作は次を受理します。

  • NaN
  • Infinity
  • -Infinity
  • 重複object key。最後の値だけを採用

Python公式ドキュメントも、これらがJSON仕様外の拡張であることを明記しています。RFC 8259はNaNとInfinityを禁止し、object member名は一意であるべきとしています。([Python documentation]1)

現在の実装では、例えば以下が成功します。

{"issue_number": NaN}
{"base_ref": "evil", "base_ref": "main"}
[Infinity]

fingerprint readinessや完全一致によって最終的に拒否されるケースはありますが、generic fallback parserの契約として「strict JSON」は成立していません。他のflow collection consumerへ非標準値が流れる可能性もあります。

次の設定が必要です。

json.loads(
    value,
    parse_constant=reject_nonstandard_constant,
    object_pairs_hook=reject_duplicate_keys,
)

NaN、±Infinity、rootおよびnested objectの重複keyを明示的にrejectするテストも追加すべきです。

4. P2 Test gap: malformedな「実コメント」を統合テストしていない

test_authority_postcondition_rejects_mismatched_or_wrong_shape_fingerprints()は、comment bodyを正常なまま固定し、verify()へ渡すexpected_fingerprint側だけを変更しています。つまり証明しているのは「正常にparseされたcommentと別のexpected dictが不一致になる」ことです。

これは以下を証明していません。

  • comment本文内のfingerprintが文字列だった場合
  • comment本文内でkeyが欠落していた場合
  • comment本文内に余分なkeyがあった場合
  • fallback parserがそれらをどう型付けしたか
  • is_fingerprint_ready_go()で拒否されたか

Issue #1927 AC7は、これらのwrong-shape fingerprintをauthority側の入力としてfail-closedにすることを要求しています。

各ケースでcomment bodyそのものを変形し、正しいexpected_fingerprintを維持した状態でpostconditionを通す必要があります。

設計上の不整合

現行impl-review-loopのSSOTは、contract snapshot、body SHA、controlled-executor receiptなどをadvisory telemetryとし、欠落・freshness・identity・digest不一致をrouting停止条件にしないと明記しています。contract_snapshot_urlも任意入力です。

Issue #1830も、通常のIssue review・implementation review・refinementをcontract snapshot等なしで進行できることをOutcomeとしています。

それに対してIssue #1927とPR本文は、このPRのマージ後にfresh snapshotが成功するまで#1153を再開しない手順を規定しています。

parser correctnessの修正自体には価値がありますが、このartifact不整合だけを理由に#1153を停止し続けるのは現行policyと矛盾します。PR本文では次を分離すべきです。

  • parser修正はoptionalなcontrolled materializationの正確性改善。
  • #1153のreview/refinement routingはlive Issue、review verdict、実テスト等で継続可能。
  • fresh snapshot失敗はwarningまたはtelemetryであり、単独のimpl_ready拒否理由にしない。

マージ条件

  1. ValueError、RecursionError、入力サイズ・深度を安全に処理する。
  2. NaN、±Infinity、duplicate keyを拒否する。
  3. stack式多段mapping実装を撤回してscalar-only修正へ戻すか、受理範囲変更として全consumerを監査する。
  4. malformedなactual comment bodyを通すauthority integration testを追加する。
  5. materialize_issue_scope_snapshot.pyをforced-fallbackで回帰させる。
  6. #1153の再開手順をadvisory artifact policyと整合させる。

根本原因の方向性は正しいため、上記を直せば小さく堅牢な修正にできます。現状は「型保存の修正」に見せかけてparser acceptance surfaceと障害面積を拡大しており、差し戻しが必要です。

PRのhead更新・CI・レビューコメントを監視し、変更があった場合だけ再レビューするタスクも設定可能です。

@squne121
squne121 marked this pull request as ready for review August 1, 2026 12:30
@squne121
squne121 merged commit 03bc8d2 into main Aug 1, 2026
21 checks passed
@squne121
squne121 deleted the worktree-issue-1927-fallback-parser-contract-fingerprint branch August 1, 2026 12:30
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.

実装: fallback parserでcontract fingerprintのJSON flow mappingを保持する

1 participant