fix: surface agent timeout as state['error'] in CliAgentEnv#1170
Merged
fix: surface agent timeout as state['error'] in CliAgentEnv#1170
Conversation
When the agent background job exceeds timeout_seconds, wait_for_completion previously set only agent_timed_out=True and left state["error"] unset. Rollouts with no trajectory then returned error=None, which the orchestrator scheduler logs as a generic "Empty trajectory" with no root cause. Mirror the behavior of the Exception branch and set state["error"] to an AgentError naming the timeout so downstream consumers can distinguish a timed-out rollout from a silently empty one. agent_timed_out=True is kept for existing downstream checks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CliAgentEnv.wait_for_completioncatchesasyncio.TimeoutErrorbut only setsstate["agent_timed_out"] = True, leavingstate["error"]unset. When the agent times out without producing any trajectory, the rollout comes back withtrajectory=[], error=None, and the orchestrator scheduler reschedules it as a generic "Empty trajectory" with no diagnostic — indistinguishable from a genuinely silent empty rollout.Fix
In the
asyncio.TimeoutErrorbranch, also setstate["error"] = AgentError(f"Agent timed out after {self.timeout_seconds}s"), mirroring the style of theexcept Exceptionbranch directly below.agent_timed_out=Trueis preserved for existing downstream checks elsewhere in the file.Context
Third in a series closing silent-failure holes in
CliAgentEnv:A companion fix in prime-rl reorders the scheduler's
if empty / elif errorso that the error branch is checked first (otherwise this surfaced error would still be hidden behind the empty-trajectory branch). See companion PR in prime-rl.Tests
No regression test was added. The existing
tests/test_cli_agent_env.pycoverstimeout_reached(the stop-condition) but does not exercisewait_for_completion'sasyncio.TimeoutErrorpath. Adding such a test would require mockingasyncio.wait_forand the background-job polling loop, which felt out of scope for a 3-line fix — flagged here for a follow-up if desired.Checks
uv run ruff check verifiers/envs/experimental/cli_agent_env.py— passeduv run ruff format --check verifiers/envs/experimental/cli_agent_env.py— already formattedNote
Low Risk
Small, localized change to timeout handling that only affects how errors are surfaced in rollout state; minimal behavioral impact beyond improved diagnostics and potential downstream branching on
state["error"].Overview
CliAgentEnv.wait_for_completionnow records timeouts as a real failure by settingstate["error"]to anAgentErrorwhenasyncio.wait_forhitsTimeoutError, in addition to the existingstate["agent_timed_out"] = Trueflag.This ensures timeout rollouts surface a diagnostic error instead of looking like a silent empty trajectory to downstream schedulers/consumers.
Reviewed by Cursor Bugbot for commit e88fd94. Bugbot is set up for automated code reviews on this repo. Configure here.