From 90d0b20e1c438f1455dcea324137fab10d65b0b7 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Wed, 18 Nov 2026 23:05:26 -0800 Subject: [PATCH] fix(agents): an agent's clock sync sends its control token follow() posted clock/v1 sync_time with the sandbox's headers only, so an agent whose extension routes take its control token (protocol 0.1.582 and later) refused it with a 401, and every task that arms the env's clock failed at sync_env_clock or at the deploy of an agent while the clock runs. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/a2a_agent/clock.py | 3 ++- tst/unit/task_step/agent_clock_test.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/agent_env/a2a_agent/clock.py b/src/agent_env/a2a_agent/clock.py index 87156d198..469c590e4 100644 --- a/src/agent_env/a2a_agent/clock.py +++ b/src/agent_env/a2a_agent/clock.py @@ -93,7 +93,8 @@ async def follow(agent: DeployedAgent, env: DeployedEnv, *, env_get_time_url: Op url = (agent.a2a_url or agent.api_url).rstrip("/") + path try: async with httpx.AsyncClient() as client: - answer = await client.post(url, json=body, timeout=timeout, headers=sandbox_request_headers_for_url(url)) + answer = await client.post(url, json=body, timeout=timeout, + headers={**sandbox_request_headers_for_url(url), **agent.control_headers}) except httpx.HTTPError as e: why = f"({type(e).__name__}): {e}" else: diff --git a/tst/unit/task_step/agent_clock_test.py b/tst/unit/task_step/agent_clock_test.py index 089a28b24..595ee7bfc 100644 --- a/tst/unit/task_step/agent_clock_test.py +++ b/tst/unit/task_step/agent_clock_test.py @@ -7,6 +7,7 @@ from types import SimpleNamespace import pytest +from agentenv_protocol import CONTROL_TOKEN_HEADER from agent_env.env.gateway.constants import EXT_CLOCK_URI from agent_env.task_step.context import DeployedAgent, StepContextError, TaskStepContext @@ -16,6 +17,7 @@ _step) AGENT_URL = "http://solver:8000" +AGENT_CONTROL_TOKEN = "the-agents-control-token" SYNC_TIME = {"method": "POST", "endpoint": "/ext/clock/sync-time", "request": {"required": ["env_get_time_url"], "optional": ["timezone", "watch_url", "name", "read_token"]}} @@ -23,7 +25,8 @@ def _agent(name="solver", sync_time=SYNC_TIME, env_ids=("e1",)) -> DeployedAgent: extensions = [{"uri": EXT_CLOCK_URI, "params": {"endpoint": "/ext/clock", "methods": {"sync_time": sync_time}}}] return DeployedAgent(agent_name=name, api_url=AGENT_URL, a2a_url=AGENT_URL, env_ids=list(env_ids), - a2a_card={"capabilities": {"extensions": extensions if sync_time else []}}) + a2a_card={"capabilities": {"extensions": extensions if sync_time else []}}, + control_token=AGENT_CONTROL_TOKEN) async def _context(*agents) -> TaskStepContext: @@ -49,6 +52,7 @@ async def test_an_agent_is_declared_a_follower_then_handed_its_config_with_the_s declared, synced = sent[3], sent[4] assert (declared.method, str(declared.url)) == ("PUT", f"{_CARD}/clock/followers") assert (synced.method, str(synced.url)) == ("POST", f"{AGENT_URL}/ext/clock/sync-time") + assert synced.headers[CONTROL_TOKEN_HEADER] == AGENT_CONTROL_TOKEN declaration, config = json.loads(declared.content), json.loads(synced.content) assert declaration == {"name": "agent-solver", "read_token": config["read_token"]} and len(config["read_token"]) > 30 assert config == {"env_get_time_url": CLOCK_URL, "watch_url": "http://gw/clock/watch", "name": "agent-solver",