Skip to content

実装: stale base-bound contract snapshot をfresh materializationする #1655

Open

Description

@squne121

Machine-Readable Contract

contract_schema_version: v1
issue_kind: implementation
parent_issue: "none"
goal_ref: "body-current CONTRACT_REVIEW_RESULT_V1 status: go の base_sha_at_snapshot が default branch の live tip と不一致になったとき、dedupe を安全に避けて fresh source-bound snapshot を materialize できるようにする"
change_kind: code

Parent Issue

none

Parent Goal Ref

  • Goal: impl-review-loop の contract snapshot が Issue body と default branch base SHA の両方に束縛され、controlled commit の ISSUE_SCOPE_SNAPSHOT_V1 materialization を不必要に停止しない。
  • Desired Destination: stale base binding を検出した既存 go snapshot は再利用・dedupe せず、同一 body に対する fresh source-bound go snapshot だけを final authority readback 後に返す。

Current Validated Scope

  • ensure_contract_snapshot.py は body-current な go comment を default branch の live tip と比較し、base_sha_at_snapshot drift を検出して再利用を拒否する。
  • 同じ Issue body SHA の idempotency marker /既存 go 候補があると、fresh base binding を持つ snapshot の controlled materialization に到達できず、ISSUE_SCOPE_SNAPSHOT_V1 の base fingerprint と current main SHA が一致しない。
  • Issue 実装: materializerのAllowed Paths正規化をcontract snapshotと統一する #1653 は materialize_issue_scope_snapshot.py の Allowed Paths Markdown 正規化だけを対象とし、contract snapshot publisher の stale base refresh は変更しない。

Remaining Parent Gaps

Outcome

ensure_contract_snapshot.py とその unit tests を更新した Draft PR が、body-current だが stale base_sha_at_snapshot の go comment を dedupe/reuse せず、fresh base-bound snapshot を controlled two-phase publish と final authority readback で materialize できる状態。

In Scope

  • stale base binding を既存 go reuse と post-window dedupe の双方で識別し、fresh snapshot materialization へ route する限定変更。
  • fresh publish が current default branch ref/SHA、Issue body SHA、comment ID、trusted publisher binding を final readback で満たした場合だけ status: ok を返す回帰テスト。
  • stale go の idempotency marker が存在しても、新しい comment ID と current base SHA を持つ fresh snapshot を作れる回帰テスト。
  • body / updatedAt / trusted comment / base binding の途中 drift、または controlled publisher binding 失敗が従来どおり fail-close となる回帰テスト。

Out of Scope

Acceptance Criteria

  • AC1: body SHA が current で base SHA だけが stale の existing go は check-only で status: ok として再利用されない。
  • AC2: AC1 の stale go がある auto --post 相当では、同一 body SHA の stale marker / comment があっても fresh base ref/SHA と新しい comment ID を含む snapshot を two-phase publish できる。
  • AC3: post-window に stale base-bound go が現れても dedupe せず、fresh snapshot を publish するか、authority input が drift した場合は fail-close する。
  • AC4: fresh snapshot の final authority readback が Issue body SHA、updatedAt、trusted publisher comment ID/body SHA、および live base ref/SHA の全てを一致確認した場合だけ status: ok と non-null contract_snapshot_url を返す。
  • AC5: body / updatedAt / trusted comment / base ref/SHA のいずれかが materialization 中に drift した場合、stale snapshot を成功扱いにせず fail-close を維持する。

Verification Commands

# AC1
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q
# AC2
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q
# AC3
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py -q
# AC4
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot_fingerprint_patch.py -q
# AC5
$ uv run --locked pytest .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot_fingerprint_patch.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
  • .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot_fingerprint_patch.py

Runtime Verification Applicability

decision: not_applicable
reason: GitHub transport / default-branch readbackは fixture-based deterministic unit testsで再現でき、外部 runtime 起動を必要としない。

