Skip to content

fix(openclaw_agent): report Gym-enforced timeouts as not finished naturally - #4234

Draft
giuliolovisotto wants to merge 2 commits into
mainfrom
glovisotto/openclaw-timeout-not-natural
Draft

giuliolovisotto wants to merge 2 commits into
mainfrom
glovisotto/openclaw-timeout-not-natural

Conversation

@giuliolovisotto

Copy link
Copy Markdown
Contributor

What does this PR do?

openclaw_agent runs the openclaw CLI as a subprocess under two Gym-enforced limits: setup_timeout for openclaw onboard and timeout for openclaw agent. When either limit fires, the agent keeps the rollout scoreable: on an agent-run timeout it salvages the partial session from disk, and on a setup timeout it pads an empty assistant message. In both cases the output still ends in an assistant message, so run() reported finished_naturally=True, which made a timed-out rollout look the same as a normal finish.

This PR:

  • returns a timed_out flag from _run_openclaw (set when the agent-run timeout fires) and sets it in _create_response when the setup timeout propagates;
  • carries it from /v1/responses to run() as an internal response key, _ng_agent_timed_out, set only on timed-out runs. This follows how the agent already passes _ng_agent_observations, and matches the timeout fix for opencode_agent (fix(opencode): align timeout completion status #4233);
  • in run(), removes that key from the response before calling /verify, reports finished_naturally=False for those runs and adds an explicit agent_timed_out: bool to the verify response. The name matches anyterminal_agent, anyswe_agent and swe_agents.

The salvaged or padded output, the /verify payload, and the reward are unchanged. OpenClaw's own internal idle watchdog is out of scope.

Related: #2831, #3182 (rollout observability / error-recovery signals). No dedicated issue: this is a small reporting fix.

This will conflict with draft #3637 (OpenClaw in native task sandboxes); whichever lands second rebases.

Validation

  • pytest responses_api_agents/openclaw_agent/tests (worktree dev venv): 67 passed.
  • ng_test +entrypoint=responses_api_agents/openclaw_agent (same command CI runs for changed servers): passed.
  • New TestTimeoutReporting tests drive run() end-to-end with a mocked subprocess (_run_exec) for a natural finish, an agent-run timeout and a setup timeout. They check finished_naturally, agent_timed_out, the unchanged reward, that the salvaged/padded output is what gets verified, and that /verify receives neither the internal key nor any timeout metadata. Without the fix, both timeout tests fail with finished_naturally is True.
  • pre-commit run --all-files: passed.

Rollouts

N/A: this changes only how a timed-out run is reported (finished_naturally, agent_timed_out). Agent behavior, the output items and the verifier are untouched. The timeout paths are covered with a mocked subprocess, because reproducing them against a real model would only mean waiting for a limit to expire.

Compatibility and benchmark impact

  • Rewards and scores: unchanged.
  • finished_naturally changes from True to False for rollouts that hit setup_timeout or timeout. Any aggregate of finished_naturally for OpenClaw runs drops by the timed-out fraction.
  • New verify-response field agent_timed_out (default False).
  • _run_openclaw (private) now returns a 4-tuple. No callers outside this module.

Checklist

  • I have read the contributing guidelines.
  • The change is focused; unrelated "drive-by" edits are tracked as separate issues/PRs.
  • Tests added or updated and pass locally, or N/A for docs-only / non-code changes (so CI unit/server checks pass when applicable).
  • Documentation added or updated, or N/A with justification. N/A: the README does not document verify-response fields.
  • Pre-commit checks pass locally (pre-commit run --all-files) (so CI lint/format checks pass).
  • New source files include the required Apache-2.0 SPDX header. N/A: no new files.
  • All commits have DCO sign-off (git commit -s) (so the DCO check passes).

🤖 Generated with Claude Code

giuliolovisotto and others added 2 commits October 6, 2026 17:36
…urally

When the OpenClaw CLI hit setup_timeout (onboard) or timeout (agent run),
the agent salvaged the partial session or padded an empty assistant
message, so run() reported finished_naturally=True, the same as a normal
finish.

Carry the timeout from _run_openclaw to the response metadata
(openclaw_agent_timed_out="true", only set on timeout) and have run()
report finished_naturally=False plus an explicit agent_timed_out flag.
The salvaged/padded output, what gets verified and the reward are
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
…nse key

Replace the openclaw_agent_timed_out response metadata with an internal
_ng_agent_timed_out key, set only when setup_timeout or timeout fired.
run() pops it from the /v1/responses JSON before calling /verify, so the
verify payload is the same as before this change, matching how
opencode_agent carries its timeout. finished_naturally and agent_timed_out
are reported as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Giulio Lovisotto <[email protected]>
@giuliolovisotto giuliolovisotto added bug Something isn't working area:agent Agent harnesses and Responses API agent behavior labels Oct 8, 2026
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Agent harnesses and Responses API agent behavior bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant