Skip to content

Retry OpenCodeSessionFactory.create() with backoff#1009

Open
sergiopaniego wants to merge 1 commit into
huggingface:mainfrom
sergiopaniego:opencode-factory-create-retry
Open

Retry OpenCodeSessionFactory.create() with backoff#1009
sergiopaniego wants to merge 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 behavior aside from up to two extra retries on failure; no auth or data-path changes.

Overview
OpenCodeSessionFactory.create() now retries flaky session startup instead of failing a rollout on the first transient error.

The factory accepts create_attempts (default 3) and create_backoff_s (default 2s, exponential 2**i), in the same spirit as existing _exec_with_retry. Per-attempt provisioning lives in _create_once, which still kills the sandbox on failure so retries do not leak resources.

Lifecycle tests pin create_attempts=1 so they exercise a single attempt’s teardown; new tests cover success after transient failures and re-raising after all attempts are exhausted.

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

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

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