Skip to content

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

Open
sergiopaniego wants to merge 2 commits into
huggingface:mainfrom
sergiopaniego:fix-hf-sandbox-client-timeout-and-retry
Open

Fix OpenCodeEnv client timeout and retry transient sandbox-API polls#1005
sergiopaniego wants to merge 2 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
Targeted client timeout and poll-retry logic with unit tests; no auth, data, or API contract changes.

Overview
Improves robustness for long OpenCode rollouts and Hugging Face sandbox background-job polling.

OpenCodeEnv now defaults message_timeout_s to 1800s (via a new __init__) so MCP run_rollout calls are not cut off by the inherited 60s client timeout while the server allows runs up to ~900s.

HFBgJob.wait() in the shared HF sandbox backend retries httpx.TransportError on Sandbox.processes() polls instead of failing on a single API blip; it stops after 10 consecutive transient errors and still respects finite timeout deadlines. Unit tests cover recovery, persistent failure, and timeout-vs-transient behavior.

Reviewed by Cursor Bugbot for commit 94a5ed5. 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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

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 017dedc. Configure here.

Comment thread envs/opencode_env/sandbox/hf.py Outdated
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.
@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.

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.
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.

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.

2 participants