Skip to content

feat(reporting): reconcile all_media_buys obligations against a seller-frozen media-buy set - #3778

Merged
rachitm022 merged 2 commits into
mainfrom
rachitm022/reporting-all-media-buys-membership
Nov 23, 2026
Merged

rachitm022 merged 2 commits into
mainfrom
rachitm022/reporting-all-media-buys-membership

Conversation

@rachitm022

Copy link
Copy Markdown
Collaborator

Summary

Buyers can now reconcile reliable-reporting obligations for a delivery config registered with scope: {all_media_buys: true}. Under that scope the seller decides which media buys each period covers, freezing the set at period.end.

  • New ExpectedReportingPeriod.membership:
    • {kind:'media_buy_ids'} is the default. Reconciliation behaves exactly as before.
    • {kind:'all_media_buys', requiredMediaBuyIds?} covers all-scope periods. These expectations carry no mediaBuyIds or coverage pins.
  • How an all-scope expected period matches an obligation. It matches on identity only: config, version, definition, feed, profile, destination, finality, mode and period. A seller's existing obligation is therefore never reported as obligation_missing.
  • What makes a matched all-scope obligation blocking. Each check below adds a reason, and the obligation becomes non-definitive with no receipt:
    • SCOPE_CUTOFF_MISMATCH: scope_resolved_at is not the same instant as period.end, or coverage.evaluated_at is not the same instant as scope_resolved_at. Instants are compared by value, so .000Z and Z are equal.
    • COVERAGE_SCOPE_MISMATCH: coverage.media_buy_ids differs from obligation.media_buy_ids, or the coverage partition or status is invalid.
    • COVERAGE_REQUIREMENT_NOT_MET: the requirement is full but the status is not full. An empty buy set with full coverage is valid.
  • Missing required buy. If a requiredMediaBuyIds entry is absent from the obligation, the result gets a blocking REPORTING_SCOPE_MEMBER_MISSING issue and becomes non-definitive. The obligation still counts for the buys it lists, but a buy the seller left out is never treated as covered.
  • Invalid expectations. INVALID_EXPECTED_MEMBERSHIP is thrown, before any seller read, for: all-scope combined with pins, an unknown kind, or bad requiredMediaBuyIds.
  • Subscription expectations always use exact buy-set comparison. Any membership a template supplies at runtime is stripped.
  • @adcp/reporting-storage: the GCS delivery fence refuses all-scope expectations.

Breaking for type consumers

ExpectedReportingPeriod is now a union. Reading .mediaBuyIds or .coverage without first narrowing to the explicit-buy variant now gives T | undefined. agentic-api's revision-spend.ts needs a one-line change when it bumps.

Spec basis

AdCP 3.2 core/reporting-obligation.json. Its x-adcp-validation rules scope_resolution and coverage_resolution say:

  • scope_resolved_at equals period.end;
  • coverage.evaluated_at equals scope_resolved_at;
  • coverage.media_buy_ids equals media_buy_ids.

core/reporting-coverage.json defines the coverage partition and status rules.

Cross-repo context

This is one of four coordinated changes:

  • this PR, the buyer reconciler;
  • Python adcp SDK seller hook, on next;
  • embedded-sales-agent seller support;
  • agentic-api buyer registration.

agentic-api uses all-scope only for managed ESA sellers, behind a switch that is off by default.

Test plan

  • npm run build:lib, typecheck, typecheck:reporting-storage, lint, lint:boundaries
  • node --test test/reporting-reconciliation.test.js: 165/165, including new cases for each rule above (formatting-only instant match, each real mismatch, missing required buy, invalid membership, subscription strip)
  • All reporting tests: 1321/1321. npm run test:reporting-storage: 194 pass, 1 skipped
  • Independent code review; all findings fixed in a795473
  • Verify end to end against ESA in staging once the seller side ships

🤖 Generated with Claude Code

rachitm022 and others added 2 commits November 23, 2026 22:47
…sen membership

ExpectedReportingPeriod gains `membership` (ExpectedReportingMembership).
The default `{ kind: 'media_buy_ids' }` keeps exact mediaBuyIds and coverage
equality. `{ kind: 'all_media_buys', requiredMediaBuyIds? }` omits both and
instead requires valid coverage evidence whose partition equals the
obligation's own media_buy_ids, scope_resolved_at == period.end,
coverage.evaluated_at == scope_resolved_at, and coverageRequirement. A
required buy the seller omitted is a blocking REPORTING_SCOPE_MEMBER_MISSING
issue on ObligationReconciliation.issues: the obligation still matches for
the buys it lists, but the result is not definitive.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fuse ambiguous membership

- Match an all_media_buys expected period on identity only. The frozen-set
  checks (cutoff, coverage partition and denominator, coverage requirement)
  surface as blocking reasons on the matched obligation, so the buyer never
  posts obligation_missing for an obligation that exists.
- Compare all_media_buys cutoff instants by value, so `00.000Z` equals `00Z`.
- Throw INVALID_EXPECTED_MEMBERSHIP for all_media_buys with mediaBuyIds or
  coverage pins, an unknown kind, or malformed requiredMediaBuyIds.
- Strip a runtime `membership` from subscription expectation templates, which
  otherwise skipped the subscription buy-set comparison (fail-open).
- Test the GCS fence's all_media_buys branch; correct the changeset wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rachitm022
rachitm022 marked this pull request as ready for review November 23, 2026 19:05

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ladon verdict: Approve

Approve — adds all_media_buys seller-chosen membership to reporting reconciliation.

Checked:

  • ExpectedReportingPeriod becomes a union over ExpectedReportingMembership; all_media_buys expectations match on identity alone and never report missing, with cutoff/coverage/requirement failures surfacing as blocking reasons on the matched obligation.
  • pinnedMembership guards every coverage/buy-set comparison; the default pinned path only loosens when pinned===undefined, so existing behavior is unchanged.
  • assertExpectedMemberships fails closed before any seller read (test asserts statusReads===0).
  • sameCutoff→sameInstant→normalizedInstant (reconciliation.ts:2715) normalizes RFC-3339 to UTC, scoped to the all_media_buys arm.
  • Rollup logic keeps per-buy REPORTING_SCOPE_MEMBER_MISSING non-definitive while the obligation stays definitive for listed buys.
  • GCS fence refuses all_media_buys with CONTENT_CONFLICT.
  • Changeset present (minor/patch), documents the union type-narrowing on an experimental surface — consistent with wire-change impact.
  • Test file (+357) covers zero-buy full coverage, formatting-only instant equality, cutoff edge cases, partial/none/unknown coverage, and config-error rejection.

No blocking or medium findings. One Low follow-up recorded (reconciliation.ts:273 — trusts media_buy_ids pins) is omitted per severity model.

Decision table: no critical/high (row 1 n/a); gated_paths false (row 2 n/a); high_risk false (rows 3,5 n/a); no medium findings (rows 4,8 n/a); no prior escalation (row 6 n/a); no team gate (row 7 n/a). Falls through to row 9 → approve.

@rachitm022
rachitm022 merged commit b389edc into main Nov 23, 2026
46 checks passed
@rachitm022
rachitm022 deleted the rachitm022/reporting-all-media-buys-membership branch November 23, 2026 19:10
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.

1 participant