Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/reporting-release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ delivery.
an account obligation with such coverage publishes no revision. An exact
scope with a whole-configuration roster, or none, behaves as before.

## Reporting status issues stay within the protocol limit

`ReportingStatusHandler` returns at most 100 `issues` in summary and periods
responses and in each period projection, matching the AdCP response schema.
`action_required` issues are retained before `delayed` issues, with the existing
deterministic issue order preserved within each severity. Obligation counts still
cover the complete selected scope and are not reduced when the issue projection is
truncated. Adopters using the seller-side Reliable Reporting handler should upgrade
before serving scopes that can contain more than 100 concurrent reporting issues.

## Protocol-shape control totals

New Core revisions bind `{name, value, value_type[, unit]}` control totals in
Expand Down
3 changes: 2 additions & 1 deletion src/adcp/reporting/feed/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
_adjustment_to_wire,
_consumer_status_to_wire,
_filters,
_issues_to_wire,
_obligation_to_wire,
_parse,
_revision_to_wire,
Expand Down Expand Up @@ -574,7 +575,7 @@ def shown_prefix(boundaries: tuple[Any, ...]) -> tuple[Any, ...]:
obligations=tuple(p.obligation for p in scope_result.obligations),
),
"health": scope_result.health,
"issues": [issue.to_wire() for issue in scope_result.issues],
"issues": _issues_to_wire(scope_result.issues),
}
if representation_version == 2 and not (
scope_result.health == "complete" and "adcp_version" in filters
Expand Down
13 changes: 10 additions & 3 deletions src/adcp/reporting/ledger/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
"adjustment": "adjustments",
"consumer_status": "consumer_statuses",
}
_STATUS_ISSUE_LIMIT = 100
_ISSUE_SEVERITY_PRIORITY = {"action_required": 0, "delayed": 1, "info": 2}


def _utc(value: datetime) -> datetime:
Expand All @@ -120,6 +122,11 @@ def _iso(value: datetime) -> str:
return _utc(value).isoformat().replace("+00:00", "Z")


def _issues_to_wire(issues: Sequence[ReportingIssue]) -> list[dict[str, Any]]:
prioritized = sorted(issues, key=lambda issue: _ISSUE_SEVERITY_PRIORITY[issue.severity])
return [issue.to_wire() for issue in prioritized[:_STATUS_ISSUE_LIMIT]]


@dataclass(frozen=True)
class ReportingStatusCaller:
"""The authenticated caller, resolved from transport, never from the body.
Expand Down Expand Up @@ -566,7 +573,7 @@ def render_snapshot(
"data_through": _iso(watermark) if watermark else None,
**({"next_expected_at": _iso(next_expected)} if next_expected is not None else {}),
"obligation_counts": counts,
"issues": [i.to_wire() for i in result.issues],
"issues": _issues_to_wire(result.issues),
}
owners = {o.reporting_obligation_id: o for o in obligations}
records: dict[tuple[str, str], Any] = {
Expand Down Expand Up @@ -602,7 +609,7 @@ def render_snapshot(
payload = {
**common,
"health": result.health,
"issues": [issue.to_wire() for issue in result.issues],
"issues": _issues_to_wire(result.issues),
"changes_checkpoint": _encode_checkpoint(sequence, caller=caller),
"periods": page["periods"],
"revisions": page["revisions"],
Expand Down Expand Up @@ -1060,7 +1067,7 @@ def _obligation_to_wire(
"production_status": production_status,
"revision_count": len(revisions),
"adjustment_count": 0,
"issues": [issue.to_wire() for issue in issues],
"issues": _issues_to_wire(issues),
}
if obligation.schedule.period_timezone is not None:
payload["schedule"]["period_timezone"] = obligation.schedule.period_timezone
Expand Down
50 changes: 48 additions & 2 deletions tests/conformance/reporting/test_reporting_feed_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

import pytest

from adcp.reporting.ledger import ReportingMaterializationCheck
from adcp.reporting.ledger import ReportingMaterializationCheck, derive_period
from adcp.reporting.ledger.status import ReportingStatusCaller, ReportingStatusHandler
from adcp.types import GetReportingStatusResponse

from ._feed_support import (
ARRAYS,
feed_harness,
feed_request,
feeds,
mixed_case,
Expand All @@ -21,12 +22,57 @@
without_feed,
)
from ._generation_support import configuration, revision_for
from ._receipt_support import extra_materialization, request_for
from ._receipt_support import extra_materialization, receipt_case, request_for
from .test_reporting_notification_outbox import statement

__all__ = ["feeds"]


async def test_frozen_feed_caps_and_prioritizes_status_issues() -> None:
async with feed_harness("memory") as h:
case = await receipt_case(h)
ledger_as_of = h.clock() + timedelta(days=10)
for ordinal in range(1, 102):
period = derive_period(
case.obligation.schedule, account_timezone="UTC", ordinal=ordinal
)
await h.store.commit_obligation(
replace(
case.obligation,
reporting_obligation_id=f"delayed-obligation-{ordinal:03d}",
period=period,
scope_resolved_at=period.end,
automated_recovery_deadline_at=ledger_as_of + timedelta(days=1),
created_at=period.end,
)
)
period = derive_period(case.obligation.schedule, account_timezone="UTC", ordinal=102)
await h.store.commit_obligation(
replace(
case.obligation,
reporting_obligation_id="action-required-obligation",
period=period,
scope_resolved_at=period.end,
automated_recovery_deadline_at=ledger_as_of,
created_at=period.end,
)
)
h.clock.now = ledger_as_of

page = await h.store.read_reporting_feed(
feed_request(case, limit=100), caller=case.binding.principal
)

GetReportingStatusResponse.model_validate(page)
assert len(page["issues"]) == 100
assert page["issues"][0]["severity"] == "action_required"
delayed_issue_ids = [
issue["issue_id"] for issue in page["issues"] if issue["severity"] == "delayed"
]
assert delayed_issue_ids == sorted(delayed_issue_ids)
assert page["pagination"]["total_count"] == 105


@pytest.mark.parametrize("limit", [1, 5, 6, 7])
async def test_allowlist_exact_totals_dependency_order_and_final_only_checkpoint(feeds, limit):
h = feeds
Expand Down
92 changes: 92 additions & 0 deletions tests/test_reporting_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,98 @@ async def test_summary_escalates_after_the_automated_recovery_window() -> None:
assert payload["issues"][0]["recommended_action"] == "contact_seller"


async def test_status_issue_limit_keeps_actionable_issues_and_complete_counts() -> None:
from adcp.validation.schema_loader import get_named_validator

ledger_as_of = datetime(2026, 9, 30, tzinfo=timezone.utc)
store = InMemoryReportingLedgerStore(clock=lambda: ledger_as_of)
configuration = _configuration()
await store.put_configuration(configuration)
for ordinal in range(1, 102):
await store.commit_obligation(
_obligation(
configuration,
ordinal=ordinal,
automated_recovery_deadline_at=ledger_as_of + timedelta(days=1),
)
)
await store.commit_obligation(
_obligation(
configuration,
ordinal=102,
automated_recovery_deadline_at=ledger_as_of - timedelta(days=1),
)
)

handler = ReportingStatusHandler(store, page_size=1_000)
validator = get_named_validator("media-buy/get-reporting-status-response.json")
assert validator is not None
for view in ("summary", "periods"):
payload = await handler.handle(
{"view": view, "pagination": {"max_results": 100}}, caller=CALLER
)

errors = sorted(validator.iter_errors(payload), key=str)
assert errors == []
assert len(payload["issues"]) == 100
assert payload["issues"][0]["severity"] == "action_required"
delayed_issue_ids = [
issue["issue_id"] for issue in payload["issues"] if issue["severity"] == "delayed"
]
assert delayed_issue_ids == sorted(delayed_issue_ids)
if view == "summary":
assert payload["obligation_counts"] == {
"total": 102,
"waiting": 0,
"healthy": 0,
"delayed": 101,
"action_required": 1,
"complete": 0,
}
else:
assert len(payload["periods"]) == 100
assert all(len(period["issues"]) == 1 for period in payload["periods"])
assert payload["pagination"]["total_count"] == 102
assert payload["pagination"]["has_more"] is True
assert payload["pagination"]["cursor"]


def test_period_projection_applies_the_status_issue_limit() -> None:
from adcp.reporting.ledger.models import ReportingIssue
from adcp.reporting.ledger.status import _obligation_to_wire

issues = tuple(
ReportingIssue(
issue_id=f"issue_{index:03d}",
code="REPORT_OVERDUE",
severity="delayed",
responsible_party="seller",
recommended_action="wait_for_retry",
)
for index in range(101)
) + (
ReportingIssue(
issue_id="issue_action_required",
code="REPORT_OVERDUE",
severity="action_required",
responsible_party="seller",
recommended_action="contact_seller",
),
)

payload = _obligation_to_wire(
_obligation(_configuration()),
revisions=(),
health="action_required",
production_status="pending",
issues=issues,
statuses=(),
)

assert len(payload["issues"]) == 100
assert payload["issues"][0]["issue_id"] == "issue_action_required"


async def test_periods_view_paginates_one_snapshot() -> None:
store, obligation = await _seeded()
revision, rows = _revision(obligation)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_reporting_status_paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ async def _re_versioned_ledger(generations: int, *, buys: int) -> InMemoryReport
@pytest.mark.slow
async def test_a_heavily_re_versioned_account_pages_within_budget_and_completely() -> None:
# Staging's account 6082151998 had 334 generations. Every page repeats the
# scope (the whole evaluated denominator) and, for a horizon that starts
# before ledger_retained_from, one HISTORY_UNAVAILABLE issue per generation.
# Neither shrinks with the page, so the records must make room for them.
# scope (the whole evaluated denominator) and bounded issues for a horizon
# that starts before ledger_retained_from. The records must make room for
# both projections.
store = await _re_versioned_ledger(334, buys=8)
request = {
"view": "periods",
Expand All @@ -236,7 +236,7 @@ async def test_a_heavily_re_versioned_account_pages_within_budget_and_completely
assert page["issues"] == pages[0]["issues"]
assert page["ledger_snapshot_id"] == pages[0]["ledger_snapshot_id"]
assert len(pages[0]["scope"]["delivery_config_generations"]) == 334
# Today's per-generation horizon issue (follow-up: #1968).
assert sum(i["code"] == "HISTORY_UNAVAILABLE" for i in pages[0]["issues"]) == 334
assert len(pages[0]["issues"]) == 100
assert all(i["code"] == "HISTORY_UNAVAILABLE" for i in pages[0]["issues"])
seen = [record for page in pages for record in _record_ids(page)]
assert len(seen) == len(set(seen)) == pages[0]["pagination"]["total_count"] == 668