From af1c55eb9993677ca29db28a1f762c50821a4e87 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 14:04:59 -0800 Subject: [PATCH 1/3] feat(task_step): wake and delivered lines are labelled in the task's time zone always_on, prompt_agent's delivered lines and the advance-to-next-event hook labelled every line in UTC, so a person in Denver whose first message came at 5:30 PM on Friday reached the agent as "Sat Feb 6, 12:30 AM UTC", while the computer's screen showed Friday evening. Lines now read in the task's zone and name it ("Fri Feb 5, 5:30 PM MST"): the user sim's zone, else the one sync_env_clock gave the world, else UTC, as before. Co-Authored-By: Claude Opus 5.5 --- .../examples/advance-to-next-event/README.md | 3 +- .../artifacts/advance-to-next-event/hook.py | 13 +++++--- .../task_step/task_steps/always_on.py | 17 ++++++---- .../task_steps/notification_delivery.py | 31 ++++++++++++----- .../task_step/task_steps/prompt_agent.py | 5 +-- .../test_advance_to_next_event_hook.py | 8 +++++ .../test_always_on_agent_verifier.py | 6 ++-- tst/unit/task_step/test_always_on_budget.py | 2 +- tst/unit/task_step/test_always_on_checks.py | 2 +- .../task_step/test_always_on_clock_rate.py | 2 +- tst/unit/task_step/test_always_on_endings.py | 4 +-- tst/unit/task_step/test_always_on_graded.py | 32 +++++++++--------- tst/unit/task_step/test_always_on_loop.py | 10 +++--- tst/unit/task_step/test_always_on_time.py | 6 ++-- .../test_always_on_user_sim_inputs.py | 2 +- .../test_prompt_agent_notifications.py | 33 +++++++++++++++++-- .../task_step/test_user_sim_opening_files.py | 4 +-- 17 files changed, 119 insertions(+), 61 deletions(-) diff --git a/src/agent_env/examples/advance-to-next-event/README.md b/src/agent_env/examples/advance-to-next-event/README.md index 75708f4a1..d52a94757 100644 --- a/src/agent_env/examples/advance-to-next-event/README.md +++ b/src/agent_env/examples/advance-to-next-event/README.md @@ -26,7 +26,8 @@ recorded as `triggers_still_firing`, if triggers are still running when `settle_ than treat unfinished work as nothing left to happen. Envs whose clock was never armed are left out. Reference the hook from a `prompt_agent` step, after `sync_env_clock` (frozen: `virtual_seconds_per_real_second: 0`) -and `configure_scheduled_checks` (`"roles": ["default"]`). Delivered lines, the person's included, are labelled in UTC: +and `configure_scheduled_checks` (`"roles": ["default"]`). Delivered lines, the person's included, are labelled in +the world's time zone, the one `sync_env_clock` armed the clock in, and in UTC when it has none, as in this example: ```json {"id": "week", "type": "prompt_agent", "prompt": "Keep an eye on curbfinch this week for an 8x10 rug.", diff --git a/src/agent_env/examples/advance-to-next-event/artifacts/advance-to-next-event/hook.py b/src/agent_env/examples/advance-to-next-event/artifacts/advance-to-next-event/hook.py index d9abe2f7d..68732517c 100644 --- a/src/agent_env/examples/advance-to-next-event/artifacts/advance-to-next-event/hook.py +++ b/src/agent_env/examples/advance-to-next-event/artifacts/advance-to-next-event/hook.py @@ -33,7 +33,10 @@ async def post_turn(turn, params): answer = await turn.user_triggers() if answer is not None: return answer - t0 = min([_utc((await env.invoke(CLOCK, "state"))["t0"]) for env in envs]) + states = [await env.invoke(CLOCK, "state") for env in envs] + t0 = min([_utc(state["t0"]) for state in states]) + zones = {state.get("time_zone") for state in states} - {None} + zone = zones.pop() if len(zones) == 1 else "UTC" # as prompt_agent labels what it delivers end = _end_instant(end_time, t0) sent = _delivered_person(turn) for jump in range(max_jumps + 1): @@ -44,7 +47,7 @@ async def post_turn(turn, params): turn.record({"woke_at": _iso(now), "for": due + ["person"] * len(due_person), **({"person_at": [_iso(m["at"]) for m in due_person]} if due_person else {})}) # prompt_agent puts what came due on notifications/v1 ahead of this; [] sends only that - return {"message": _person_message(due_person) if due_person else []} + return {"message": _person_message(due_person, zone) if due_person else []} if jump == max_jumps: # checked above: what the last jump made due still wakes the agent return _end(turn, "max_jumps_per_turn", at=_iso(now)) nxt = await _next(envs, role, person, now, sent) @@ -134,9 +137,9 @@ def _delivered_person(turn): return sent -def _person_message(person): - """One line per message, oldest first, each saying when it was written.""" - return "\n".join(f"[{label_time(_iso(m['at']))}] {m['text']}" for m in person) +def _person_message(person, zone): + """One line per message, oldest first, each saying when it was written, in the world's time zone.""" + return "\n".join(f"[{label_time(_iso(m['at']), zone)}] {m['text']}" for m in person) async def _advance(env, target): diff --git a/src/agent_env/task_step/task_steps/always_on.py b/src/agent_env/task_step/task_steps/always_on.py index e7123728a..8662ce921 100644 --- a/src/agent_env/task_step/task_steps/always_on.py +++ b/src/agent_env/task_step/task_steps/always_on.py @@ -1006,7 +1006,7 @@ async def _open(self) -> None: opened_at = _utc(self.opening["at"]) await self._chat_user(self._opening_parts(lambda text: self._chat_part(opened_at, text, kind="opening"))) due = await take_due(self.notification_envs, self.recipient) if self.notification_envs else [] - await self.wake([*delivered_parts(due), + await self.wake([*delivered_parts(due, self.zone), *self._opening_parts(lambda text: self._user_part(opened_at, text, opening=True))], woke_by=[f"notification:{d['channel']}" for d in due] + ["user_request"], notifications=[{k: d.get(k) for k in ("at", "channel", "source", "source_id", "to")} @@ -1144,7 +1144,7 @@ def _opening_parts(self, labelled) -> list[dict]: def _user_part(self, at: datetime, text: str, opening: bool = False) -> dict: first = self.person["first"] body = re.sub(rf"^\s*{re.escape(first)}\s*:\s*", "", text) - return {"kind": "text", "text": f"[{label_time(_iso(at))}] {first}: {body}", + return {"kind": "text", "text": f"[{label_time(_iso(at), self.zone)}] {first}: {body}", "metadata": {"agentenv": {"source": "user", "at": _iso(at), "opening": opening}}} # ---- the graded conversation: the user's chat ---------------------------------------------------------------- @@ -1183,7 +1183,8 @@ async def _chat_end(self, now: datetime) -> None: if self.reaction: parts.append(_step_part(f"({first} {self.reaction['said']})", "user_reaction")) parts[-1]["metadata"]["agentenv"].update(outcome=self.reaction["outcome"], at=self.reaction["at"]) - parts.append({"kind": "text", "text": f"[End of run · {label_time(_iso(now))}] {self.end_note} (A note from " + when = label_time(_iso(now), self.zone) + parts.append({"kind": "text", "text": f"[End of run · {when}] {self.end_note} (A note from " f"the run, not a message from {first}.)", "metadata": {"agentenv": {"source": "end_marker", "end_reason": self.end_reason, "at": _iso(now)}}}) @@ -1202,7 +1203,7 @@ async def _wake_with(self, now: datetime, lines: list[dict], replies: list[dict] """Wake the agent with what came due for it, then the user's lines and replies in time order, then ``notes`` (the step's own lines); ``last`` marks the run's last wake.""" due = await take_due(self.notification_envs, self.recipient) if self.notification_envs else [] - parts = delivered_parts(due) + parts = delivered_parts(due, self.zone) user_msgs = sorted([{"at": l["at"] or _iso(now), "text": l["text"], "kind": l.get("source", "user_says"), "trigger_id": l.get("trigger_id")} for l in lines] + [{"at": _iso(r["deliver_at"]), "text": r["text"], "kind": "user_reply", @@ -1449,7 +1450,7 @@ def _sent(self, messages: list[dict], after_nudge: bool = False, leftover: bool sent = {"at": m.get("at"), "text": m["text"], "wake": self.wakes} self.unread.append(sent) self.all_messages.append(sent) - self.chat_pending.append({"kind": "text", "text": f"[{label_time(m.get('at'))}] {m['text']}", + self.chat_pending.append({"kind": "text", "text": f"[{label_time(m.get('at'), self.zone)}] {m['text']}", "metadata": {"agentenv": {"source": "message_user", "at": m.get("at"), "wake": self.wakes}}}) @@ -1701,7 +1702,8 @@ async def finish(self) -> None: ctx.metadata.setdefault(ALWAYS_ON_KEY, {})[step.id] = record # The graded response is the user's whole chat from the agent, each message with its pretend time; never its # closing text, which she never saw. - self._append_prompt_response("\n\n".join(f"[{label_time(m.get('at'))}] {m['text']}" for m in self.all_messages)) + self._append_prompt_response("\n\n".join(f"[{label_time(m.get('at'), self.zone)}] {m['text']}" + for m in self.all_messages)) async def _store_timeline(self, record: dict) -> None: """Store the run's full record, its timeline included, and give ``record`` (what stays in the run's metadata, @@ -1784,6 +1786,7 @@ def render_for_judge(record: dict) -> str: "with no known actor (made outside the env's gateway, such as on a website reached directly), each with " "when it was seen. The user saw only the messages the assistant sent."] wakes = [e for e in timeline if e["event"] == "wake"] + zone = next((e.get("time_zone") for e in timeline if e["event"] == "start"), None) or "UTC" for wake in wakes[:JUDGE_WAKES]: n = wake["n"] turn = turns.get(n) or {} @@ -1791,7 +1794,7 @@ def render_for_judge(record: dict) -> str: calls = f" · {turn['tool_calls']} tool calls" if turn.get("tool_calls") is not None else "" state = f" · its turn {turn['state']}" if turn.get("state") not in (None, "completed", "TaskState.completed") \ else "" - lines.append(f"- Wake {n} · {label_time(wake.get('virtual_time'))} · woken by " + lines.append(f"- Wake {n} · {label_time(wake.get('virtual_time'), zone)} · woken by " f"{woke_by_text(wake.get('woke_by'))} · sent the user {sent} message{'s' if sent != 1 else ''}" f"{calls}{state}") made = changes.get(n, []) diff --git a/src/agent_env/task_step/task_steps/notification_delivery.py b/src/agent_env/task_step/task_steps/notification_delivery.py index 51d335f54..4d867bf97 100644 --- a/src/agent_env/task_step/task_steps/notification_delivery.py +++ b/src/agent_env/task_step/task_steps/notification_delivery.py @@ -8,7 +8,8 @@ [Mon Feb 1, 3:00 PM UTC · your scheduled check] See if Dana replied about the 2BR on Alder St [Mon Feb 1, 3:10 PM UTC · Curbfinch alert] New listing: 2BR on Ivy St, $3,050/mo -Times are in UTC, and say so, like everything else the agent reads about time (``get_time``, ``schedule_check``). +Times are in the task's time zone and name it (``MST``, ``CET``), so they read as the person and the computer's screen +read them; UTC when the task has none. ``get_time`` answers in a zone too, and ``schedule_check`` takes any offset. Each delivered part carries ``metadata.agentenv``, the item without its parts (``source`` and ``source_id`` among them), so a verifier reading the stored conversation can tell a delivered line from what the person wrote in the same @@ -31,6 +32,7 @@ import uuid from datetime import datetime, timezone from typing import Any, Iterable, Optional +from zoneinfo import ZoneInfo from agent_env.env.gateway.constants import EXT_NOTIFICATIONS_URI @@ -39,31 +41,42 @@ _EARLIEST = datetime.min.replace(tzinfo=timezone.utc) -def label_time(at: Optional[str]) -> str: - """'Mon Feb 1, 3:00 PM UTC'; 'now' for an item with no time (queued while the env clock was unset).""" +def label_time(at: Optional[str], zone: str = "UTC") -> str: + """'Fri Feb 5, 5:30 PM MST' in the IANA ``zone`` ('Mon Feb 1, 3:00 PM UTC' by default), a zone with no + abbreviation named by its offset ('UTC-03'); 'now' for an item with no time (queued while the env clock was + unset).""" if not at: return "now" - at = _utc(at) - return f"{at.strftime('%a %b')} {at.day}, {at.strftime('%I:%M %p').lstrip('0')} UTC" + at = _utc(at).astimezone(ZoneInfo(zone)) + name = at.strftime("%Z") + name = f"UTC{name}" if name[:1] in "+-" else name + return f"{at.strftime('%a %b')} {at.day}, {at.strftime('%I:%M %p').lstrip('0')} {name}" -def delivered_line(item: dict) -> str: +def labels_zone(clocks: list[dict]) -> str: + """The zone lines are labelled in when no user names one: the one sync_env_clock gave the world, else UTC, as it is + when the world has several.""" + zones = {c["timezone"] for c in clocks if c.get("timezone")} + return zones.pop() if len(zones) == 1 else "UTC" + + +def delivered_line(item: dict, zone: str = "UTC") -> str: """A taken item's text as the agent reads it: ``[when · channel]``, then its text parts.""" - when = label_time(item.get("at")) + when = label_time(item.get("at"), zone) times = item.get("times", 1) again = f" (it came due {times} times while you were away)" if times > 1 else "" text = "\n\n".join(p["text"] for p in item["parts"] if p.get("kind") == "text") return f"[{when} · {item['channel']}] {text}{again}" -def delivered_parts(items: Iterable[dict]) -> list[dict]: +def delivered_parts(items: Iterable[dict], zone: str = "UTC") -> list[dict]: """Per taken item, oldest first: one text part, its ``delivered_line``, then any parts that aren't text, as they are. Each carries ``metadata.agentenv``: the item without its parts, with the ``env_id`` it came from when the item has one.""" parts = [] for item in sorted(items, key=_oldest_first): meta = {"agentenv": {k: v for k, v in item.items() if k != "parts"}} - parts.append({"kind": "text", "text": delivered_line(item), "metadata": meta}) + parts.append({"kind": "text", "text": delivered_line(item, zone), "metadata": meta}) parts.extend({**p, "metadata": meta} for p in item["parts"] if p.get("kind") != "text") return parts diff --git a/src/agent_env/task_step/task_steps/prompt_agent.py b/src/agent_env/task_step/task_steps/prompt_agent.py index f260e0e8f..e94f6e1b3 100644 --- a/src/agent_env/task_step/task_steps/prompt_agent.py +++ b/src/agent_env/task_step/task_steps/prompt_agent.py @@ -39,7 +39,7 @@ from agent_env.entity.refs import EntityRef from agent_env.entity.scopes import FieldScope from agent_env.task_step.task_step import RetryConfig, TaskStep, TaskStepDependency -from agent_env.task_step.task_steps.notification_delivery import delivered_parts, next_message, take_due +from agent_env.task_step.task_steps.notification_delivery import delivered_parts, labels_zone, next_message, take_due from agent_env.task_step.task_steps.post_turn_hooks import PostTurnHooks, run_post_turn_hooks, validate_hook_specs from agent_env.task_step.task_steps.agent import user_sim_versions from agent_env.task_step.task_steps.agent.user_sim_common import iso, person_of, task_zone, utc @@ -614,6 +614,7 @@ async def _converse( # What comes due for the agent's role on these envs (notifications/v1) opens its next message. notification_envs = [d for d in context.deployed_envs if d.supports(EXT_NOTIFICATIONS_URI, "take")] recipient = agent.role or DEFAULT_ROLE + zone = built_in[1] if built_in else labels_zone(context.metadata.get("clock_configurations") or []) final_terminal = protocol.TerminalResponse(response_text="") # Each turn's terminal reports only that turn's tool calls, so the conversation's count is # their sum. None until a turn reports one, so agents that don't report it stay None. @@ -752,7 +753,7 @@ def record_turn() -> None: # The conversation goes on: what came due for the agent goes first, the user side's reply after it. # An answer that ended it, or the last turn, takes nothing, so what is due stays queued on the env. due = await take_due(notification_envs, recipient) if notification_envs else [] - current_user_parts = next_message(delivered_parts(due), answer["message"]) + current_user_parts = next_message(delivered_parts(due, zone), answer["message"]) end_after = answer.get("end_after") if not current_user_parts: # a hook said nothing ([]) and nothing came due logger.info(f"Turn {turn+1}: nothing to send the agent; ending multi-turn (nothing_to_send)") diff --git a/tst/unit/task_step/test_advance_to_next_event_hook.py b/tst/unit/task_step/test_advance_to_next_event_hook.py index ec86d9d86..73192431c 100644 --- a/tst/unit/task_step/test_advance_to_next_event_hook.py +++ b/tst/unit/task_step/test_advance_to_next_event_hook.py @@ -173,6 +173,14 @@ async def test_the_person_s_messages_arrive_at_their_times_once_each(hook, gatew {"end": "nothing_can_wake_the_agent"}] +@pytest.mark.asyncio +async def test_the_person_s_messages_are_labelled_in_the_zone_the_clock_was_armed_in(hook, gateway): + gateway._clock.set_time(MONDAY, rate=0, time_zone="America/Chicago") + params = {"person_messages": [{"at": "2026-03-03T15:00:00Z", "text": "I'm up"}]} + sent = await _turns(hook, _context(), params=params) + assert sent == [["[Tue Mar 3, 9:00 AM CST] I'm up"], {"end": "nothing_can_wake_the_agent"}] + + @pytest.mark.asyncio async def test_another_conversation_delivering_a_message_at_the_same_time_does_not_skip_this_one(hook, gateway): context = _context() diff --git a/tst/unit/task_step/test_always_on_agent_verifier.py b/tst/unit/task_step/test_always_on_agent_verifier.py index 12b2bf751..f112d8d7b 100644 --- a/tst/unit/task_step/test_always_on_agent_verifier.py +++ b/tst/unit/task_step/test_always_on_agent_verifier.py @@ -76,13 +76,13 @@ async def test_the_judge_grades_from_the_chat_and_the_run_wake_by_wake_not_the_t await verifier.execute(ctx) prompt = captured["prompt"] - assert "[Mon Nov 9, 2:00 PM UTC] Casa Jacarandas is $855. Book it?" in prompt and "PRIVATE" not in prompt + assert "[Mon Nov 9, 9:00 AM EST] Casa Jacarandas is $855. Book it?" in prompt and "PRIVATE" not in prompt conversation = prompt[prompt.index("## Conversation"):prompt.index("## Trigger firings")] assert "Linda: yes please" in conversation and "[End of run" in conversation wakes = prompt[prompt.index("## The run, wake by wake"):] - assert "- Wake 2 · Mon Nov 9, 2:00 PM UTC · woken by the user's reply · sent the user 1 message" in wakes + assert "- Wake 2 · Mon Nov 9, 9:00 AM EST · woken by the user's reply · sent the user 1 message" in wakes assert " - it changed: INSERT public.bookings row 1 (request 855 USD)" in wakes - assert "- Wake 3 · Tue Nov 10, 2:00 PM UTC · woken by an alert (noor 30)" in wakes + assert "- Wake 3 · Tue Nov 10, 9:00 AM EST · woken by an alert (noor 30)" in wakes assert "## How the run ended\nNothing could wake the assistant again, and nothing was pending." in wakes assert ctx.metadata["verifications"]["rubric"]["score"] == 1 assert verifier.to_dict() == stored # the step, shared by concurrent rollouts, is untouched diff --git a/tst/unit/task_step/test_always_on_budget.py b/tst/unit/task_step/test_always_on_budget.py index 749ffe937..a5bb85aa3 100644 --- a/tst/unit/task_step/test_always_on_budget.py +++ b/tst/unit/task_step/test_always_on_budget.py @@ -49,7 +49,7 @@ def agent(n, texts, rig): assert reached["real_seconds"] == 10800 assert record["end_reason"] == "time_budget" and record["error_type"] is None assert rig.events(ctx, "user_sim_read")[-1]["last_read"] is True - assert rig.chat(ctx)[-1]["texts"][-1].startswith("[End of run · Wed Nov 11, 2:00 PM UTC] The run was cut off by " + assert rig.chat(ctx)[-1]["texts"][-1].startswith("[End of run · Wed Nov 11, 9:00 AM EST] The run was cut off by " "its real-time budget.") diff --git a/tst/unit/task_step/test_always_on_checks.py b/tst/unit/task_step/test_always_on_checks.py index 03277825f..36bdb6b0d 100644 --- a/tst/unit/task_step/test_always_on_checks.py +++ b/tst/unit/task_step/test_always_on_checks.py @@ -67,7 +67,7 @@ def agent(n, texts, rig): wake = rig.events(ctx, "wake")[1] assert wake["virtual_time"] == "2026-11-12T14:00:00Z" and wake["woke_by"] == ["notification:your scheduled check"] - assert "[Thu Nov 12, 2:00 PM UTC · your scheduled check] book La Ola, it opens at 9" in rig.sent[1] + assert "[Thu Nov 12, 9:00 AM EST · your scheduled check] book La Ola, it opens at 9" in rig.sent[1] @pytest.mark.parametrize("end_time,setting,on", [(None, None, False), ("PT6H", None, False), ("P5D", False, False), diff --git a/tst/unit/task_step/test_always_on_clock_rate.py b/tst/unit/task_step/test_always_on_clock_rate.py index 62bb08127..6b34a7a89 100644 --- a/tst/unit/task_step/test_always_on_clock_rate.py +++ b/tst/unit/task_step/test_always_on_clock_rate.py @@ -33,7 +33,7 @@ async def test_a_slow_contact_reply_between_turns_doesn_t_move_the_clock(monkeyp ctx = await rig.run(rig.step(settle_timeout_seconds=0.2)) [_, alerted] = rig.events(ctx, "wake") - assert "[Mon Nov 9, 3:00 PM UTC · Gmail · Live Oak Arbor]" in alerted["parts_text"] + assert "[Mon Nov 9, 10:00 AM EST · Gmail · Live Oak Arbor]" in alerted["parts_text"] assert alerted["virtual_time"].startswith("2026-11-09T15:00:00") assert rig.record(ctx)["settings"]["clock"] == {"envs": [{"env_id": "world", "rate": RATE, "frozen_between_turns": True}]} diff --git a/tst/unit/task_step/test_always_on_endings.py b/tst/unit/task_step/test_always_on_endings.py index 48585d69f..81a85261a 100644 --- a/tst/unit/task_step/test_always_on_endings.py +++ b/tst/unit/task_step/test_always_on_endings.py @@ -88,7 +88,7 @@ async def test_a_task_s_final_line_is_hers_and_comes_with_the_notice(monkeypatch await rig.run(rig.step(end_time="P2D", final="send me the rundown")) texts = rig.sent[-1] - assert "[Wed Nov 11, 2:00 PM UTC] Linda: send me the rundown" in texts and DEFAULT_FINAL not in texts + assert "[Wed Nov 11, 9:00 AM EST] Linda: send me the rundown" in texts and DEFAULT_FINAL not in texts assert texts[-1] == NOTICE and ao.WAKE_REMINDER_TEXT not in texts assert [s["text"] for s in rig.reads[-1]["you_sent"]] == ["sort the cdmx weekend", "send me the rundown"] @@ -321,7 +321,7 @@ def agent(n, texts, rig): ctx = await rig.run(rig.step()) [response] = ctx.prompt_responses - assert response.response == "[Mon Nov 9, 2:00 PM UTC] found it: the blue house, $855" + assert response.response == "[Mon Nov 9, 9:00 AM EST] found it: the blue house, $855" assert response.error_type == "agent_turn_timeout" [sent] = rig.events(ctx, "message_to_user") assert sent["leftover"] is True diff --git a/tst/unit/task_step/test_always_on_graded.py b/tst/unit/task_step/test_always_on_graded.py index 2a0a3a004..9e9d3ad6a 100644 --- a/tst/unit/task_step/test_always_on_graded.py +++ b/tst/unit/task_step/test_always_on_graded.py @@ -52,9 +52,9 @@ async def test_the_graded_response_is_every_message_user_text_in_order_with_its_ ctx = await rig.run(rig.step()) [response] = ctx.prompt_responses - assert response.response == ("[Mon Nov 9, 2:00 PM UTC] blue house or green?\n\n" - "[Mon Nov 9, 2:00 PM UTC] flights: two options\n\n" - "[Mon Nov 9, 2:00 PM UTC] booked the blue one") + assert response.response == ("[Mon Nov 9, 9:00 AM EST] blue house or green?\n\n" + "[Mon Nov 9, 9:00 AM EST] flights: two options\n\n" + "[Mon Nov 9, 9:00 AM EST] booked the blue one") assert "PRIVATE" not in response.response and response.error_type is None verifier = AgentPromptResponseVerifierTaskStep("check", None, prompt_id="ask", verifier_id="words", criteria=[ {"type": "response_contains", "needles": ["blue house or green?", "booked the blue one"]}]) @@ -78,10 +78,10 @@ async def test_the_conversation_is_what_she_saw_her_messages_and_the_agent_s_mes turns = await _turns(ctx) assert turns[:3] == [ - ("[Mon Nov 9, 2:00 PM UTC] Linda: sort the cdmx weekend", "[Mon Nov 9, 2:00 PM UTC] blue house or green?"), - ("[Mon Nov 9, 2:00 PM UTC] Linda: blue", "[Mon Nov 9, 2:00 PM UTC] booked it"), - ("[Tue Nov 10, 3:00 PM UTC] Linda: any news from Sam?", - "[Tue Nov 10, 3:00 PM UTC] Sam says she suspects nothing"), + ("[Mon Nov 9, 9:00 AM EST] Linda: sort the cdmx weekend", "[Mon Nov 9, 9:00 AM EST] blue house or green?"), + ("[Mon Nov 9, 9:00 AM EST] Linda: blue", "[Mon Nov 9, 9:00 AM EST] booked it"), + ("[Tue Nov 10, 10:00 AM EST] Linda: any news from Sam?", + "[Tue Nov 10, 10:00 AM EST] Sam says she suspects nothing"), ] seen = repr(rig.chat(ctx)) for never_shown in ("PRIVATE", "Sam: shh", "noor 30", ao.WAKE_REMINDER_TEXT, ao.MESSAGE_RULES, @@ -98,7 +98,7 @@ async def test_messages_sent_on_several_wakes_before_she_answers_are_one_reply_i ctx = await rig.run(rig.step()) [first, *_] = await _turns(ctx) - assert first[1] == "[Mon Nov 9, 2:00 PM UTC] on it\n[Tue Nov 10, 2:00 PM UTC] Sam is in" + assert first[1] == "[Mon Nov 9, 9:00 AM EST] on it\n[Tue Nov 10, 9:00 AM EST] Sam is in" assert [p["metadata"]["agentenv"]["wake"] for p in rig.chat(ctx)[1]["parts"]] == [1, 2] @@ -112,9 +112,9 @@ async def test_her_done_reaches_the_conversation(monkeypatch, tmp_path): ctx = await rig.run(rig.step()) turns = await _turns(ctx) - assert turns[1] == ("[Mon Nov 9, 2:00 PM UTC] Linda: thanks!", "[Mon Nov 9, 2:00 PM UTC] glad to help!") + assert turns[1] == ("[Mon Nov 9, 9:00 AM EST] Linda: thanks!", "[Mon Nov 9, 9:00 AM EST] glad to help!") assert rig.chat(ctx)[2]["parts"][0]["metadata"]["agentenv"]["done"] is True - assert turns[-1][0].startswith("[End of run · Mon Nov 9, 2:00 PM UTC] Linda signed off.") + assert turns[-1][0].startswith("[End of run · Mon Nov 9, 9:00 AM EST] Linda signed off.") @pytest.mark.asyncio @@ -142,12 +142,12 @@ def recap(n, texts, rig): ctx = await rig.run(rig.step(end_time="P2D", final="send me the rundown")) turns = await _turns(ctx) - assert turns[-2] == ("[Wed Nov 11, 2:00 PM UTC] Linda: send me the rundown", - "[Wed Nov 11, 2:00 PM UTC] RESULT: all booked") + assert turns[-2] == ("[Wed Nov 11, 9:00 AM EST] Linda: send me the rundown", + "[Wed Nov 11, 9:00 AM EST] RESULT: all booked") last = rig.chat(ctx)[-1] assert last["texts"] == [ - "[Wed Nov 11, 2:00 PM UTC] Linda: you're the best (sent after the assistant's last turn; it never saw this)", - "[End of run · Wed Nov 11, 2:00 PM UTC] The run reached its end time. (A note from the run, not a message " + "[Wed Nov 11, 9:00 AM EST] Linda: you're the best (sent after the assistant's last turn; it never saw this)", + "[End of run · Wed Nov 11, 9:00 AM EST] The run reached its end time. (A note from the run, not a message " "from Linda.)"] assert last["parts"][-1]["metadata"]["agentenv"] == {"source": "end_marker", "end_reason": "end_time", "at": "2026-11-11T14:00:00Z"} @@ -164,7 +164,7 @@ def chatty(n, texts, rig): ctx = await rig.run(rig.step(max_wakes=2)) last = rig.chat(ctx)[-1] - assert last["texts"][-1].startswith("[End of run · Mon Nov 9, 2:00 PM UTC] The run was cut off at its cap of 2 " + assert last["texts"][-1].startswith("[End of run · Mon Nov 9, 9:00 AM EST] The run was cut off at its cap of 2 " "wakes.") assert "Linda: ok (sent after the assistant's last turn" in last["texts"][0] @@ -183,7 +183,7 @@ async def test_messages_queued_before_the_run_are_not_the_run_s(monkeypatch, tmp ctx = await rig.run(rig.step()) [response] = ctx.prompt_responses - assert response.response == "[Mon Nov 9, 2:00 PM UTC] on it" + assert response.response == "[Mon Nov 9, 9:00 AM EST] on it" assert [m["text"] for m in rig.reads[0]["assistant_messages"]] == ["on it"] assert [(m["from"], m["text"]) for m in chat.state()["pending"]] == [("other", "from another assistant")] [before] = rig.events(ctx, "user_chat_before_run") diff --git a/tst/unit/task_step/test_always_on_loop.py b/tst/unit/task_step/test_always_on_loop.py index 96b8cd1e4..5cfc50171 100644 --- a/tst/unit/task_step/test_always_on_loop.py +++ b/tst/unit/task_step/test_always_on_loop.py @@ -50,7 +50,7 @@ async def test_a_notify_alert_wakes_the_agent_labelled_with_its_time_and_channel assert _woke(ctx, rig) == [("2026-11-09T14:00:00Z", ["user_request"]), ("2026-11-10T14:00:00Z", ["notification:noor 30"])] - assert "[Tue Nov 10, 2:00 PM UTC · noor 30] Sam: she suspects nothing" in rig.sent[1] + assert "[Tue Nov 10, 9:00 AM EST · noor 30] Sam: she suspects nothing" in rig.sent[1] assert rig.record(ctx)["end_reason"] == "finished_nothing_pending" @@ -62,7 +62,7 @@ async def test_a_scripted_user_line_reaches_the_agent_as_the_user_and_counts_as_ ctx = await rig.run(rig.step()) assert _woke(ctx, rig)[1] == ("2026-11-10T15:00:00Z", ["user_says"]) - assert "[Tue Nov 10, 3:00 PM UTC] Linda: also find a dinner spot" in rig.sent[1] + assert "[Tue Nov 10, 10:00 AM EST] Linda: also find a dinner spot" in rig.sent[1] [read] = rig.reads assert [s["text"] for s in read["you_sent"]] == ["sort the cdmx weekend", "also find a dinner spot"] assert [e["text"] for e in rig.events(ctx, "scripted_user_line")] == ["also find a dinner spot"] @@ -81,7 +81,7 @@ def book(rig): ctx = await rig.run(rig.step()) assert _woke(ctx, rig)[1] == ("2026-11-12T13:00:00Z", ["notification:your scheduled check"]) - assert "[Thu Nov 12, 1:00 PM UTC · your scheduled check] book La Ola when it opens" in rig.sent[1] + assert "[Thu Nov 12, 8:00 AM EST · your scheduled check] book La Ola when it opens" in rig.sent[1] assert [j["to"] for j in rig.events(ctx, "clock_jump")] == ["2026-11-12T13:00:00Z"] @@ -96,7 +96,7 @@ async def test_a_reply_is_held_for_the_reply_time_then_wakes_the_agent(monkeypat assert read["virtual_time"] == "2026-11-09T14:00:00Z" and read["mode"] == "work" assert read["deliver_at"] == "2026-11-09T16:30:00Z" assert _woke(ctx, rig)[1] == ("2026-11-09T16:30:00Z", ["user_reply"]) - assert "[Mon Nov 9, 4:30 PM UTC] Linda: the blue one" in rig.sent[1] + assert "[Mon Nov 9, 11:30 AM EST] Linda: the blue one" in rig.sent[1] @pytest.mark.asyncio @@ -223,7 +223,7 @@ async def test_done_ends_a_one_sitting_run_after_the_agent_s_turn_on_her_sign_of ctx = await rig.run(rig.step()) assert rig.record(ctx)["end_reason"] == "user_done" and len(rig.sent) == 2 - assert "[Mon Nov 9, 2:00 PM UTC] Linda: thanks!" in rig.sent[1] + assert "[Mon Nov 9, 9:00 AM EST] Linda: thanks!" in rig.sent[1] assert len(rig.reads) == 1 and rig.events(ctx, "user_sim_read")[0]["ends_run"] is True diff --git a/tst/unit/task_step/test_always_on_time.py b/tst/unit/task_step/test_always_on_time.py index c9c0e28d3..38f93673a 100644 --- a/tst/unit/task_step/test_always_on_time.py +++ b/tst/unit/task_step/test_always_on_time.py @@ -20,13 +20,13 @@ async def test_wakes_carry_the_task_s_time_on_each_line_and_no_date_line(monkeyp rig.triggers(rig.notify_at("sam", "2026-11-10T14:00:00Z", "Sam: shh", channel="noor 30")) ctx = await rig.run(rig.step(system_prompt=PROMPT)) - assert [texts[0] for texts in rig.sent] == ["[Mon Nov 9, 2:00 PM UTC] Linda: sort the cdmx weekend", - "[Tue Nov 10, 2:00 PM UTC · noor 30] Sam: shh"] + assert [texts[0] for texts in rig.sent] == ["[Mon Nov 9, 9:00 AM EST] Linda: sort the cdmx weekend", + "[Tue Nov 10, 9:00 AM EST · noor 30] Sam: shh"] assert rig.parts[0][0]["metadata"]["agentenv"]["opening"] is True sources = {p.get("metadata", {}).get("agentenv", {}).get("source") for parts in rig.parts for p in parts} assert "time" not in sources assert not any("computer's clock" in t for texts in rig.sent for t in texts) - assert rig.events(ctx, "wake")[1]["parts_text"].startswith("[Tue Nov 10, 2:00 PM UTC · noor 30]") + assert rig.events(ctx, "wake")[1]["parts_text"].startswith("[Tue Nov 10, 9:00 AM EST · noor 30]") @pytest.mark.asyncio diff --git a/tst/unit/task_step/test_always_on_user_sim_inputs.py b/tst/unit/task_step/test_always_on_user_sim_inputs.py index 799953488..4d0d8936b 100644 --- a/tst/unit/task_step/test_always_on_user_sim_inputs.py +++ b/tst/unit/task_step/test_always_on_user_sim_inputs.py @@ -225,7 +225,7 @@ async def test_c2_c4_a_reply_or_a_done_reaches_the_agent_after_her_reply_time(mo [read] = rig.events(ctx, "user_sim_read") assert read["virtual_time"] == "2026-11-09T14:00:00Z" and read["deliver_at"] == "2026-11-09T16:30:00Z" - assert _woken_by_user(rig)[-1] == "[Mon Nov 9, 4:30 PM UTC] Linda: blue, thanks!" + assert _woken_by_user(rig)[-1] == "[Mon Nov 9, 11:30 AM EST] Linda: blue, thanks!" assert rig.events(ctx, "wake")[1]["virtual_time"] == "2026-11-09T16:30:00Z" diff --git a/tst/unit/task_step/test_prompt_agent_notifications.py b/tst/unit/task_step/test_prompt_agent_notifications.py index b3aa579e1..fc1e47a5b 100644 --- a/tst/unit/task_step/test_prompt_agent_notifications.py +++ b/tst/unit/task_step/test_prompt_agent_notifications.py @@ -14,7 +14,7 @@ from agent_env.env.gateway.constants import EXT_NOTIFICATIONS_URI from agent_env.env.gateway.notifications import Notifications from agent_env.task_step.task_steps import notification_delivery -from agent_env.task_step.task_steps.notification_delivery import delivered_line, next_message +from agent_env.task_step.task_steps.notification_delivery import delivered_line, label_time, labels_zone, next_message from agent_env.task_step.task_steps.prompt_agent import PromptAgentTaskStep from tst.unit.task_step.test_prompt_agent_post_turn_hooks import EnvPeers, _env, _hook from tst.unit.task_step.test_prompt_agent_user_side import AGENT, ENV, USER, _USER_SIM_CARD, _context, sim, text @@ -140,7 +140,7 @@ async def test_the_last_turn_takes_nothing(monkeypatch): @pytest.mark.asyncio -async def test_labels_are_in_utc_and_say_so(monkeypatch): +async def test_labels_are_in_utc_and_say_so_when_the_task_names_no_zone(monkeypatch): peers = GatewayQueue(monkeypatch, {AGENT: [text("one"), text("two")], USER: [sim("ok"), sim("bye", done=True)]}) _alder_and_ivy_due(peers) ctx = _ctx() @@ -151,6 +151,35 @@ async def test_labels_are_in_utc_and_say_so(monkeypatch): f"[Mon Feb 1, 11:10 PM UTC · Curbfinch alert] {IVY}", "ok"] +@pytest.mark.asyncio +async def test_labels_are_in_the_zone_sync_env_clock_gave_the_world_and_name_it(monkeypatch): + peers = GatewayQueue(monkeypatch, {AGENT: [text("one"), text("two")], USER: [sim("ok"), sim("bye", done=True)]}) + _alder_and_ivy_due(peers) + ctx = _ctx() + ctx.metadata["clock_configurations"] = [{"step_id": "clock", "timezone": "America/Los_Angeles"}] + + await _step().execute(ctx) + + assert [p["text"] for p in _to_agent(ctx)[1]] == [f"[Mon Feb 1, 3:00 PM PST · your scheduled check] {ALDER}", + f"[Mon Feb 1, 3:10 PM PST · Curbfinch alert] {IVY}", "ok"] + + +@pytest.mark.parametrize("at, zone, label", [ + ("2027-02-06T00:30:00Z", "America/Denver", "Fri Feb 5, 5:30 PM MST"), + ("2027-07-01T00:30:00Z", "America/Denver", "Wed Jun 30, 6:30 PM MDT"), + ("2027-02-06T00:30:00Z", "America/Sao_Paulo", "Fri Feb 5, 9:30 PM UTC-03"), + ("2027-02-06T00:30:00Z", "UTC", "Sat Feb 6, 12:30 AM UTC"), +], ids=["standard-time", "daylight-time", "a-zone-named-by-its-offset", "utc"]) +def test_a_label_reads_the_time_in_its_zone_and_names_the_zone(at, zone, label): + assert label_time(at, zone) == label + + +def test_lines_take_the_one_zone_the_world_was_given_and_utc_without_one_or_with_several(): + assert labels_zone([{"step_id": "a", "timezone": "America/Denver"}, {"step_id": "b"}]) == "America/Denver" + assert labels_zone([]) == "UTC" + assert labels_zone([{"timezone": "America/Denver"}, {"timezone": "Europe/Paris"}]) == "UTC" + + @pytest.mark.asyncio async def test_only_what_is_due_for_the_agents_own_role_reaches_it(monkeypatch): peers = GatewayQueue(monkeypatch, {AGENT: [text("one"), text("two")], USER: [sim("ok"), sim("bye", done=True)]}) diff --git a/tst/unit/task_step/test_user_sim_opening_files.py b/tst/unit/task_step/test_user_sim_opening_files.py index e16faa3d0..15c54e450 100644 --- a/tst/unit/task_step/test_user_sim_opening_files.py +++ b/tst/unit/task_step/test_user_sim_opening_files.py @@ -175,7 +175,7 @@ async def test_always_on_sends_the_files_on_the_first_wake_in_their_place_and_th later = {"kind": "text", "text": "the hotels i looked at are in the sheet"} ctx = await rig.run(_always_on(), await _always_on_context(monkeypatch, rig, [*OPENING[:2], later, SHORTLIST])) - line = f"[Mon Nov 16, 3:50 PM UTC] Hannah: {TEXT}\n{later['text']}" + line = f"[Mon Nov 16, 7:50 AM PST] Hannah: {TEXT}\n{later['text']}" opening = rig.parts[0] assert [p.get("text") for p in opening if p.get("kind") == "text"].count(line) == 1 at = next(i for i, p in enumerate(opening) if p.get("text") == line) @@ -206,7 +206,7 @@ async def test_always_on_with_a_text_only_opening_sends_and_shows_only_the_text( assert {p.get("kind") for p in rig.parts[0]} == {"text"} assert all("files" not in w for w in rig.events(ctx, "wake")) [first_turn, *_] = [m for m in rig.chat(ctx) if m["role"] == "user"] - assert first_turn["texts"] == [f"[Mon Nov 16, 3:50 PM UTC] Hannah: {TEXT}"] + assert first_turn["texts"] == [f"[Mon Nov 16, 7:50 AM PST] Hannah: {TEXT}"] [call] = rig.user_calls assert f"\nYOU SENT YOUR AI ASSISTANT:\n [7:50 AM] {TEXT}\n\nNEW FROM" in call["parts"][0]["text"] From 5a3138e190c3898a314fb423e74294b4c5f0f16e Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 14:10:25 -0800 Subject: [PATCH 2/3] fix(task_step): labels take each env's latest clock arm, and the judge's summary the run's own zone Co-Authored-By: Claude Opus 5.5 --- src/agent_env/task_step/task_steps/always_on.py | 3 ++- .../task_step/task_steps/notification_delivery.py | 7 ++++--- tst/unit/task_step/test_always_on_agent_verifier.py | 6 ++++++ tst/unit/task_step/test_prompt_agent_notifications.py | 9 +++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/agent_env/task_step/task_steps/always_on.py b/src/agent_env/task_step/task_steps/always_on.py index 8662ce921..a02fd21a6 100644 --- a/src/agent_env/task_step/task_steps/always_on.py +++ b/src/agent_env/task_step/task_steps/always_on.py @@ -1786,7 +1786,8 @@ def render_for_judge(record: dict) -> str: "with no known actor (made outside the env's gateway, such as on a website reached directly), each with " "when it was seen. The user saw only the messages the assistant sent."] wakes = [e for e in timeline if e["event"] == "wake"] - zone = next((e.get("time_zone") for e in timeline if e["event"] == "start"), None) or "UTC" + zone = (record.get("time_zone") or next((e.get("time_zone") for e in timeline if e["event"] == "start"), None) + or "UTC") # the record's own, since a tail kept when the store failed may have lost the start for wake in wakes[:JUDGE_WAKES]: n = wake["n"] turn = turns.get(n) or {} diff --git a/src/agent_env/task_step/task_steps/notification_delivery.py b/src/agent_env/task_step/task_steps/notification_delivery.py index 4d867bf97..8736cfa26 100644 --- a/src/agent_env/task_step/task_steps/notification_delivery.py +++ b/src/agent_env/task_step/task_steps/notification_delivery.py @@ -54,9 +54,10 @@ def label_time(at: Optional[str], zone: str = "UTC") -> str: def labels_zone(clocks: list[dict]) -> str: - """The zone lines are labelled in when no user names one: the one sync_env_clock gave the world, else UTC, as it is - when the world has several.""" - zones = {c["timezone"] for c in clocks if c.get("timezone")} + """The zone lines are labelled in when no user names one: the one sync_env_clock gave the world, by each env's + latest arm, else UTC, as it is when the world has several.""" + latest = {c.get("env_id"): c.get("timezone") for c in clocks} # a later arm of an env replaces an earlier one + zones = {zone for zone in latest.values() if zone} return zones.pop() if len(zones) == 1 else "UTC" diff --git a/tst/unit/task_step/test_always_on_agent_verifier.py b/tst/unit/task_step/test_always_on_agent_verifier.py index f112d8d7b..37bb3d27f 100644 --- a/tst/unit/task_step/test_always_on_agent_verifier.py +++ b/tst/unit/task_step/test_always_on_agent_verifier.py @@ -140,6 +140,12 @@ async def test_a_prompt_no_always_on_step_made_is_refused_when_it_is_graded(monk await verifier.execute(ctx) +def test_the_wake_by_wake_text_is_in_the_run_s_zone_though_its_kept_tail_lost_the_start(): + record = {"time_zone": "America/Denver", "timeline_tail": [ + {"event": "wake", "n": 30, "virtual_time": "2027-02-06T00:30:00Z", "woke_by": ["user_reply"]}]} + assert "- Wake 30 · Fri Feb 5, 5:30 PM MST · woken by" in ao.render_for_judge(record) + + def test_the_wake_by_wake_text_says_when_the_record_is_unreadable(): text = ao.render_for_judge({"object_url": "file:///nowhere/at/all.json", "end_reason": "end_time"}) assert text.startswith("## The run, wake by wake\n(The run's record could not be read:") diff --git a/tst/unit/task_step/test_prompt_agent_notifications.py b/tst/unit/task_step/test_prompt_agent_notifications.py index fc1e47a5b..d621d05bf 100644 --- a/tst/unit/task_step/test_prompt_agent_notifications.py +++ b/tst/unit/task_step/test_prompt_agent_notifications.py @@ -175,9 +175,14 @@ def test_a_label_reads_the_time_in_its_zone_and_names_the_zone(at, zone, label): def test_lines_take_the_one_zone_the_world_was_given_and_utc_without_one_or_with_several(): - assert labels_zone([{"step_id": "a", "timezone": "America/Denver"}, {"step_id": "b"}]) == "America/Denver" + assert labels_zone([{"env_id": "a", "timezone": "America/Denver"}, {"env_id": "b"}]) == "America/Denver" assert labels_zone([]) == "UTC" - assert labels_zone([{"timezone": "America/Denver"}, {"timezone": "Europe/Paris"}]) == "UTC" + assert labels_zone([{"env_id": "a", "timezone": "America/Denver"}, {"env_id": "b", "timezone": "Europe/Paris"}]) == "UTC" + + +def test_an_env_armed_again_in_another_zone_is_labelled_in_the_zone_it_was_armed_in_last(): + assert labels_zone([{"env_id": "office", "timezone": "America/Los_Angeles"}, + {"env_id": "office", "timezone": "America/Denver"}]) == "America/Denver" @pytest.mark.asyncio From 7fff99ecb6c103362b60c21b1261d95028ed9f87 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 16 Nov 2026 14:14:38 -0800 Subject: [PATCH 3/3] fix(task_step): a clock rate change keeps the zone its env was armed in Co-Authored-By: Claude Opus 5.5 --- .../task_steps/notification_delivery.py | 5 +++-- .../test_prompt_agent_notifications.py | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/agent_env/task_step/task_steps/notification_delivery.py b/src/agent_env/task_step/task_steps/notification_delivery.py index 8736cfa26..3f80d1280 100644 --- a/src/agent_env/task_step/task_steps/notification_delivery.py +++ b/src/agent_env/task_step/task_steps/notification_delivery.py @@ -55,8 +55,9 @@ def label_time(at: Optional[str], zone: str = "UTC") -> str: def labels_zone(clocks: list[dict]) -> str: """The zone lines are labelled in when no user names one: the one sync_env_clock gave the world, by each env's - latest arm, else UTC, as it is when the world has several.""" - latest = {c.get("env_id"): c.get("timezone") for c in clocks} # a later arm of an env replaces an earlier one + latest arm, else UTC, as it is when the world has several. A rate change (set_env_clock_rate's entry, which has + no ``env_get_time_url``) keeps the zone its env was armed in.""" + latest = {c.get("env_id"): c.get("timezone") for c in clocks if "env_get_time_url" in c} zones = {zone for zone in latest.values() if zone} return zones.pop() if len(zones) == 1 else "UTC" diff --git a/tst/unit/task_step/test_prompt_agent_notifications.py b/tst/unit/task_step/test_prompt_agent_notifications.py index d621d05bf..7d2645a83 100644 --- a/tst/unit/task_step/test_prompt_agent_notifications.py +++ b/tst/unit/task_step/test_prompt_agent_notifications.py @@ -156,7 +156,7 @@ async def test_labels_are_in_the_zone_sync_env_clock_gave_the_world_and_name_it( peers = GatewayQueue(monkeypatch, {AGENT: [text("one"), text("two")], USER: [sim("ok"), sim("bye", done=True)]}) _alder_and_ivy_due(peers) ctx = _ctx() - ctx.metadata["clock_configurations"] = [{"step_id": "clock", "timezone": "America/Los_Angeles"}] + ctx.metadata["clock_configurations"] = [_arm("env", "America/Los_Angeles")] await _step().execute(ctx) @@ -175,14 +175,22 @@ def test_a_label_reads_the_time_in_its_zone_and_names_the_zone(at, zone, label): def test_lines_take_the_one_zone_the_world_was_given_and_utc_without_one_or_with_several(): - assert labels_zone([{"env_id": "a", "timezone": "America/Denver"}, {"env_id": "b"}]) == "America/Denver" + assert labels_zone([_arm("a", "America/Denver"), _arm("b")]) == "America/Denver" assert labels_zone([]) == "UTC" - assert labels_zone([{"env_id": "a", "timezone": "America/Denver"}, {"env_id": "b", "timezone": "Europe/Paris"}]) == "UTC" + assert labels_zone([_arm("a", "America/Denver"), _arm("b", "Europe/Paris")]) == "UTC" -def test_an_env_armed_again_in_another_zone_is_labelled_in_the_zone_it_was_armed_in_last(): - assert labels_zone([{"env_id": "office", "timezone": "America/Los_Angeles"}, - {"env_id": "office", "timezone": "America/Denver"}]) == "America/Denver" +def _arm(env_id: str, zone: str | None = None) -> dict: + """A clock configuration as sync_env_clock records an arm.""" + return {"step_id": "clock", "env_id": env_id, "env_get_time_url": "http://gateway/clock/time", + **({"timezone": zone} if zone else {})} + + +def test_an_env_armed_again_is_labelled_in_the_zone_of_its_latest_arm_and_a_rate_change_keeps_it(): + rate_change = {"step_id": "running", "env_id": "office", "virtual_seconds_per_real_second": 1.0} + assert labels_zone([_arm("office", "America/Los_Angeles"), _arm("office", "America/Denver")]) == "America/Denver" + assert labels_zone([_arm("office", "America/Denver"), rate_change]) == "America/Denver" + assert labels_zone([_arm("office", "America/Denver"), _arm("office")]) == "UTC" @pytest.mark.asyncio