Repository navigation
feat(training-agent): deterministic inventory delivery engine (#9025) - #9037
Merged
Merged
Conversation
Part B of #9025, slice 1: the engine behind the two inventory tenants. It lives in server/src/training-agent/inventory-sim/engine/ with no imports from the rest of the training agent, so it can move into @adcp/sdk later. - A season seed defines regions, non-overlapping audience profiles, segments, properties, placements (with formats, floors and rates), products, collections, traffic shape, forecast error and scripted events. - Traffic is generated once per seed as cells (day x region x property x placement x profile, plus installment for content placements), in a forecast table and an actual table that differs by keyed noise and events. - Each simulated day serves bookings confirmed by the end of the previous day; share-of-voice first, then impression goals by the high-water mark method, then a first-price auction above the floor; installments run, postpone or cancel; delivery is recorded per booking and per cell. - Forecasts subtract guaranteed reservations and come out in AdCP's forecast shape. Delivery is released at each product's reporting lag. - Two seeds: an ad server (display, video, takeover, a scripted outage and a traffic spike) and a content platform (podcast, newsletter, creator series, a cancelled episode and a postponed video). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — self-contained, deterministic inventory-delivery engine plus unit tests, all new files (2240 additions, 0 deletions).
Checked:
- No protocol surface touched (no static/schemas/source/, docs/reference/, or dist/** changes), so no changeset/schema-docs/immutability/oneOf obligations apply.
- No external I/O; operational-readiness N/A.
- Allocation math exact and never over-allocates (allocation.ts takeEqualShare largest-remainder, L54-71); no div-by-zero (serving filter guarantees day<flight_end_day).
- Determinism holds via keyed FNV-1a/mulberry32 draws and immutable per-seed SeasonTraffic cache.
- Forecast reservations clamp booked to capacity; SOV sold-out and spend cap sound.
Only finding is Low (test fixture uses format_ids instead of formats — cosmetic, tests excluded from tsconfig). Low findings do not block.
Gate status: gated_paths false, no high-risk paths, no no-auto-approve team match, no prior decision. No critical/high/medium findings. Falls through decision table to row 9.
Nit (non-blocking):
- server/tests/unit/inventory-sim-engine.test.ts:62 — Test fixture uses format_ids instead of formats
…#9025) Ladon nit on #9037: the scarce-seed fixture named the field format_ids; SeedPlacement calls it formats. The engine never reads it, and the server tsconfig excludes tests, so nothing caught it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part B of #9025, slice 1 of 5. This is the engine behind the two simulated inventory agents (the inventory role in #8993). Nothing serves it in this PR.
Stack: this PR, then #9038 (ad server tenant), then #9039 (
sandbox_clock), then #9040 (content tenant), then #9041 (docs and deploy smoke). Review and merge them in that order.Decisions confirmed with @bokelley for the series:
inventory-adserverandinventory-content.sandbox_clockis a new scenario, offered on those two tenants only. It moves the same per-callersimulated_nowthatreporting_subscription_probealready moves.What it is
The engine is in
server/src/training-agent/inventory-sim/engine/. It imports nothing from the rest of the training agent, so it can move into@adcp/sdkunchanged. The same seed and the same calls always give the same results. Every random draw is keyed by what it is for, using FNV-1a and mulberry32 with integer arithmetic only, so results don't depend on the order of calls.types.ts,seeds/). A seed defines:traffic.ts).curves.ts): newsletter over 3 days, podcast over 30, video over 42.simulation.ts). Each simulated day runs in this order:allocation.ts).forecastshape (forecast-shape.ts).adserver-2027: display, video and a homepage takeover. Scripted events: a five-day outage on the sports hero unit (2027-01-08 to 2027-01-12) and a spike in news traffic.content-2027: a podcast, a newsletter and a creator series. Scripted events: episodemorning_brief_012is cancelled, and videomaker_studio_006is postponed to 2027-01-23.Tests
server/tests/unit/inventory-sim-engine.test.tshas 22 tests.Checks run locally
npx tsc --project server/tsconfig.json --noEmit: clean.tests/lint-format-identity-boundaries.test.cjs: passes.server/tests/unit/inventory-sim-engine.test.tsandserver/tests/unit/training-agent-inventory-tenants.test.ts(run from the repo root): pass.Committed and pushed with
HUSKY=0, which @bokelley approved for this series. Under host load of 40 to 80, the pre-commit server unit suite timed out in unrelated suites (addie/matched-pair-ni/exact-inference). A local storyboard matrix run against the stack's tip was stopped after 66 minutes, by which point/signalshad passed (57 clean against a floor of 45). CI's storyboard job is the check that existing storyboards still pass.No changeset: this touches only the training agent and docs, not the protocol surface.
Refs #9025, #8993
🤖 Generated with Claude Code