Skip to content

Commit 3e16e8c

Browse files
fix(task_step): sync_env_clock raises StepContextError for a server that can't take the clock the task asks for (#632)
1 parent 05b71fc commit 3e16e8c

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎src/agent_env/task_step/task_steps/sync_env_clock.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ async def _sync_one(self, deployed, gateway_url: str, service: str, env_get_time
182182
if tolerate:
183183
logger.info(f"sync_env_clock: {service} does not advertise {EXT_CLOCK_URI}; skipping")
184184
return {"synced": False, "reason": "not_advertised"}
185-
raise RuntimeError(f"{service} does not advertise {EXT_CLOCK_URI}")
185+
raise StepContextError(f"{service} does not advertise {EXT_CLOCK_URI}")
186186
if not env_get_time_url:
187187
raise RuntimeError(f"gateway did not expose env_get_time_url; cannot sync {service}")
188188
params = {"env_get_time_url": env_get_time_url}
189189
if self.timezone is not None:
190190
method = protocol_v1.find_extension_method(card, EXT_CLOCK_URI, "sync_time") or {}
191191
if "timezone" not in ((method.get("request") or {}).get("properties") or {}):
192-
raise RuntimeError(f"{service} advertises {EXT_CLOCK_URI} but its sync_time takes no timezone; "
192+
raise StepContextError(f"{service} advertises {EXT_CLOCK_URI} but its sync_time takes no timezone; "
193193
f"rebuild its image or drop timezone={self.timezone!r} from the task")
194194
params["timezone"] = self.timezone
195195
result = await protocol_v1.invoke_extension(base_url, card, EXT_CLOCK_URI,

‎tst/unit/task_step/sync_env_clock_test.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from agent_env.env.env import DeployedEnv, DeployedGatewayEnv, EnvCapabilityUnsupported
88
from agent_env.env.gateway.constants import EXT_CLOCK_URI
9-
from agent_env.task_step.context import TaskStepContext
9+
from agent_env.task_step.context import StepContextError, TaskStepContext
1010
from agent_env.task_step.task_steps import sync_env_clock as mod
1111
from agent_env.task_step.task_steps.sync_env_clock import SyncEnvClockTaskStep, resolve_virtual_time
1212

@@ -254,7 +254,7 @@ async def test_strict_execute_skips_websites_but_not_mcp_servers_that_do_not_fol
254254
assert [(s["service"], s["reason"]) for s in record["skipped"]] == [("shop", "not_advertised"), ("legacy", "no_env_card")]
255255

256256
unsynced = TaskStepContext(deployed_envs=[_carded(await _composed_card({"mcp-email": [], "shop": [_CLOCK_EXT]}))])
257-
with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(RuntimeError, match="email does not advertise"):
257+
with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(StepContextError, match="email does not advertise"):
258258
await _step(tolerate_missing_sync_time=False).execute(unsynced)
259259

260260

@@ -378,7 +378,7 @@ async def test_a_server_that_cannot_take_the_zone_fails_the_step_before_any_sync
378378
monkeypatch.setattr("agent_env.env.env.Env.get", lambda *a, **k: SimpleNamespace(environment_name="email"))
379379
context = TaskStepContext(deployed_envs=[_carded(await _composed_card({"mcp-email": [_OLD_EXT]}))])
380380

381-
with pytest.raises(RuntimeError, match="takes no timezone"):
381+
with pytest.raises(StepContextError, match="takes no timezone"):
382382
await _zoned(tolerate_missing_sync_time=tolerate).execute(context)
383383
assert not any(str(r.url).endswith("/sync_time") for r in sent)
384384

@@ -415,7 +415,7 @@ async def test_a_zoned_step_tells_a_website_that_takes_the_zone_and_fails_on_one
415415

416416
_mock_http(monkeypatch, state={"env_get_time_url": CLOCK_URL})
417417
older = TaskStepContext(deployed_envs=[_carded(await _composed_card({"shop": [_OLD_EXT]}))])
418-
with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(RuntimeError, match="shop advertises .* takes no timezone"):
418+
with patch("agent_env.env.env.Env.get", return_value=env), pytest.raises(StepContextError, match="shop advertises .* takes no timezone"):
419419
await _zoned().execute(older)
420420

421421

0 commit comments

Comments
 (0)