Skip to content

Retry OpenCodeSessionFactory.create() with backoff - #1009

Merged
burtenshaw merged 1 commit into
huggingface:mainfrom
sergiopaniego:opencode-factory-create-retry
Jul 29, 2026
Merged

Retry OpenCodeSessionFactory.create() with backoff#1009
burtenshaw merged 1 commit into
huggingface:mainfrom
sergiopaniego:opencode-factory-create-retry

Conversation

@sergiopaniego

@sergiopaniego sergiopaniego commented Jul 24, 2026

Copy link
Copy Markdown
Member

Adds retry-with-backoff to OpenCodeSessionFactory.create().

Why

Session creation spins up a sandbox, installs opencode, and starts the proxy + agent. It is the flakiest step in a rollout (sandbox-API blips, cold install, proxy start). Today a single transient failure drops the whole rollout as unscorable, which shrinks the effective group size and silently weakens the training signal. This is one of the TODO(@openenv) gaps flagged in TRL's loop-owning harness work (huggingface/trl#6420).

Change

  • create() now retries up to create_attempts (default 3) with exponential backoff (create_backoff_s * 2**i, default base 2s), matching the existing _exec_with_retry style.
  • The per-attempt logic moved verbatim into _create_once, which already tears its own sandbox down on any post-provision failure, so a retry never leaks a sandbox.

Tests

The two existing teardown tests now pin create_attempts=1 (they test a single attempt's cleanup). Two new tests cover the wrapper: retries-then-succeeds, and raises-after-exhausting-attempts.

pi_env's PiSessionFactory.create() mirrors this and gets the same change on its own PR (#999).

AI-assisted.


Note

Low Risk
Isolated harness resilience change with defaults preserving prior single-attempt semantics only when callers override; rollout provisioning path only, no auth or data handling.

Overview
OpenCodeSessionFactory.create() now retries transient provisioning failures instead of failing the whole rollout on the first error.

The factory accepts create_attempts (default 3) and create_backoff_s (default 2s, exponential 2**i). The previous single-shot logic lives in _create_once, which still kills the sandbox on failure so retries do not leak sandboxes. Failed attempts are logged at warning level before sleep/retry; the last exception is re-raised when attempts are exhausted.

Lifecycle tests pin create_attempts=1 so teardown behavior stays single-attempt; new tests cover success after flaky failures and failure after all attempts.

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

Copilot AI review requested due to automatic review settings July 24, 2026 06:18

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.

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.

Session creation spins up a sandbox, installs opencode, and starts the proxy +
agent, the flakiest step in a rollout; a single transient failure used to drop
the rollout as unscorable, shrinking the effective group size. create() now
retries create_attempts times with exponential backoff. The per-attempt logic
moved to _create_once, which already tears its own sandbox down on failure, so
a retry never leaks a sandbox.
@burtenshaw
burtenshaw force-pushed the opencode-factory-create-retry branch from 0cd39bf to 34af51a Compare July 29, 2026 10:38
Copilot AI review requested due to automatic review settings July 29, 2026 10:38

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 1b6e9a9 into huggingface:main Jul 29, 2026
8 checks passed
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