Repository navigation
fix(agents): normalize provider errors for better failover - #58856
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2308727178
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // Together AI / Fireworks: specific rate limit messages | ||
| { | ||
| test: /\bconcurrency limit\b.*\breached\b/i, |
There was a problem hiding this comment.
Match concurrency-limit reached errors
The Together AI/Fireworks classifier only matches concurrency limit ... breached, but the provider message this change targets is commonly phrased as concurrency limit ... reached (including the new test case), so these rate-limit responses still fall through as unclassified. In that scenario, classifyFailoverReason returns null and the model-switch failover path is skipped when it should treat the error as rate_limit.
Useful? React with 👍 / 👎.
Greptile SummaryThis PR adds a new Key issues found:
Confidence Score: 4/5Mostly safe to merge, but two P1 issues should be addressed: the Vertex context-overflow/format mismatch and the overly broad "model is not ready" pattern that could cause wrong failover behavior in production. Two P1 findings remain: (1) Vertex INVALID_ARGUMENT context overflow is classified as "format" but not detected by isContextOverflowError(), which could silently bypass context-compression recovery logic; (2) the "model is not ready" alternation is broad enough to match non-Bedrock errors and cause infinite retries. The P2 findings are minor (stale JSDoc, unused field, missing test variant) and don't block merge on their own. src/agents/pi-embedded-helpers/provider-error-patterns.ts — lines 60-62 (Vertex format mapping) and lines 72-74 (model is not ready broadness) Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 60-62
Comment:
**Vertex context overflow bypasses `isContextOverflowError()`**
The Vertex `INVALID_ARGUMENT` pattern is added to `PROVIDER_SPECIFIC_PATTERNS` (returning `"format"`) but is NOT added to `PROVIDER_CONTEXT_OVERFLOW_PATTERNS`. This creates a behavioral split: `classifyFailoverReason()` will return `"format"` for these errors, but `isContextOverflowError()` will still return `false`.
If the failover engine calls `isContextOverflowError()` to decide whether to compress the context before retrying, Vertex context overflow errors will never trigger that code path — they'll be treated as format errors and take the wrong recovery strategy instead.
To fix this, add the Vertex pattern to `PROVIDER_CONTEXT_OVERFLOW_PATTERNS` as well, or remove it from `PROVIDER_SPECIFIC_PATTERNS` entirely (leaving classification as `null`) until the two functions can be made consistent. Classifying it as `"format"` is semantically incorrect for a context overflow.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 72-74
Comment:
**`model is not ready` alternation is dangerously broad**
The second alternation `model is not ready` will match any error containing that phrase from any provider, not just AWS Bedrock. This phrase can appear in generic user-facing messages (e.g., a model that is still initializing in a local/Ollama deployment, or a message from a completely unrelated service). Classifying all such errors as `"overloaded"` — which implies transient overload with retry logic — could cause infinite retries against a model that is permanently unavailable.
Consider tightening this to require the Bedrock exception class prefix:
```suggestion
test: /ModelNotReadyException/i,
```
If `model is not ready` is needed as a standalone pattern, it should at minimum require a Bedrock-specific namespace prefix (e.g., `bedrock.*model is not ready`) to avoid false positives.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 98-103
Comment:
**Stale JSDoc function name**
The JSDoc for `matchesProviderContextOverflow` references `isLikelyContextOverflowError()`, but the actual function in `errors.ts` that calls it is `isContextOverflowError()`. This will confuse anyone trying to trace the call chain.
```suggestion
* Call this from `isContextOverflowError()` to catch provider-specific wording.
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 11-18
Comment:
**Unused `provider` field in `ProviderErrorPattern`**
The `provider?: string` field is declared and documented ("Optional: only match when this provider is in use"), but `classifyProviderSpecificError` never reads it — it only calls `pattern.test.test(errorMessage)`. This gives a false impression that patterns are scoped per-provider. Either implement the provider-scoping logic (pass the current provider into `classifyProviderSpecificError`) or remove the dead field to avoid misleading future contributors.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.test.ts
Line: 54-56
Comment:
**Test string doesn't match the PR's stated example**
The PR description lists the fixed Together AI example as `"concurrency limit reached"`, but the test uses `"concurrency limit has been reached"`. Both happen to match the pattern `/\bconcurrency limit\b.*\breached\b/i`, so the test passes. However, it would be more valuable to also test the exact string from the PR description table to ensure the documented real-world error is covered:
```suggestion
expect(classifyProviderSpecificError("concurrency limit has been reached")).toBe("rate_limit");
expect(classifyProviderSpecificError("concurrency limit reached")).toBe("rate_limit");
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(agents): normalize provider errors f..." | Re-trigger Greptile |
| test: /INVALID_ARGUMENT.*(?:exceeds? the (?:maximum|max)|input.*too (?:long|large))/i, | ||
| reason: "format", // context overflow manifests as format error in Vertex | ||
| }, |
There was a problem hiding this comment.
Vertex context overflow bypasses
isContextOverflowError()
The Vertex INVALID_ARGUMENT pattern is added to PROVIDER_SPECIFIC_PATTERNS (returning "format") but is NOT added to PROVIDER_CONTEXT_OVERFLOW_PATTERNS. This creates a behavioral split: classifyFailoverReason() will return "format" for these errors, but isContextOverflowError() will still return false.
If the failover engine calls isContextOverflowError() to decide whether to compress the context before retrying, Vertex context overflow errors will never trigger that code path — they'll be treated as format errors and take the wrong recovery strategy instead.
To fix this, add the Vertex pattern to PROVIDER_CONTEXT_OVERFLOW_PATTERNS as well, or remove it from PROVIDER_SPECIFIC_PATTERNS entirely (leaving classification as null) until the two functions can be made consistent. Classifying it as "format" is semantically incorrect for a context overflow.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 60-62
Comment:
**Vertex context overflow bypasses `isContextOverflowError()`**
The Vertex `INVALID_ARGUMENT` pattern is added to `PROVIDER_SPECIFIC_PATTERNS` (returning `"format"`) but is NOT added to `PROVIDER_CONTEXT_OVERFLOW_PATTERNS`. This creates a behavioral split: `classifyFailoverReason()` will return `"format"` for these errors, but `isContextOverflowError()` will still return `false`.
If the failover engine calls `isContextOverflowError()` to decide whether to compress the context before retrying, Vertex context overflow errors will never trigger that code path — they'll be treated as format errors and take the wrong recovery strategy instead.
To fix this, add the Vertex pattern to `PROVIDER_CONTEXT_OVERFLOW_PATTERNS` as well, or remove it from `PROVIDER_SPECIFIC_PATTERNS` entirely (leaving classification as `null`) until the two functions can be made consistent. Classifying it as `"format"` is semantically incorrect for a context overflow.
How can I resolve this? If you propose a fix, please make it concise.| test: /ModelNotReadyException|model is not ready/i, | ||
| reason: "overloaded", | ||
| }, |
There was a problem hiding this comment.
model is not ready alternation is dangerously broad
The second alternation model is not ready will match any error containing that phrase from any provider, not just AWS Bedrock. This phrase can appear in generic user-facing messages (e.g., a model that is still initializing in a local/Ollama deployment, or a message from a completely unrelated service). Classifying all such errors as "overloaded" — which implies transient overload with retry logic — could cause infinite retries against a model that is permanently unavailable.
Consider tightening this to require the Bedrock exception class prefix:
| test: /ModelNotReadyException|model is not ready/i, | |
| reason: "overloaded", | |
| }, | |
| test: /ModelNotReadyException/i, |
If model is not ready is needed as a standalone pattern, it should at minimum require a Bedrock-specific namespace prefix (e.g., bedrock.*model is not ready) to avoid false positives.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 72-74
Comment:
**`model is not ready` alternation is dangerously broad**
The second alternation `model is not ready` will match any error containing that phrase from any provider, not just AWS Bedrock. This phrase can appear in generic user-facing messages (e.g., a model that is still initializing in a local/Ollama deployment, or a message from a completely unrelated service). Classifying all such errors as `"overloaded"` — which implies transient overload with retry logic — could cause infinite retries against a model that is permanently unavailable.
Consider tightening this to require the Bedrock exception class prefix:
```suggestion
test: /ModelNotReadyException/i,
```
If `model is not ready` is needed as a standalone pattern, it should at minimum require a Bedrock-specific namespace prefix (e.g., `bedrock.*model is not ready`) to avoid false positives.
How can I resolve this? If you propose a fix, please make it concise.| /** | ||
| * Check if an error message matches any provider-specific context overflow pattern. | ||
| * Call this from `isLikelyContextOverflowError()` to catch provider-specific wording. | ||
| */ | ||
| export function matchesProviderContextOverflow(errorMessage: string): boolean { | ||
| return PROVIDER_CONTEXT_OVERFLOW_PATTERNS.some((pattern) => pattern.test(errorMessage)); |
There was a problem hiding this comment.
The JSDoc for matchesProviderContextOverflow references isLikelyContextOverflowError(), but the actual function in errors.ts that calls it is isContextOverflowError(). This will confuse anyone trying to trace the call chain.
| /** | |
| * Check if an error message matches any provider-specific context overflow pattern. | |
| * Call this from `isLikelyContextOverflowError()` to catch provider-specific wording. | |
| */ | |
| export function matchesProviderContextOverflow(errorMessage: string): boolean { | |
| return PROVIDER_CONTEXT_OVERFLOW_PATTERNS.some((pattern) => pattern.test(errorMessage)); | |
| * Call this from `isContextOverflowError()` to catch provider-specific wording. |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 98-103
Comment:
**Stale JSDoc function name**
The JSDoc for `matchesProviderContextOverflow` references `isLikelyContextOverflowError()`, but the actual function in `errors.ts` that calls it is `isContextOverflowError()`. This will confuse anyone trying to trace the call chain.
```suggestion
* Call this from `isContextOverflowError()` to catch provider-specific wording.
```
How can I resolve this? If you propose a fix, please make it concise.| type ProviderErrorPattern = { | ||
| /** Regex or string to match against the raw error message. */ | ||
| test: RegExp; | ||
| /** The failover reason this pattern maps to. */ | ||
| reason: FailoverReason; | ||
| /** Optional: only match when this provider is in use. */ | ||
| provider?: string; | ||
| }; |
There was a problem hiding this comment.
Unused
provider field in ProviderErrorPattern
The provider?: string field is declared and documented ("Optional: only match when this provider is in use"), but classifyProviderSpecificError never reads it — it only calls pattern.test.test(errorMessage). This gives a false impression that patterns are scoped per-provider. Either implement the provider-scoping logic (pass the current provider into classifyProviderSpecificError) or remove the dead field to avoid misleading future contributors.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.ts
Line: 11-18
Comment:
**Unused `provider` field in `ProviderErrorPattern`**
The `provider?: string` field is declared and documented ("Optional: only match when this provider is in use"), but `classifyProviderSpecificError` never reads it — it only calls `pattern.test.test(errorMessage)`. This gives a false impression that patterns are scoped per-provider. Either implement the provider-scoping logic (pass the current provider into `classifyProviderSpecificError`) or remove the dead field to avoid misleading future contributors.
How can I resolve this? If you propose a fix, please make it concise.| it("classifies concurrency limit as rate_limit", () => { | ||
| expect(classifyProviderSpecificError("concurrency limit has been reached")).toBe("rate_limit"); | ||
| }); |
There was a problem hiding this comment.
Test string doesn't match the PR's stated example
The PR description lists the fixed Together AI example as "concurrency limit reached", but the test uses "concurrency limit has been reached". Both happen to match the pattern /\bconcurrency limit\b.*\breached\b/i, so the test passes. However, it would be more valuable to also test the exact string from the PR description table to ensure the documented real-world error is covered:
| it("classifies concurrency limit as rate_limit", () => { | |
| expect(classifyProviderSpecificError("concurrency limit has been reached")).toBe("rate_limit"); | |
| }); | |
| expect(classifyProviderSpecificError("concurrency limit has been reached")).toBe("rate_limit"); | |
| expect(classifyProviderSpecificError("concurrency limit reached")).toBe("rate_limit"); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-helpers/provider-error-patterns.test.ts
Line: 54-56
Comment:
**Test string doesn't match the PR's stated example**
The PR description lists the fixed Together AI example as `"concurrency limit reached"`, but the test uses `"concurrency limit has been reached"`. Both happen to match the pattern `/\bconcurrency limit\b.*\breached\b/i`, so the test passes. However, it would be more valuable to also test the exact string from the PR description table to ensure the documented real-world error is covered:
```suggestion
expect(classifyProviderSpecificError("concurrency limit has been reached")).toBe("rate_limit");
expect(classifyProviderSpecificError("concurrency limit reached")).toBe("rate_limit");
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 29082578d7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /\bdeepseek\b.*(?:input.*too long|context.*exceed)/i, | ||
|
|
||
| // Google Vertex / Gemini: INVALID_ARGUMENT with token-related messages is context overflow. | ||
| /INVALID_ARGUMENT.*(?:exceeds? the (?:maximum|max)|input.*too (?:long|large))/i, |
There was a problem hiding this comment.
Narrow Vertex INVALID_ARGUMENT overflow matching
The new Vertex/Gemini pattern INVALID_ARGUMENT.*(?:exceeds? the (?:maximum|max)|...) now treats any INVALID_ARGUMENT mentioning a maximum value as context overflow, including non-context validation errors such as parameter bounds (for example, temperature/topK limits). Because isContextOverflowError() now calls this matcher, these requests can be misreported as context-overflow and routed through overflow recovery paths instead of format/validation handling.
Useful? React with 👍 / 👎.
|
CI failures are in |
|
This seems incomplete and only additive, not refactoring the existing classifications. |
Add provider-specific error patterns for AWS Bedrock, Ollama, Mistral, Cohere, DeepSeek, Together AI, and Cloudflare Workers AI. These providers return errors in non-standard formats that the generic classifiers miss, causing incorrect failover behavior (e.g., context overflow misclassified as format error, ThrottlingException not recognized as rate limit). Wire provider patterns into isContextOverflowError() and classifyFailoverReason() as catch-all layers after generic classifiers.
|
Landed via temp rebase onto
Thanks @aaron-he-zhu! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b157eaefa3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| // Together AI / Fireworks: specific rate limit messages | ||
| { | ||
| test: /\bconcurrency limit\b.*\breached\b/i, |
There was a problem hiding this comment.
Match breached concurrency-limit errors
The Together/Fireworks pattern uses \breached\b, which in JS regex means a word boundary plus reached (not the literal word breached), so messages like "concurrency limit has been breached" do not match this classifier. In those cases classifyProviderSpecificError() returns null, and rate-limit failover is skipped when the error text only contains this provider-specific wording.
Useful? React with 👍 / 👎.
Fixes #58837
Related: #58347 #58305 #58377 #58392 (LiveSessionModelSwitchError cluster)
Summary
Add provider-specific error patterns for AWS Bedrock, Ollama, Mistral, Cohere, DeepSeek, Together AI, and Cloudflare Workers AI. These providers return errors in non-standard formats that the generic classifiers miss, causing incorrect failover behavior.
provider-error-patterns.tswith provider-specific matchersmatchesProviderContextOverflow()catches context overflow patterns the generic regex missesclassifyProviderSpecificError()maps provider errors toFailoverReasonisContextOverflowError()andclassifyFailoverReason()as catch-all layersExamples fixed:
ThrottlingExceptionrate_limitModelNotReadyExceptionoverloadedmodel_is_deactivatedmodel_not_foundconcurrency limit reachedrate_limitTest plan
matchesProviderContextOverflow(8 provider samples + negatives)classifyProviderSpecificError(5 provider mappings)isContextOverflowErrorandclassifyFailoverReasontsgo --noEmitclean,oxlintclean,oxfmt --checkclean