Simulated time
Run reminders, waits, scheduled jobs and multi-day conversations in milliseconds on a simulated clock, in code and as multi-episode YAML cases.
Agents that act over time (a reminder the day before, a follow-up after three days, an approval that expires) are hard to test on a real clock. A simulated clock runs a week of business in milliseconds, deterministically, and every event in the trajectory carries simulated timestamps, so you can assert when something happened.
The clock
simulated_clock(start) / simulatedClock(start) creates a clock at an ISO instant. Time moves when you move it:
| Python | TypeScript | Does |
|---|---|---|
await clock.advance("2d") | await clock.advance("2d") | move forward, waking every timer due on the way, one due time at a time |
await clock.run_until(iso) | await clock.runUntil(iso) | move to an instant |
await clock.idle() | await clock.idle() | jump to each next timer until nothing waits on the clock |
await clock.hold(work) | await clock.hold(work) | mark work as busy so time cannot jump past it |
clock.now(), clock.iso() | clock.now(), clock.iso() | the current simulated time |
A woken task runs before the next timer wakes, so a timer set by a woken task inside the window fires too.
Simultaneous timers wake in the order they were set. Time only auto-advances when nothing is busy: model calls
through the replay and live transports, core tool calls and anything in hold count as busy. max_simulated
(default 30 days) stops a runaway interval with evals.simulated_time_exceeded.
Run code on it
Pass the clock to trace(). With patch="timers", code that does not take a clock follows it too:
- TypeScript:
Date,Date.now,setTimeoutandsetInterval. Refused withevals.clock_unsupportedwhile vitest fake timers are on. - Python: the running event loop's time (
asyncio.sleep,wait_for,call_later), andtime.sleepcalled from a worker thread.time.timeanddatetime.nowfollow throughtime-machine(theviewport-evals[clock]extra; without it, wall patching warns once and does nothing). uvloop is not supported.
Scopes may overlap and run concurrently (Promise.all, asyncio.gather). Each global is replaced once, while any
scope needs it, and restored exactly when the last one exits, in any order. Every read dispatches to the clock of the
current async context (AsyncLocalStorage, ContextVar), so each scope sees its own time and code outside every scope
sees real time. One exception in Python: an event loop has a single timeline, so concurrent patch="timers" scopes
on one loop must share a clock; a second clock is evals.clock_unsupported.
The default, patch="wall", patches only wall-clock reads; patch=False patches nothing. In pytest, the clock
fixture gives each test a simulated clock.
async def test_holds_takes_the_deposit_confirms_and_reminds_a_day_ahead() -> None:
model = booking_script()
calendar_world = studio.create(STUDIO_SEED)
payments_world = shop.create(SHOP_SEED)
desk = BookingDesk(model.async_anthropic(), [*calendar_world.tools, *payments_world.tools])
clock = simulated_clock("2026-11-23T09:00:00Z") # a Monday
async with trace(clock=clock, patch="timers") as t:
await desk.handle("Can you do a full detail on Saturday at 9? This is Odile Ferreira, customer CU-1.")
await desk.handle(webhook({"type": "checkout.completed", "booking_id": "B-1", "customer_id": "CU-1"}))
await clock.run_until("2026-11-28T09:00:00Z") # the week passes; the reminder timer fires on Friday
# What it did, in order, and the studio's rules over the whole run.
assert t.tool_names == [
"find_free_slots",
"create_event",
"send_deposit_link",
"create_charge",
"confirm_booking",
"send_reminder",
]
assert t.upholds(BOOKING_RULES)
assert t.calls("send_reminder")[0].started_at == "2026-11-27T09:00:00.000Z" # 24 hours before 9:00 Saturday
# What changed: one booked event on the calendar, one $50 charge.
assert calendar_world.state["events"]["E-2"]["title"] == "Booked: full detail for Odile Ferreira (B-1)"
assert payments_world.changed == ["$.charges['CH-1']"]
assert payments_world.state["charges"]["CH-1"]["idempotency_key"] == "deposit:B-1"
model.assert_consumed()
async def test_confirming_before_the_deposit_breaks_the_studio_rule() -> None:
model = script(
tool_call(
"create_event",
title="Hold: full detail for Odile Ferreira (B-1)",
start="2026-11-28T09:00:00Z",
end="2026-11-28T12:00:00Z",
),
tool_call("confirm_booking", event_id="E-2"),
reply("You're booked."),
)
calendar_world = studio.create(STUDIO_SEED)
desk = BookingDesk(model.async_anthropic(), list(calendar_world.tools))
async with trace(clock=simulated_clock("2026-11-23T09:00:00Z")) as t:
await desk.handle("Saturday at 9, please.")
desk.close() # the reminder it scheduled for the wrongly confirmed booking never fires
check = t.upholds(BOOKING_RULES)
assert not check
assert "no booking confirmation before the deposit is paid" in repr(check)
test("holds, takes the deposit, confirms, and reminds a day ahead", async () => {
const model = bookingScript();
const calendarWorld: WorldInstance<CalendarState> = studio.create(studioSeed);
const paymentsWorld: WorldInstance<PaymentsState> = shop.create(shopSeed);
const desk = new BookingDesk(model.anthropic(), [...calendarWorld.tools, ...paymentsWorld.tools]);
const clock = simulatedClock("2026-11-23T09:00:00Z"); // a Monday
const t = await trace(
async () => {
await desk.handle("Can you do a full detail on Saturday at 9? This is Odile Ferreira, customer CU-1.");
await desk.handle(webhook({ type: "checkout.completed", booking_id: "B-1", customer_id: "CU-1", amount: 5000 }));
await clock.runUntil("2026-11-28T09:00:00Z"); // the week passes; the reminder timer fires on Friday
},
{ clock, patch: "timers" },
);
// What it did, in order, and the studio's rules over the whole run.
expect(t.toolNames).toEqual([
"find_free_slots",
"create_event",
"send_deposit_link",
"create_charge",
"confirm_booking",
"send_reminder",
]);
expect(t.upholds(bookingRules).passed).toBe(true);
expect(t.calls("send_reminder")[0]?.started_at).toBe("2026-11-27T09:00:00.000Z"); // 24 hours before 9:00 Saturday
// What changed: one booked event on the calendar, one $50 charge.
expect(calendarWorld.state.events["E-2"]).toMatchObject({ title: "Booked: full detail for Odile Ferreira (B-1)" });
expect(paymentsWorld.changed).toEqual(["$.charges['CH-1']"]);
expect(paymentsWorld.state.charges["CH-1"]).toMatchObject({ amount: 5000, idempotency_key: "deposit:B-1" });
model.assertConsumed();
});
test("confirming before the deposit breaks the studio's rule", async () => {
const model = script(
toolCall("create_event", {
title: "Hold: full detail for Odile Ferreira (B-1)",
start: "2026-11-28T09:00:00Z",
end: "2026-11-28T12:00:00Z",
}),
toolCall("confirm_booking", { event_id: "E-2" }),
reply("You're booked."),
);
const calendarWorld = studio.create(studioSeed);
const desk = new BookingDesk(model.anthropic(), calendarWorld.tools);
const t = await trace(() => desk.handle("Saturday at 9, please."), { clock: simulatedClock("2026-11-23T09:00:00Z") });
desk.close(); // the reminder it scheduled for the wrongly confirmed booking never fires
const check = t.upholds(bookingRules);
expect(check.passed).toBe(false);
expect(check.message).toContain("no booking confirmation before the deposit is paid");
});The first test runs a week: an inquiry on Monday, a payment webhook, and a reminder that fires on Friday at 09:00, 24 hours before the appointment. It checks the tools in order, the studio's invariants, the reminder's simulated timestamp and the worlds' end state.
Multi-episode cases
A YAML case can tell the same story. clock: { start } gives every run its own simulated clock, and input.script
replaces prompt with a list of episodes:
| Step | Does |
|---|---|
user: "..." | a user message; the agent runs with it as the prompt |
approval: { status, approval_id?, tool_name?, by?, reason?, edited_args? } | a human's decision arrives; the agent runs with it as event. edited_args approves with edits (status: approved only) |
event: { type, ... } | an external typed event, such as a webhook; the agent runs with it as event |
advance: 5d | the case clock moves forward and due timers wake; the agent is not called |
The agent receives event (the episode's typed event; user messages arrive as { type: "user" }) and episode
(its index) in CaseInput, and keeps state across episodes in session. A script step is input, never evidence:
an approval step is not an approval event in the trajectory (the step itself stays in the trajectory's
input.script). approvals:, gated: and invariant approval selectors see only the approval events the agent or
its gate records, so an agent that ignores a scripted denial and acts anyway fails them. To exercise approve with
edits, pass the step's edited_args to your gate (HITL: approve(edited_args=...)) and assert the call it ran.
Events carry episode_id
(ep_0, ep_1, ...), so events[].where can pin an event to the episode it happened in. Inside an episode
simulated time stands still; work started in one episode that waits on the clock, such as a durable sleep, completes
on a later advance step. timeout_ms stays on wall time.
# yaml-language-server: $schema=https://getviewport.com/schemas/evals/case/v1.json
# A week at the studio as one case: Odile texts on Monday, pays the deposit, and gets her reminder on Friday.
# Every step of input.script is an episode; `advance` moves this run's simulated clock and wakes due timers.
id: inquiry-to-paid-booking-to-reminder
description: Hold, deposit, confirmation, then a reminder 24 hours before the appointment.
clock: { start: 2026-11-23T09:00:00Z }
world:
studio:
seed:
events:
E-1:
id: E-1
title: "Booked: ceramic coat for Ruiz"
start: "2026-11-28T13:00:00Z"
end: "2026-11-28T16:00:00Z"
attendees: [[email protected]]
status: confirmed
shop:
seed:
customers:
CU-1:
id: CU-1
name: Odile Ferreira
email: [email protected]
card: { brand: visa, last4: "4242", status: valid }
input:
script:
- user: "Can you do a full detail on Saturday at 9? This is Odile Ferreira, customer CU-1."
- event: { type: checkout.completed, booking_id: B-1, customer_id: CU-1, amount: 5000 }
- advance: 5d
expect:
tools:
in_order: [find_free_slots, create_event, send_deposit_link, create_charge, confirm_booking, send_reminder]
calls:
- { tool_name: create_charge, args: { amount: 5000, idempotency_key: "deposit:B-1" } }
events:
# The reminder fires in the advance episode, 24 hours before 9:00 Saturday.
- type: tool_call
where: { tool_name: send_reminder, episode_id: ep_2, started_at: "2026-11-27T09:00:00.000Z" }
count: 1
invariants:
- name: no booking confirmation before the deposit is paid
each: { tool: confirm_booking }
after: { tool: create_charge, ok: true }
- name: at most one deposit per booking
each: { tool: create_charge, ok: true }
limit: { max: 1, by: $.args.idempotency_key }
- name: reminders only for confirmed bookings
each: { tool: send_reminder }
after: { tool: confirm_booking }
world:
studio:
only_changed: ["$.events['E-2']"]
state:
{ events: { E-2: { title: "Booked: full detail for Odile Ferreira (B-1)", start: "2026-11-28T09:00:00Z" } } }
shop:
changed: ["$.charges['CH-1']"]
state: { charges: { CH-1: { amount: 5000, customer_id: CU-1 } } }
output: { contains: booked }
def test_yaml_case() -> None:
"""The same story as one multi-episode case (evals/booking.yaml): a text, a payment webhook, then five days pass.
Each run gets fresh worlds and its own simulated clock; the desk lives in ``case_input.session`` across episodes."""
async def agent(case_input: CaseInput) -> str:
if "desk" not in case_input.session:
tools = [*case_input.worlds["studio"].tools, *case_input.worlds["shop"].tools]
case_input.session["desk"] = BookingDesk(booking_script().async_anthropic(), tools)
desk: BookingDesk = case_input.session["desk"]
event = case_input.event or {}
return await desk.handle(case_input.prompt if event.get("type") == "user" else webhook(event))
cases = load_cases("evals/*.yaml", cwd=Path(__file__).parent)
config = resolve_config(agent=agent, worlds={"studio": studio, "shop": shop})
report = run_cases(cases, config=config, mode="live")
assert report["ok"], report["verdicts"]
// The same story as one multi-episode case (evals/booking.yaml): a text, a payment webhook, then five days pass.
// Each run gets fresh worlds and its own simulated clock; the desk lives in `input.session` across the episodes.
describeCases("evals/*.yaml", {
cwd: import.meta.dirname,
mode: "live",
config: {
worlds: { studio, shop },
agent: async (input) => {
input.session.desk ??= new BookingDesk(bookingScript().anthropic(), [
...(input.worlds.studio?.tools ?? []),
...(input.worlds.shop?.tools ?? []),
]);
const desk = input.session.desk as BookingDesk;
return desk.handle(input.event?.type === "user" ? input.prompt : webhook(input.event ?? {}));
},
},
});Durable workflows
DBOS workflows run on simulated time in Python: a 24-hour DBOS.sleep_async takes milliseconds. See the
DBOS guide. A Temporal bridge is not in 0.1: Temporal's time-skipping test server is a binary
downloaded at runtime, which cannot be verified offline.
Next: production replay.
Worlds
Simulated systems your agent acts on, with tools that change their state and end-state assertions on what changed. Ships with crm, calendar, payments and inbox packs.
Simulated users
A turn producer plays the user in multi-turn conversations, scripted or backed by an existing simulator, in code and in the case runner.