Skip to content

実装: open-pr の契約束縛 overlap readback waiver を一般化する - #1627

Merged
squne121 merged 8 commits into
mainfrom
worktree-issue-1509-open-pr-contract-bound-waiver
Jul 20, 2026
Merged

squne121 merged 8 commits into
mainfrom
worktree-issue-1509-open-pr-contract-bound-waiver

Conversation

@squne121

@squne121 squne121 commented Jul 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

open_pr.py の overlap preflight hard gate が持つ overlap_readback_waiver 機構を、Issue #1477 専用に固定 binding された一回限りの仕組みから、linked Issue の live body と trusted CONTRACT_REVIEW_RESULT_V1 status: go snapshot に同一 SHA で束縛された汎用 generic consumer へ拡張した。既存の #1477 固定 waiver(_load_verified_overlap_readback_waiver / _has_only_fixed_readback_incomplete_blockers)はバイト単位で無変更のまま維持し、新しい generic consumer(_load_verified_generic_overlap_readback_waiver 等)を additive に追加した。両経路は is_fixed_1477_target guard で完全に分離されており、相互に干渉しない。

本PRは Issue #1509 を解決する(Closes #1509)。

受け入れ条件の達成状況

Checks

  • uv run --locked pytest .claude/skills/open-pr/scripts/tests/test_open_pr_contract_bound_waiver.py -q — 21件成功(AC1〜AC3 に対応する VC を含む)
  • uv run --locked pytest .claude/skills/open-pr/scripts/tests/test_open_pr_overlap_gate.py -q — 61件成功(既存 実装: Scope Collision Preflight で Allowed Paths 未記載 Issue を候補から除外する #1477 固定 waiver 経路の回帰テスト、無変更のまま通過)
  • uv run --locked pytest .claude/skills/open-pr/scripts/tests/ -q — 262件成功(open-pr スイート全体)
  • ruff check — 警告なしで完了

Schema Change Applicability

このPRは live Issue body の overlap_readback_waiver YAML block に、repository・linked issue・candidate 番号・updated_at・reason・expiry・approver を必須化した generic contract を additive に追加する。既存の #1477 固定 waiver の入力・出力形式は一切変更しない。

Schema Consumer Inventory

N/A(not_schema_change のため)

Safety Claim Matrix

# SAFETY_CLAIMS_V1
safety_claims:
  - claim: "generic waiver は live body と最新 trusted go snapshot が同一 body_sha256 の場合にのみ有効化し、comment のみでは有効化しない"
    implemented: "yes"
    evidence:
      - ".claude/skills/open-pr/scripts/tests/test_open_pr_contract_bound_waiver.py::test_contract_bound_waiver_rejects_invalid_live_contract_or_snapshot"
    not_controlled: []
    follow_up: []
  - claim: "candidate 集合差分・reason 差分・updated_at drift・追加 C2b/C3 candidate・期限切れ・repository/linked issue 不一致は fail-closed で拒否する"
    implemented: "yes"
    evidence:
      - ".claude/skills/open-pr/scripts/tests/test_open_pr_contract_bound_waiver.py::test_contract_bound_waiver_rejects_candidate_timestamp_or_reason_drift"
      - ".claude/skills/open-pr/scripts/tests/test_open_pr_contract_bound_waiver.py の期限切れ・repository不一致テスト群"
    not_controlled: []
    follow_up: []
  - claim: "既存の #1477 固定 waiver 経路(`_load_verified_overlap_readback_waiver`)は本PRで一切変更しない"
    implemented: "yes"
    evidence:
      - "test_open_pr_overlap_gate.py 61/61 pass(unchanged)"
    not_controlled: []
    follow_up: []

Notes

squne121 and others added 2 commits July 19, 2026 09:38
#1509)

#1477 に固定された overlap_readback_waiver(issue_numbers: [519, 520,
1429] の決め打ち)に加え、linked Issue 自身の live body に自己宣言され、
live body と最新 trusted `status: go` snapshot の同一 SHA で束縛された
waiver を検証する generic consumer を追加する。fresh evidence の
readback-incomplete candidate 集合・reason・updated_at が waiver と完全一
致し、他の readback 完了済み candidate が C1/C2a だけである場合に限り
`proceed_with_collision_evidence` として扱う。

#1477 の (repository, linked_issue) の組は既存の固定 binding 分岐のみを
通り、generic 経路には一切到達しないため、Allowed Paths 外にある既存の
test_open_pr_overlap_gate.py(61 tests)の挙動は完全に維持される。新規
test_open_pr_contract_bound_waiver.py(21 tests)で AC1-AC3 を検証し、
SKILL.md に generic waiver のスキーマと安全性 predicate を追記した。

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

