Repository navigation
fix(training-agent): refuse inventory goal bookings above the available forecast - #9206
Conversation
…le forecast The inventory tenants booked a guaranteed impression goal however far it exceeded the forecast, so the shortfall surfaced only as under-delivery. - create_media_buy refuses a goal package (explicit impressions, or what the budget buys) whose goal exceeds the available forecast for its cells and flight, net of existing reservations, using the same computation forecast() reports. It surfaces as PRODUCT_UNAVAILABLE, naming the goal and the available impressions, with field pointing at impressions or budget. - update_media_buy applies the same check when impressions rise, excluding the package's own reservation; lowering always succeeds, and a refused raise leaves the booking unchanged. - reservations() spreads each goal booking's remaining goal over its own serving days, from tomorrow or its flight start, and adds only the days inside the query window, so a forecast that opens mid-flight no longer understates availability. Fixes #9198 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for picking this up so fast. Two gaps with overlapping goals (sports_fans cells sit inside ros_display):
Both go away if reservations are made one booking at a time on the residual forecast, narrowest daily supply first (the delivery order), and the check runs that with the candidate included, refusing only if some booking can't be fully reserved. Our fork PR does the first part (yvassiliadis#2); happy to rebase it onto #9206 and extend it to the check, or leave it to you. Minor: #9206 spreads from tomorrow; today hasn't served yet, so starting today avoids a slight over-reservation. |
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean fix with no blocking or medium findings.
The change refuses guaranteed goal bookings above available forecast (on create and on raised impressions), netting out other bookings and the booking's own reservation. The reservations refactor (servingDays/netForecast, simulation.ts) correctly spreads each goal's remaining impressions over its own serving days and adds only the in-window share, fixing the mid-flight-window understatement. Engine-level goal-first ordering plus save-only-on-success persistence means a refused raise discards the whole patch (tests confirm "the refusal books nothing"). INSUFFICIENT_INVENTORY→PRODUCT_UNAVAILABLE mapping and field selection are correct; delivery pacing never reads reservations.
Scope is training-agent code plus a non-normative docs page — no schema/oneOf/dist/governance/changeset concerns apply. Docs↔code claim holds. 75/75 suites pass with 10 new tests. No critical/high/medium findings.
Decision table: no blocking findings (rows 1), gated_paths false (row 2), high_risk false (rows 3-5), no prior decision (row 6), no team gate (row 7), zero medium findings (row 8) → falls through to row 9 = approve. Note: review_decision is REVIEW_REQUIRED but gated_paths is false, so row 2 does not fire.
…today's service Review follow-ups on the #9198 goal check: - A booking confirmed before today also serves today, which has not run yet, so its serving days (and its reservation spread) start today. A raise near the end of a flight is no longer refused against tomorrow's capacity alone. A new booking and forecast() still start tomorrow. - update_media_buy applies raised impressions after every other change in the request, and re-checks each raised goal against the state the whole request leaves, so the outcome no longer depends on package order. - Root canceled: true ignores the request's other fields, and a package's canceled: true ignores its sibling fields, as update_media_buy's cancellation precedence requires; a raise beside a cancellation can no longer block it. Refs #9198 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@yvassiliadis thanks, this is a careful read. You're right on 1 and 2. Both come from the proportional reservation model that Point 3 is in a3a7568. A booking confirmed before today now counts today among its serving days, both in the reservation spread and in the raise check. Residual allocation in delivery order is the right next step. Once #9206 merges, please rebase yvassiliadis#2 onto main and extend |
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — training-agent inventory-sim refactor with no blocking or medium findings.
Checked:
platform.tsupdate_media_buy restructure: root/package cancel precedence correctly short-circuits; deferred raises applied after other changes and re-checked together when >1; individual raise checks are optimistic (cannot falsely fail); a refused raise throws beforemarket.save()so the whole request discards — confirmed by the tenant reread test.simulation.tsservingDays "today counts" change and newrequireGoalAvailable: servingDays/forecast remain consistent (existing booking counts today, new booking starts tomorrow).- Added engine/tenant unit tests cover the new branches.
- One non-normative docs line under
docs/building/**.
Scope/gates:
- No
static/schemas/source/**,dist/**, task-definition, or normativedocs/reference/**surface touched — no changeset required; training-agent + non-normative docs only. - No oneOf discriminator surface, no schema↔docs coherence concern, no async/worker/billing path.
- high_risk: false; gated_paths: false; no no-auto-approve team match.
- Prior decision was
approve; this subsequent pass over the delta surfaces no new findings.
No critical/high/medium findings → decision table falls through to row 9 (approve).
|
Plan for the follow-up after #9206 merges, one modelling question first. Flight-total reservations (ours and #9206's) overstate or understate room when a new booking starts mid-way through a live one on shared cells, because delivery paces daily (ceil(left/daysLeft)) and can only catch up later. Test seed: ROS days 0-30, goal 225k; sports_fans wants days 15-30: flight totals allow 75k, the true maximum is 37.5k, #9206 gives 22.5k. Proposal: compute Separately, for you: a share-of-voice booking is only checked against other share-of-voice bookings, so it can starve goals; and shortening flight_end is never re-checked. |
|
@yvassiliadis The dry run is the right model. Please take it in the follow-up rather than documenting the gap. Since it checks every change against delivery, please use it for share-of-voice bookings and for a shortened |
…, certification retry (adcontextprotocol#9196), release-audit changesets (adcontextprotocol#8879), reporting subscriber suspend and resume (adcontextprotocol#9199), inventory goal forecast refusal (adcontextprotocol#9206), enum hoisting annotations (adcontextprotocol#9167), format_option_ref (adcontextprotocol#8876), claim-priority indexes (adcontextprotocol#9219) Two conflicts. Resolution ledger: - semantic: package.json `test` -> union: this branch's chain (the suites it added and the build-cache and git-env steps) plus main's test:build-schemas-hoist-enum-annotations and test:build-schemas-hoist-inside-definitions, after test:build-schemas-exit-status. Every script main's chain runs is in the merged chain. Dependencies auto-merged to main's versions. - semantic: server/src/training-agent/gcs-reporting.ts imports -> union: this branch's narrow `@adcp/sdk/utils` import of canonicalize; main's randomUUID import and its added `@adcp/sdk/server` names. The rest of the file auto-merged. - mechanical: package-lock.json -> main's (auto-merged; this branch does not change it). Checks: npm ci on main's lockfile (SDK 17.0.0-beta.40), npm run typecheck, and the pre-commit hook's full run.
Fixes #9198.
Summary
The inventory tenants (
/inventory-adserver,/inventory-content) accepted a guaranteed impression goal larger than the forecast available to it. The shortfall showed up only later, as under-delivery. Separately, a forecast window that started mid-flight of an existing booking understated availability.create_media_buy.InventorySimulation.book()refuses a goal booking whose goal exceeds the forecast'savailablefor its cells and flight, net of existing reservations. It refuses rather than caps. The goal is either the package'simpressionsor what its budget buys at the fixed price. The check runs through the samenetForecast()computation thatforecast()uses, so theget_productsfigure and the check agree. The new engine codeINSUFFICIENT_INVENTORYmaps to wirePRODUCT_UNAVAILABLE, the same mappingSOLD_OUTalready gets. The message names the requested goal and the available impressions, for exampleRequested 9196934 impressions, but only 3065645 are available on ros_display_guaranteed for this flight and targeting.fieldispackages[i].impressions, orpackages[i].budgetwhen the goal came from the budget.update_media_buy.impressionsgets the same check. The package's own reservation is excluded, andnewGoal − deliveredis weighed against what its remaining serving days have available. A booking that already serves counts today, which has not run yet. Lowering the goal or leaving it unchanged always succeeds.end_time, pauses. When more than one goal is raised, each is re-checked against the state the whole request leaves (requireGoalAvailable). The outcome therefore does not depend on package order.update_media_buy.mdx. Rootcanceled: trueignores the request's other fields. A package'scanceled: trueignores its sibling fields. Before this PR, those other fields were applied anyway. With the new check, a raise sent alongside a cancel could also have blocked the cancel.reservations(). Each goal booking's remaining goal is spread over its own serving days, whatever the query window, and only the days inside the window are added. Those serving days run from today for a booking already serving, and from tomorrow or the flight start for a new one. On the reporter's flight, booking A at 75% used to consume the whole of a Feb 15–28 window. That window now holds only A's in-window share, about 4.6M of 6.1M.simulated-inventory-agents.mdxnow describes the refusal on create, on raisedimpressions, and the cancellation precedence.Checks requested in the handoff
runDaytargetsceil(left / daysLeft), anddelivery()'sexpected_impressionsis a straight line. Neither callsreservations().Known limits
The check deliberately keeps
forecast()'s proportional reservation model, so that the check and the forecast agree. That model is approximate where products overlap (sports_fans inside ros_display): it can over-count free inventory on shared cells, and it can refuse a narrower goal behind a wider one. The reporter's residual-allocation model (yvassiliadis#2) is the follow-up. See the PR conversation.Tests
All new tests are in two files:
server/tests/unit/inventory-sim-engine.test.ts, undergoal against forecast (#9198):server/tests/unit/training-agent-inventory-tenants.test.ts, each with a fresh credential and the clock pinned to 2026-12-31T12:00Z:packages[0].impressionsand books nothing. A raise is refused, and a decrease is accepted.packages[0].budget.Results:
npm run typecheckis clean.node scripts/link-compliance-symbols.mjs --checkis clean.Notes
check-changeset-protocol-scope.cjsreports no protocol-scoped changes.end_time. That is out of scope, per the issue.🤖 Generated with Claude Code