Skip to content

fix: page get_reporting_status by max_results and size; validate a server's own large responses - #1967

Merged
rachitm022 merged 3 commits into
nextfrom
claude/issue-1966-reporting-status-paging-and-response-cap
Nov 25, 2026
Merged

rachitm022 merged 3 commits into
nextfrom
claude/issue-1966-reporting-status-paging-and-response-cap

Conversation

@rachitm022

@rachitm022 rachitm022 commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes two SDK problems that staging hit in the embedded sales agent (ESA). ESA works around both today in scope3data/embedded-sales-agent#1362. Closes #1966.

  1. get_reporting_status periods pages now honour pagination.max_results and are bounded by size.
  2. The 10,000-node validator cap no longer refuses a server's own valid responses. Requests and buyer-side response parsing keep the cap.

1. ReportingStatusHandler paging

Problem. The handler served periods in a fixed page of 100 records and ignored pagination.max_results. Each record names every buy in its generation: an obligation of an 80-buy generation is about 350 nodes. On staging, one 69-record page was 11,671 nodes, and the SDK's own response validation refused it.

Spec. core/pagination-request.json (3.2 and 3.3) defines max_results as an integer from 1 to 100, default 50, the "maximum number of items to return per page". The get-reporting-status response says pagination is over the flat union of obligations, revisions, adjustments and consumer statuses, and every page reached from a cursor MUST keep ledger_snapshot_id, ledger_as_of and changes_checkpoint. So a page shorter than max_results is allowed.

Fix (src/adcp/reporting/ledger/status.py):

  • A page carries the buyer's max_results records, or 50 when the buyer omits it. A value outside 1-100, or a non-integer, is refused with INVALID_PAGE_SIZE, an existing correctable reporting code. The handler's page_size (default 100) is the seller's ceiling.
  • The handler renders records one at a time and stops before the page would pass page_node_budget JSON nodes. The default is DEFAULT_STATUS_PAGE_NODE_BUDGET = 8,000, four fifths of the 10,000-node cap. The buyer's SDK still applies that cap to what it receives (see §2), so pages must stay under it whatever the seller's own validation allows. The other 2,000 nodes leave room for version conversion, subscription_coverage and response enhancers.
  • The cursor stores the absolute offset of the next record, under the same snapshot and lower bound. The walk returns every record exactly once. A page always carries at least one record, so every walk ends. A single record that doesn't fit alongside the scope is still served, and a warning names the account and the node counts.
  • ReportingStatusHandler(store, page_size=..., page_node_budget=...) are public keyword arguments, and both are read-only properties too. page_node_budget=None bounds a page by record count only. The handler type is unchanged, so status-notification readiness (type(projection) is ReportingStatusHandler) still accepts it.

Default page size. Previously every page held up to 100 records. Now a request without max_results gets the schema default of 50. A request with max_results gets that many, up to 100. Both are correct steps of the same cursor walk, so a buyer that follows pagination.cursor sees no difference except the number of pages.

2. The response node cap

