From 56dcce8ff1c69b0581a78d146e9b6639743e92ee Mon Sep 17 00:00:00 2001 From: Andrew Park Date: Thu, 12 Nov 2026 03:42:18 +0000 Subject: [PATCH] fix(task_step): sync_env_clock raises StepContextError for a server that can't take the clock the task asks for --- src/agent_env/task_step/task_steps/sync_env_clock.py | 4 ++-- tst/unit/task_step/sync_env_clock_test.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/agent_env/task_step/task_steps/sync_env_clock.py b/src/agent_env/task_step/task_steps/sync_env_clock.py index b4c92793e..6f52b0abc 100644 --- a/src/agent_env/task_step/task_steps/sync_env_clock.py +++ b/src/agent_env/task_step/task_steps/sync_env_clock.py @@ -181,14 +181,14 @@ async def _sync_one(self, deployed, gateway_url: str, service: str, env_get_time if tolerate: logger.info(f"sync_env_clock: {service} does not advertise {EXT_CLOCK_URI}; skipping") return {"synced": False, "reason": "not_advertised"} - raise RuntimeError(f"{service} does not advertise {EXT_CLOCK_URI}") + raise StepContextError(f"{service} does not advertise {EXT_CLOCK_URI}") if not env_get_time_url: raise RuntimeError(f"gateway did not expose env_get_time_url; cannot sync {service}") params = {"env_get_time_url": env_get_time_url} if self.timezone is not None: method = protocol_v1.find_extension_method(card, EXT_CLOCK_URI, "sync_time") or {} if "timezone" not in ((method.get("request") or {}).get("properties") or {}): - raise RuntimeError(f"{service} advertises {EXT_CLOCK_URI} but its sync_time takes no timezone; " + raise StepContextError(f"{service} advertises {EXT_CLOCK_URI} but its sync_time takes no timezone; " f"rebuild its image or drop timezone={self.timezone!r} from the task") params["timezone"] = self.timezone result = await protocol_v1.invoke_extension(base_url, card, EXT_CLOCK_URI, diff --git a/tst/unit/task_step/sync_env_clock_test.py b/tst/unit/task_step/sync_env_clock_test.py index e95acf2b3..e8d01e65c 100644 --- a/tst/unit/task_step/sync_env_clock_test.py +++ b/tst/unit/task_step/sync_env_clock_test.py @@ -6,7 +6,7 @@ from agent_env.env.env import DeployedEnv, DeployedGatewayEnv, EnvCapabilityUnsupported from agent_env.env.gateway.constants import EXT_CLOCK_URI -from agent_env.task_step.context import TaskStepContext +from agent_env.task_step.context import StepContextError, TaskStepContext from agent_env.task_step.task_steps import sync_env_clock as mod from agent_env.task_step.task_steps.sync_env_clock import SyncEnvClockTaskStep, resolve_virtual_time @@ -254,7 +254,7 @@ async def test_strict_execute_skips_websites_but_not_mcp_servers_that_do_not_fol assert [(s["service"], s["reason"]) for s in record["skipped"]] == [("shop", "not_advertised"), ("legacy", "no_env_card")] unsynced = TaskStepContext(deployed_envs=[_carded(await _composed_card({"mcp-email": [], "shop": [_CLOCK_EXT]}))]) - with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(RuntimeError, match="email does not advertise"): + with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(StepContextError, match="email does not advertise"): await _step(tolerate_missing_sync_time=False).execute(unsynced) @@ -378,7 +378,7 @@ async def test_a_server_that_cannot_take_the_zone_fails_the_step_before_any_sync monkeypatch.setattr("agent_env.env.env.Env.get", lambda *a, **k: SimpleNamespace(environment_name="email")) context = TaskStepContext(deployed_envs=[_carded(await _composed_card({"mcp-email": [_OLD_EXT]}))]) - with pytest.raises(RuntimeError, match="takes no timezone"): + with pytest.raises(StepContextError, match="takes no timezone"): await _zoned(tolerate_missing_sync_time=tolerate).execute(context) assert not any(str(r.url).endswith("/sync_time") for r in sent) @@ -415,7 +415,7 @@ async def test_a_zoned_step_tells_a_website_that_takes_the_zone_and_fails_on_one _mock_http(monkeypatch, state={"env_get_time_url": CLOCK_URL}) older = TaskStepContext(deployed_envs=[_carded(await _composed_card({"shop": [_OLD_EXT]}))]) - with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(RuntimeError, match="shop advertises .* takes no timezone"): + with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(StepContextError, match="shop advertises .* takes no timezone"): await _zoned().execute(older)