๐คฏ 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 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.tsindex 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.tsindex 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.tsindex 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.tsindex 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.jsonindex 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.jsonindex 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.tsindex 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.tsindex 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.tsindex 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-ignorediff --git a/packages/model-runtime/src/core/streams/protocol.test.ts b/packages/model-runtime/src/core/streams/protocol.test.tsindex 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.tsindex 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.tsindex 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.tsindex 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.tsindex 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