Skip to content

fix(reporting): pick each obligation's current revision by its own finality - #3831

Merged
rachitm022 merged 1 commit into
mainfrom
rmatani/ai-25649-ts-sdk-pick-each-obligations-current
Nov 30, 2026
Merged

rachitm022 merged 1 commit into
mainfrom
rmatani/ai-25649-ts-sdk-pick-each-obligations-current

Conversation

@rachitm022

Copy link
Copy Markdown
Collaborator

Problem

A seller can owe two obligations for the same account, report, media buys and period that differ only in required_finality: a provisional (snapshot) feed and an official feed. A revision doesn't name its obligation. core/reporting-revision.json says "one canonical revision may fan out through many caller/account-bound obligations", so reconcileReporting joined both obligations to every revision in the slice.

Once the official revision existed:

  • It became the snapshot obligation's current revision too (officials[0] ?? current[0]). The snapshot generation pins no official finality rule, so the selection failed with EXPECTED_FINALITY_POLICY_MISMATCH. Nothing was read, and the buyer posted revision_missing for the snapshot obligation, superseding its earlier received.
  • Both obligations got ASSOCIATED_HISTORY_INCOMPLETE. The SDK seller counts revision_count per obligation, but the consumer counted the whole slice.
  • reconcileReportingCoreV1 threw Core reporting revision history is incomplete or ambiguous for the same ledger.
  • getMediaBuyDelivery didn't receive the obligation being read, so a client serving several obligations had to infer which one a revision belonged to.

Fix

Selection (selectCurrent, reconcileReportingCoreV1). This only applies when another obligation shares the slice at a different required_finality. In that case each obligation chooses among the revisions at its own finality.

  • Spec: core/reporting-obligation.json says complete "requires a published revision at required_finality … A snapshot-required pacing obligation may therefore become complete from a snapshot revision". core/reporting-consumer-status.json says revision_missing "means the obligation existed but no required revision was available".
  • A revision the seller materialized for an obligation (an explicit materialization join) stays that obligation's candidate whatever its finality.
  • Supersession and fork checks run over the obligation's candidates. The predecessor-existence check runs over the whole slice, so an official close that names the snapshot it replaces (the fan-out model) doesn't make the official obligation indeterminate.
  • revision_count matches if it equals either the obligation's own candidates (one chain per obligation, as the SDK seller does) or the whole slice (one chain fanned out).

Unchanged behaviour. A slice with one obligation, or whose obligations all require the same finality, takes the exact pre-change code path: candidates are the whole slice and a unique official still takes precedence. Every existing reconciliation test passes unchanged, including the official-precedence matrix.

Reader context. client.getMediaBuyDelivery(params, options) now receives options.reportingObligation, which is { reportingObligationId, deliveryConfigId, deliveryConfigVersion } (exported type ReportingRevisionReadObligation). It is backwards compatible:

  • It's a new optional field on the SDK-local options argument.
  • The wire request is unchanged.
  • The consumer runtime's abortable wrapper forwards it.
  • Readers that ignore it need no change.

It's documented in docs/guides/REPORTING-RECONCILIATION.md.

Tests

test/lib/reporting-consumer-finality-siblings.test.js runs the real SDK seller: two producers on one in-memory ledger, one generation per finality.

  • Snapshot publishes, then the snapshot obligation is received and the official obligation is revision_missing with MISSING_CURRENT_REVISION. Then the official close publishes, then the official obligation is received and the snapshot obligation stays received (unchanged). No revision_missing is ever posted for the snapshot chain, and neither obligation gets ASSOCIATED_HISTORY_INCOMPLETE, EXPECTED_FINALITY_POLICY_MISMATCH or AMBIGUOUS_REVISION_CHAIN.
  • Every read carries its own obligation in options.reportingObligation, and the wire params are unchanged.
  • Fan-out seller (the official supersedes the snapshot, and both obligations count the slice): each obligation still reads the head at its own finality.
  • No sibling: the official close still takes precedence for a snapshot obligation whose generation pins the finality rule.
  • reconcileReportingCoreV1 joins each obligation to its own finality instead of throwing.
  • A single-obligation slice reads and posts exactly as before.

packages/reporting-storage/test/reporting-consumer-finality-siblings-pg.test.js runs the same end-to-end flow against the PostgreSQL store.

