Skip to content

feat(reporting): support PT5M reliable reporting periods - #3854

Open
rachitm022 wants to merge 6 commits into
mainfrom
rachitm022/pt5m-rr-conformance
Open

rachitm022 wants to merge 6 commits into
mainfrom
rachitm022/pt5m-rr-conformance

Conversation

@rachitm022

Copy link
Copy Markdown
Collaborator

Summary

  • support source-timezone elapsed sub-day reporting periods, including PT5M across DST, with protocol phase and duration guards
  • commit zero-row periods and suppress unchanged provisional restatements while preserving successful-read watermarks and crash-safe replay
  • prove 288 periods per account-day through production, status paging, inline source, and notification coverage

Verification

  • npm test
  • npm run typecheck
  • npm run format:check
  • npm run lint:boundaries
  • focused reporting source, inline, ledger, and service suites

The PostgreSQL notification test requires a database URL and was skipped locally; CI supplies the integration environment.

Notification behavior

This intentionally preserves the current reporting.ledger_changed event for an empty first snapshot. If adcontextprotocol/adcp#9354 lands, the suppression belongs in packages/reporting-storage/src/postgres.ts commitRevision immediately before recordLedgerChanged.

Linear: AI-26996.

@rachitm022
rachitm022 requested a review from bokelley December 6, 2026 09:23

@bokelley bokelley left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this. PT5M support is a big step, and the DST and paging work is careful. A hand review while the bot is down: one blocker, plus a few issues to fix before merge. Line numbers are against the head I reviewed and may have shifted after the branch was updated from main.

Blocker: the seller's sub-day grid is counted from 1970, not from each local day

  • Where: src/lib/reporting/service/index.ts ~2304 anchors on origin1970 + n·period. The phase scans (service/index.ts ~2313 and producer.ts ~2116) check offsets from the anchor or the 400-day horizon, not from the local day.

  • Effect: in zones whose 1970 offset isn't a whole multiple of the period, periods start off the local boundary. Probed against our own buyer calendar (createReportingPeriodCalendarV1):

    Zone, period This PR (local) Spec/buyer (local)
    Asia/Singapore PT1H 08:30, 09:30 08:00, 09:00
    Asia/Kathmandu PT30M 05:45, 06:15 06:00, 06:30
    Africa/Monrovia PT5M 00:04, 00:09 00:00, 00:05

    The buyer then reports every period as missing, so the ledger never becomes definitive. The spec says hourly periods start on the local hour in every zone, whatever its 1970 offset. The vector sub-daily-local-periods-start-on-the-local-hour-asia-singapore in adcp's reporting-subscriptions/vectors.json encodes exactly this.

  • Fix: for local sub-day schedules, check that the anchor's local time of day is a multiple of the period, rather than (anchor − origin1970) % period. Please run the seller grid against the sub-daily vectors.

Issues

  1. The change-only check can compare against a stale read after a crash (producer.ts ~749). If the process crashes after commitRevision but before updateObligation, with no suppressed read before it, lastSourceRead is read N−1 while the ledger holds read N. An unchanged re-read then commits a duplicate revision, and content that reverts to N−1 is suppressed, leaving stale data. Suggest taking latestSuccessfulRead as the newer of lastSourceRead and the latest publication (by observedAt), plus a crash-after-commit test with no earlier suppressed read.
  2. The UTC sub-day check now depends on the season (service/index.ts ~1956/1977). assertConstantUtcOffset only runs for day-length periods, so a utc + PT5M offering pinned to Europe/London validates in December and throws in July. Please keep the constant-offset check for UTC sub-day schedules.
  3. The account-timezone guard is removed with no replacement (service/index.ts ~1243). Owed sub-day periods are no longer checked against the source timezone's grid. Please add a sub-day version of the guard.
  4. start_date/end_date now carry either a date or an instant (inline.ts ~41, ~2658), on the stable reporting/source surface. A host that forwards them to get_media_buy_delivery breaks that schema's YYYY-MM-DD pattern. Please add explicit start_time/end_time instead.
  5. Semver: @adcp/sdk/reporting/source is a stable subpath, and reportingUtcOffsetsPreservePeriodPhaseV1 (source.ts ~727) becomes public API there. Sub-day offerings that used to be refused are now accepted, so this should be a minor changeset. Please keep the phase helper internal unless it needs to be public.

Nits

  • The producer uses Date.now() instead of its injected clock, and the sub-day phase check is duplicated in the producer and the service with different scan windows.
  • The PG test went from 7 rows to 0, which loses the non-empty case.
  • Paging is tested at 288 periods but not at 300 (fall-back day).
  • Docs note: with the default maxHistorySlicesPerSource of 10, a day of backfill takes 29 cycles. One PT5M feed fills the buyer's default maxRecords (100k) in about 85 days, so buyers need changes_after.

Spec side: we'll add PT5M vectors to adcp: America/New_York spring-forward (276 periods) and fall-back (300), Africa/Monrovia, and Australia/Lord_Howe.

The baseline CI failures (registry types, security audit) are fixed on main. I've updated the branch, so they should clear.

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

Copy link
Copy Markdown
Collaborator Author

Addressed the review in c1dab6a57:

  • Source-local sub-day grids now restart from each local day using the same normative calendar implementation as reporting subscriptions. Regression coverage pins Singapore PT1H, Kathmandu PT30M, Monrovia PT5M, New York PT5M spring/fall counts, and Lord Howe PT1H across its half-hour offset change.
  • Crash recovery now prefers a committed publication when commitRevision survived but the obligation update did not, so an unchanged retry cannot create a duplicate revision or suppress a later correction against stale content. The regression crashes immediately after the durable commit with no earlier suppressed read.
  • UTC-aligned schedules validate a zero source offset over the operational horizon for sub-day periods too; the London regression checks both January and July.
  • account_timezone owed sub-day periods are checked against the source-local calendar grid.
  • Inline whole-day reads retain start_date/end_date; sub-day reads now use mutually exclusive RFC 3339 start_time/end_time fields.
  • The phase helper remains internal and the changeset is now minor.

The review nits are covered as well: the injected installation clock is reused, schedule validation is shared, the PostgreSQL non-empty notification case is restored, fall-back paging covers 300 periods/600 status records, and the history/paging budgets are documented.

Verification completed for the changed surface: build, typecheck, boundary lint, formatting, changeset status, and 268 focused reporting tests all pass. The full local suite reached its slow CLI group with one unrelated child-process test exiting before it produced output under concurrent machine load; CI is now running against this commit.

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

Copy link
Copy Markdown
Collaborator Author

Follow-up 1f4dffafb removes redundant service setup that pushed reliable-reporting-service.test.js over CI's 60-second per-file ceiling. The failed shard had 9,275 passes, zero assertion failures, and one timeout cancellation.

Coverage remains complete: the focused producer case keeps the unique 276-period New York spring-forward day; the Monrovia vector covers an ordinary 288-period day; and the paging/zero-row test covers the 300-period New York fall-back day. The service file now passes locally with the same 60-second timeout in 18.7 seconds.

This branch has not been deployed

No deployments
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.

2 participants