fix(providers): share the error reader, cover the last swallowed message, raise timeouts - #11
Merged
Merged
Conversation
…age, raise timeouts Finishes the provider-error and timeout work started in #9. Counts below are from the VPS request log (4618 requests, 2205 errors). SHARED ERROR READER. readProviderErrorText moved from openai-compat.ts into base.ts and given the Cloudflare `errors[0].message` shape, so all four provider classes use one implementation. Documented shapes confirmed by probing each provider with an invalid token on 2026-08-23: {error:{message}} Groq, OpenRouter, SambaNova, Zhipu, Vercel, Kilo, Google, GitHub {type,title,status,detail} NVIDIA NIM (RFC 7807) {message} Cerebras, Cohere {detail} Mistral {error:"string"} Hugging Face {errors:[{message}]} Cloudflare COHERE was the last provider still reading only error.message. It answers {"id":"...","message":"..."}, so every failure displayed as bare statusText ("Cohere API error 401: Unauthorized"). Its own class meant #9's fix did not reach it. NESTED 2xx ERROR BODIES. OpenRouter reports upstream failures as HTTP 200 with {error:{code,...}} and often no `message`, putting the reason in metadata.raw and the upstream's name in metadata.provider_name. throwIfOpenAIErrorBody defaulted straight to 'Provider returned error', which is why 531 of the 682 logged OpenRouter failures read "OpenRouter API error 429: Provider returned error" and told us nothing. TIMEOUTS. BaseProvider gained an overridable defaultTimeoutMs so the hand-written classes can raise it — previously only OpenAICompatProvider could. Raised to 60s: google (67 aborts), sambanova (31), mistral (11), zhipu (7), llm7 (4), plus openrouter, kilo, pollinations, cohere and cloudflare on catalog risk. Pollinations was measured at 29.9s across three trials, so it aborted every single time. Groq and Cerebras deliberately stay at 15s: both run custom inference silicon and logged zero aborts across 161 and 30 failures. Each fix was verified by reverting it and confirming the new tests fail — the reverted output reproduces the exact production strings.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Finishes the provider-error and timeout work started in #9. All counts are from the VPS request log (4618 requests, 2205 errors, 47.7% failure rate).
1. One shared error reader
readProviderErrorTextmoves fromopenai-compat.tsintobase.tsand gains the Cloudflareerrors[0].messageshape, so all four provider classes use one implementation instead of five hand-rolled expressions. Shapes confirmed by probing each provider with an invalid token on 2026-08-23:{error:{message}}{type,title,status,detail}{message}{detail}{error:"string"}{errors:[{message}]}2. Cohere — the last swallowed message
cohere.tsis its own class, so #9's fix never reached it. Cohere answers{"id":"…","message":"…"}, so every failure displayed as bare status text:Cohere API error 401: Unauthorized.3. Nested 2xx error bodies
OpenRouter reports upstream failures as HTTP 200 with
{error:{code,…}}and frequently nomessage, putting the reason inmetadata.rawand the upstream's name inmetadata.provider_name.throwIfOpenAIErrorBodydefaulted straight to'Provider returned error'— which is why 531 of the 682 logged OpenRouter failures readOpenRouter API error 429: Provider returned errorand told us nothing.4. Timeouts
BaseProvidergains an overridabledefaultTimeoutMs; previously onlyOpenAICompatProvidercould set one, leaving Google, Cohere and Cloudflare stuck on 15s with no way out.Raised to 60s — logged aborts in parentheses: google (67), sambanova (31), mistral (11), zhipu (7), llm7 (4), plus openrouter, kilo, pollinations, cohere, cloudflare on catalog risk. Pollinations was measured at 29.9s across three trials, so it aborted every single time.
An abort also costs a 120s key cooldown in
classifyProviderError, so a slow provider benches itself for two minutes per timeout — the multiplier that made this worth fixing.Groq and Cerebras deliberately stay at 15s: both run custom inference silicon and logged zero aborts across 161 and 30 failures. A test pins that so nobody "fixes" it later.
Verification
tsccleanOpenRouter API error 429: Provider returned errorandCohere API error 401: Unauthorizeddist: vitest resolves the source, so patchingdistproves nothing🤖 Generated with Claude Code