Repository navigation
feat(training-agent): run the inventory tenants on a season file (#9025) - #9142
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
IPR Policy Agreement Required@yvassiliadis — thanks for the contribution. Before this PR can be merged, the AgenticAdvertising.Org IPR Policy requires your agreement. To agree, post a new comment on this PR with the exact phrase: Your signature is recorded once and covers all contributions to AAO repositories. See |
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — clean, well-tested training-agent feature.
This PR adds the ability to load a SeasonSeed from a YAML/JSON file to run the two inventory tenants on a supplied season. No protocol surface is touched (no static/schemas/source/**, no docs/reference/**), so no changeset is required and check-changeset-protocol-scope passes correctly.
Reviewed highlights:
- The three-pass loader in
season-file.tsis sound: zod strictObject shape pass,referenceProblemsfor engine-unchecked cases, thentrafficFor/coverage. Layering is correct — unknown ids and share-sum/days-range rules are backstopped by the engine'sSeasonTrafficconstructor; thecollection &&guard at :346 is safe. - Compile-time
Equalscheck enforces schema↔SeasonSeedparity. - Season resolution is a synchronous boot-time
readFileSyncthat fails closed (server refuses to start, error names env var + path) — correct for a startup path, no timeout needed. Hosted deploy sets neither env var, so output is unchanged.
No Critical/High/Medium findings. Not path-gated (gated_paths: false), not high-risk, no no-auto-approve team match, first review. Falls through to row 9.
|
I have read the IPR Policy |
IPR Policy — signedThanks, @yvassiliadis. Your agreement to the IPR Policy is recorded at |
bokelley
left a comment
There was a problem hiding this comment.
Thanks Yannis, this is well built. Happy to approve once it's rebased. It's 28 commits behind main and has one conflict, so it needs a fresh approval after the rebase anyway.
Blocking after the rebase
- The new tenant test will fail on current main. Since #9149,
get_productsreturnsACCOUNT_NOT_FOUNDfor an account that was never synced. The twoget_productscases intraining-agent-inventory-season-file-tenant.test.ts(around lines 85-99) call it with an unprovisioned account. Add thesync_accountsstep that main'straining-agent-inventory-tenants.test.tsuses (provision()). - The only textual conflict is the import line in
tenants/inventory.ts. Keep main'sresetMarket, withCallerMarketsalongside your additions. Nothing in #9147's per-caller serialization, #9148 or #9150 is affected. Seeded products use the loaded season's placements, so season files work withseed_product.
Small hardening (please include)
- Require at least one placement and one product. With
placements: [], main'sseeded-products.tsreadsseed.placements[0].channelandseed_productthrows a TypeError. - Cap
collections[].count, or reject installments scheduled after the season ends. Today a huge count loads. - Cap the file size.
- Wrap
toJS()so a YAML alias-limit error comes back asINVALID_SEEDrather than a plain error. It already fails closed.
Worth noting in the PR or docs
- The season comes from an environment variable and applies to the whole server, so this is for local and self-hosted runs. Setting it on the hosted test agent would change every caller's market. A per-caller season on the hosted agent is a separate design change, if we want one later.
- Follow-up, not for this PR:
market-store.tschecks onlyseed_idwhen deciding whether a stored market is current, so editing a season file without changingseed_idwould replay old bookings against new placements. Storing a content hash with the market would make that safe.
The rest looks right: strict zod validation, safe YAML handling, the compile-time check that the schema matches SeasonSeed, and real round-trip and run-equality tests.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… var Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…'t serve Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oducts Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…lments, size, aliases Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
74892e9 to
5e3a7ef
Compare
|
Thanks Brian. Rebased on main; the only conflict was the import line in tenants/inventory.ts, resolved by keeping resetMarket, withCallerMarkets. Changes:
|
…ing their date Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Ladon verdict: Approve
Approve.
The only delta since the prior approve is dateIfRepresentable (season-file.ts:313-318), which guards calendar.dateOf() against day values beyond JavaScript's ±8.64e15 Date range that previously threw "Invalid time value". The guard mirrors dateOf's date math exactly, and lastDate uses the daysUsable-bounded seed.days - 1 so it stays representable. New tests cover cadence_days of 1e9 and MAX_SAFE_INTEGER. Training-agent/test-only, no protocol surface (static/schemas/source/**, docs/reference/**, dist artifacts) touched, so no changeset is required. Reviewer reported no findings.
Gate checks: no no-auto-approve team match; gated_paths is false; high_risk is false. No critical/high/medium findings. None of decision-table rows 1–8 fire, so this falls through to row 9 → approve.
CodeQL (js/file-system-race) flagged readSeasonFile: it stat-ed the path, then read it by path, so the file could change between the size check and the read. Open it once, fstat and read through the same descriptor, and re-check the size of what was actually read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bokelley
left a comment
There was a problem hiding this comment.
Approved at Brian's direction: his 21 Nov findings are all addressed (provisioning, imports, placement/product minimums, installment and size caps, INVALID_SEED wrapping). Added one commit fixing the CodeQL file-system race in readSeasonFile (check and read through one descriptor).
There was a problem hiding this comment.
Ladon verdict: Approve
Approve — single-file hardening of readSeasonFile with no blocking or medium findings.
What I checked
- The delta hardens
season-file.ts(L327-343): replacesstatSync+readFileSyncwith a single descriptor flow (openSync→fstatSync→readFileSync(fd)undertry/finally closeSync), closing the TOCTOU window between stat and read, plus a post-readBuffer.byteLengthsize recheck. - No descriptor leak:
invalid()throws (never), and thefinallycloses the fd on the throw path. Node does not auto-close an fd passed toreadFileSync, and the code handles that correctly. - Not protocol surface: changes are confined to
server/**training-agent code, a docs page underdocs/building/**(non-normative), and tests/fixtures. Nostatic/schemas/source/**, nodist/**artifacts, no migrations — schema↔docs coherence, changeset-scope, oneOf-discriminator, and artifact-immutability gates do not apply. - No high-risk flag, no gated paths, no author-team gate,
review_decisionnot required here.
Findings: none (reviewer reports a clean pass; prior approve had no blockers, none re-surfaced).
Rows 1–8 do not fire → row 9 approve.
main added a third root install with install scripts enabled in training-agent-storyboards.yml (the inventory-adserver / inventory-content job, from #9142) after this PR was written. Route it through .github/scripts/npm-ci.mjs like the other root installs, and update the helper's coverage note to 13 root installs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #9025.
Summary
Lets anyone run the two simulated inventory tenants (
/inventory-adserver,/inventory-content) on a season they supply as a file, rather than only the two seasons compiled into the code. This answers the "Do you need your own seeds?" question in #9025. Builders of a market simulator need seasons of their own, including held-out ones that must never be uploaded to a hosted service. With this change those seasons run on the builder's own machine.Format. A season file is YAML 1.2 or JSON with the same fields as
SeasonSeed(engine/types.ts).inventory-sim/season-file.tsrefuses a season the tenants could not serve. Each problem is reported with its path (placements[0].floor_cpm: must be 0 or more). It checks:count)All of these except the engine's rules list every problem they find at once. YAML errors, including the alias limit, come back in the same
INVALID_SEEDformat with the file's path. A strict compile-time equality check failsnpm run typecheckif the schema andSeasonSeeddrift apart, including an optional field added to only one side.Choosing a season. Two env vars,
TRAINING_AGENT_INVENTORY_ADSERVER_SEASON_FILEandTRAINING_AGENT_INVENTORY_CONTENT_SEASON_FILE.The engine is unchanged.
inventory-sim/engine/gains no imports and no edits, so it can still move into@adcp/sdk. Library users can callreadSeasonFileand pass the result toInventorySimulation.create.Docs. A "Run on your own season" section at the end of the simulated inventory agents page covers:
seasonToYaml)FLY_PROCESS_GROUP=webso a local run starts no crawlers or scheduled jobsseed_idwhenever a season changesWhy the shipped seasons stay TypeScript constants
Moving them into files would add runtime-asset plumbing and make the server read files at boot, with no change in behaviour. A test proves the format instead. Each shipped season is written to YAML and to JSON and loaded back unchanged, and the same scripted run on the loaded season and on the constant gives an identical
SimulationStateand forecast.Hosted tenants
Nothing changes. The hosted deploy sets neither variable, so both tenants serve the shipped seasons by identity, and the same calls at the same simulated time give the same results.
The variables apply to the whole server: every caller of a tenant gets the file's season. So this is for local and self-hosted runs, and the docs say so. A per-caller season on the hosted agent would be a separate design.
Testing
server/tests/unit/inventory-sim-season-file.test.tscovers:INVALID_SEED2_200_000)server/tests/unit/training-agent-inventory-season-file-tenant.test.tsboots the router with the ad server pointed at the starter fixture, provisions the account withsync_accounts, and checks over MCP, against the canonical schemas, thatget_productsserves exactly the fixture's products. It then books the guaranteed product, advances the sandbox clock and reads its delivery.training-agent-inventory-tenants.test.ts,training-agent-inventory-market-concurrency.test.ts,inventory-sim-engine.test.tsandtests/run-storyboards-sharding.test.cjspass unchanged on current main.npm run typecheckpasses, and the pre-commit suite passes.get_productson the local ad server tenant returned the fixture's products.check-changeset-protocol-scopepasses).Relation to recent inventory changes
Rebased on current main, including #9116 (creative library) and #9147–#9150. Seeded products (
seed_product) read the loaded season, so they work with a season file. #9116 makes the platform build each placement's format options when the tenant is built. The format check here makes a season with an unknown format fail at load with its path, instead of failing during that build.Follow-up
seed_idonly, so editing a season file without changingseed_idwould replay old bookings against new placements. The docs tell people to changeseed_id; storing a content hash with the market would make it safe. Not in this PR.🤖 Generated with Claude Code