Skip to content

feat(training-agent): inventory-adserver tenant over the delivery engine (#9025) - #9038

Merged
bokelley merged 2 commits into
mainfrom
inventory-sim/adserver-tenant
Nov 15, 2026
Merged

bokelley merged 2 commits into
mainfrom
inventory-sim/adserver-tenant

Conversation

@bokelley

@bokelley bokelley commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Part B of #9025, slice 2 of 5. This PR adds a simulated ad server inventory agent at /inventory-adserver/mcp, serving the engine's adserver-2027 seed. It is stacked on #9037, so the diff shows this slice only.

  • get_products:
    • Returns the seed's products, each with an engine forecast for the flight in filters.start_date and filters.end_date. The default flight is the next 30 days.
    • filters.countries narrows the forecast; delivery_type and channels filter the products.
    • cache_scope is account, because forecasts subtract the caller's own bookings.
  • create_media_buy books each package into the caller's simulated market:
    • A guaranteed package takes its impressions as its goal. Without one, the goal is what the budget buys at the fixed price.
    • The homepage takeover takes share of voice.
    • An auction package bids bid_price above the floor.
    • targeting_overlay.geo_countries narrows a package.
    • Unknown products are refused with PRODUCT_NOT_FOUND, and a wrong pricing option with INVALID_PRICING_OPTION.
  • update_media_buy pauses, resumes and cancels, and changes a package's budget, goal or bid, or the buy's end time. It honours revision (CONFLICT on a mismatch).
  • get_media_buys and get_media_buy_delivery read back the bookings. Delivery includes by_package and daily_breakdown rows, and pacing_index for guaranteed packages.
  • One simulated market per caller and tenant. It is stored next to the caller's sandbox document in the session store, and every call catches it up to the caller's sandbox clock.

Keeping existing tenants unchanged

  • The tenant is mounted beside the others but kept out of TENANT_IDS. So brand.json, adagents.json, the /mcp-strict routes and the tenant-listing tests are unchanged. It is not served on the 3.0 compatibility route.
  • If an inventory tenant fails to register, the failure is logged and the other tenants stay up. In testing, a single SDK config error had taken down the whole registry, /sales included.
  • product-factory.ts gains an exported formatOptionsForTrainingFormats, so the seeds' format labels map to canonical format_options.

Tests

  • server/tests/unit/training-agent-inventory-tenants.test.ts boots the router and calls the tenant over MCP. Every response is checked against getCanonicalToolValidator(tool, 'sync', { adcpVersion: '3.2' }).
  • Existing suites run against this slice, all passing:
    • integration tests for legacy MCP, tool-catalog drift, brand.json and tool dispatch (tool-catalog drift needed a rerun on its own after a timeout under load);
    • tenant-smoke.test.ts and served-release-shape.test.ts.

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.ts and server/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 /signals had 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

@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-only feature (new inventory-adserver tenant over the sim engine). No touch to static/schemas/source/, docs/reference/, dist/**, or package.json version; changeset correctly omitted (training-agent is out of published-protocol scope). storyboardCompat 3.0 gating verified consistent across index.ts and registry.ts; optional-tenant registration isolation confirmed.

Medium findings (1):

  • server/src/training-agent/inventory-sim/platform.ts:274 — Lost-update race in per-caller market store (duplicate media_buy_id, dropped booking under concurrent same-principal requests)

With 1 medium finding, no critical/high, gated_paths false, high_risk false, no team gate, and no prior escalation, none of rows 1–8 fire. Falls through to row 9 → approve. The race is worth a follow-up but is non-blocking per the decision table.

Medium findings

  • server/src/training-agent/inventory-sim/platform.ts:274 — Lost-update race in per-caller market store (duplicate media_buy_id, dropped booking)

@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 work only, no protocol surface touched.

Checked:

  • All 8 delta files reviewed (== full PR). No Critical/High findings.
  • platform.ts createMediaBuy verified fail-fast: a mid-batch engine error throws before market.save(), mutating only a discarded structuredClone, so no partial booking persists. buyStatus/delivery/pacing and account scoping check out.
  • registry.ts optional-register fallback correctly isolates inventory-tenant registration failure.
  • No static/schemas/source/** or docs/reference/** changes → no changeset required, no schema↔docs/oneOf/artifact-immutability concerns.
  • gated_paths: false; review_decision APPROVED; no no-auto-approve team match; high_risk: false.

Medium findings (1):

  • server/src/training-agent/inventory-sim/market-store.ts:103 — Lost-update race in per-caller market store (duplicate ids, dropped booking). This is the prior run's finding, now re-pinned to its real site.

With 1 medium finding, no escalation trigger, and no team/gate block, this falls through to row 9 (approve). The single medium is a carried-over concurrency note on a training-agent simulation path, not a blocker.

Medium findings

  • server/src/training-agent/inventory-sim/market-store.ts:103 — Lost-update race in per-caller market store (duplicate ids, dropped booking)

aao-secretariat[bot]
aao-secretariat Bot previously approved these changes Nov 15, 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 — app-only training-agent change (new /inventory-adserver tenant over the sim engine); no protocol surface touched, so the no-changeset decision is correct, and responses validate against canonical AdCP schemas in the new test suite.

Medium findings

  • server/src/training-agent/inventory-sim/platform.ts:498 — Lost-update race in per-caller market store: openMarket clones after an await and save() writes the clone whole, so two concurrent writes from the same caller can lose an update (duplicate media_buy_id, dropped booking).

This is the same single medium finding re-surfaced from the prior run (line shifted from 274 to 498). The reviewer verified createMediaBuy's partial-failure rollback, account_id isolation on all read paths, and the optional-registration fix are all sound. With one medium finding, no critical/high, no gated-path or team-gate trigger, high_risk false, and review_decision APPROVED, this falls through to row 9.

Medium findings

  • server/src/training-agent/inventory-sim/platform.ts:498 — Lost-update race in per-caller market store (duplicate media_buy_id, dropped booking)

Base automatically changed from inventory-sim/engine to main November 15, 2026 20:32
@bokelley
bokelley dismissed aao-secretariat[bot]’s stale review November 15, 2026 20:32

The base branch was changed.

bokelley and others added 2 commits November 15, 2026 20:32
…ine (#9025)

Part B of #9025, slice 2: a simulated ad server inventory agent at
/inventory-adserver/mcp, serving the engine's adserver-2027 seed.

- get_products returns the seed's products with engine forecasts for the
  requested flight (filters.start_date/end_date, default 30 days),
  narrowed by filters.countries, delivery_type and channels.
- create_media_buy books each package into the caller's market:
  guaranteed packages take an impression goal (or what the budget buys),
  the takeover takes share of voice, auction packages bid above the
  floor. update_media_buy pauses, cancels and changes budget, goal, bid
  and end time. get_media_buys and get_media_buy_delivery read the
  bookings; delivery is released at each product's reporting lag.
- One market per caller and tenant, kept beside the caller's sandbox
  document in the session store and caught up to the caller's sandbox
  clock on every call.
- Mounted beside the other tenants but outside TENANT_IDS, so brand.json,
  adagents.json and the /mcp-strict routes are unchanged; not served on
  the 3.0 compat route. A failed inventory registration is logged and
  leaves the other tenants up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… clock (#9025)

Review on #9042: a caller's sandbox clock is shared by every tenant, and
any tenant's reset_state unpins it (back to the wall clock). A market that
had already run days the clock now has not reached would keep its buys
but report no delivery, since every recorded day lies in the clock's
future. Such a market belongs to the discarded timeline, so openMarket
and advanceMarket now start it fresh, as they do for a changed seed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bokelley
bokelley force-pushed the inventory-sim/adserver-tenant branch from a16afe0 to 3846d7b Compare November 15, 2026 20:38

@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 — app/training-agent change with no blocking findings.

This is a subsequent review (prior decision: approve) of the full inventory-tenant PR (delta == full, 8 files). The new code is clean: registry optional-tenant isolation keeps a failed inventory tenant from taking down others, correct 3.0-compat gating in index.ts/registry.ts, per-principal+per-account market isolation, atomic-on-failure booking, and tests validate responses against the canonical AdCP 3.2 schemas. This is an app/training-agent change (not a static/schemas/source/** wire change), so no changeset is required per repo conventions.

Medium findings (non-blocking):

  • server/src/training-agent/inventory-sim/platform.ts:498 — Lost-update race in per-caller market store (duplicate media_buy_id, dropped booking)

Only one medium finding (not a data-loss/schema/infra escalation category in this app context, not on a modified high-risk path). No critical/high. high_risk is false; gated_paths is false. Author is not on a no-auto-approve team. With a single medium finding and no escalation trigger, rows 1–8 do not fire — falls through to row 9: approve. The prior escalation sticky rule (row 6) does not apply (prior was approve).

Medium findings

  • server/src/training-agent/inventory-sim/platform.ts:498 — Lost-update race in per-caller market store (duplicate media_buy_id, dropped booking)

@bokelley
bokelley merged commit 0206ab4 into main Nov 15, 2026
56 checks passed
@bokelley
bokelley deleted the inventory-sim/adserver-tenant branch November 15, 2026 21:17
bokelley added a commit that referenced this pull request Nov 15, 2026
…ck (#9025)

Review on #9042 and #9038:

- reset_state on an inventory tenant unpins the caller's sandbox clock,
  which every tenant shares, so it now discards the caller's market on
  every inventory tenant, not only the one it was called on.
- sandbox_clock now advances only the market of the tenant it is called
  on, so its write stays under the router's lock for that tenant (which
  serializes a tenant's requests from transport through session flush).
  The caller's other markets run the same days on their next read, with
  the same results. The response reports days_crossed, the UTC days the
  clock moved across, instead of days_run.
- A test unpins the clock the way /sales reset_state does and shows the
  inventory market starting fresh rather than reporting nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
bokelley added a commit that referenced this pull request Nov 15, 2026
…#9025) (#9039)

* feat(training-agent): sandbox_clock scenario on the inventory tenants (#9025)

Part A of #9025, scoped to the inventory tenants: a comply_test_controller
scenario that reads and moves the caller's one sandbox clock.

  { "scenario": "sandbox_clock", "params": { "operation": "get" } }
  { "scenario": "sandbox_clock", "params": { "operation": "advance_time", "to": "2027-01-15T00:00:00Z" } }
  { "scenario": "sandbox_clock", "params": { "operation": "advance_time", "by": "P30D" } }

- It moves the same per-caller simulated_now that
  reporting_subscription_probe advance_time moves, so there is one clock.
  It only moves forward, refuses months and years in durations, and is
  listed in list_scenarios and compliance_testing.scenarios.
- Advancing catches up every inventory market the caller has (the
  engine's day steps for each day crossed) and runs the same
  post-advance hooks as the probe (runSandboxClockAdvanceHooks).
- reset_state on an inventory tenant unpins the clock, as the probe's
  reset does, and discards the caller's market on that tenant.
- The router answers sandbox_clock and list_scenarios for the inventory
  tenants, because the SDK's controller config has no slot for a scenario
  of our own; reset_state goes through the SDK.
- Tests only: setSandboxWallClockForTesting moves where an unpinned clock
  starts, so the seeds' scripted 2027 events stay reachable whenever the
  suite runs.

The existing probes and tenants are unchanged.

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

* fix(training-agent): reset every inventory market with the shared clock (#9025)

Review on #9042 and #9038:

- reset_state on an inventory tenant unpins the caller's sandbox clock,
  which every tenant shares, so it now discards the caller's market on
  every inventory tenant, not only the one it was called on.
- sandbox_clock now advances only the market of the tenant it is called
  on, so its write stays under the router's lock for that tenant (which
  serializes a tenant's requests from transport through session flush).
  The caller's other markets run the same days on their next read, with
  the same results. The response reports days_crossed, the UTC days the
  clock moved across, instead of days_run.
- A test unpins the clock the way /sales reset_state does and shows the
  inventory market starting fresh rather than reporting nothing.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
bokelley added a commit that referenced this pull request Nov 16, 2026
The post-deploy smoke now probes /inventory-adserver/mcp and
/inventory-content/mcp, the two simulated inventory tenants merged in
#9038 and #9040. An inventory tenant that fails to register is logged
and left down without affecting the others, so without this probe a
production-only registration failure would go unnoticed; with it, the
deploy fails like any other tenant's.

Split out of #9041 so the docs can land without the
.github/workflows review gate.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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