π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(model-runtime): classify more error patterns (#16866)
Arvin Xued86b88b8fa8
diff --git a/packages/model-runtime/src/errors/match.test.ts b/packages/model-runtime/src/errors/match.test.tsindex d43dc92e833..9066749485d 100644--- a/packages/model-runtime/src/errors/match.test.ts+++ b/packages/model-runtime/src/errors/match.test.ts@@ -364,3 +364,120 @@ describe('matchErrorPattern β second residue convergence round', () => {expect(code).not.toBe(AgentRuntimeErrorType.ExceededContextWindow);});});++describe('matchErrorPattern β gateway user/upstream residues by category', () => {+ const groups: { cases: [string, string, string?][]; name: string }[] = [+ {+ cases: [+ [+ 'Your balance is used up. Please top up to continue.',+ AgentRuntimeErrorType.InsufficientQuota,+ ],+ ['have reached your weekly usage limit', AgentRuntimeErrorType.InsufficientQuota],+ ['ε·²θΎΎε° Token Plan η¨ιδΈι', AgentRuntimeErrorType.InsufficientQuota],+ ['Token Plan usage limit reached', AgentRuntimeErrorType.InsufficientQuota],+ ['The free quota has been exhausted', AgentRuntimeErrorType.InsufficientQuota],+ ],+ name: 'quota and plan limits',+ },+ {+ cases: [+ ['Too many requests', AgentRuntimeErrorType.RateLimitExceeded],+ ['LLM stream error: Console API returned 429', AgentRuntimeErrorType.RateLimitExceeded],+ ['rate limit exceeded: per-user model TPM limit', AgentRuntimeErrorType.RateLimitExceeded],+ ['"quota exceeded"', AgentRuntimeErrorType.RateLimitExceeded],+ ],+ name: 'rate limiting',+ },+ {+ cases: [+ ['no channel available for model', AgentRuntimeErrorType.NoAvailableChannel],+ ['"code":"NOT_FOUND","msg":"route not found"', AgentRuntimeErrorType.NoAvailableChannel],+ ['Unknown Model, please check the model code', AgentRuntimeErrorType.ModelNotFound],+ ['404 page not found', AgentRuntimeErrorType.UserConfigError],+ ['OpenAIException - {"detail":"Not Found"}', AgentRuntimeErrorType.UserConfigError],+ ],+ name: 'routing, model, and endpoint configuration',+ },+ {+ cases: [+ [+ 'Authentication is not set up. Please provide either a project and location',+ AgentRuntimeErrorType.InvalidVertexCredentials,+ 'vertexai',+ ],+ ['No active credentials for provider', AgentRuntimeErrorType.InvalidProviderAPIKey],+ ['<h1>403 Forbidden</h1>', AgentRuntimeErrorType.PermissionDenied],+ ],+ name: 'credentials and access',+ },+ {+ cases: [+ [+ 'The model rejected this request. It may not support the input you sent',+ AgentRuntimeErrorType.CapabilityNotSupported,+ ],+ ['sensitive words detected', AgentRuntimeErrorType.ContentModeration],+ ['θ―·εΏειζ’ζ΅θ―·ζ±', AgentRuntimeErrorType.ContentModeration],+ ],+ name: 'capability and moderation',+ },+ {+ cases: [+ [+ 'Request body too large for deepseek-r1 model',+ AgentRuntimeErrorType.InvalidRequestFormat,+ ],+ [+ 'error getting file type: failed to download file from https://example.com/a.png',+ AgentRuntimeErrorType.InvalidRequestFormat,+ ],+ [+ 'error getting file type: failed to download file, status code: 404',+ AgentRuntimeErrorType.InvalidRequestFormat,+ ],+ ['422 status code (no body)', AgentRuntimeErrorType.InvalidRequestFormat],+ ],+ name: 'request format and file retrieval',+ },+ {+ cases: [+ ['503 "Service Unavailable"', AgentRuntimeErrorType.ProviderServiceUnavailable],+ ['Hα» thα»ng Δang bαΊn', AgentRuntimeErrorType.ProviderServiceUnavailable],+ ],+ name: 'service unavailable',+ },+ ];++ for (const { cases, name } of groups) {+ it.each(cases)(`classifies ${name}: %j`, (message, expected, provider) => {+ expect(+ matchErrorPattern({+ errorType: AgentRuntimeErrorType.ProviderBizError,+ message,+ provider,+ })?.code,+ ).toBe(expected);+ expect(isUserSideError(AgentRuntimeErrorType.ProviderBizError, message, provider)).toBe(true);+ });+ }++ it('keeps Vertex setup errors on the Vertex credential code', () => {+ const message =+ 'Authentication is not set up. Please provide either a project and location, or an API key, or a custom base URL.';++ expect(+ matchErrorPattern({+ errorType: AgentRuntimeErrorType.ProviderBizError,+ message,+ }),+ ).toBeUndefined();+ expect(+ matchErrorPattern({+ errorType: AgentRuntimeErrorType.ProviderBizError,+ message,+ provider: 'vertexai',+ })?.code,+ ).toBe(AgentRuntimeErrorType.InvalidVertexCredentials);+ });+});diff --git a/packages/model-runtime/src/errors/match.ts b/packages/model-runtime/src/errors/match.tsindex c960c92582c..813fe29e890 100644--- a/packages/model-runtime/src/errors/match.ts+++ b/packages/model-runtime/src/errors/match.ts@@ -63,14 +63,18 @@ export const matchErrorPattern = (input: MatchInput): MatchResult | undefined =>* ExceededContextWindow, network drops as 500), so the message-pattern step* is the gating mechanism β a substring hit overrides the upstream label.*/-export const isUserSideError = (errorType?: string, message?: string): boolean => {+export const isUserSideError = (+ errorType?: string,+ message?: string,+ provider?: string,+): boolean => {if (errorType) {const spec = getErrorCodeSpec(errorType);if (spec && !spec.countAsFailure) return true;}if (message) {- const match = matchErrorPattern({ errorType, message });+ const match = matchErrorPattern({ errorType, message, provider });if (match) {const spec = getErrorCodeSpec(match.code);if (spec && !spec.countAsFailure) return true;diff --git a/packages/model-runtime/src/errors/patterns.ts b/packages/model-runtime/src/errors/patterns.tsindex e5bc5b99a79..e1421e9d31c 100644--- a/packages/model-runtime/src/errors/patterns.ts+++ b/packages/model-runtime/src/errors/patterns.ts@@ -379,6 +379,23 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('Your account requires verification before using the API'),note: 'freemodel.dev phone verification',},+ {+ code: AgentRuntimeErrorType.InsufficientQuota,+ match: sub('Your balance is used up. Please top up to continue.'),+ },+ {+ code: AgentRuntimeErrorType.InsufficientQuota,+ match: sub('reached your weekly usage limit', { caseInsensitive: true }),+ },+ { code: AgentRuntimeErrorType.InsufficientQuota, match: sub('ε·²θΎΎε° Token Plan η¨ιδΈι') },+ {+ code: AgentRuntimeErrorType.InsufficientQuota,+ match: sub('Token Plan usage limit reached'),+ },+ {+ code: AgentRuntimeErrorType.InsufficientQuota,+ match: sub('The free quota has been exhausted'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// RateLimitExceeded β short-window rate limit (transient, retryable)@@ -446,6 +463,11 @@ export const ERROR_PATTERNS: ErrorPattern[] = [code: AgentRuntimeErrorType.RateLimitExceeded,match: sub('Request rate increased too quickly'),},+ { code: AgentRuntimeErrorType.RateLimitExceeded, match: sub('Console API returned 429') },+ {+ code: AgentRuntimeErrorType.RateLimitExceeded,+ match: sub('per-user model TPM limit'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// ProviderServiceUnavailable β 503 / overload (transient)@@ -518,6 +540,10 @@ export const ERROR_PATTERNS: ErrorPattern[] = [{ code: AgentRuntimeErrorType.ProviderServiceUnavailable, match: sub('502: Bad gateway') },{ code: AgentRuntimeErrorType.ProviderServiceUnavailable, match: sub('502 <!DOCTYPE html>') },{ code: AgentRuntimeErrorType.ProviderServiceUnavailable, match: sub('503 Gateway Error') },+ {+ code: AgentRuntimeErrorType.ProviderServiceUnavailable,+ match: sub('503 "Service Unavailable"'),+ },{code: AgentRuntimeErrorType.ProviderServiceUnavailable,match: sub('Hα» thα»ng Δang bαΊn'),@@ -600,6 +626,7 @@ export const ERROR_PATTERNS: ErrorPattern[] = [},{ code: AgentRuntimeErrorType.NoAvailableChannel, match: sub('no available channels for model') },{ code: AgentRuntimeErrorType.NoAvailableChannel, match: sub('No available channel for model') },+ { code: AgentRuntimeErrorType.NoAvailableChannel, match: sub('no channel available for model') },{ code: AgentRuntimeErrorType.NoAvailableChannel, match: sub('ζ ε―η¨ζΈ ι') },{code: AgentRuntimeErrorType.NoAvailableChannel,@@ -629,6 +656,10 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('upstream rejected the request payload'),note: 'freethe routing short-circuit',},+ {+ code: AgentRuntimeErrorType.NoAvailableChannel,+ match: sub('"code":"NOT_FOUND","msg":"route not found"'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// ModelNotFound@@ -677,6 +708,20 @@ export const ERROR_PATTERNS: ErrorPattern[] = [{ code: AgentRuntimeErrorType.ModelNotFound, match: sub('not available for integrator') },{ code: AgentRuntimeErrorType.ModelNotFound, match: sub('is not available. Please use') },{ code: AgentRuntimeErrorType.ModelNotFound, match: sub('The requested model is not available') },+ {+ code: AgentRuntimeErrorType.ModelNotFound,+ match: sub('Unknown Model, please check the model code'),+ },++ // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ // InvalidVertexCredentials+ // βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ+ {+ code: AgentRuntimeErrorType.InvalidVertexCredentials,+ match: sub('Authentication is not set up. Please provide either a project and location'),+ note: '@google/genai Vertex setup error: missing project/location or ADC credentials.',+ provider: 'vertexai',+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// InvalidProviderAPIKey@@ -713,6 +758,10 @@ export const ERROR_PATTERNS: ErrorPattern[] = [code: AgentRuntimeErrorType.InvalidProviderAPIKey,match: sub('invalidapikey', { caseInsensitive: true }),},+ {+ code: AgentRuntimeErrorType.InvalidProviderAPIKey,+ match: sub('No active credentials for provider'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// InvalidGithubToken / InvalidGithubCopilotToken@@ -819,6 +868,10 @@ export const ERROR_PATTERNS: ErrorPattern[] = [code: AgentRuntimeErrorType.CapabilityNotSupported,match: sub('does not support tool calling.'),},+ {+ code: AgentRuntimeErrorType.CapabilityNotSupported,+ match: sub('The model rejected this request. It may not support the input you sent'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// ContentModeration@@ -864,6 +917,8 @@ export const ERROR_PATTERNS: ErrorPattern[] = [note: 'MiniMax',},{ code: AgentRuntimeErrorType.ContentModeration, match: sub('sensitive_words_detected') },+ { code: AgentRuntimeErrorType.ContentModeration, match: sub('sensitive words detected') },+ { code: AgentRuntimeErrorType.ContentModeration, match: sub('θ―·εΏειζ’ζ΅θ―·ζ±') },{code: AgentRuntimeErrorType.ContentModeration,match: sub('Output data may contain inappropriate content'),@@ -1019,6 +1074,12 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('function_declarations'),note: 'custom gemini proxies mangle tool schema; lobehub-native schema bug fixed in #14740',},+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('Request body too large for') },+ {+ code: AgentRuntimeErrorType.InvalidRequestFormat,+ match: sub('error getting file type: failed to download file'),+ },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('422 status code (no body)') },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// UserConfigError@@ -1056,6 +1117,10 @@ export const ERROR_PATTERNS: ErrorPattern[] = [{ code: AgentRuntimeErrorType.UserConfigError, match: sub('page not found') },{ code: AgentRuntimeErrorType.UserConfigError, match: sub('No route for that URI') },{ code: AgentRuntimeErrorType.UserConfigError, match: sub('url.not_found') },+ {+ code: AgentRuntimeErrorType.UserConfigError,+ match: sub('OpenAIException - {"detail":"Not Found"}'),+ },// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ// UpstreamGatewayError β proxy / gateway-layer failure (openresty, litellm,