Skip to content

fix: stale retries continue with old model after real-time model switch #66

Closed

Description

@arena-ai-coding-agent

Bug

Real-time model switching does not reliably take effect when the current request is retrying after an LLM/API failure.

Reproduction

  1. Active provider reaches quota / returns a retryable error.
  2. Request fails and retry/backoff begins in SessionProcessor.process.
  3. User switches to another model/provider via session.update.
  4. The session continues retrying the old failed provider because the retry loop in processor.ts captures streamInput (including model) in a closure and replays it on every retry attempt.

This is especially problematic with exponential backoff (delays up to 30s between retries, up to 5 retries) — the user can spend a long time waiting for a provider they already abandoned.

Root cause

In packages/opencode/src/session/processor.ts, process(streamInput) captures streamInput at call time. The inner Effect.retry(SessionRetry.policy(...)) re-runs llm.stream(streamInput) on each retry — always with the original model, never re-reading the session's current model selection from the database.

turnSelection() in prompt.ts correctly samples the latest model at the start of each turn, but the retry lives inside a single turn — it never yields control back to the loop until retries are exhausted.

Expected behavior

  • An already-started request is not mutated in place (turn-boundary semantics preserved).
  • A pending retry observes the latest valid model selection.
  • Switching away from a failed provider cancels/invalidates stale retries.
  • Normal retry behavior remains unchanged when the model has not changed.

Proposed fix

Add an invalidate hook to SessionRetry.policy that the processor uses to check (during each retry delay step) whether the session model has changed since the turn started. If the model changed, the retry schedule terminates immediately, the processor returns, and runLoop picks up the new model on the next iteration via turnSelection().

Activity

  1. added a commit that references this issue on Aug 31, 2026
    adb4492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions