Repository navigation
feat(training-agent): implement package and shared MediaBuy frequency caps - #7494
Conversation
… caps Closes #7488. The three frequency-cap compliance scenarios from #7438 and #7449 were gated on capabilities the reference seller never advertised, so they had never executed. The training agent now implements the spec section "Frequency-cap scope and product support": - Advertise media_buy.frequency_capping and the complete executable media_buy.aggregate_frequency_capping domain (sales tenant and legacy capabilities handler). - Resolve product support with seller-wide inheritance for overlay_support.frequency_cap / frequency_cap_support and media_buy_support.frequency_cap (+ frequency_cap_constraints); default catalog products declare both legacy package support and shared-counter participation. - Discovery honours required_overlay_support.frequency_cap_support, required_media_buy_support, and exact media_buy_frequency_cap; returned products carry media_buy_support regardless of fields; proposals echo the bound root cap. - Create, buy, update, and control validate package caps against resolved product constraints and root caps against seller-wide plus every product, rejecting with UNSUPPORTED_FEATURE before any mutation and never clamping. Root caps replace or clear (null) without resetting counters; new_packages are checked against the resulting state; ineligible packages and non-mutable root caps return ACTION_NOT_ALLOWED before capability checks. - available_actions carries update_frequency_caps with applicable_package_ids for heterogeneous buys and update_media_buy_frequency_cap when every active product can change the root cap. - Proposal refinement clears an inherited root cap through remove_media_buy_frequency_cap, replaces it through criteria.media_buy_frequency_cap, and is unable when the revised mix cannot share it. - Delivery totals report reach and frequency at or below the tightest enforced cap. - Requests addressing a synced account by account_id reach the same media buy and fixture catalog as natural-form requests. Compliance: add media_buy_frequency_cap_updates; give the multi-package frequency-cap scenarios explicit bids after the first package (the runner only injects a bid for the first) and use affected_package_ids[*] for membership checks. Spec: state that a root-cap change without update_media_buy_frequency_cap returns ACTION_NOT_ALLOWED ahead of the capability check, and that mutable_fields governs changes to an existing cap. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — reference-seller implementation of package and shared MediaBuy frequency caps.
What I checked:
- No schema-source change (
static/schemas/source/**untouched); the wire surface shipped previously in #7438/#7449 and is present in base schemas, so schema↔docs coherence is not at issue here. - The docs change (
docs/media-buy/specification.mdx) is a one-sentence normative clarification, consistent with the existing wire shape. - Additive compliance scenarios under
static/compliance/source/protocols/media-buy/scenarios/**— new files, not edits to releaseddist/**artifacts, so immutability rules are not implicated. - Changeset present (
.changeset/training-agent-frequency-caps.md) and correctly scoped as a patch for the reference-seller/training-agent implementation. - Reviewer verified authorization-before-capability ordering, resulting-state root-cap rule, AND-semantics validation, and cross-session account bridging against the implementation and test suite.
- New tests accompany the new branches (proposal-negotiation-profiles, frequency-caps).
Decision path: No critical/high/medium findings. gated_paths is false, high_risk is false, no no-auto-approve team match, no prior decision. Rows 1–8 do not fire (review_decision: REVIEW_REQUIRED does not block absent a gated path). Falls through to row 9 → approve.
…cap levels The package-cap paragraph never stated that available_actions authorization runs before the capability check, so the root-cap sentence added earlier referenced a rule the spec did not make. State the order once for package caps (authorization, then capability, then accepted commercial terms) and have the root-cap paragraph apply the same order. Make the training agent honour that order for package caps on control_media_buy as well: the cap gate now runs ahead of the accepted- envelope REQUOTE_REQUIRED checks, so a cap that is both outside capability and outside accepted terms reports UNSUPPORTED_FEATURE. Add unit coverage for authorization-before-capability (out-of-range count on a create-only package, mixed request) and capability-before-terms, and a frequency_cap_capability_updates step that sends an out-of-range count to the create-only package and expects ACTION_NOT_ALLOWED. Co-Authored-By: Claude Fable 5.1 <[email protected]>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean subsequent pass, no blocking findings.
This is a follow-up to a prior approve (head 1473e2d). The reviewer reports zero findings. The delta is correct and consistent: explicit error-code ordering in docs/media-buy/specification.mdx, a pure idempotent frequencyCapMutationRejection gate added to handleControlMediaBuyUnlocked ahead of the REQUOTE_REQUIRED loop, with authorization → capability → accepted-terms ordering and no false rejection on the accepted-terms path. No schema/dist/oneOf/async surface touched; a changeset is present.
Gate checks:
- No critical/high findings (row 1 clear).
- gated_paths: false — row 2 does not apply despite review_decision being REVIEW_REQUIRED.
- high_risk: false — rows 3/5 clear.
- No medium findings (rows 4/8 clear).
- No no-auto-approve team match (row 7 clear).
- Prior decision was approve, not escalate (row 6 clear).
No breaking-class protocol change: this is a training-agent server behavior addition plus normative doc clarification with proper changeset scope. Falls through to row 9 → approve.
Closes #7488.
Why
#7438 and #7449 shipped structured package frequency-cap constraints and the shared MediaBuy-level cap with three compliance scenarios, but every one of them was gated on a capability the reference training seller never advertised, so none of them had ever executed. This makes the training agent implement the spec section "Frequency-cap scope and product support" as written, adds the follow-up
media_buy_frequency_cap_updatesscenario, and gets all four frequency-cap scenarios running green in the storyboard matrix.What changed
Training agent (
server/src/training-agent/)frequency-caps.ts: seller-wide declarations (media_buy.frequency_capping,media_buy.aggregate_frequency_capping), product support resolution with seller-wide inheritance (omitted structured fields inherit and never broaden; product values absent from the seller-wide list are dropped), requirement containment (frequency_cap_support,required_media_buy_support, exactmedia_buy_frequency_cap), cap validation against control mode / per unit / count preset-or-range / window unit-and-interval / suppression, root-cap validation against seller-wide plus every selected product, andmutable_fieldschange detection.overlay_support.frequency_cap: trueandmedia_buy_support.frequency_cap: true; controller-seededoverlay_support.frequency_cap/frequency_cap_support/media_buy_supportflow through the existing fixture path unchanged.required_overlay_support.frequency_cap_supportmatches legacytrueor a containing structured declaration after inheritance (mutable_fields: []never matches a non-empty requirement);required_media_buy_supportandmedia_buy_frequency_capfilter on participation and exact executability;media_buy_supportis projected whenever requested regardless offields; concretetargeting_overlay.frequency_capat discovery resolves through either declaration form; legacy proposals echofrequency_capand compact proposals carrycommercial_terms.frequency_cap.UNSUPPORTED_FEATUREbefore any mutation, never clamped; package caps echoed inpackages[].targeting_overlay, root cap at the response root; proposal execution takes the cap from accepted terms;buy_productsbinds the root cap into the accepted commercial terms.get_media_buysechoes root and package caps separately;available_actions[]carriesupdate_frequency_capswithapplicable_package_idsnaming only eligible packages when the buy is heterogeneous, andupdate_media_buy_frequency_capwhen every active product participates and can change the root cap.update_frequency_capsalone (notupdate_targeting); ineligible package →ACTION_NOT_ALLOWED; field outsidemutable_fieldsor outside constraints →UNSUPPORTED_FEATURE; root replace andnullclear throughcontrol_media_buyandupdate_media_buywith no counter reset;new_packagesrejected atomically when a product cannot join, evaluated on the resulting state (frequency_cap: null+new_packagesadds them uncapped); root-cap changes outside accepted terms →REQUOTE_REQUIRED;ACTION_NOT_ALLOWED.attempted_actionmay beupdate_media_buy_frequency_cap.remove_media_buy_frequency_cap: trueclears an inherited root cap,criteria.media_buy_frequency_capreplaces it, and a revised mix that cannot share the cap isunablewithunsatisfied_constraints: ["media_buy_frequency_cap"].reachandfrequencywith observed frequency at or below the tightest cap.account_id(the runner sends raw sample requests forexpect_errorsteps andcontrol_media_buy) now reach the same media buy and fixture catalog as natural-form requests for the same synced account.Compliance
media_buy_frequency_cap_updatesscenario (17 steps): mutable-root discovery, create with root + independent package cap,update_media_buy_frequency_capavailability, root replace viacontrol_media_buy,new_packagesrejection,frequency_cap: null+new_packagesresulting-state rule, andACTION_NOT_ALLOWEDonce the mix can no longer share a counter.bid_priceon auction packages after the first (the SDK runner only injects a bid for the first package), andaffected_package_ids[*]wildcard paths forfield_containsmembership (a bare array path compares the scalar against the whole array).Spec (
docs/media-buy/specification.mdx): the package-cap paragraph that listsACTION_NOT_ALLOWED/UNSUPPORTED_FEATURE/REQUOTE_REQUIREDnow states the check order explicitly (available_actionsauthorization, then product capability, then accepted commercial terms; the earliest failing check wins), and the root-cap paragraph applies the same order, namingACTION_NOT_ALLOWEDfor a change withoutupdate_media_buy_frequency_cap. The root-cap text previously said the action was required without naming the error code, which the new scenario's negative path needed. The training agent evaluates in that order at both levels:control_media_buyruns the cap gate ahead of the accepted-envelopeREQUOTE_REQUIREDchecks, covered by new unit tests (out-of-range count on a create-only package →ACTION_NOT_ALLOWED; a cap outside seller-wide capability that also differs from the accepted purchase →UNSUPPORTED_FEATURE) and by a newfrequency_cap_capability_updatesstep (reject_create_only_out_of_range_update) that the original in-range step could not distinguish.Testing
Frequency-cap scenarios,
TENANT_PATH=sales, current source bundle (ADCP_STORYBOARD_CANDIDATE_VERSION_MODE=1, as CI runs PRs to main), final code:media_buy_seller/frequency_cap_enforcementmedia_buy_seller/frequency_cap_capability_updatesmedia_buy_seller/media_buy_frequency_cap_readbackmedia_buy_seller/media_buy_frequency_cap_updates(new)storyboards: 4/4 clean | selection: 4 applicable | steps: 51 passed | 0 failed | 0 skipped(re-run on the final head). Before this change all four gradedcapability_unsupported(0 steps executed) because neithermedia_buy.frequency_cappingnormedia_buy.aggregate_frequency_cappingwas advertised.Full
bash scripts/run-storyboards-matrix.sh(same env), every tenant above its floor and all 31 required-clean / required-exact checks passing:si_baselineandsi_sponsored_context_accountabilityclean)Also run locally:
npx tsc --project server/tsconfig.json --noEmitclean.vitest run --config server/vitest.config.ts tests/unit/(full server unit suite, includes the newtraining-agent-frequency-caps.test.tswith 12 tests and 5 new root-cap cases inproposal-negotiation-profiles.test.ts) 614 files, 9388 passed, 31 skipped;npm run test:unit71 files, 1063 passed.node --test tests/lint-storyboard-*.test.cjs228/228;npm run build:compliance(symbol links current);test:storyboard-doc-parity,test:compliance-source-authority,test:compliance-packaged-refs,test:sdk-runner-capability-gates,test:doc-compliance-drift,test:storyboard-sample-request-schema,test:storyboard-response-schema,test:compliance-snippets,test:json-schema,test:schemasall pass.node scripts/check-changeset-protocol-scope.cjs origin/mainandchangeset status --since=origin/main(onepatchbump) pass.Expert review:
code-reviewer,security-reviewer, andad-tech-protocol-expertagents ran on the diff; every Must Fix / Should Fix finding was addressed (two-pass authorization-before-capability ordering, exact-overlap matching for id→natural account bridging, owner-partition catalog precedence, root-capmutable_fieldsenforcement, structural cap validation, softened over-constraining scenario assertions,PACKAGE_NOT_FOUNDpreserved for unknownnew_packagesproducts).Behavior notes for reviewers:
targeting_overlayno longer classifies asupdate_targeting(it is an exact restatement, not a change); a cap-only overlay on a package that has other targeting still classifies as bothupdate_targetingandupdate_frequency_capsbecause the overlay replaces the whole targeting state.reach/frequencyfor any buy with an enforced frequency cap, not only reach-goal buys, and the placeholder reach rounds up soimpressions / reachnever exceeds the cap (a reach-goal buy at 100 impressions now reports reach 34 instead of 33).control_media_buymirrors the pre-existingupdate_media_buyandget_media_buysfallbacks; it does not widen what an authenticated principal can reach, but the pre-existing brand-plus-operator matching for natural-reference buys under one principal is unchanged.Follow-ups
@adcp/sdk14.0.0-rc.35validateRefineProposalsRequestrejectsremove_media_buy_frequency_cap(not in its revise-key allowlist) andcriteria.media_buy_frequency_cap/criteria.required_media_buy_support(not in its criteria-key allowlist), so the training agent's refinement handling is unit-tested directly and cannot yet be exercised through the hostedrefine_proposalstool. Tracked in refine_proposals: SDK preflight rejects remove_media_buy_frequency_cap and criteria.media_buy_frequency_cap #7493, which also covers the scenario step to add once an SDK with the allowlist fix is adopted.🤖 Generated with Claude Code
Open workspace in Conductor