Skip to content

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

Merged
bokelley merged 2 commits into
mainfrom
inventory-sim/sandbox-clock
Nov 15, 2026
Merged

bokelley merged 2 commits into
mainfrom
inventory-sim/sandbox-clock

Conversation

@bokelley

@bokelley bokelley commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Part A of #9025, slice 3 of 5. This PR adds the sandbox_clock controller scenario, offered on the inventory tenants only, as agreed. It is stacked on #9038.

{ "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" } }
  • One clock per caller. It moves the same per-caller simulated_now that reporting_subscription_probe advance_time moves (account-sandbox.ts).
  • It only moves forward. An earlier instant is refused with INVALID_TRANSITION. Durations given in months or years are refused, because their length depends on the date.
  • It is discoverable. It is listed in list_scenarios and in compliance_testing.scenarios.
  • Advancing runs the simulation. Moving the clock catches up every inventory market the caller has, running the engine's day step for each day crossed. It also runs the probe's existing post-advance hooks, through a new runSandboxClockAdvanceHooks (the probe now calls it too).
  • reset_state on an inventory tenant unpins the clock, the same way the probe's reset does, and discards the caller's market on that tenant.
  • Where it is handled: the SDK's controller config has no slot for a custom scenario, so the router answers sandbox_clock and list_scenarios for the inventory tenants (the same way seed_collection is handled on /sales). reset_state goes through the SDK's resetState.
  • A test-only seam: setSandboxWallClockForTesting sets where an unpinned clock starts, so the seeds' scripted 2027 events stay reachable whenever the suite runs. Faking Date instead makes the SDK re-validate the tenants and refuse traffic.

Tests

  • A month of buys: pin the clock at 2026-12-31, book a guaranteed and an auction buy, then advance P31D (days_run: 31). Checked:
    • the sports hero guarantee delivers less than half its normal daily volume during the outage;
    • afterwards it delivers above its earlier pace, and finishes within 3% of its goal;
    • the auction buy's actual delivery differs from its forecast, within the seeded error.
  • Refusals and reset: moving backwards and a P1M duration are refused; reset_state unpins the clock and clears the caller's buys.
  • Existing clock and controller suites pass (154 tests): account requests, comply-test-controller, preview version.

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 — clean training-agent change, no blocking or medium findings.

Scope: training-agent only (server/src/training-agent/**), no protocol surface (static/schemas/source/**, docs/reference/**, dist/**), so the omitted changeset is correct.

Checked: parseDuration rejects months/years and empty P/PT (P1M→INVALID_PARAMS test); forward-only guard and 10-year MAX_ADVANCE cap hold; principal plumbing consistent across sandbox_clock, create_media_buy (principalOf), and reset; save-then-reload reads updated simulated_now before advanceMarket; the minimal {mode:'open',principal} ctx is safe for the advance hook; unfiltered list_scenarios vs enum-filtered capabilities faithfully reproduces the established sales pattern (router.ts:306, 901-905) — intentional, not drift.

No gated paths, no high-risk flag, no author team gate, no prior decision. Rows 1–8 do not fire → row 9 approve.

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

Checked: all 7 changed files live under server/src/training-agent/**, an in-memory training/compliance simulator. No protocol surface (static/schemas/source/**, docs/reference/**, dist/**) is touched, so no changeset is required. sandbox-clock.ts is forward-only (INVALID_TRANSITION on backward moves), bounded by MAX_ADVANCE_MS (10y), refuses month/year durations, and fails closed on account.sandbox === false. router.ts orders the inventory comply interceptor before the local one, resolves served version first, and wraps the mutating path in runWithSessionContext + flushDirtySessions. The subscription-probe refactor (runSandboxClockAdvanceHooks) is behavior-preserving.

No critical/high/medium findings. gated_paths is false and review_decision is APPROVED; high_risk is false; no no-auto-approve team match. Prior decision was also approve. Falls through to decision table row 9.

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 — clean pass, no blocking or medium findings.

Scope is confined to server/src/training-agent/** app/platform code (sandbox clock, inventory-sim platform, tenant router interceptor, subscription probe, account sandbox, and unit tests). No static/schemas/source/**, docs/reference/**, or dist/** surface is touched, so no changeset is required and none of the spec-coherence / changeset-scope / oneOf / immutable-artifact / 3.1.x-eligibility gates apply.

Checked:

  • sandbox-clock.ts: parseDuration rejects P/T-only and month/year durations; handleSandboxClock enforces forward-only and the 10-year cap before any new Date(target).toISOString(), so the success path can't hit a RangeError.
  • router.ts interceptor tryHandleInventoryComplyScenario: correctly gated to inventory tenants, leaves reset_state to the SDK, wraps the handler in session context + flush.
  • Capabilities projection: inventory scenarios injected ahead of the served-version enum filter.
  • Test coverage present for the new branches.

Gate check: no no-auto-approve team match; gated_paths false; review_decision APPROVED; high_risk false. Prior decision was also approve with no findings. No decision-table rows 1–8 fire → row 9 approve.

@bokelley
bokelley force-pushed the inventory-sim/adserver-tenant branch from a16afe0 to 3846d7b Compare November 15, 2026 20:38
Base automatically changed from inventory-sim/adserver-tenant to main November 15, 2026 21:17
@bokelley
bokelley dismissed aao-secretariat[bot]’s stale review November 15, 2026 21:17

The base branch was changed.

bokelley and others added 2 commits November 15, 2026 21:18
…#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]>
…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
bokelley force-pushed the inventory-sim/sandbox-clock branch from 8c7e6bc to 84be9e3 Compare November 15, 2026 21:19

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

Checked all 7 changed files. The PR adds a sandbox_clock compliance scenario for inventory training tenants (get / forward-only advance_time via RFC 3339 to or ISO 8601 by), a test-only wall-clock seam in account-sandbox.ts, a shared runSandboxClockAdvanceHooks, and router interception. Validation is forward-only, caps advance at ~10 years, refuses month/year durations; market catch-up is per-caller/per-tenant keyed with timeline-staleness discard; hook refactor is behavior-preserving.

No protocol surface under static/schemas/source/**, docs/reference/**, dist/**, or changeset scope is touched — all changes are confined to server/src/training-agent/** and its unit test, so no changeset is owed and no schema↔docs coherence check applies.

Gate review: high_risk=false; gated_paths=false (so row 2 does not fire despite review_decision=REVIEW_REQUIRED); no no-auto-approve team match; no deletions in sensitive paths. Prior decision was approve with no findings — consistent. No critical/high/medium findings surfaced, so rows 1–8 do not fire; falls through to row 9.

@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 — subsequent pass on PR #9039 (sandbox_clock scenario on inventory training tenants), clean.

Checked all 7 changed files (server/src/training-agent/** + unit test). sandbox-clock.ts duration parsing with fail-closed forward-only/10-year guards; router interception gates sandbox_clock on account.sandbox and runs in-memory under session context (no external I/O, so no timeout surface). No changes to static/schemas/source/, docs/reference/, dist/**, or release scripts — the published protocol surface is untouched, so no changeset is required and the no-changeset justification holds. No schema↔docs drift, no oneOf regression, no released-artifact mutation.

No critical/high/medium findings. Prior pass was also clean (approve) with no blockers to re-surface. Not gated (gated_paths: false), not high-risk, no no-auto-approve team match. Falls through to row 9.

@bokelley
bokelley merged commit 484e3f5 into main Nov 15, 2026
64 of 109 checks passed
@bokelley
bokelley deleted the inventory-sim/sandbox-clock branch November 15, 2026 22:01
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