# tinker_cookbook.rl.RetryOnFailure ## *class* [**tinker_cookbook.rl.RetryOnFailure**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L128)(*[RolloutStrategy](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/rolloutstrategy/index.md)*) Retry failed or timed-out trajectories with fresh environments. When a trajectory fails (container crash, sandbox flake, transient error) or exceeds `per_rollout_timeout` seconds, a fresh env is created via `make_envs()` and the rollout is retried. This continues until either all trajectories succeed or the retry budget is exhausted. If the retry budget is exhausted and a failure still occurs, the remaining in-flight tasks are cancelled and the exception is re-raised. This avoids partial-group bias from training on an incomplete set of trajectories. Uses `asyncio.wait(FIRST_COMPLETED)` so retries start as soon as a failure is detected, without waiting for other in-flight rollouts. **Fields:** - [**max_retries**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L153) (*int*, default: `3`) - [**per_rollout_timeout**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L154) (*float*, default: `0`) ### [**execute**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L160)(*env_group_builder*, *policy*) Run rollouts with automatic retry on individual trajectory failures. Creates environments, launches all rollouts concurrently, and retries any that fail (or time out) by creating a fresh environment. Uses `asyncio.wait(FIRST_COMPLETED)` so retries begin immediately upon detecting a failure. **Parameters:** - [**env_group_builder**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L162) (*[EnvGroupBuilder](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/envgroupbuilder/index.md)*) – Builder used to create (and re-create on retry) environments for this rollout group. - [**policy**](https://github.com/thinking-machines-lab/tinker-cookbook/blob/main/tinker_cookbook/rl/rollout_strategy.py#L163) (*[TokenCompleter](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/completers/tokencompleter/index.md)*) – The policy used to generate actions. **Returns:** *RolloutResult* – Result containing the successfully completed trajectories, surviving environments, and a list of any errors encountered (including retried ones). **Raises:** - Exception: Re-raises the failing exception when the retry budget - is exhausted, after cancelling all remaining in-flight tasks.