feat: per-model retry/fallback and detailed error reporting for Ask inference and MCP
Fixes #
Problem
When an inference request failed inside Ask (or the MCP ask_codebase tool), the system surfaced a generic "operation failed" error with no provider details, and had no retry or fallback strategy — making outages undebuggable and brittle.
Changes
- Detailed errors: shared
inferenceRetry.server.tsreports[provider/model] message (status N) | provider response: ...with the provider status preserved (INFERENCE_ERROR); wired into streaming chat,askCodebase, search-assist, and review-agent. - Per-model retry: new
retry: { maxRetries, initialBackoffMs, maxBackoffMs }on every model (defaults 3/500ms/8000ms); transient failures only (network, 408/429/5xx). - Per-model fallback: new ordered
fallbackModelsper model;askCodebase(MCP + blocking API) falls through the chain and aggregates all attempts on total failure. Streaming chat retries without switching models. - Chat-name generation in
askCodebaseis now best-effort instead of failing the request. - Schema, generated types/docs (via codegen), docs section, and CHANGELOG updated.
[!NOTE]
Medium Risk
Touches core Ask/MCP inference behavior and error surfaces; misconfigured fallbacks or retry policy could change which model runs or how failures appear to clients.
Overview
Adds [EE] per-model retry and ordered fallback configuration for Ask inference, documented in config guides and reflected across the v3 language-model schema docs.
Each model can set retry (maxRetries, initialBackoffMs, maxBackoffMs) for transient failures (network, 408/429/5xx) with exponential backoff. fallbackModels (up to five references to other configured models) apply to blocking Ask paths—the MCP ask_codebase tool and the blocking chat API—while interactive streaming chat is documented as retry-only on the selected model.
When all attempts fail, clients get per-model error details (model, message, status); full provider bodies stay out of responses, with truncated snippets reserved for server logs. The unreleased CHANGELOG entry matches this behavior and the improved provider error reporting for Ask, MCP, and the blocking chat API.
Reviewed by Cursor Bugbot for commit 121c560d17f0ff41eb9aee2096df3ab3ecf66c25. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Fixes #1156 by adding per-model retries and ordered fallbacks to Ask inference and the MCP ask_codebase tool, so transient provider failures no longer immediately fail requests and exhausted failures expose actionable context.
- Retries default to three attempts with exponential backoff from 500ms to 8s for network, 408, 429, and 5xx failures.
- Blocking Ask paths try up to five fallbacks; streaming chat retries on the selected model without switching.
- Fallbacks that reference the model already in use are skipped instead of silently no-op'ing.
- Errors include the provider/model, status, and a whitespace-collapsed response-body snippet capped at 500 characters; chat, search assist, and review agent use
INFERENCE_ERROR. - Chat-name generation is best effort and runs without retries so it never delays blocking Ask answers; config schemas and docs cover
retryandfallbackModels.
Summary by CodeRabbit
-
New Features
- Added configurable retries with exponential backoff for language-model inference.
- Added ordered fallback models for programmatic Ask and codebase requests after repeated transient failures.
- Improved provider error details across Ask, codebase queries, chat, and search assistance.
- Chat-name generation now continues using the query if inference fails.
-
Documentation
- Documented retry and fallback settings, limits, defaults, and error-reporting behavior.
- Updated language-model configuration schemas with
retryandfallbackModelsoptions.
-
Chores
- Updated the unreleased changelog with retry, fallback, and error-reporting details.