๐คฏ 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 upstream-message fallbacks out of UpstreamHttpError (#16024)
Arvin Xudcd16501672d
diff --git a/packages/model-runtime/src/errors/match.test.ts b/packages/model-runtime/src/errors/match.test.tsindex 8652e525711..df83a007c87 100644--- a/packages/model-runtime/src/errors/match.test.ts+++ b/packages/model-runtime/src/errors/match.test.ts@@ -268,3 +268,36 @@ describe('formatErrorRef / parseErrorRef', () => {expect(parseErrorRef('E9999')).toBeUndefined();});});++describe('matchErrorPattern โ refines the UpstreamHttpError fallback bucket', () => {+ // Real messages that were landing as the bare-HTTP fallback (a 4xx+ // ProviderBizError whose message matched nothing โ codeFromHttpStatus โ+ // UpstreamHttpError). Each must now resolve to a precise code.+ const cases: [string, string][] = [+ [+ 'Hแป thแปng ฤang bแบญn, vui lรฒng thแปญ lแบกi sau รญt phรบt.',+ AgentRuntimeErrorType.ProviderServiceUnavailable,+ ],+ ['ๆๅกๅจ้ฎ้ข่ฐ่ฏไธญ', AgentRuntimeErrorType.ProviderServiceUnavailable],+ ['1m ไธไธๆๅทฒ็ปๅ จ้ๅฏ็จ๏ผ่ฏทๅฏ็จ 1m ไธไธๆๅ้่ฏ', AgentRuntimeErrorType.ExceededContextWindow],+ [+ 'Request body too large for gpt-4o model. Max size: 1000000 tokens.',+ AgentRuntimeErrorType.ExceededContextWindow,+ ],+ ["Model 'glm-5.2:cloud' is not allowed on this server.", AgentRuntimeErrorType.ModelNotFound],+ ['User has been banned (request id: 2026...)', AgentRuntimeErrorType.PermissionDenied],+ ['Only Codex clients can use this group', AgentRuntimeErrorType.PermissionDenied],+ [+ "messages.content.type ๅๆฐ้ๆณ๏ผๅๅผ่ๅด ['text']",+ AgentRuntimeErrorType.InvalidRequestFormat,+ ],+ ['ๅๆฐ้่ฏฏ่ถ ่ฟ100ไธช', AgentRuntimeErrorType.InvalidRequestFormat],+ ['max_tokens must be at least 1, got -1.', AgentRuntimeErrorType.InvalidRequestFormat],+ ];++ it.each(cases)('classifies %j', (message, expected) => {+ expect(+ matchErrorPattern({ errorType: AgentRuntimeErrorType.ProviderBizError, message })?.code,+ ).toBe(expected);+ });+});diff --git a/packages/model-runtime/src/errors/patterns.ts b/packages/model-runtime/src/errors/patterns.tsindex 896200f3aca..23ad58e7315 100644--- a/packages/model-runtime/src/errors/patterns.ts+++ b/packages/model-runtime/src/errors/patterns.ts@@ -122,6 +122,17 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('content exceeds maximum length of 100KB'),},{ code: AgentRuntimeErrorType.ExceededContextWindow, match: sub('ๅ ่ดนAPI้ๅถๆจกๅ่พๅ ฅtokenๅฐไบ') },+ { code: AgentRuntimeErrorType.ExceededContextWindow, match: sub('Request body too large') },+ {+ code: AgentRuntimeErrorType.ExceededContextWindow,+ match: sub('conversation is too long'),+ note: 'Anthropic suggests /compact when the context overflows',+ },+ {+ code: AgentRuntimeErrorType.ExceededContextWindow,+ match: sub('ไธไธๆๅทฒ็ปๅ จ้ๅฏ็จ'),+ note: 'proxy gates 1m context โ request overflowed the default window',+ },// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// InsufficientQuota โ account balance / billing exhausted (long-term)@@ -496,6 +507,13 @@ 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('Hแป thแปng ฤang bแบญn'),+ note: 'Vietnamese proxy: system busy, retry shortly',+ },+ { code: AgentRuntimeErrorType.ProviderServiceUnavailable, match: sub('ๆๅกๅจ้ฎ้ข่ฐ่ฏไธญ') },+ { code: AgentRuntimeErrorType.ProviderServiceUnavailable, match: sub('undergoing an upgrade') },// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// ProviderNetworkError โ connection / timeout@@ -629,6 +647,19 @@ export const ERROR_PATTERNS: ErrorPattern[] = [match: sub('reached its end of life on'),note: 'newapi-style 410 Gone',},+ {+ code: AgentRuntimeErrorType.ModelNotFound,+ match: sub('is not allowed on this server'),+ note: 'ollama allow-list rejects the requested model',+ },+ {+ code: AgentRuntimeErrorType.ModelNotFound,+ match: sub('Publisher Model'),+ note: 'Vertex: publisher model path not found',+ },+ { code: AgentRuntimeErrorType.ModelNotFound, match: sub('ไฝ ่ฏทๆฑ็ๆจกๅ') },+ { code: AgentRuntimeErrorType.ModelNotFound, match: sub('ไธๅญๅจๆๆชไธ็บฟ') },+ { code: AgentRuntimeErrorType.ModelNotFound, match: sub('has no provider supported') },// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// InvalidProviderAPIKey@@ -697,6 +728,13 @@ export const ERROR_PATTERNS: ErrorPattern[] = [{ code: AgentRuntimeErrorType.PermissionDenied, match: sub('This token has no access to model') },{ code: AgentRuntimeErrorType.PermissionDenied, match: sub('่ฏฅไปค็ๆ ๆ่ฎฟ้ฎๆจกๅ') },{ code: AgentRuntimeErrorType.PermissionDenied, match: sub('ๆจ็ IP ไธๅจไปค็ๅ ่ฎธ่ฎฟ้ฎ็ๅ่กจไธญ') },+ { code: AgentRuntimeErrorType.PermissionDenied, match: sub('User has been banned') },+ {+ code: AgentRuntimeErrorType.PermissionDenied,+ match: sub('Only Codex clients can use this group'),+ note: 'proxy restricts the group to Codex clients',+ },+ { code: AgentRuntimeErrorType.PermissionDenied, match: sub('not available for trial users') },// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// AccountDeactivated@@ -907,6 +945,27 @@ export const ERROR_PATTERNS: ErrorPattern[] = [},{ code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('Unknown name "definitions"') },{ code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub("function_response.response' (") },+ // Malformed-request rejections harvested from the UpstreamHttpError fallback+ // bucket. Mix of upstream-proxy quirks and request-shape rejections; a few may+ // also surface harness request-building bugs (negative max_tokens, illegal+ // content-block type) โ classifying keeps them visible under a precise code+ // instead of the bare HTTP fallback.+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('ๅๆฐ้ๆณ๏ผๅๅผ่ๅด') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('ๅๆฐ้่ฏฏ่ถ ่ฟ') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('Param Incorrect') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('tokenization failed') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('invalid image detail') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub("invalid 'parameters' schema") },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub("can't find closing '}'") },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('Unsupported parameter(s):') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('messages parameter is illegal') },+ {+ code: AgentRuntimeErrorType.InvalidRequestFormat,+ match: sub('GenerateContentRequest proto is invalid'),+ note: 'Gemini: malformed function_response / content in request',+ },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('max_tokens must be at least') },+ { code: AgentRuntimeErrorType.InvalidRequestFormat, match: sub('Yรชu cแบงu khรดng hแปฃp lแป') },// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ// UserConfigErrordiff --git a/packages/model-runtime/src/errors/refine.test.ts b/packages/model-runtime/src/errors/refine.test.tsindex 20d70415a69..5b8338bc8c6 100644--- a/packages/model-runtime/src/errors/refine.test.ts+++ b/packages/model-runtime/src/errors/refine.test.ts@@ -168,4 +168,40 @@ describe('refineErrorCode', () => {}),).toBeUndefined();});++ describe('re-refines the fallback buckets themselves', () => {+ // formatErrorForState is idempotent: an inner pass can demote a+ // ProviderBizError to UpstreamHttpError (4xx + no recognized message), then+ // an outer pass re-enriches. UpstreamHttpError must stay refinable so the+ // later pass can still upgrade it once the message is recognizable.+ it('upgrades an UpstreamHttpError once its message matches a pattern', () => {+ expect(+ refineErrorCode({+ errorType: AgentRuntimeErrorType.UpstreamHttpError,+ message: 'Hแป thแปng ฤang bแบญn, vui lรฒng thแปญ lแบกi sau รญt phรบt.',+ }),+ ).toBe(AgentRuntimeErrorType.ProviderServiceUnavailable);+ });++ it('leaves an UpstreamHttpError untouched when nothing matches', () => {+ // No status fallback for UpstreamHttpError (status-refinable is+ // ProviderBizError only), so an unrecognized 4xx residual stays put.+ expect(+ refineErrorCode({+ errorType: AgentRuntimeErrorType.UpstreamHttpError,+ httpStatus: 409,+ message: 'conflict, no details',+ }),+ ).toBeUndefined();+ });++ it('upgrades a bare-500 (InternalServerError) once its message matches', () => {+ expect(+ refineErrorCode({+ errorType: String(ChatErrorType.InternalServerError),+ message: 'ๅๆฐ้่ฏฏ่ถ ่ฟ100ไธช',+ }),+ ).toBe(AgentRuntimeErrorType.InvalidRequestFormat);+ });+ });});diff --git a/packages/model-runtime/src/errors/refine.ts b/packages/model-runtime/src/errors/refine.tsindex 847c7873ac0..cf033d93171 100644--- a/packages/model-runtime/src/errors/refine.ts+++ b/packages/model-runtime/src/errors/refine.ts@@ -9,16 +9,24 @@ import { matchErrorPattern } from './match';/*** Codes whose message is worth running through `matchErrorPattern`.*- * Besides the `ProviderBizError` upstream catch-all, this covers the two- * fallback wrappers `formatErrorForState` produces for un-typed throws: a raw- * `Error` is wrapped as `InternalServerError` (HTTP 500) and any other value as+ * Besides the `ProviderBizError` upstream catch-all, this covers the fallback+ * wrappers `formatErrorForState` produces for un-typed throws: a raw `Error` is+ * wrapped as `InternalServerError` (HTTP 500) and any other value as* `AgentRuntimeError`. They must be pattern-refinable so persistence-layer* throws (`Failed query: โฆ`) and state-store drops reach the registry โ without* them those land as a bare, un-classified 500.+ *+ * `UpstreamHttpError` is itself a fallback bucket โ it's what the status+ * fallback below emits for a 4xx whose message matched nothing. It must stay+ * refinable too: `formatErrorForState` is idempotent and re-enriches an+ * already-normalized error, so a code demoted to `UpstreamHttpError` on an inner+ * pass would otherwise be frozen there. Keeping it open lets a later pass (or a+ * historical batch-rewrite) still upgrade it once the message is recognizable.*/const PATTERN_REFINABLE_CODES = new Set<string>([AgentRuntimeErrorType.AgentRuntimeError,AgentRuntimeErrorType.ProviderBizError,+ AgentRuntimeErrorType.UpstreamHttpError,String(ChatErrorType.InternalServerError),]);