Repository navigation
fix: page get_reporting_status by max_results and size; validate a server's own large responses - #1967
Conversation
…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]>
There was a problem hiding this comment.
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: trueonly becausesrc/adcp/server/mcp_tools.pyis(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_statusperiods paging now honourspagination.max_results(default 50, range 1–100, elseINVALID_PAGE_SIZE) and stops before an 8,000-node budget; the server validates its own large responses up to a configurableserver_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
takenguard, 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]>
There was a problem hiding this comment.
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.
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.
get_reporting_statusperiods pages now honourpagination.max_resultsand are bounded by size.1.
ReportingStatusHandlerpagingProblem. 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) definesmax_resultsas 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 keepledger_snapshot_id,ledger_as_ofandchanges_checkpoint. So a page shorter thanmax_resultsis allowed.Fix (
src/adcp/reporting/ledger/status.py):max_resultsrecords, or 50 when the buyer omits it. A value outside 1-100, or a non-integer, is refused withINVALID_PAGE_SIZE, an existing correctable reporting code. The handler'spage_size(default 100) is the seller's ceiling.page_node_budgetJSON nodes. The default isDEFAULT_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_coverageand response enhancers.ReportingStatusHandler(store, page_size=..., page_node_budget=...)are public keyword arguments, and both are read-only properties too.page_node_budget=Nonebounds 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_resultsgets the schema default of 50. A request withmax_resultsgets that many, up to 100. Both are correct steps of the same cursor walk, so a buyer that followspagination.cursorsees no difference except the number of pages.2. The response node cap
History.
git log -S _MAX_PAYLOAD_NODESfinds 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 beforeiter_errorswalks 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_callerinsrc/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 toget_media_buys,list_accountsandget_reporting_statuson 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.
ADCPClienthooks,validate_responsedefault)server_response_max_nodes(default 100,000)extra={"adcp_validation": "response_over_budget", "adcp_tool", "adcp_validation_budget"}server_response_max_nodes=NoneWhy this is safe.
validate_requeststill uses the fixed cap and takes no new parameter. A test sends a 10,001-node request to a server configured withserver_response_max_nodes=Noneand confirms it is still refused withVALIDATION_ERROR.get_media_buys(3,300 nodes in 41 ms; 99,000 nodes in 1.43 s, compared with 5 ms forjson.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 onlist_accountsbefore ESA trimmed it, and 11,000 to 16,000 nodes on status pages.extrakey 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 setsNone.contains2,792 times andmaxItemswidely. Truncating arrays changes whichif/thenbranch matches and hidesmaxItemsviolations. 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.Nonemeans no cap and is meant only for payloads this process built.adcp.validation.DEFAULT_MAX_PAYLOAD_NODESandadcp.validation.count_payload_nodes(payload, limit=None)are now public. The private_MAX_PAYLOAD_NODESand_count_nodesstay 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_NODESand_count_nodes. The public replacements:handler._page_size = n, set from aContextVarin_reporting_status_handler_for_supportReportingStatusHandler(store, page_size=..., page_node_budget=...)if ESA ever needs other limits_reporting_status_within_budgetretry loop,_StatusPageOverrun,_status_page_overrun,_status_page_records,_STATUS_PAGE_SIZE,_STATUS_PAGE_ATTEMPTSSTATUS_PAGE_NODE_BUDGET = _MAX_PAYLOAD_NODES * 4 // 5adcp.reporting.ledger.DEFAULT_STATUS_PAGE_NODE_BUDGET(same value, 8,000)_count_nodes(value, sys.maxsize)adcp.validation.count_payload_nodes(value)_MAX_PAYLOAD_NODESadcp.validation.DEFAULT_MAX_PAYLOAD_NODESOnce ESA pins a release containing this PR, it can remove all of #1362's
get_reporting_statuspage-shrinking: the block under# --- get_reporting_status page size, the_reporting_status_handler_for_supportoverride, and_reporting_status_within_budget, so thatget_reporting_statuscallssuper()directly. The testsTestStatusPageBudgetandtest_the_cut_page_size_reaches_the_sdks_own_handlergo with it. Until then #1362 keeps working on this release: its_page_sizewrite 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_accountsgeneration retention (_listed_generations). That change fixes ESA's own data and the account schema'smaxItems: 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 aperiodhorizon beforeledger_retained_from, oneHISTORY_UNAVAILABLEissue per generation (about 12 nodes each). The scope-levelissueslist also carries one issue per open obligation (for exampleREPORT_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
scopeandissues, 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:
scopeas the "Exact denominator evaluated for summary or periods health", and top-levelhealthandissuesdescribe 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_wirealready documents that the scope must be identical on every page.status_retained_fromtakes the newest generation's activation asledger_retained_from, so any earlier horizon reportscoverage_complete: falseand oneHISTORY_UNAVAILABLEper 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
get_reporting_statusperiods pages honourpagination.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 oneledger_snapshot_id. A buyer that omitsmax_resultsnow gets 50 records per page instead of 100. New:ReportingStatusHandler(page_size=..., page_node_budget=...)andadcp.reporting.ledger.DEFAULT_STATUS_PAGE_NODE_BUDGET.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_nodesandDEFAULT_MAX_PAYLOAD_NODES.Tests
tests/test_reporting_status_paging.py(22):max_resultsis honoured, and a walk returns every record exactly once under one snapshot;max_resultsgives 50; 100 is served in full; the seller'spage_sizecaps the buyer;max_resultsvalues (0, 101, -1,"5", 2.5,True) are refused;None;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):validate_request, the client request hook and the server dispatcher still refuse an oversized request, even withserver_response_max_nodes=None;get_media_buysresponse is sent under strict validation. That is the staging failure, which takes the conversion path (3.3-rc.3 → 3.2);extrakey, in both strict and warn mode;Nonevalidates in full; the config is validated.make lintandmake typecheck-allare 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 localtests/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 andkillpgones fail the same way on unmodifiednextlocally.🤖 Generated with Claude Code