Skip to content

๐Ÿคฏ 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.

๐Ÿ› 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.ts
index 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.ts
index 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แป‡') },
// โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
// UserConfigError
diff --git a/packages/model-runtime/src/errors/refine.test.ts b/packages/model-runtime/src/errors/refine.test.ts
index 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.ts
index 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),
]);