Required Skills

  • Python 3(subprocess boundary、deterministic state routing、pytest)

Required Design References

  • docs/dev/workflow.md
  • docs/dev/agent-skill-boundaries.md
  • docs/dev/agent-runtime-ops.md

Stop Conditions

  • Allowed Paths 外の変更が必要と判明した場合
  • In Scope の固定契約(キー集合・スキーマ・型定義)の変更が必要になった場合
  • 新規 Issue の起票が必要と判断した場合(スコープ分割が発生する場合)
  • 後続 Phase / 別スコープへの波及が判明した場合
  • nested SubAgent delegation が必要になった場合
  • 外部サービス利用・権限昇格・既存テスト大規模改変が必要になった場合
  • stale base binding を新規 snapshot materialization と final authority readback の両方で fail-close に維持できない場合

Scope Collision

Delivery Rule

Activity

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

    @squne121
    OwnerAuthor

    判定

    REQUEST_CHANGES — reframe_in_place。現状の Issue #1655 は実装着手不可です。

    問題意識自体は妥当ですが、Issue本文が想定する欠陥経路と現在の main の実装が一致していません。Issue #1655 には現時点で補足コメントがなく、具体的な失敗結果・comment ID・base SHA・実行ログも提示されていません。

    Findings

    P0-1 — #1635 / PR #1640 と実質的に重複している

    Issue #1635 は既に次を受け入れ条件としていました。

    • stale な base_sha_at_snapshot を check-only で再利用しない
    • auto --post では live default branch SHA を持つ新しい go comment を materialize する
    • post-window の競合と最終 authority drift を fail-close にする

    この変更は PR #1640 としてマージ済みです。

    現在の実装も、初回再利用判定で live base と一致しなければ fresh materialization 経路へ落とし、post-window dedupe でも base が一致する go だけを採用しています。

    さらに既存テストには、stale な既存goがある状態で auto --post が新しいcommentを投稿し、current base SHAをfingerprintへ入れるケースが既にあります。

    したがって、#1655 の AC1〜AC3 は実装前から成功する可能性が高く、差分を正当化できません。最低限、現在の main で失敗する named test または実際の失敗証跡が必要です。再現できなければ #1635 の duplicate として閉じるべきです。


    P0-2 — 「idempotency marker がfresh publishを止める」という根拠がコードと一致しない

    ensure_contract_snapshot.py は run_contract_review_once.py を skip_idempotency_check=True で実行します。つまり upstream の既存go dedupeは明示的に迂回されています。

    また投稿直前の実経路は、body-only markerを組み立てた後、comment集合を再取得し、goが body-current・fingerprint-ready・base-current のすべてを満たす場合だけdedupeします。stale baseのgoはこの条件を通りません。

    実際に残っている可能性が高い問題は、marker dedupeではなく次の transport 境界です。

    • POSTがremoteでは成功したが、CLIがtimeoutまたは通信失敗を返した
    • provisional commentが残った後にPATCHが失敗した
    • 同じIssue/bodyで複数プロセスが同時にmaterializeした
    • GitHubがvalidation/spam判定として422を返した

    現行 post_comment() は成功時にURLだけを取り、timeoutや曖昧なtransport errorをcomment再取得でreconcileしません。 GitHubのCreate issue comment APIは201のほか、403・404・410・422を返し得て、422はvalidation失敗またはspam判定です。サーバー提供のidempotency keyも公開契約にはありません。([GitHub Docs]1)

    要求する修正

    Issue本文に実際の失敗を次の形で固定してください。

    old comment ID:
    old base_sha_at_snapshot:
    live base SHA:
    ensure result.status:
    ensure result.post_status:
    errors:
    post-window comments:
    materializer error:
    

    その証跡が post_comment() の曖昧成功であるなら、スコープは「stale base dedupe」ではなく、attempt-scoped publicationとambiguous POST reconciliation に変更すべきです。


    P0-3 — AC5の「trusted comment drift」は現行authority helperでは検出できない

    verify_snapshot_authority_postcondition() は全commentを取得しますが、その後に対象commentだけを取り出し、parse_contract_review_results([comment], ...) として単独解析しています。

    このため、例えば次の競合を見逃します。

    T0: fresh goをPATCH
    T1: trusted publisherが新しいblocked commentを投稿
    T2: authority helperが対象goだけを単独parse
    T3: status: ok
    

    初回・post-window判定では「latest trusted blocked wins」を使っている一方、最終barrierではcomment集合全体のprecedenceを再評価していません。これは #1655 の AC5 にある「trusted comment driftをfail-close」と矛盾します。

    最終readbackでは少なくとも以下が必要です。

    1. 全trusted resultをparseする
    2. find_latest_result(..., trusted_only=True) を再実行する
    3. 最新trusted resultがblockedなら拒否する
    4. expected commentが現在のauthoritative goであることを確認する
    5. より新しいcurrent goがある場合のwinner規則を固定する
    6. 初回と最終のtrusted schema-like comment集合に追加・編集・削除がないか検証する

    これは #1655 に残す価値がある、現在の実装との差分です。


    P0-4 — Runtime Verificationをnot_applicableにするのは不適切

    Issue #1655 はGitHub commentのPOST、comment ID、PATCH、readback、publisher identity、base SHAを扱っています。それにもかかわらず、Runtime Verificationをfixture-onlyのnot_applicableとしています。

    リポジトリには既に、使い捨てIssueを作成して実際のGitHub APIに対しPOST・PATCH・再取得を行う github_live テストがあります。テストファイル自身も、transport部分をmockへ置き換えた成功をruntime verificationとして扱わない契約を明記しています。

    一方、通常のpytestは設定により github_live を除外します。したがってIssue記載の次のようなコマンドでは、live testは実行されません。

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

    Runtime Verificationは次のように変更すべきです。

    decision: immediate
    applicable_acs:
      - fresh stale-base refresh
      - new comment ID binding
      - final base SHA binding
    execution_environment:
      auth_required: true
      network_required: true
    fallback_policy:
      mocked_transport_success_is_pass: false

    実行コマンドには明示的に -m github_live とnamed nodeを指定してください。


    P1-1 — Verification Commandsが差分検出能力を持たない

    AC1〜AC3が同じテストファイル全体、AC4〜AC5も同じテストファイル全体を指しています。しかも既存テストには既に stale base refresh 成功ケースがあります。

    各ACは、未実装時に失敗するnamed testへ一対一に束縛すべきです。例えば:

    # baseline-expect: fail
    uv run --locked pytest \
      .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py::TestStaleBaseRefresh::test_same_body_stale_final_go_posts_new_comment \
      -q
    # baseline-expect: fail
    uv run --locked pytest \
      .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py::TestAuthorityPostconditionReadback::test_newer_trusted_blocked_rejects_target_go \
      -q
    # baseline-expect: fail
    uv run --locked pytest \
      .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot.py::TestAmbiguousPublication::test_applied_post_timeout_is_reconciled_by_attempt_marker \
      -q
    uv run --locked pytest -m github_live \
      .claude/skills/impl-review-loop/tests/test_ensure_contract_snapshot_fingerprint_patch.py::TestStaleBaseRefreshLive::test_stale_snapshot_creates_new_bound_comment \
      -q

    P1-2 — producerを原因と断定する前にmaterializer側を除外できていない

    producerの capture_base_ref_and_sha() は、GraphQLの単一responseからdefault branch名とtip SHAを取得するよう修正済みです。

    一方、materialize_issue_scope_snapshot.py は現在も:

    1. repository APIでdefault_branchを取得
    2. 別のGit ref APIでそのbranchのSHAを取得

    という2回のreadbackを行っています。呼び出し間にdefault branch変更やbranch tip更新があると、一貫しない観測になる余地があります。

    また、producerのfinal authority成功後からmaterializerのbase readbackまでにmainが進めば、materializerがrejectするのは正常です。これは「dedupe bug」ではなく、snapshotの有効期間とhandoff transactionの問題です。

    したがって #1655 は、以下を証跡で区別する必要があります。

    • producerがstale commentを返した
    • producerがfresh commentを返したがmaterializer開始前にmainが進んだ
    • materializerが一貫しないbase pairを取得した
    • comment POST/PATCHがambiguousに終わった

    producerがPOST前に停止している証拠がない限り、materialize_issue_scope_snapshot.py を無条件にOut of Scopeとするのは早計です。


    P1-3 — 並行実行時のpublication semanticsが未定義

    GitHubのCreate issue comment APIには、公開されたexactly-once機構やcompare-and-swap機構はありません。したがって二つのagentが同時にrefreshすると、両方が有効なfresh commentを投稿する可能性があります。これは公式API契約から導かれる設計上の推論です。([GitHub Docs]1)

    Issueでは次のどちらかを明記すべきです。

    • at-least-once: 同等な複数fresh commentを許し、返却するcommentだけを完全にauthority-boundにする
    • canonical winner: full comment-set readback後、唯一のwinnerを決め、それ以外のプロセスはdedupedまたはstaleとして終了する

    GitHubはmutationを並列化せず直列化し、連続するmutative request間に間隔を設けることを推奨しています。POST直後にPATCHする現在の二段階公開では、secondary rate limitも明示的に考慮すべきです。([GitHub Docs]2)


    P1-4 — #1490 / #1513との統合順序が不足している

    同じproducerを変更する未解決Issueとして、次が残っています。

    #1655でattempt markerやpending bodyを変更すると、これらのreceipt schema・comment body hash・既存snapshot lookupへ直接影響します。単なる「実装直前に再読する」では不足しており、少なくとも次を契約化すべきです。

    Issue本文の推奨再定義

    #1655を残すなら、Goalを次のように絞るべきです。

    stale base-bound goが存在する場合に、attempt-scopedな二段階publicationを行い、曖昧なPOST結果を安全にreconcileし、full trusted comment-setとlive baseの最終readbackを満たした新しいcommentだけを返す。

    必要なACは以下です。

    1. 現在のmainで失敗する実再現fixtureがある。
    2. stale final goと同一body markerが存在しても、新comment IDを発行する。
    3. post-windowにstale goが現れてもdedupeしない。
    4. POST適用後timeoutはattempt markerで一件だけreconcileする。
    5. reconcile候補が0件または複数ならfail-closeする。
    6. PATCH失敗で残ったpending commentをauthoritativeとして扱わない。
    7. final readbackで後発trusted blockedがあればokを返さない。
    8. final readbackでIssue body、updatedAt、対象comment、publisher、fingerprint、live base、comment-set precedenceをすべて再検証する。
    9. unit testに加えて実GitHub APIによるdisposable Issue testを実行する。
    10. publisherがfreshだったのにmaterializer時点でbaseが進んだケースは、別のbounded handoff/retry問題として分類する。

    結論

    このIssueで再度base比較ロジックを追加するのは誤りです。 その部分は #1635 / PR #1640 で既に実装されています。

    #1655は次のいずれかにするべきです。

    • 再現不能なら 実装: contract snapshot の base SHA freshness を強制する #1635 のduplicateとしてclose
    • 実際の欠陥がtransport ambiguityなら、attempt-scoped POST reconciliationへ再定義
    • 欠陥が最終comment precedenceなら、full trusted comment-set authority barrierへ再定義
    • 欠陥がmaterializerとのhandoffなら、producerではなくtransaction境界またはmaterializer側へ分割

    現状のまま実装すると、既に解決済みの分岐へ重複変更を加え、本当に残っている競合窓を温存する可能性が高いです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/implementerenhancementphase/implementationtriage-required

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions