Skip to content

Fix OpenCodeEnv client timeout and retry transient sandbox-API polls - #1005

Merged
burtenshaw merged 3 commits into
huggingface:mainfrom
sergiopaniego:fix-hf-sandbox-client-timeout-and-retry
Jul 29, 2026
Merged

Fix OpenCodeEnv client timeout and retry transient sandbox-API polls#1005
burtenshaw merged 3 commits into
huggingface:mainfrom
sergiopaniego:fix-hf-sandbox-client-timeout-and-retry

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Jul 23, 2026

Copy link
Copy Markdown
Member

Follow-up to #998, which landed HFSandboxBackend. Two small robustness fixes surfaced while validating loop-owning training on remote HF sandboxes.

1. OpenCodeEnv client timeout

OpenCodeEnv inherited MCPToolClient's 60s message_timeout_s default, but a rollout runs up to 900s server-side (_RUN_ROLLOUT_TIMEOUT_S). So run_rollout() timed out client-side mid-rollout. Adds an __init__ defaulting message_timeout_s to 1800s, matching the fix already in PiEnv (#999).

2. Retry transient sandbox-API polls

HFBgJob.wait() polls Sandbox.processes(), which occasionally drops a single poll with httpx.TransportError (observed RemoteProtocolError: Server disconnected without sending a response, also read timeouts). Before this, one blip aborted the whole rollout. Now it retries on the next poll tick and gives up only after a run of consecutive failures, so a transient disconnect no longer kills a training step. wait() lives in opencode_env/sandbox/hf.py, shared by both opencode_env and pi_env, so this covers both.

Tests

Two new unit tests in test_opencode_hf_sandbox.py: retry recovers from a few transient poll errors, and a persistent outage re-raises instead of looping forever. Full suite green.

Validated end-to-end: loop-owning AsyncGRPO training on HF Jobs (h200x2, opencode on remote HF sandboxes) completes cleanly with the transient poll errors now absorbed.


Note

Low Risk
Operational robustness only—timeout defaults and retry logic on sandbox polling—with unit tests and no changes to auth, rewards, or rollout semantics.

Overview
OpenCodeEnv now defaults message_timeout_s to 1800s (via an explicit constructor that forwards timeouts to MCPToolClient), so long run_rollout calls are not cut off by the previous ~60s client default while the server allows runs up to ~900s.

HFBgJob.wait() in the HF sandbox backend retries Sandbox.processes() when polls fail with httpx.TransportError, up to 10 consecutive failures, and still raises TimeoutError when a finite deadline expires. That shared wait path applies to remote HF sandbox rollouts for both opencode and pi envs.

Tests cover session client timeout forwarding and transient vs persistent poll failures.

Reviewed by Cursor Bugbot for commit 7556826. Bugbot is set up for automated code reviews on this repo. Configure here.

Copilot AI review requested due to automatic review settings July 23, 2026 13:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Comment thread envs/opencode_env/sandbox/hf.py Outdated
@sergiopaniego
sergiopaniego force-pushed the fix-hf-sandbox-client-timeout-and-retry branch from 017dedc to cf2e876 Compare July 23, 2026 13:57
Copilot AI review requested due to automatic review settings July 23, 2026 13:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 23, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 27, 2026 13:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

OpenCodeEnv inherited MCPToolClient's 60s message_timeout_s default, but a
rollout runs up to 900s server-side, so run_rollout timed out client-side
mid-rollout. Add __init__ defaulting message_timeout_s to 1800s, matching PiEnv.

HFBgJob.wait() polls Sandbox.processes(), which occasionally drops a single
poll with httpx.TransportError (RemoteProtocolError, read timeout). Retry on
the next tick and give up only after a run of consecutive failures, so a
transient disconnect no longer aborts the rollout.
HFBgJob.wait() retried httpx.TransportError from processes() without checking
the deadline, so a finite timeout could be exceeded by up to
_MAX_TRANSIENT_POLL_ERRORS * _WAIT_POLL_INTERVAL_S and a blip near the limit
raised TransportError instead of the TimeoutError callers rely on. Fall through
to the single deadline check + sleep on both the normal poll and the retry.
@burtenshaw
burtenshaw force-pushed the fix-hf-sandbox-client-timeout-and-retry branch from 00e89ac to cbfe8cd Compare July 29, 2026 10:23
Copilot AI review requested due to automatic review settings July 29, 2026 10:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cbfe8cd. Configure here.

Comment thread envs/opencode_env/client.py Outdated
Copilot AI review requested due to automatic review settings July 29, 2026 10:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@burtenshaw
burtenshaw merged commit 0e05687 into huggingface:main Jul 29, 2026
8 checks passed
@cursor cursor Bot mentioned this pull request Sep 8, 2026
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants