You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: stale retries continue with old model after real-time model switch #66
Real-time model switching does not reliably take effect when the current request is retrying after an LLM/API failure.
Reproduction
Active provider reaches quota / returns a retryable error.
Request fails and retry/backoff begins in SessionProcessor.process.
User switches to another model/provider via session.update.
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
fix: cancel stale retries when model is switched mid-backoff