Skip to content

fix(training-agent): inventory-content claims only sales-guaranteed; spend never drifts by cents (#9025) - #9052

Merged
bokelley merged 1 commit into
mainfrom
inventory-sim/followups
Nov 16, 2026
Merged

bokelley merged 1 commit into
mainfrom
inventory-sim/followups

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Two follow-ups from the hosted smoke test of the #9025 inventory tenants.

/inventory-content declares only sales-guaranteed

Each inventory tenant now derives its sales specialisms from the delivery types its seed actually sells (inventory-sim/platform.ts).

  • /inventory-content sells guaranteed sponsorships only, so it no longer claims sales-non-guaranteed.
  • /inventory-adserver still declares both.

Spend no longer drifts by cents

Each day's spend was rounded to the cent independently, so a booking's total could drift from its exact cost. On the hosted agent, a guarantee of 180,000 impressions at $14 CPM billed $2,520.02.

  • The fix: each day's spend is now the change in the booking's rounded running total. The engine keeps the unrounded running total in a new field, Booking.spend_exact, so the total is always exact.
  • Bid changes: if a bid changes mid-flight, impressions after the change are priced at the new bid.
  • Older saved state: state saved before this change has no spend_exact, and the engine falls back to delivered.spend.
  • Share-of-voice: the budget cap on share-of-voice buys is unchanged.

Tests

  • Engine: a guarantee of 180,000 impressions at $14 CPM bills exactly $2,520.00, and each buy's daily spends sum to its total. An auction buy whose bid changes from $3.333 to $2.777 mid-flight bills the exact amount. Against the old engine this test fails: it bills $239.93 instead of $239.95.
  • Tenants: /inventory-content declares ['sales-guaranteed'].

Checks run locally

  • npx tsc --project server/tsconfig.json --noEmit: clean.
  • tests/lint-format-identity-boundaries.test.cjs: passes.
  • Both inventory suites pass: 35 tests.

Committed and pushed with HUSKY=0, under the approval for this series. CI's storyboard job is the check that existing storyboards still pass. No changeset: this touches only the training agent.

Refs #9025

🤖 Generated with Claude Code

…spend never drifts by cents (#9025)

Two follow-ups from the hosted smoke of the #9025 inventory tenants:

- An inventory tenant now declares the sales specialisms its seed
  actually sells. /inventory-content sells guaranteed sponsorships only,
  so it drops sales-non-guaranteed; /inventory-adserver keeps both.
- A booking's daily spend is now the change in its rounded cumulative
  spend (Booking.spend_exact), so per-day rounding no longer drifts the
  total: 180,000 impressions at $14 CPM bill $2,520.00, not $2,520.02. A
  bid change mid-flight prices impressions from then on. States saved
  before this fall back to delivered.spend.

The new engine test fails on the old code (an auction at $3.333 then
$2.777 CPM came to $239.93 instead of $239.95).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 diff, no blocking or medium findings.

Two changes in the inventory training-sim:

  1. simulation.ts bills each day as the delta of rounded cumulative spend via a new spend_exact field, so daily rounding telescopes and delivered.spend stays exactly roundMoney(cumulative). Zero-impression days and the SoV budget cap both yield non-negative daily spend; pre-existing saved states degrade safely via ?? delivered.spend.
  2. platform.ts derives specialisms from the seed's actual delivery_types (both enum values mapped) instead of a hardcoded pair.

Both changes are backed by tests. This is non-protocol code: no static/schemas/source/**, docs, or dist edits, so no changeset obligation and no spec drift. high_risk is false, no author team gate, and gated_paths is false (so the REVIEW_REQUIRED status does not trigger row 2). No critical/high/medium findings — falls through to row 9.

@bokelley
bokelley merged commit 36ee5f9 into main Nov 16, 2026
57 checks passed
@bokelley
bokelley deleted the inventory-sim/followups branch November 16, 2026 15:35
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.

1 participant