Skip to content

Retry OpenCodeSessionFactory.create() with backoff - #1009

Open
sergiopaniego wants to merge 2 commits into
huggingface:mainfrom
sergiopaniego:opencode-factory-create-retry
Open

Retry OpenCodeSessionFactory.create() with backoff#1009
sergiopaniego wants to merge 2 commits 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

Medium Risk
Changes rollout/session startup behavior and can add delay on repeated failures, but scope is limited to factory create retries with existing per-attempt cleanup.

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

The factory accepts create_attempts (default 3) and create_backoff_s (default 2s). create() loops with exponential backoff (create_backoff_s * 2**i), logs warnings between tries, and re-raises the last error when attempts are exhausted. The previous single-shot logic lives unchanged in _create_once, which still kills the sandbox on post-provision failure so retries do not leak sandboxes.

Lifecycle tests pin create_attempts=1 so teardown behavior stays single-attempt; new tests cover succeed-on-third-try and fail-after-all-attempts.

Reviewed by Cursor Bugbot for commit 0cd39bf. 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.

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.

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