Skip to content

docs(server): document media_buy_ids[] pass-through contract (#1342) - #1395

Merged
bokelley merged 2 commits into
mainfrom
bokelley/media-buy-ids-fanout
May 3, 2026
Merged

bokelley merged 2 commits into
mainfrom
bokelley/media-buy-ids-fanout

Conversation

@bokelley

@bokelley bokelley commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1342 by picking Option B from the issue's three-way design choice: framework passes the media_buy_ids[] array through; platform owns fan-out and aggregation.

Why pass-through, not framework fan-out

GetMediaBuyDeliveryResponse.aggregated_totals carries cross-buy fields that can't be synthesized correctly by a naive framework loop:

  • reach — "Deduplicated reach across all media buys (if the seller can deduplicate across buys)" — only the seller knows their dedup capability
  • new_to_brand_rate — "weighted by conversion volume, not a simple average of per-buy rates"
  • frequency — depends on cross-buy dedup
  • attribution_window — applied uniformly across the result; framework can't pick which window

A capability-flag default of "framework fans out" (Option C) would just let adopters opt out of broken behavior. Better: keep domain decisions with the seller. Sellers who can compute cross-buy fields populate them; sellers who can't omit them and buyers fall back to per-buy values from media_buy_deliveries[].

The same reasoning applies to getCreativeDelivery, which carries media_buy_ids[] and creative_ids[].

Changes

JSDoc additions on the two methods carrying multi-id arrays:

  • SalesPlatform.getMediaBuyDelivery — explicit "platform MUST iterate every id; reading only media_buy_ids[0] silently truncates" note, plus a recommended-pattern code snippet
  • CreativeAdServerPlatform.getCreativeDelivery — same contract for both media_buy_ids[] and creative_ids[]

Test — test/server-decisioning-media-buy-ids-fanout.test.js exercises:

  • 3-id request → platform sees all 3 ids, response carries 3 deliveries
  • Order preservation (z, a, m → z, a, m)
  • Single-id as 1-element array (no special-case)
  • Omitted media_buy_ids → platform receives undefined (paginated-list contract per the wire schema)

No library behavior change — the framework dispatch already passes params through verbatim. This PR documents the contract that's already in effect, plus a test asserting it stays in effect.

Test plan

  • 4 new tests in test/server-decisioning-media-buy-ids-fanout.test.js pass
  • npm run build:lib clean
  • npm run format:check clean
  • Empty changeset (test + docstring only, no library behavior change)

🤖 Generated with Claude Code

bokelley and others added 2 commits May 2, 2026 21:26
Picks Option B from #1342 — framework passes the array through, platform
owns fan-out. The decision is documented in JSDoc on the two specialism
methods that take `media_buy_ids[]`:

- `SalesPlatform.getMediaBuyDelivery`
- `CreativeAdServerPlatform.getCreativeDelivery`

Why pass-through, not framework fan-out (Options A or C-when-default):

`aggregated_totals` carries `reach` (depends on cross-buy dedup
capability), `new_to_brand_rate` (weighted across buys, not a per-buy
average), and `frequency` (depends on dedup) — these can't be
synthesized correctly by a naive framework loop because the dedup
strategy is platform-domain knowledge. A capability flag with naive
sum-and-concat as the false-default would just let adopters opt out
of broken behavior.

Pass-through keeps domain decisions with the seller. Sellers who can
compute the cross-buy fields populate them; sellers who can't omit
them, and buyers fall back to per-buy values.

Closes #1342.

Test-only behavior change (JSDoc clarification + test asserting the
contract is honored). No changeset entry — empty changeset for
test-only / docstring changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
… + getMediaBuys

Two changes in response to expert review:

1. **Flip the recommended pattern** (product expert). Real reporting
   APIs (GAM ReportService, TTD, DV360, Magnite, PubMatic, retail
   media) accept multi-id queries natively; the per-id loop is an
   N-roundtrip anti-pattern that triggers rate limits on 50-buy
   reports. Show the multi-id pattern first, with the loop as
   fallback for genuinely-single-id upstreams.

2. **Extend the contract to getMediaBuys** (protocol expert). Same
   `media_buy_ids[]` shape on `getMediaBuys` — and it's REQUIRED
   for non-guaranteed sellers, so it'll hit more adopters than the
   optional `getMediaBuyDelivery`. Add the same JSDoc note;
   reference #1342 for the rationale.

The multi-id contract on `sync_creatives` / `sync_plans` /
`sync_catalogs` / `get_plan_audit_logs` is already obvious because
those are sync/upsert surfaces; the delivery-style aggregation
hazard doesn't apply there.

Per protocol-expert review on PR #1395.
@bokelley
bokelley merged commit d225e01 into main May 3, 2026
10 checks passed
bokelley added a commit that referenced this pull request May 3, 2026
Came in via the main merge (#1342 → #1395). Buyers calling
get_media_buy_delivery / get_creative_delivery with multiple
media_buy_ids hand the array to the platform as-is — framework
doesn't synthesize per-buy fan-out because cross-buy aggregates
(reach, new_to_brand_rate, frequency) depend on dedup capability
that's platform-domain knowledge.

Closes one of the gaps the upstream-feedback screenshot flagged as
"Not yet — adapters can still silently truncate." composeMethod
test recipes (the other gap) are tracked separately in #1371.

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.

design: media_buy_ids[] fan-out semantics on getMediaBuyDelivery — framework aggregates vs. platform's job

1 participant