Skip to content

fix(training-agent): refuse inventory goal bookings above the available forecast - #9206

Merged
bokelley merged 2 commits into
mainfrom
fix/inventory-sim-goal-over-forecast-9198
Nov 24, 2026
Merged

bokelley merged 2 commits into
mainfrom
fix/inventory-sim-goal-over-forecast-9198

Conversation

@bokelley

@bokelley bokelley commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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's available for its cells and flight, net of existing reservations. It refuses rather than caps. The goal is either the package's impressions or what its budget buys at the fixed price. The check runs through the same netForecast() computation that forecast() uses, so the get_products figure and the check agree. The new engine code INSUFFICIENT_INVENTORY maps to wire PRODUCT_UNAVAILABLE, the same mapping SOLD_OUT already gets. The message names the requested goal and the available impressions, for example Requested 9196934 impressions, but only 3065645 are available on ros_display_guaranteed for this flight and targeting. field is packages[i].impressions, or packages[i].budget when the goal came from the budget.
  • update_media_buy.
    • Raising impressions gets the same check. The package's own reservation is excluded, and newGoal − delivered is 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.
    • Raised goals are applied after every other change in the request: cancels, decreases, budgets, 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.
    • A refusal fails the whole request, and nothing is saved.
    • Cancellation precedence follows update_media_buy.mdx. Root canceled: true ignores the request's other fields. A package's canceled: true ignores 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.
  • Docs. simulated-inventory-agents.mdx now describes the refusal on create, on raised impressions, and the cancellation precedence.

Checks requested in the handoff

  • Budget-derived goals go through the same check. The goal is derived before the check runs.
  • Delivery pacing never read the reservation spread. runDay targets ceil(left / daysLeft), and delivery()'s expected_impressions is a straight line. Neither calls reservations().
  • The content tenant's built-in products are all share-of-voice sponsorships, so its goal bookings come only from seeded guaranteed products.

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:

  • Engine. In server/tests/unit/inventory-sim-engine.test.ts, under goal against forecast (#9198):
    • the reporter's case, hard-coded to 12,262,579 / 9,196,934 / 3,065,645;
    • an exact fit, and a goal one impression over;
    • a budget-derived goal;
    • raises: refused, and an exact fit, with the booking's own reservation excluded;
    • a raise after delivery, and a raise on the last serving day;
    • a new booking still starts tomorrow;
    • a refused raise leaves the whole patch unapplied;
    • a decrease, and an unchanged goal;
    • the mid-flight window;
    • overlapping products, where the final re-check catches an earlier raise in either order.
  • Tenant, over MCP. In server/tests/unit/training-agent-inventory-tenants.test.ts, each with a fresh credential and the clock pinned to 2026-12-31T12:00Z:
    • adserver: A then B at 75% each. B is refused on packages[0].impressions and books nothing. A raise is refused, and a decrease is accepted.
    • adserver: a budget-only goal over the forecast, refused on packages[0].budget.
    • adserver: the mid-flight window.
    • adserver: multi-package raise and decrease in either package order. A double raise is refused and changes nothing.
    • adserver: root and package cancellation precedence.
    • content: a seeded guaranteed product, where an over-forecast goal and a second 75% goal are refused.

Results:

  • The three inventory suites pass, 81/81.
  • npm run typecheck is clean.
  • node scripts/link-compliance-symbols.mjs --check is clean.
  • Inventory storyboards on 4999bcf match main exactly: adserver 164/179 clean with 238 passed steps, content 164/178 clean with 220 passed steps.

Notes

  • No changeset: the training agent and a non-normative docs page only. check-changeset-protocol-scope.cjs reports no protocol-scoped changes.
  • Not checked against the forecast: shortening a goal booking's end_time. That is out of scope, per the issue.

🤖 Generated with Claude Code

…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]>
@yvassiliadis

Copy link
Copy Markdown

Thanks for picking this up so fast. Two gaps with overlapping goals (sports_fans cells sit inside ros_display):

  1. Phantom availability: each goal still spreads its reservation evenly over its own cells, independently of the others, so where goals overlap the forecast over-counts what's free, and an overbook on shared cells can pass the new check.
  2. False refusals: requireAvailable checks the candidate against the others' independent reservations. Example on the test seed: ROS books 40% of its forecast first and reserves 24% of the sports cells; sports_fans then asks for its full 60%, sees 36% free and is refused, although high-water-mark serving would deliver both.

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.

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Nov 24, 2026

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

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 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]>
@bokelley

Copy link
Copy Markdown
Contributor Author

@yvassiliadis thanks, this is a careful read. You're right on 1 and 2. Both come from the proportional reservation model that forecast() already used: each goal spreads over its own cells independently of the others. Where products overlap, as sports_fans does inside ros_display, that has two effects. The forecast over-counts what is free on the shared cells. And a narrower goal can be refused behind a wider one, even though high-water-mark delivery would serve it first. #9206 keeps that model on purpose, so that the booking check and the forecast a caller sees agree. What it fixes is the same-product overbooking you reported, and the mid-flight forecast window.

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 requireAvailable to run that allocation with the candidate included. The seam is netForecast() / reservations() in engine/simulation.ts. The create check goes through both, and so does requireGoalAvailable, which update_media_buy runs on each raised goal once the whole request is applied. Changing the model there keeps the forecast and the checks in agreement.

@aao-secretariat aao-secretariat Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ladon verdict: Approve

Approve — training-agent inventory-sim refactor with no blocking or medium findings.

Checked:

  • platform.ts update_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 before market.save() so the whole request discards — confirmed by the tenant reread test.
  • simulation.ts servingDays "today counts" change and new requireGoalAvailable: 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 normative docs/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).

@yvassiliadis

Copy link
Copy Markdown

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 available as the largest goal that a dry run of delivery on the forecast (share-of-voice first, then high-water mark with daily targets, no state written) serves without growing any other guarantee's shortfall, found by bisection. Forecast and check still agree by construction. Two of #9206's tests would change (the "squeezes the earlier raise" case is deliverable and would be accepted; a raise just past capacity is refused instead). OK to go that way, or keep flight totals and document the mid-flight gap?

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.

@bokelley

Copy link
Copy Markdown
Contributor Author

@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 end_time too, which covers both of your separate points. Updating #9206's two tests to match is fine. The one thing to watch is get_products cost, since every product's forecast becomes a bisection of dry runs. Memoisation per simulated day and booking revision, a bounded bisection, and a get_products latency figure for the adserver catalogue in the PR would help the review. #9206 stays as scoped: it errs toward refusing, which is the safe side for now.

@bokelley
bokelley merged commit 0fac687 into main Nov 24, 2026
68 checks passed
@bokelley
bokelley deleted the fix/inventory-sim-goal-over-forecast-9198 branch November 24, 2026 09:45
KonstantinMirin added a commit to KonstantinMirin/adcp that referenced this pull request Nov 25, 2026
…, 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.
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.

Inventory tenants accept a guaranteed booking larger than the available forecast

2 participants