Copy link
Copy Markdown
Contributor

Preview URL

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

The preview will be removed when this PR is closed.

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review 結果(pr-review-judge)

Issue #1509 の contract(Outcome / Acceptance Criteria / Allowed Paths / Verification Commands)と PR diff を照合し、独立に再検証した。

  • Allowed Paths gate: status: ok(changed files 3件すべて Issue #1509 の Allowed Paths 内、trusted go snapshot と body_sha256 一致確認済み)
  • コード変更は additive で、既存 #1477 固定 waiver 経路(_load_verified_overlap_readback_waiver / _has_only_fixed_readback_incomplete_blockers)はバイト単位で無変更と確認
  • テスト: test_open_pr_contract_bound_waiver.py(21件)+ test_open_pr_overlap_gate.py(61件、既存回帰)+ open-pr スイート全体(262件)すべて pass
  • CI: 全ジョブ SUCCESS(ci_verdict_summary.py で status: all_pass 確認)
  • PR本文の ## 受け入れ条件の達成状況 セクションで AC1〜AC4 の evidence を確認
  • mergeability: mergeable: MERGEABLE, merge_state_status: CLEAN

blocker なし。

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "bbc725df6f66e62fcde9087acbd4a4bce920ca93"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    status: ok
    producer_role: review_subagent
    worker_report_used_as_canonical: false
    violations: []

@squne121

Copy link
Copy Markdown
Owner Author

結論

REQUEST_CHANGESです。現HEAD 3c06f4b… のCIは全件成功していますが、CI未検出の P1ブロッカーが2件あります。PRは現在もDraftです。

P1 — fresh evidenceのIssue本文と、waiver本文が同じSHAに束縛されていない

producerのevidenceには current_issue.body_sha256 が含まれています。ところがconsumer側の安全性検査は current_issue.number しか確認せず、後から取得したlive bodyのSHAと比較していません。

現在の処理順では、次が成立します。

  1. overlap producerがIssue本文Aを読み、body_sha256=A のfresh evidenceを生成
  2. その後Issue本文がBへ更新される
  3. generic loaderが本文Bと、本文Bに対応するtrusted status: go snapshotを取得
  4. candidate番号・updated_at・reasonが一致すれば、本文Aで計算したoverlap判定を本文Bのwaiverで解除

loaderはlive bodyとsnapshot間だけを検証し、その戻り値はwaiver本体だけです。gateもcandidate照合後にrouteを書き換えるだけで、AとBを接続していません。

これは#1491で明示的に保証対象外とした「最後のreadbackからPR createまでの非原子性」とは異なります。producer evidenceとwaiver readbackの間に存在する、実装内で閉じられるbinding漏れです。#1491はcandidate集合・reason・updated_at driftをfail-closed境界として記録しています。

必要な修正

  • generic loaderから waiver と検証済み live_body_sha256 を返す
  • fresh.current_issue.body_sha256 == live_body_sha256 をwaiver適用前に必須化
  • 欠落、型不正、SHA形式不正もfail-closed
  • gh issue view は body、url に加えて number、updatedAt も取得可能なので、監査情報として併用する ([GitHub CLI]1)

最低限、次のテストが必要です。

  • fresh本文A/live本文B+snapshot B → 拒否
  • fresh本文A/live本文A+snapshot A → 許可
  • current_issue.body_sha256 欠落・不正 → 拒否

P1 — Issue #1509のAC4と実装が正面から矛盾している

Issue #1509のIn ScopeとAC4は、#1477の固定bindingをgeneric contract validationに置換することを要求しています。

一方、PR本文とテストは以下を明示しています。

  • 固定#1477経路はバイト単位で変更しない
  • generic経路をadditiveに追加
  • #1477はgeneric経路へ到達させない

PR本文はそれにもかかわらずAC4を完了扱いにしています。 テストも#1477をgeneric経路から明示的に除外しています。

どちらかが必要です。

  • 実装を契約どおり変更する:固定#1477も同一generic validatorへ移行し、旧形式を互換入力として扱う
  • 契約を変更する:Issue #1509を「固定経路維持+generic追加」に修正し、trusted contract snapshotを再発行する

現状のまま Closes #1509 でmergeするのは不正です。Issue本文を修正する場合、現在のsnapshotは本文SHAに束縛されているため再生成が必須です。

P2 — reasonの「完全一致」ではなく部分一致になっている

実装はfresh candidateの全reasonが readback_incomplete prefixを持つことを確認した後、waiverのreasonがリストに含まれるかしか確認していません。

したがって、次も通過します。

fresh_reasons = [
    "readback_incomplete_missing_outcome_or_in_scope",
    "readback_incomplete_new_unsafe_condition",
]
waiver_reason = "readback_incomplete_missing_outcome_or_in_scope"

これはIssueの「reason差分をfail-closed」「candidate集合・reason・updated_atが完全一致」という契約に反します。既存テストはreasonを別の1件へ置き換えるケースしかなく、許可済みreasonへの追加を検証していません。

現在の単一reasonスキーマを維持するなら、reasons == [entry["reason"]] としてください。複数reasonを許すなら、waiver側も reasons: [...] にして集合の完全一致を要求すべきです。

P2 — YAML contractが閉じたスキーマとして検証されていない

現在のparserには以下の曖昧性があります。

  • 複数のwaiver blockがあっても、最初にparseできたものを採用
  • top-level/candidate要素の未知キーを許可
  • YAML重複キーを明示的に拒否しない
  • updated_at は空でない文字列なら通過
  • expires_on は文書上 YYYY-MM-DD なのに、date.fromisoformat() が受理する全形式を許可

該当実装は、最初のvalid blockを即returnし、schema validatorも必須フィールドの存在と型しか確認していません。

YAML 1.2ではmapping keyは一意である必要があります。(YAML) しかし手元のPyYAML 6.0.3では重複キーが後勝ちになることを再現しました。人間が上側の値をレビューし、consumerが下側の値を使う解釈差が発生し得ます。

またPython 3.11以降の date.fromisoformat() は 20191204 やISO週形式も受理するため、YYYY-MM-DD の検証にはなりません。([Python documentation]3)

リポジトリ内の HUMAN_C1_DECISION_V1 parserは、schema blockの重複、field重複、未知・欠落キーをすべて拒否しており、こちらを設計の基準にできます。

必要な修正

  • waiver blockは正確に1個だけ許可
  • duplicate keyを拒否するSafeLoaderを使用
  • 各階層でキー集合を完全一致
  • issue_number/linked_issue は正の整数
  • expires_on は正規表現+parseで厳密な YYYY-MM-DD
  • updated_at はproducerと同じRFC 3339形式をparse検証

P2 — mixed-caseのrepository名でgeneric consumerが誤停止する

repository identityは小文字化されていますが、Issue URLは小文字化した文字列との完全一致で検証しています。

GitHubのowner/repoパラメーターは大小文字を区別しませんが、APIレスポンスの full_name やURLは表示上のcaseを保持できます。公式例も octocat/Hello-World を返しています。([GitHub Docs]4)

そのため、Owner/MyRepo のようなrepositoryでは、正当なURLが返ってもlowercaseの expected_url と一致せず拒否され得ます。「ANY repository」を名乗るgeneric consumerとして不完全です。

URL文字列の完全一致ではなく、URLをparseしてowner/repoを同じcanonicalizerへ通し、Issue番号も独立に比較してください。

P3 — expiry境界が実行ホストのtimezone依存

期限判定が date.today() なので、開発端末、CI、コンテナのtimezoneによってwaiverが失効する瞬間が変わります。 Pythonの date.today() はcurrent local dateです。([Python documentation]5)

generic contractとしては、UTCかJSTかをschemaで固定し、aware datetimeから日付を得るべきです。UTCを採るなら datetime.now(timezone.utc).date() が明確です。([Python documentation]5)

レビュー・競合状態

  • 現HEADのCIは全workflow成功しています。
  • 既存の承認相当コメントは bbc725d… をレビュー対象としており、現HEADは 3c06f4b… です。形式上は再レビューが必要です。
  • 姉妹PR #1626もopenで open_pr.py を変更しているため、merge順序を固定し、後着PRでrebase後の統合テストが必要です。
  • PR本文が報告するpytest結果は確認しましたが、こちらではsuite全体を独立再実行していません。

merge条件は、少なくともP1の2件を解消し、reason追加ケース、body SHA drift、duplicate YAML、mixed-case repositoryの回帰テストを追加することです。

squne121 and others added 5 commits July 19, 2026 17:59
#1509)

PR #1627 のレビュー fix_delta (iteration 1) に対応する。

- generic waiver ロード時に読み戻す live body の SHA を fresh evidence 自身の
  current_issue.body_sha256 と照合し、producer の readback と waiver 検証の
  live body 読み戻しの間に本文が更新される TOCTOU を閉じる
  (_load_verified_waiver_binding / _load_verified_generic_overlap_readback_waiver)
- #1477 固定 waiver と generic waiver を同一の generic contract validation
  core (_load_verified_waiver_binding) に統合する (Issue #1509 AC4)
- candidate の reason は waiver 宣言の単一 reason に完全一致させ、subset 許容
  だった partial match を修正する
- waiver YAML の複数ブロック・重複キー・未知キー・非正整数・expires_on /
  updated_at の形式を fail-closed で厳密化する
- repository 識別子の比較を case-insensitive canonicalizer 経由にし、waiver
  の期限判定を UTC 固定にする (date.today() timezone 依存を解消)

Co-Authored-By: Claude Sonnet 5 <[email protected]>

@squne121 squne121 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOOP_VERDICT_V2

PR #1627(head a41ec7569d5e3d1d6133860181d434fa3239b45e)を、人間 owner の REQUEST_CHANGES コメント(#issuecomment-5014987898)に対する fix_delta iteration として再レビューした。

確認した修正内容:

  • P1: overlap producer の fresh evidence body_sha256 と live issue body SHA の binding gap(TOCTOU)→ run_overlap_preflight_gate 内で fresh.current_issue.body_sha256 == live_body_sha256 を waiver 適用前に必須化。欠落・型不正・SHA形式不正は fail-closed。
  • P1: Issue #1509 AC4 と実装の矛盾(#1477固定経路がgeneric validationへ統合されていない)→ 新設の共有 _load_verified_waiver_binding() core を #1477 固定経路・generic 経路の両方が使用するよう変更。既存の frozen regression gate(test_open_pr_overlap_gate.py)61件は無変更で全pass。
  • P2: waiver reason 検証が部分一致だった → reasons == [entry["reason"]] の完全一致に変更。
  • P2: waiver YAML contract が閉じたスキーマでなかった → 重複キー拒否 SafeLoader、単一 waiver block 強制、top-level/candidate 双方の閉じたキー集合、expires_on/updated_at の厳密な正規表現検証を追加。
  • P2: mixed-case repository 名での誤停止 → URL を parse して owner/repo を canonicalize してから比較する方式に変更。
  • P3: expiry 判定の timezone 依存 → datetime.now(timezone.utc).date() に固定。

独立検証:

  • 上記6件すべてを diff・コードで直接確認済み(自己申告のみに依拠せず)。
  • 新規/既存テスト: test_open_pr_contract_bound_waiver.py 26件 pass(binding-gap mismatch/match/missing/malformed の4ケース、extra-reason regression 含む)、test_open_pr_overlap_gate.py(frozen #1477 regression gate)61件 pass、open-pr/scripts/tests/ 全体275件 pass。ruff check clean。
  • allowed_paths_review_gate.py を Issue #1509 の trusted contract snapshot(body_sha256=sha256:84f2546a..., contract_source_id=5013484194)に束縛して再計算 → status: ok、violation なし。変更ファイルは Allowed Paths 3件(open_pr.py / test_open_pr_contract_bound_waiver.py / SKILL.md)と完全一致。
  • ci_verdict_summary.py --expected-head-sha a41ec7569d5e3d1d6133860181d434fa3239b45e → status: all_pass。stale head なし。
  • 姉妹PR #1626(同じ open_pr.py を変更)は既に main へ merge済み(7a458860)であることを確認。PR #1627 は origin/main を取り込んだ上でこの修正を積んでおり、conflict なし。

blocker なし。

LOOP_VERDICT_V2:
  verdict: APPROVE
  reviewed_head_sha: "a41ec7569d5e3d1d6133860181d434fa3239b45e"
  merge_ready: true
  mergeability:
    mergeable: MERGEABLE
    merge_state_status: CLEAN
  blockers: []
  required_auto_actions: []
  auto_fix_applied: []
  follow_up_issue_requests: []
  allowed_paths_gate:
    status: ok
    producer_role: review_subagent
    worker_report_used_as_canonical: false
    changed_files_source: git_diff_name_status_find_renames_z
    changed_files:
      - ".claude/skills/open-pr/SKILL.md"
      - ".claude/skills/open-pr/scripts/open_pr.py"
      - ".claude/skills/open-pr/scripts/tests/test_open_pr_contract_bound_waiver.py"
    violations: []
    contract_fingerprint:
      issue_number: 1509
      contract_source_kind: issue_comment
      contract_source_id: "5013484194"
      contract_body_sha256: "sha256:84f2546aaa4a1486b08f5e3cc085219f9891019657b4e08f919689a68b17e5f2"
      base_ref: main
      base_sha_at_snapshot: "bb1d320ef063670308192f0fb0c3faeddc27a27f"

@squne121
squne121 marked this pull request as ready for review July 20, 2026 10:03
@squne121
squne121 merged commit f7fdd1a into main Jul 20, 2026
22 checks passed
@squne121
squne121 deleted the worktree-issue-1509-open-pr-contract-bound-waiver branch July 20, 2026 10:03
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.

実装: open-pr の契約束縛 overlap readback waiver を一般化する

1 participant