History. git log -S _MAX_PAYLOAD_NODES finds one commit: 5bf9434 (#256 review, 2026-04-23). It added "Cap issue list at 50 and payload node count at 10k to bound CPU on hostile or accidentally-huge payloads before iter_errors walks them". The threat is a peer sending a payload large enough to make the receiver spend its CPU in jsonschema.

Problem. The server dispatcher (create_tool_caller in src/adcp/server/mcp_tools.py) applied that cap to the seller's own responses, both before version conversion (application version) and after (wire version). A large valid response was refused outright, so the buyer got nothing. This happened to get_media_buys, list_accounts and get_reporting_status on staging.

Decision. The cap stays wherever the payload comes from a peer. A server's own responses get a separate budget, and a response over that budget is sent and logged as an error, never refused for size.

payload before after
inbound request (server) refused at 10,000 nodes unchanged
response parsed by a client (ADCPClient hooks, validate_response default) refused at 10,000 nodes unchanged
server's own response, under server_response_max_nodes (default 100,000) refused at 10,000 nodes validated in full; strict still refuses any schema violation
server's own response, at or over the budget refused sent without validation, logged at ERROR with extra={"adcp_validation": "response_over_budget", "adcp_tool", "adcp_validation_budget"}
server_response_max_nodes=None n/a every response validated in full

Why this is safe.

  • Request-side protection doesn't change. validate_request still uses the fixed cap and takes no new parameter. A test sends a 10,001-node request to a server configured with server_response_max_nodes=None and confirms it is still refused with VALIDATION_ERROR.
  • The DoS threat doesn't apply to a server's own output. The server built the response and is about to serialize and send it. A buyer can't make it larger than the seller's own handler already chose, and every request input is capped first.
  • The budget still bounds CPU. I measured jsonschema at about 13-15 µs per node on get_media_buys (3,300 nodes in 41 ms; 99,000 nodes in 1.43 s, compared with 5 ms for json.dumps). Validation is synchronous on the event loop, so no budget at all would let a very large response stall the loop. 100,000 nodes caps the stall at about 1.5 s and covers the staging cases with room to spare: 31,352 media-buy ids on list_accounts before ESA trimmed it, and 11,000 to 16,000 nodes on status pages.
  • No response is skipped silently. Over the budget, the SDK logs an ERROR every time, with a stable extra key that alerts can match. The message names the tool, the budget, and how to change it. An adopter who wants every response validated whatever the cost sets None.
  • Why I didn't use a cheaper fallback validation. I considered validating a sample (arrays truncated to their first N items) and rejected it. The bundled schemas use contains 2,792 times and maxItems widely. Truncating arrays changes which if/then branch matches and hides maxItems violations. The result would neither prove the response valid nor reliably flag an invalid one. An honest ERROR is better than a false pass or a false refusal.

API.

  • ValidationHookConfig.server_response_max_nodes: int | None = DEFAULT_SERVER_RESPONSE_MAX_NODES (100,000). It is checked in __post_init__ and applies only to the server dispatcher.
  • validate_response(..., max_nodes=DEFAULT_MAX_PAYLOAD_NODES) takes a keyword-only override. None means no cap and is meant only for payloads this process built.
  • adcp.validation.DEFAULT_MAX_PAYLOAD_NODES and adcp.validation.count_payload_nodes(payload, limit=None) are now public. The private _MAX_PAYLOAD_NODES and _count_nodes stay as aliases so existing imports, including ESA's, keep working.

ESA follow-up (scope3data/embedded-sales-agent#1362)

#1362 relies on three private SDK internals: ReportingStatusHandler._page_size, adcp.validation.schema_validator._MAX_PAYLOAD_NODES and _count_nodes. The public replacements:

#1362 uses replacement
handler._page_size = n, set from a ContextVar in _reporting_status_handler_for_support nothing: size-bounded paging is the default. ReportingStatusHandler(store, page_size=..., page_node_budget=...) if ESA ever needs other limits
_reporting_status_within_budget retry loop, _StatusPageOverrun, _status_page_overrun, _status_page_records, _STATUS_PAGE_SIZE, _STATUS_PAGE_ATTEMPTS nothing: the SDK cuts the page at render time, in one pass with no ledger re-read
STATUS_PAGE_NODE_BUDGET = _MAX_PAYLOAD_NODES * 4 // 5 adcp.reporting.ledger.DEFAULT_STATUS_PAGE_NODE_BUDGET (same value, 8,000)
_count_nodes(value, sys.maxsize) adcp.validation.count_payload_nodes(value)
_MAX_PAYLOAD_NODES adcp.validation.DEFAULT_MAX_PAYLOAD_NODES

Once ESA pins a release containing this PR, it can remove all of #1362's get_reporting_status page-shrinking: the block under # --- get_reporting_status page size, the _reporting_status_handler_for_support override, and _reporting_status_within_budget, so that get_reporting_status calls super() directly. The tests TestStatusPageBudget and test_the_cut_page_size_reaches_the_sdks_own_handler go with it. Until then #1362 keeps working on this release: its _page_size write is still honoured as the seller ceiling. The SDK's page already fits ESA's 8,000-node budget, so the retry loop only runs if something added after rendering, such as subscription coverage, pushes the page over.

ESA should keep #1362's list_accounts generation retention (_listed_generations). That change fixes ESA's own data and the account schema's maxItems: 16, so this PR doesn't replace it.

Scope-wide generations and issues (split to #1968)

Every page also repeats parts that grow with the account, not the page: scope.delivery_config_generations (about 4 nodes per generation) and, for a period horizon before ledger_retained_from, one HISTORY_UNAVAILABLE issue per generation (about 12 nodes each). The scope-level issues list also carries one issue per open obligation (for example REPORT_OVERDUE).

This PR bounds the page around them. The records give way to the fixed part. A new test reproduces staging's 334-generation account (hourly re-versions) with a horizon that predates retention. Every page stays within 8,000 nodes, carries an identical scope and issues, and the walk returns all 668 records once under one snapshot. The measured fixed part is about 5,500 nodes, so it fits up to roughly 500 generations with a horizon (about 2,000 without one).

Shrinking the scope itself is split out to #1968, for these reasons:

  • Per-page filtering would break the spec. The schema defines scope as the "Exact denominator evaluated for summary or periods health", and top-level health and issues describe that whole denominator. Listing only generations that own a period on the page would make health and scope disagree and change mid-walk. _scope_to_wire already documents that the scope must be identical on every page.
  • Horizon filtering is allowed but doesn't help staging. Restricting the denominator to generations whose lifetime overlaps the horizon is permitted by the spec. Staging's generations were all created within days, though, so any realistic horizon overlaps all of them.
  • The driver is semantic and shared with push. status_retained_from takes the newest generation's activation as ledger_retained_from, so any earlier horizon reports coverage_complete: false and one HISTORY_UNAVAILABLE per generation, even though nothing was owed before that activation. Fixing that changes health in summary, periods and status push notifications. It needs its own review, an interop check against the TS SDK, and possibly spec clarification.

Release notes

  • Fix (reporting): get_reporting_status periods pages honour pagination.max_results (default 50, range 1-100; out of range → INVALID_PAGE_SIZE). Pages also stop before 8,000 JSON nodes, so a large account comes back over more, smaller pages under one ledger_snapshot_id. A buyer that omits max_results now gets 50 records per page instead of 100. New: ReportingStatusHandler(page_size=..., page_node_budget=...) and adcp.reporting.ledger.DEFAULT_STATUS_PAGE_NODE_BUDGET.
  • Fix (server validation): the server no longer refuses its own valid response for exceeding the 10,000-node validator cap. It validates its own responses in full up to ValidationHookConfig.server_response_max_nodes (default 100,000; None = always). Above that budget it sends the response and logs an ERROR (adcp_validation=response_over_budget). Inbound requests and client-side response parsing keep the 10,000-node cap. New public helpers: adcp.validation.count_payload_nodes and DEFAULT_MAX_PAYLOAD_NODES.

Tests

  • tests/test_reporting_status_paging.py (22):
    • max_results is honoured, and a walk returns every record exactly once under one snapshot;
    • an omitted max_results gives 50; 100 is served in full; the seller's page_size caps the buyer;
    • out-of-schema max_results values (0, 101, -1, "5", 2.5, True) are refused;
    • an 80-buy generation renders over 10,000 nodes unbounded. With the default budget, every page is at most 8,000 nodes and the walk returns all 80 records once, with the same snapshot id and checkpoint;
    • an explicit budget works, as do a single oversized record (one per page, with a warning) and None;
    • invalid constructor limits are refused;
    • a 334-generation account with a horizon before retention (marked slow, ~17 s): every page is at most 8,000 nodes, carries an identical scope and issues, and the walk returns all 668 records once.
  • tests/test_schema_validation_size_budget.py (22):
    • node counting and the private aliases;
    • client and hook response parsing still refuse oversize;
    • validate_request, the client request hook and the server dispatcher still refuse an oversized request, even with server_response_max_nodes=None;
    • a 13,000-node valid get_media_buys response is sent under strict validation. That is the staging failure, which takes the conversion path (3.3-rc.3 → 3.2);
    • a 13,000-node response with one invalid record at index 399 is still refused, so full validation ran;
    • over the budget, the response is sent with an ERROR carrying the extra key, in both strict and warn mode;
    • None validates in full; the config is validated.
  • Gates: make lint and make typecheck-all are clean. The reporting, validation, server, MCP and public-API suites pass. The Postgres reporting conformance files (test_pg_reporting_ledger, status wire contract, caller ownership, status lifecycle, feed transports, projection rc6) pass against a local Postgres 16: 277 passed. Full local tests/ run (xdist -n 10, one shared local Postgres): 25,153 passed. The 172 failures were checked: the 146 Postgres lock, lease and feed tests all pass when rerun serially on a fresh database (146 passed), so they were contention on the shared database. The other 34 are installed-wheel, packaging, process-kill and interop-harness tests. They need the CI lanes' isolated builds and process groups, and the interop and killpg ones fail the same way on unmodified next locally.

🤖 Generated with Claude Code

rachitm022 and others added 2 commits November 25, 2026 16:59
…ble budget

The 10,000-node validator cap (#256) bounds the CPU a hostile peer can make
iter_errors spend. The server dispatcher also applied it to the seller's own
responses, before and after version conversion, so a large valid
get_media_buys or list_accounts response was refused and the buyer got
nothing.

Requests and client-side response parsing keep the fixed cap. A server's own
responses are now validated in full up to
ValidationHookConfig.server_response_max_nodes (default 100,000, about 1.5 s
of validation). At or over it the response is sent without schema
validation and logged at ERROR with
extra={"adcp_validation": "response_over_budget"}; None validates every
response in full.

count_payload_nodes and DEFAULT_MAX_PAYLOAD_NODES are now public; the
private spellings remain as aliases.

Refs #1966

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es by size

ReportingStatusHandler served periods in a fixed page of 100 records and
ignored pagination.max_results. Each record names every buy in its
generation, so a staging page of 69 records rendered to 11,671 JSON nodes
and failed the SDK's own 10,000-node validation.

A periods page now carries the buyer's max_results records (schema default
50, range 1-100, otherwise INVALID_PAGE_SIZE), never more than the
handler's page_size, and stops adding records once it would pass
page_node_budget JSON nodes (DEFAULT_STATUS_PAGE_NODE_BUDGET, 8,000: four
fifths of the cap a buyer's SDK applies to responses). The cursor carries
the absolute offset of the next record under the same ledger_snapshot_id,
so a shorter page is a correct step and the walk returns every record once.
A page always carries at least one record; one that cannot fit is served
with a warning.

page_size and page_node_budget are public constructor arguments and
read-only properties. The handler type is unchanged, so status-notification
readiness still accepts it.

Refs #1966

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 review with no blocking findings and nothing Medium-or-worse.

What I checked:

  • No no-auto-approve team match and gated_paths: false, so no hard gate applies.
  • high_risk: true only because src/adcp/server/mcp_tools.py is (modified) — but the reviewer surfaced no Medium-or-higher concern on that file, so per the high-risk guidance a modification that preserves the contract is presumed safe (row 5 does not fire without a medium finding).
  • Two staging fixes: get_reporting_status periods paging now honours pagination.max_results (default 50, range 1–100, else INVALID_PAGE_SIZE) and stops before an 8,000-node budget; the server validates its own large responses up to a configurable server_response_max_nodes (default 100,000) and sends-with-ERROR-log above it.
  • Paging math is conservative (node estimate ≥ actual), progress is guaranteed (first record always served under the taken guard, warning when it alone overflows), the cursor walk returns every record exactly once under one snapshot, and the untrusted-input 10,000-node cap stays on requests and client-parsed responses.
  • New tests accompany both branches (test_reporting_status_paging.py, test_schema_validation_size_budget.py); public-API snapshot updated.

No critical/high (row 1), no gated-paths trigger (row 2), no deletions (row 3), no medium data-loss/schema/infra finding (row 4), no medium on modified high-risk file (row 5), no prior escalation (row 6), no team gate (row 7), fewer than three medium findings (row 8). Falls through to row 9 → approve.

…budget

334 hourly generations (staging's account 6082151998) with a horizon that
predates ledger_retained_from: every page repeats the full scope and one
HISTORY_UNAVAILABLE issue per generation, stays within
DEFAULT_STATUS_PAGE_NODE_BUDGET, and the walk returns all 668 records once
under one snapshot with an identical scope on every page.

Bounding the scope-wide part itself is a semantic change to the shared
health projection, tracked in #1968.

Refs #1966

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 — test-only delta with no blocking findings.

This PR adds _re_versioned_ledger plus a slow reproduction test for the periods node-budget paging failure observed in staging (334 config generations, account 6082151998). The reviewer verified helper kwargs (delivery_config_version, activated_at, deactivated_at, media_buy_ids, reporting_obligation_id) are valid passthroughs and deactivated_at is a real ReportingConfiguration field. Assertions are load-bearing (budget ends the first page, scope/issues/snapshot invariant across pages, 668 records once with no duplicates). Production paging is unchanged since the prior clean pass.

High-risk flag is true only because src/adcp/server/mcp_tools.py was modified, but the reviewer surfaced no medium-or-higher concerns on that file, so the modification is presumed safe (not an escalation trigger on the flag alone). gated_paths is false and review_decision is APPROVED. No no-auto-approve team match. No current findings and no prior blockers to re-surface (prior decision was also approve). Falls through to row 9.

Blocking findings: none.
Medium findings: none.

@rachitm022
rachitm022 merged commit 7f89012 into next Nov 25, 2026
41 checks passed
@rachitm022
rachitm022 deleted the claude/issue-1966-reporting-status-paging-and-response-cap branch November 25, 2026 12:32
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