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 a provider-closed stream as ProviderStreamInterrupted (#22565)

Arvin Xu16c795ac6254
diff --git a/apps/server/src/services/bot/__tests__/replyTemplate.test.ts b/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
index 4d049d0daef..56e6ea24a38 100644
--- a/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
+++ b/apps/server/src/services/bot/__tests__/replyTemplate.test.ts
@@ -748,6 +748,25 @@ describe('replyTemplate', () => {
expect(zh).toContain('็ฝ‘็ปœ่ฟžๆŽฅๅผ‚ๅธธ');
});
+ it('treats a provider-closed stream as a transient network drop, not an internal error', () => {
+ const en = renderAgentError(
+ 'ProviderStreamInterrupted',
+ 'Stream ended unexpectedly',
+ 'op-stream',
+ );
+ expect(en).toContain('Network error talking to the model provider');
+ expect(en).toContain('E6005');
+ expect(en).not.toContain('Something went wrong on our side');
+
+ const zh = renderAgentError(
+ 'ProviderStreamInterrupted',
+ 'Stream ended unexpectedly',
+ 'op-stream',
+ 'zh-CN',
+ );
+ expect(zh).toContain('็ฝ‘็ปœ่ฟžๆŽฅๅผ‚ๅธธ');
+ });
+
it('maps provider-capacity codes to the temporarily-unavailable copy', () => {
const unavailable = renderAgentError('ProviderServiceUnavailable', undefined, 'op-1');
const noChannel = renderAgentError('NoAvailableChannel', undefined, 'op-1');
diff --git a/apps/server/src/services/bot/replyTemplate.ts b/apps/server/src/services/bot/replyTemplate.ts
index 4843faccf33..71362c84f97 100644
--- a/apps/server/src/services/bot/replyTemplate.ts
+++ b/apps/server/src/services/bot/replyTemplate.ts
@@ -639,6 +639,9 @@ const FRIENDLY_ERROR_BY_TYPE: Record<string, keyof SystemStrings> = {
// model provider, so it keeps the provider-specific "switch model" copy. Other
// system codes (state-store reads) hit the provider-neutral `system` fallback.
ProviderNetworkError: 'errorTransientNetwork',
+ // The provider dropped the stream mid-response: same transient-network
+ // guidance, not the harness "something went wrong on our side" tier.
+ ProviderStreamInterrupted: 'errorTransientNetwork',
// โ”€โ”€ harness watchdog: harness-owned but retry-friendly, so it gets its
// own retry-oriented copy rather than the generic internal-error tier โ”€โ”€
OperationInactivityTimeout: 'errorTimeout',
diff --git a/apps/server/src/services/goal/failureClass.test.ts b/apps/server/src/services/goal/failureClass.test.ts
index 257ceacea40..f87e32972b0 100644
--- a/apps/server/src/services/goal/failureClass.test.ts
+++ b/apps/server/src/services/goal/failureClass.test.ts
@@ -27,6 +27,7 @@ describe('classifyGoalFailure', () => {
'The device connection service hit an error while starting this run. Nothing started on the device. This is usually temporary โ€” try again in a moment.',
'fetch failed: ECONNRESET',
'RateLimitExceeded',
+ 'ProviderStreamInterrupted',
])('reads %s as transient', (error) => {
expect(classifyGoalFailure(error).class).toBe('transient');
});
diff --git a/apps/server/src/services/goal/failureClass.ts b/apps/server/src/services/goal/failureClass.ts
index 8ac6c425f64..e51903f6c76 100644
--- a/apps/server/src/services/goal/failureClass.ts
+++ b/apps/server/src/services/goal/failureClass.ts
@@ -100,7 +100,7 @@ const TRANSIENT_PATTERNS = [
/"error"\s*:\s*"TIMEOUT"/,
/\boperation-not-running\b|\bstale-operation\b/,
/\bFailed to persist tool_result\b/i,
- /\b(?:RateLimitExceeded|ProviderServiceUnavailable|ProviderNetworkError|GatewayTimeout)\b/,
+ /\b(?:RateLimitExceeded|ProviderServiceUnavailable|ProviderNetworkError|ProviderStreamInterrupted|GatewayTimeout)\b/,
/ECONNRESET|ECONNREFUSED|ETIMEDOUT|EAI_AGAIN|ENOTFOUND|fetch failed|network error|socket hang up|service unavailable|bad gateway|gateway timeout|\boverloaded\b|\b50[234]\b/i,
];
diff --git a/locales/en-US/modelRuntime.json b/locales/en-US/modelRuntime.json
index 87c00092311..ba4adcdc90c 100644
--- a/locales/en-US/modelRuntime.json
+++ b/locales/en-US/modelRuntime.json
@@ -45,6 +45,7 @@
"ProviderNetworkError": "Connection to the provider timed out or was dropped. Please check your network and try again.",
"ProviderNoImageGenerated": "The provider returned no image for this request. Try rephrasing the request, or choose a model that supports image generation.",
"ProviderServiceUnavailable": "The provider is temporarily overloaded or unavailable. Please try again shortly.",
+ "ProviderStreamInterrupted": "The provider closed the connection before finishing the response. This is usually temporary, please try again.",
"QuotaLimitReached": "Sorry, the token usage or request count has reached the quota limit for this key. Please increase the key's quota or try again later.",
"RateLimitExceeded": "Sorry, the token usage or request count has reached the rate limit for this key. Please try again later or increase the key's quota.",
"RemoteMediaDownloadTimeout": "The provider timed out while downloading an attached image or file. Please try again.",
diff --git a/locales/zh-CN/modelRuntime.json b/locales/zh-CN/modelRuntime.json
index ef0d8df4d9a..17a4eda4563 100644
--- a/locales/zh-CN/modelRuntime.json
+++ b/locales/zh-CN/modelRuntime.json
@@ -45,6 +45,7 @@
"ProviderNetworkError": "ไธŽๆไพ›ๅ•†็š„่ฟžๆŽฅ่ถ…ๆ—ถๆˆ–่ขซไธญๆ–ญใ€‚่ฏทๆฃ€ๆŸฅๆ‚จ็š„็ฝ‘็ปœๅนถ้‡่ฏ•ใ€‚",
"ProviderNoImageGenerated": "ๆไพ›ๅ•†ๆœชไธบ่ฟ™ๆฌก่ฏทๆฑ‚่ฟ”ๅ›žๅ›พ็‰‡ใ€‚่ฏท่ฐƒๆ•ดๆ็คบ่ฏๅŽ้‡่ฏ•๏ผŒๆˆ–้€‰ๆ‹ฉๆ”ฏๆŒๅ›พ็‰‡็”Ÿๆˆ็š„ๆจกๅž‹ใ€‚",
"ProviderServiceUnavailable": "ๆไพ›ๅ•†ๆš‚ๆ—ถ่ฟ‡่ฝฝๆˆ–ไธๅฏ็”จใ€‚่ฏท็จๅŽ้‡่ฏ•ใ€‚",
+ "ProviderStreamInterrupted": "ๆจกๅž‹ๆœๅŠกๅ•†ๅœจๅ›žๅคๅฎŒๆˆๅ‰ๆ–ญๅผ€ไบ†่ฟžๆŽฅ๏ผŒ้€šๅธธๆ˜ฏไธดๆ—ถ้—ฎ้ข˜๏ผŒ่ฏท้‡่ฏ•ใ€‚",
"QuotaLimitReached": "ๆŠฑๆญ‰๏ผŒๆญคๅฏ†้’ฅ็š„ไปค็‰Œไฝฟ็”จ้‡ๆˆ–่ฏทๆฑ‚ๆฌกๆ•ฐๅทฒ่พพๅˆฐ้…้ข้™ๅˆถใ€‚่ฏทๅขžๅŠ ๅฏ†้’ฅ้…้ขๆˆ–็จๅŽ้‡่ฏ•ใ€‚",
"RateLimitExceeded": "ๆŠฑๆญ‰๏ผŒๆญคๅฏ†้’ฅ็š„ไปค็‰Œไฝฟ็”จ้‡ๆˆ–่ฏทๆฑ‚ๆฌกๆ•ฐๅทฒ่พพๅˆฐ้€Ÿ็އ้™ๅˆถใ€‚่ฏท็จๅŽ้‡่ฏ•ๆˆ–ๅขžๅŠ ๅฏ†้’ฅ้…้ขใ€‚",
"RemoteMediaDownloadTimeout": "ๆไพ›ๅ•†ไธ‹่ฝฝ้™„ๅŠ ็š„ๅ›พ็‰‡ๆˆ–ๆ–‡ไปถๆ—ถ่ถ…ๆ—ถใ€‚่ฏท้‡่ฏ•ใ€‚",
diff --git a/packages/locales/src/default/modelRuntime.ts b/packages/locales/src/default/modelRuntime.ts
index 50483eee67c..68774c54d24 100644
--- a/packages/locales/src/default/modelRuntime.ts
+++ b/packages/locales/src/default/modelRuntime.ts
@@ -91,6 +91,8 @@ export default {
'The provider timed out while downloading an attached image or file. Please try again.',
ProviderServiceUnavailable:
'The provider is temporarily overloaded or unavailable. Please try again shortly.',
+ ProviderStreamInterrupted:
+ 'The provider closed the connection before finishing the response. This is usually temporary, please try again.',
QuotaLimitReached:
"Sorry, the token usage or request count has reached the quota limit for this key. Please increase the key's quota or try again later.",
RateLimitExceeded:
diff --git a/packages/model-runtime/src/core/RouterRuntime/chatAttempt.test.ts b/packages/model-runtime/src/core/RouterRuntime/chatAttempt.test.ts
index 6c1d1e3f20b..b004ead50e5 100644
--- a/packages/model-runtime/src/core/RouterRuntime/chatAttempt.test.ts
+++ b/packages/model-runtime/src/core/RouterRuntime/chatAttempt.test.ts
@@ -410,6 +410,17 @@ describe('observeChatAttempt', () => {
error: { errorType: 'ContentModeration', message: 'blocked by moderation' },
errorType: 'ContentModeration',
},
+ // A provider closing the stream without a terminal event is upstream-owned, not a
+ // harness stream error, even after output was already shown.
+ {
+ error: {
+ body: { name: 'Stream parsing error', reason: 'unexpected_end' },
+ message: 'Stream ended unexpectedly',
+ name: 'Stream parsing error',
+ type: 'ProviderStreamInterrupted',
+ },
+ errorType: 'ProviderStreamInterrupted',
+ },
// Fallback buckets carry no classification of their own, so they stay StreamChunkError.
{ error: { message: 'boom', type: 'ProviderBizError' }, errorType: 'StreamChunkError' },
{ error: { message: 'Internal error encountered.' }, errorType: 'StreamChunkError' },
diff --git a/packages/model-runtime/src/core/streams/anthropic.interruption.test.ts b/packages/model-runtime/src/core/streams/anthropic.interruption.test.ts
index ed1889109e2..0d60b34f071 100644
--- a/packages/model-runtime/src/core/streams/anthropic.interruption.test.ts
+++ b/packages/model-runtime/src/core/streams/anthropic.interruption.test.ts
@@ -42,12 +42,17 @@ describe('AnthropicStream interruptions', () => {
expect(chunks.slice(-3)).toEqual([
'id: msg_1\n',
'event: error\n',
- expect.stringContaining('"type":"StreamChunkError"'),
+ expect.stringContaining('"type":"ProviderStreamInterrupted"'),
]);
expect(onErrorMock).toHaveBeenCalledWith(
- expect.objectContaining({ message: 'Stream ended unexpectedly', type: 'StreamChunkError' }),
+ expect.objectContaining({
+ message: 'Stream ended unexpectedly',
+ type: 'ProviderStreamInterrupted',
+ }),
);
- expect(onCompletionMock.mock.calls[0]?.[0].error).toMatchObject({ type: 'StreamChunkError' });
+ expect(onCompletionMock.mock.calls[0]?.[0].error).toMatchObject({
+ type: 'ProviderStreamInterrupted',
+ });
});
it('should report a dropped connection as a stream error instead of ending normally', async () => {
// @ts-ignore
diff --git a/packages/model-runtime/src/core/streams/protocol.test.ts b/packages/model-runtime/src/core/streams/protocol.test.ts
index 2822d660b23..880781eb12b 100644
--- a/packages/model-runtime/src/core/streams/protocol.test.ts
+++ b/packages/model-runtime/src/core/streams/protocol.test.ts
@@ -678,7 +678,7 @@ describe('createSSEProtocolTransformer', () => {
body: { name: 'Stream parsing error', reason: 'unexpected_end' },
message: 'Stream ended unexpectedly',
name: 'Stream parsing error',
- type: 'StreamChunkError',
+ type: 'ProviderStreamInterrupted',
};
expect(lastThree).toEqual([
diff --git a/packages/model-runtime/src/core/streams/protocol.ts b/packages/model-runtime/src/core/streams/protocol.ts
index 50125ebc0c8..a7b888a5f5d 100644
--- a/packages/model-runtime/src/core/streams/protocol.ts
+++ b/packages/model-runtime/src/core/streams/protocol.ts
@@ -388,14 +388,16 @@ export const createSSEProtocolTransformer = (
return new TransformStream({
flush(controller) {
- // If the upstream closes without sending a terminal event, emit a final error event
+ // If the upstream closes without sending a terminal event, emit a final error event.
+ // The provider cut the response short; no chunk failed to parse, so this is not a
+ // `StreamChunkError`.
if (requireTerminalEvent && !hasTerminalEvent) {
const id = streamStack?.id || 'stream_end';
const data = {
body: { name: 'Stream parsing error', reason: 'unexpected_end' },
message: 'Stream ended unexpectedly',
name: 'Stream parsing error',
- type: 'StreamChunkError',
+ type: AgentRuntimeErrorType.ProviderStreamInterrupted,
};
controller.enqueue(`id: ${id}\n`);
controller.enqueue(`event: error\n`);
diff --git a/packages/model-runtime/src/core/streams/vertex-ai.test.ts b/packages/model-runtime/src/core/streams/vertex-ai.test.ts
index cfde338fdeb..9a207c8aebc 100644
--- a/packages/model-runtime/src/core/streams/vertex-ai.test.ts
+++ b/packages/model-runtime/src/core/streams/vertex-ai.test.ts
@@ -145,7 +145,7 @@ describe('GoogleGenerativeAIStream (Vertex AI scenarios)', () => {
// requireTerminalEvent: no finishReason โ†’ stream parsing error
'id: chat_1\n',
'event: error\n',
- `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'StreamChunkError' })}\n\n`,
+ `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'ProviderStreamInterrupted' })}\n\n`,
]);
expect(onStartMock).toHaveBeenCalledTimes(1);
@@ -362,7 +362,7 @@ describe('GoogleGenerativeAIStream (Vertex AI scenarios)', () => {
// requireTerminalEvent: no finishReason โ†’ stream parsing error
'id: chat_1',
'event: error',
- `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'StreamChunkError' })}\n`,
+ `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'ProviderStreamInterrupted' })}\n`,
].map((i) => i + '\n'),
);
});
@@ -657,7 +657,7 @@ describe('GoogleGenerativeAIStream (Vertex AI scenarios)', () => {
// requireTerminalEvent: no finishReason โ†’ stream parsing error
'id: chat_1',
'event: error',
- `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'StreamChunkError' })}\n`,
+ `data: ${JSON.stringify({ body: { name: 'Stream parsing error', reason: 'unexpected_end' }, message: 'Stream ended unexpectedly', name: 'Stream parsing error', type: 'ProviderStreamInterrupted' })}\n`,
].map((i) => i + '\n'),
);
});
diff --git a/packages/model-runtime/src/errors/specs.ts b/packages/model-runtime/src/errors/specs.ts
index b239cb5b781..a0933e95ac5 100644
--- a/packages/model-runtime/src/errors/specs.ts
+++ b/packages/model-runtime/src/errors/specs.ts
@@ -421,6 +421,21 @@ export const ERROR_CODE_SPECS: SpecMap = {
description:
'A relayed model request on the user device missed its first-output or total deadline.',
},
+ [AgentRuntimeErrorType.ProviderStreamInterrupted]: {
+ code: AgentRuntimeErrorType.ProviderStreamInterrupted,
+ numericId: 6005,
+ category: 'network',
+ severity: 'warning',
+ // The provider ended the response without a terminal event. Nothing on our
+ // side failed to parse, so this is not a harness stream error.
+ attribution: 'provider',
+ httpStatus: 502,
+ retryable: true,
+ routeFallback: true,
+ countAsFailure: false,
+ description:
+ 'Provider closed the stream before sending a terminal event (stop / usage / error).',
+ },
// โ”€โ”€โ”€ 7xxx Stream / Runtime โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
[AgentRuntimeErrorType.StreamChunkError]: {
diff --git a/packages/types/src/agentRuntime.ts b/packages/types/src/agentRuntime.ts
index ddb98c509e2..fc9c6253d48 100644
--- a/packages/types/src/agentRuntime.ts
+++ b/packages/types/src/agentRuntime.ts
@@ -321,6 +321,13 @@ export const AgentRuntimeErrorType = {
InvalidBedrockCredentials: 'InvalidBedrockCredentials',
InvalidVertexCredentials: 'InvalidVertexCredentials',
StreamChunkError: 'StreamChunkError',
+ /**
+ * The provider closed the stream without a terminal event (no stop / usage /
+ * error), e.g. its connection dropped or its server gave up mid-response.
+ * Upstream-owned and transient, unlike `StreamChunkError`, which is a chunk
+ * the harness could not parse or process.
+ */
+ ProviderStreamInterrupted: 'ProviderStreamInterrupted',
/**
* The model returned an empty completion โ€” no text content, no tool calls,
* and ~0 output tokens โ€” typically after a stalled tool loop where it