From 71e19456bfb43e19087dd5514821a268f88f7450 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 15 Nov 2026 05:34:01 +0000 Subject: [PATCH 1/2] fix(task_step): give snapshot_agent_state's save the transfer timeout by default --- .../task_steps/snapshot_agent_state.py | 4 ++- .../task_step/test_snapshot_agent_state.py | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/agent_env/task_step/task_steps/snapshot_agent_state.py b/src/agent_env/task_step/task_steps/snapshot_agent_state.py index b491029d6..deff61185 100644 --- a/src/agent_env/task_step/task_steps/snapshot_agent_state.py +++ b/src/agent_env/task_step/task_steps/snapshot_agent_state.py @@ -7,6 +7,7 @@ from typing import ClassVar, Optional from agent_env.a2a_agent import A2AAgent +from agent_env.a2a_agent.object_transfer import TRANSFER_TIMEOUT_SECONDS from agent_env.store.ids import derive_id, is_local_id, validate_local_id from agent_env.task_step.context import TaskStepContext from agent_env.entity.refs import EntityRef, RefRole @@ -54,7 +55,8 @@ class SnapshotAgentStateTaskStep(TaskStep): EntityRef.env("env_id"), EntityRef.artifact("universe_artifact_id", artifact_type="environment_universe"), ) - DEFAULT_TIMEOUT_SECONDS: ClassVar[int] = 120 + # A save moves the workspace, so it gets the budget of a call that moves objects. + DEFAULT_TIMEOUT_SECONDS: ClassVar[int] = TRANSFER_TIMEOUT_SECONDS def __init__( self, diff --git a/tst/unit/task_step/test_snapshot_agent_state.py b/tst/unit/task_step/test_snapshot_agent_state.py index 551f1cd26..92d42e8b9 100644 --- a/tst/unit/task_step/test_snapshot_agent_state.py +++ b/tst/unit/task_step/test_snapshot_agent_state.py @@ -378,3 +378,34 @@ def test_a_stored_step_without_the_artifact_id_key_loads(): del data["artifact_id"] assert mod.SnapshotAgentStateTaskStep.from_dict(data).artifact_id is None + + +def test_a_save_defaults_to_the_budget_of_a_call_that_moves_objects(): + from agent_env.a2a_agent.object_transfer import TRANSFER_TIMEOUT_SECONDS + + data = _per_run_step().to_dict() + del data["timeout_seconds"] + + assert _per_run_step().timeout_seconds == TRANSFER_TIMEOUT_SECONDS + assert mod.SnapshotAgentStateTaskStep.from_dict(data).timeout_seconds == TRANSFER_TIMEOUT_SECONDS + + +@pytest.mark.asyncio +@pytest.mark.parametrize(("configured", "expected"), [(None, 600), (45, 45)]) +async def test_the_save_waits_for_the_steps_timeout_seconds(monkeypatch, configured, expected): + waited: list[float] = [] + + async def _capture(*, timeout_seconds, artifact_id, **_): + waited.append(timeout_seconds) + return agent_state_capture.WorkspaceCapture( + universe_id=artifact_id, universe_version=1, bundle_object_url="fake://b/w", capture_prefix="fake://b/", + ) + + monkeypatch.setattr(agent_state_capture, "capture_workspace", _capture) + step = _per_run_step() + if configured is not None: + step.timeout_seconds = configured + + await step.execute(_run_ctx("inst-a")) + + assert waited == [expected] From ad1a09efb1f1f1fddb8c5d327e6ae79125f00f91 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 15 Nov 2026 07:47:26 +0000 Subject: [PATCH 2/2] fix(task_step): let stored snapshot_agent_state steps pick up the default timeout to_dict wrote timeout_seconds into every stored step, so a step saved before the new default kept 120 s. Write the key only when a timeout is set, and read a stored 120, the old default, as unset. --- .../task_steps/snapshot_agent_state.py | 13 +++-- .../task_step/test_snapshot_agent_state.py | 48 ++++++++++++------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/agent_env/task_step/task_steps/snapshot_agent_state.py b/src/agent_env/task_step/task_steps/snapshot_agent_state.py index deff61185..8ba6a028c 100644 --- a/src/agent_env/task_step/task_steps/snapshot_agent_state.py +++ b/src/agent_env/task_step/task_steps/snapshot_agent_state.py @@ -57,6 +57,9 @@ class SnapshotAgentStateTaskStep(TaskStep): ) # A save moves the workspace, so it gets the budget of a call that moves objects. DEFAULT_TIMEOUT_SECONDS: ClassVar[int] = TRANSFER_TIMEOUT_SECONDS + # to_dict once wrote the default into every stored step, so a stored 120 cannot be told apart + # from a chosen one. Reading it as unset lets those steps pick up the current default. + _LEGACY_DEFAULT_TIMEOUT_SECONDS: ClassVar[int] = 120 def __init__( self, @@ -67,7 +70,7 @@ def __init__( agent_name: Optional[str] = None, env_id: Optional[str] = None, universe_artifact_id: Optional[str] = None, - timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS, + timeout_seconds: Optional[int] = None, depends_on: Optional[list[TaskStepDependency]] = None, fail_task_on_error: bool = True, ): @@ -92,11 +95,13 @@ def to_dict(self) -> dict: base["agent_name"] = self.agent_name base["env_id"] = self.env_id base["universe_artifact_id"] = self.universe_artifact_id - base["timeout_seconds"] = self.timeout_seconds + if self.timeout_seconds is not None: + base["timeout_seconds"] = self.timeout_seconds return base @classmethod def from_dict(cls, data: dict) -> SnapshotAgentStateTaskStep: + stored_timeout = data.get("timeout_seconds") return cls( **cls._base_from_dict(data), artifact_id=data.get("artifact_id"), @@ -104,7 +109,7 @@ def from_dict(cls, data: dict) -> SnapshotAgentStateTaskStep: agent_name=data.get("agent_name"), env_id=data.get("env_id"), universe_artifact_id=data.get("universe_artifact_id"), - timeout_seconds=data.get("timeout_seconds", cls.DEFAULT_TIMEOUT_SECONDS), + timeout_seconds=None if stored_timeout == cls._LEGACY_DEFAULT_TIMEOUT_SECONDS else stored_timeout, ) @property @@ -154,7 +159,7 @@ async def execute(self, context: TaskStepContext) -> TaskStepContext: agent_name=self.agent_name, a2a_context_id=a2a_context_id, artifact_id=self._resolve_artifact_id(context), - timeout_seconds=self.timeout_seconds, + timeout_seconds=self.DEFAULT_TIMEOUT_SECONDS if self.timeout_seconds is None else self.timeout_seconds, sandbox_type=deployed.sandbox_type, ) diff --git a/tst/unit/task_step/test_snapshot_agent_state.py b/tst/unit/task_step/test_snapshot_agent_state.py index 92d42e8b9..c77ff8609 100644 --- a/tst/unit/task_step/test_snapshot_agent_state.py +++ b/tst/unit/task_step/test_snapshot_agent_state.py @@ -380,19 +380,7 @@ def test_a_stored_step_without_the_artifact_id_key_loads(): assert mod.SnapshotAgentStateTaskStep.from_dict(data).artifact_id is None -def test_a_save_defaults_to_the_budget_of_a_call_that_moves_objects(): - from agent_env.a2a_agent.object_transfer import TRANSFER_TIMEOUT_SECONDS - - data = _per_run_step().to_dict() - del data["timeout_seconds"] - - assert _per_run_step().timeout_seconds == TRANSFER_TIMEOUT_SECONDS - assert mod.SnapshotAgentStateTaskStep.from_dict(data).timeout_seconds == TRANSFER_TIMEOUT_SECONDS - - -@pytest.mark.asyncio -@pytest.mark.parametrize(("configured", "expected"), [(None, 600), (45, 45)]) -async def test_the_save_waits_for_the_steps_timeout_seconds(monkeypatch, configured, expected): +async def _waited_for(monkeypatch, step) -> float: waited: list[float] = [] async def _capture(*, timeout_seconds, artifact_id, **_): @@ -402,10 +390,34 @@ async def _capture(*, timeout_seconds, artifact_id, **_): ) monkeypatch.setattr(agent_state_capture, "capture_workspace", _capture) - step = _per_run_step() - if configured is not None: - step.timeout_seconds = configured - await step.execute(_run_ctx("inst-a")) + (seconds,) = waited + return seconds + + +@pytest.mark.asyncio +async def test_a_step_built_without_a_timeout_omits_it_and_waits_the_transfer_budget(monkeypatch): + stored = _per_run_step().to_dict() + + assert "timeout_seconds" not in stored + assert await _waited_for(monkeypatch, mod.SnapshotAgentStateTaskStep.from_dict(stored)) == 600 + + +@pytest.mark.asyncio +async def test_a_stored_step_carrying_the_old_default_waits_the_transfer_budget(monkeypatch): + stored = {**_per_run_step().to_dict(), "timeout_seconds": 120} + + step = mod.SnapshotAgentStateTaskStep.from_dict(stored) + + assert "timeout_seconds" not in step.to_dict() + assert await _waited_for(monkeypatch, step) == 600 + + +@pytest.mark.asyncio +async def test_a_chosen_timeout_round_trips_and_bounds_the_save(monkeypatch): + stored = mod.SnapshotAgentStateTaskStep( + id="t-agent-snapshot", version=None, artifact_id=None, prompt_id="main", agent_name="agent", timeout_seconds=45, + ).to_dict() - assert waited == [expected] + assert stored["timeout_seconds"] == 45 + assert await _waited_for(monkeypatch, mod.SnapshotAgentStateTaskStep.from_dict(stored)) == 45