On the unfixed code the end-to-end test fails with revision_missing where received is expected, and the Core reconciler throws.

Local runs:

  • npm run typecheck, typecheck:reporting-storage, lint, lint:boundaries and prettier are clean.
  • The root reporting suites pass: 1,462/1,462.
  • The full reporting-storage PostgreSQL suite: 747 of 748 pass. The one failure is reporting-issue-events-pg.test.js "the dispatcher renders and delivers an opened event…", which fails identically on a clean origin/main build and doesn't touch this code.

🤖 Generated with Claude Code

…nality

A seller can owe a snapshot obligation and an official obligation for the
same account, report, media buys and period. Revisions do not name their
obligation, so the consumer joined both obligations to every revision in
the slice: once the official revision existed it became the snapshot
obligation's current revision, failed that generation's finality check,
and the buyer posted revision_missing over the snapshot obligation's
received. Both obligations were also flagged ASSOCIATED_HISTORY_INCOMPLETE.

When obligations at different required_finality share a slice, each now
chooses among the revisions at its own finality (core/reporting-obligation
"complete requires a published revision at required_finality"). Explicit
materialization joins stay candidates, a predecessor attributed to the
sibling is not reported missing, and revision_count matches either the
obligation's own revisions or the slice. reconcileReportingCoreV1 joins the
same way instead of throwing. Single-obligation slices are unchanged.

getMediaBuyDelivery now receives options.reportingObligation naming the
obligation each exact-revision read is for. The wire request is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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.

Clean, additive finality-sibling fix. selectCurrent (reconciliation.ts:2060) and reconcileReportingCoreV1 (core-reconciliation.ts:422) finality-filter slice candidates only when a sibling obligation shares the slice at a different required_finality; candidates === slice reference-equality (reconciliation.ts:2070) keeps the single-obligation path byte-identical. Ledger finality is binary ('snapshot'|'official'), so no third-value edge. Relaxations only loosen in sibling mode; a genuinely missing snapshot still surfaces via MISSING_CURRENT_REVISION. New optional field + exported type is additive; minor changeset is correct and exports resolve.

No Critical/High/Medium findings. Not a no-auto-approve-team author; gated_paths is false; high_risk is false. Rows 1–8 do not fire — falls through to row 9.

@rachitm022
rachitm022 merged commit b2c529d into main Nov 30, 2026
45 checks passed
@rachitm022
rachitm022 deleted the rmatani/ai-25649-ts-sdk-pick-each-obligations-current branch November 30, 2026 10:23
rachitm022 added a commit to adcontextprotocol/adcp-client-python that referenced this pull request Nov 30, 2026
…nality (#1988)

A seller can owe two obligations for one account, report, reporting
profile, media buys and period that differ only in required_finality: a
snapshot pacing feed and an official billing feed. A revision does not name
its obligation, so without explicit ownership the buyer joined both
obligations to every revision of the slice. Once the official revision
existed, the snapshot obligation selected it, both obligations were
diagnosed AMBIGUOUS_REVISION_OWNERSHIP and ASSOCIATED_HISTORY_INCOMPLETE, and
reconcile_reporting_core refused to plan any consumer status
(ConsumerStatusPlanError: the slice's revisions against a per-obligation
revision_count).

When another obligation shares the slice at a different required_finality,
each obligation now selects among the revisions at its own finality, plus
any the seller materialized for it. Supersession and fork checks run over
those options; an official revision naming the snapshot it replaces from
the sibling's chain is not a missing predecessor. revision_count matches if
it equals either the obligation's own revisions or the whole slice; any
other count is diagnosed with the logical-slice bounds as before. The
finality join settles attribution only: known owners and count bounds keep
the logical-slice association, so no ledger that was diagnosed before now
raises. A slice with one obligation, or whose obligations all require one
finality, takes the existing code path.

reconcile_reporting_core feeds the planner the evaluator's own partition.
plan_consumer_statuses takes an optional revision_slices mapping for callers
who build partitions themselves. ReportingReconciliationResult.revision_reads
lists each exact-revision read with a ReportingRevisionReadObligation
(reporting_obligation_id, delivery_config_id, delivery_config_version), local
context that is never part of the request sent to the seller.

Matches adcontextprotocol/adcp-client#3831.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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