Skip to content

fix(v2-adapter): derive buyer_ref from idempotency_key in create_media_buy (#1115) - #1123

Merged
bokelley merged 1 commit into
mainfrom
bokelley/v2.5-buyer-ref-v2
May 1, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/v2.5-buyer-ref-v2

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Closes #1115. Stacks on top of #1121 — base is bokelley/v2.5-schemas so the conformance-suite update lives in the same review. Once #1121 lands, GitHub will retarget this PR to main automatically.

Summary

v2.5's create_media_buy schema requires buyer_ref top-level + per-package as the buyer's reference for THIS media buy. The v2 adapter previously omitted it, causing every v3-buyer call against a v2 seller to fail v2.5 wire validation. This PR derives buyer_ref from idempotency_key, which already carries the client-controlled-unique-identity contract sellers need for dedupe.

Mapping

Per the protocol expert review on PR #1121 (bokelley/v2.5-schemas):

  • Top-level buyer_ref: caller-supplied wins → else idempotency_key → else omitted (v3 pre-send validation should have rejected the missing required field; on warn-mode passthrough the v2.5 validator surfaces it).
  • Per-package buyer_ref: caller-supplied wins → else package.idempotency_key → else \${parent_buyer_ref}-\${index}. Position-based composition is stable across replays.

Why not generate fresh UUIDs: replays must hit the same buyer_ref or sellers can't dedupe, defeating idempotency. Reusing idempotency_key (which already has that contract) is correct.

Why not use account.account_id: that's tenant identity, not buy identity. v2.5's buyer_ref is "buyer's reference for THIS media buy."

API change

adaptPackageRequestForV2 gains an optional second argument PackageAdapterContext ({ parentBuyerRef?, index? }). Backward-compatible — single-argument calls keep working unchanged.

Conformance

The v2.5 adapter-conformance test suite (added in #1121) flips create_media_buy from a known-drift expected_failures fixture to a passing fixture. Future regressions on this fixture surface as test failures.

7 new unit tests in test/lib/v3-compatibility.test.js:

  • Top-level buyer_ref derives from idempotency_key when caller didn't supply one
  • Caller-supplied buyer_ref wins over derivation
  • No buyer_ref emitted when neither is present (defensive — better than synthesizing an unstable value)
  • Per-package buyer_ref defaults to \${parent}-\${index}
  • Per-package idempotency_key wins over the parent-derived default
  • Caller-supplied per-package buyer_ref wins over both
  • Replay stability: identical inputs produce identical buyer_refs (pins the dedupe contract)

Test plan

Related

🤖 Generated with Claude Code

@bokelley
bokelley force-pushed the bokelley/v2.5-schemas branch from 78392b2 to 426ea19 Compare April 30, 2026 23:29
@bokelley
bokelley force-pushed the bokelley/v2.5-buyer-ref-v2 branch 3 times, most recently from 6df0526 to 34bb590 Compare May 1, 2026 00:31
@bokelley
bokelley changed the base branch from bokelley/v2.5-schemas to main May 1, 2026 00:40
…a_buy

Closes #1115.

v2.5's create_media_buy schema requires buyer_ref top-level + per-package
as the buyer's reference for THIS media buy. v3 doesn't model buyer_ref
directly, but idempotency_key carries the same
client-controlled-unique-identity contract. Reusing it preserves the
seller-side dedupe contract on replays — the same v3 input always
produces the same v2.5 buyer_ref values.

Derivation precedence:
- Top-level: caller-supplied → idempotency_key → omitted
- Per-package: caller-supplied → package.idempotency_key →
  ${parent_buyer_ref}-${index}

adaptPackageRequestForV2 gains an optional second argument
PackageAdapterContext ({ parentBuyerRef?, index? }) so callers threading
per-package derivation supply the parent's reference + index.
Backward-compatible — existing single-argument callers (update_media_buy
adapter, third parties) continue to work without derivation.

The v2.5 adapter-conformance test suite (#1121) flips create_media_buy
from a known-drift expected_failures fixture to a passing fixture. 7
new unit tests pin the derivation rules, including a replay-stability
test that asserts identical inputs produce identical buyer_refs.

Lib regression: 5485 pass / 7 skipped (pre-existing) / 0 fail.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

v2 adapter: emit buyer_ref in adaptCreateMediaBuyRequestForV2 (top-level + per-package)

1 participant