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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
import {
  type FailoverClassificationCorpusRow,
  billingSource,
  errorsSource,
  httpSource,
  matchesSource,
  messageRows,
  failoverSignalRows,
  openRouterSource,
  patternsSource,
  reason,
  retrySource,
} from "./failover-classification.corpus.test-support.js";
export const overflowServerMiscCases = [
  // Transient transport and provider failures.
  {
    id: "bedrock-incomplete-terminal-stream",
    source: "extensions/amazon-bedrock/stream.runtime.ts",
    signal: { provider: "amazon-bedrock", message: "Bedrock stream ended before messageStop" },
    expected: reason("timeout"),
  },
  {
    id: "anthropic-incomplete-terminal-stream",
    source: "packages/ai/src/transports/anthropic-transport-stream.ts",
    signal: { provider: "anthropic", message: "Anthropic stream ended before message_stop" },
    expected: reason("timeout"),
  },
  {
    id: "google-incomplete-terminal-stream",
    source: "packages/ai/src/providers/google-shared.ts",
    signal: {
      provider: "google",
      message: "Google stream ended before a terminal finish reason",
    },
    expected: reason("timeout"),
  },
  {
    id: "mistral-incomplete-terminal-stream",
    source: "packages/ai/src/providers/mistral.ts",
    signal: {
      provider: "mistral",
      message: "Mistral stream ended without a terminal finish reason",
    },
    expected: reason("timeout"),
  },
  {
    id: "openai-completions-incomplete-terminal-stream",
    source: "packages/ai/src/transports/openai-completions-stream.ts",
    signal: {
      provider: "opencode-go",
      message: "Stream ended without finish_reason",
    },
    expected: reason("timeout"),
  },
  {
    id: "openai-responses-incomplete-terminal-stream",
    source: "packages/ai/src/transports/openai-responses-stream-internal.ts",
    signal: {
      provider: "openai",
      message: "OpenAI Responses stream ended before a terminal response event",
    },
    expected: reason("timeout"),
  },
  {
    id: "proxy-incomplete-terminal-stream",
    source: "src/agents/runtime/proxy.ts",
    signal: { message: "Proxy stream ended before terminal event" },
    expected: reason("timeout"),
  },
  {
    id: "openai-responses-eof-with-unresolved-tools",
    source: "packages/ai/src/transports/openai-responses-stream-internal.ts",
    signal: { provider: "openai", message: "Responses stream ended with unresolved tool calls" },
    expected: reason("timeout"),
  },
  {
    id: "openai-responses-completed-with-unresolved-tools",
    source: "packages/ai/src/transports/openai-responses-stream-internal.ts",
    signal: {
      provider: "openai",
      message: "Responses stream completed with unresolved tool calls",
    },
    expected: null,
  },
  ...failoverSignalRows(billingSource, reason("timeout"), [
    ["billing-deadline-exceeded", { message: "deadline exceeded" }],
    ["billing-no-stream-chunks", { message: "request ended without sending any chunks" }],
    ["billing-connection-error", { message: "Connection error." }],
    ["billing-fetch-failed", { message: "fetch failed" }],
    ["billing-econnrefused", { message: "network error: ECONNREFUSED" }],
    [
      "billing-enotfound",
      { message: "dial tcp: lookup api.example.com: no such host (ENOTFOUND)" },
    ],
    ["billing-dns-eai-again", { message: "temporary dns failure EAI_AGAIN" }],
    [
      "billing-cloudflare-521",
      {
        message:
          "521 <!DOCTYPE html><html><head><title>Web server is down</title></head><body>Cloudflare</body></html>",
      },
    ],
    [
      "billing-openai-retry-guidance",
      {
        provider: "openai",
        message:
          "An error occurred while processing your request. You can retry your request, or contact us through our help center at help.openai.com if the error persists. Please include the request ID synthetic-provider-request-001 in your message.",
      },
    ],
    // #71620
    ["billing-shared-runtime-unknown-error", { message: "An unknown error occurred" }],
    ["billing-generic-410", { message: "HTTP 410 Gone" }],
    // #42149
    [
      "billing-gemini-malformed-response",
      { provider: "google", message: "Unhandled stop reason: MALFORMED_RESPONSE" },
    ],
    // #58315
    ["billing-operation-aborted", { message: "The operation was aborted" }],
    ["billing-stream-aborted", { message: "stream was aborted" }],
    ["billing-etimedout", { message: "Error: connect ETIMEDOUT 10.0.0.1:443" }],
    ["billing-ehostunreach", { message: "Error: connect EHOSTUNREACH 10.0.0.1:443" }],
    ["billing-epipe", { message: "Error: write EPIPE" }],
    // #61281
    [
      "billing-provider-network-finish-reason",
      { message: "Provider finish_reason: network_error" },
    ],
    // #69368
    ["billing-undici-socket", { message: "Error: UND_ERR_SOCKET other side closed" }],
    ["billing-undici-connect-timeout", { message: "UND_ERR_CONNECT_TIMEOUT" }],
    [
      "billing-request-failed-retries",
      { message: "Request failed after repeated internal retries." },
    ],
    [
      "billing-google-internal-500",
      {
        provider: "google",
        message:
          "provider=google model=gemini-3.1-flash-lite-preview got status: INTERNAL upstream failure code:500",
      },
    ],
    [
      "billing-mini-max-520",
      { message: '{"type":"api_error","message":"unknown error, 520 (1000)"}' },
    ],
    // #57010
    [
      "billing-anthropic-unexpected-error",
      {
        provider: "anthropic",
        message:
          '{"type":"error","error":{"type":"api_error","message":"An unexpected error occurred while processing the response"}}',
      },
    ],
    // #56242
    [
      "billing-zhipu-network-1234",
      {
        provider: "zai",
        message:
          "LLM error 1234: 网络错误,错误id:202603281427587491f4467f1c4712,请联系客服。 (request_id: 202603281427587491f4467f1c4712)",
      },
    ],
    ["billing-chinese-network-abnormal", { message: "网络异常,请稍后重试" }],
    ["billing-chinese-service-busy", { message: "服务繁忙,请稍后再试" }],
    ["billing-chinese-system-error", { message: "系统错误,请稍后重试" }],
  ]),
  ...failoverSignalRows(patternsSource, reason("timeout"), [
    [
      "patterns-cloudflare-html-502",
      {
        status: 502,
        message:
          "<!doctype html><html><head><title>502 Bad Gateway</title></head><body><h1>502 Bad Gateway</h1><p>cloudflare-nginx</p></body></html>",
      },
    ],
    [
      "patterns-cloudflare-html-503",
      {
        status: 503,
        message:
          "<!doctype html><html><head><title>503</title></head><body><h1>Service Unavailable</h1><p>Please try again. Rate limit exceeded.</p></body></html>",
      },
    ],
  ]),
  {
    id: "retry-explicit-retry-guidance",
    source: retrySource,
    signal: {
      message: "An error occurred while processing your request. You can retry your request.",
    },
    expected: reason("timeout"),
  },
  {
    id: "retry-openai-500",
    source: retrySource,
    signal: {
      provider: "openai",
      message:
        "OpenAI API error (500): 500 The server had an error while processing your request. Sorry about that!",
    },
    expected: null,
  },
  {
    id: "retry-azure-502",
    source: retrySource,
    signal: {
      provider: "azure-openai",
      message: "Azure OpenAI API error (502): Bad gateway from upstream",
    },
    expected: reason("timeout"),
  },
  {
    id: "retry-mistral-503",
    source: retrySource,
    signal: {
      provider: "mistral",
      message: "Mistral API error (503): service temporarily unavailable",
    },
    // FIXED(refactor-02): was timeout, now overloaded
    expected: reason("overloaded"),
  },
  {
    id: "retry-provider-504",
    source: retrySource,
    signal: { message: "Provider API error (504): gateway timeout" },
    expected: reason("timeout"),
  },
  {
    id: "http-provider-503",
    source: httpSource,
    signal: { status: 503, message: "Provider API error (503)" },
    expected: reason("timeout"),
  },
  {
    id: "openrouter-network-finish",
    source: openRouterSource,
    signal: { provider: "openrouter", message: "Provider finish_reason: network_error" },
    expected: reason("timeout"),
  },
  {
    id: "errors-malformed-streaming-fragment",
    source: errorsSource,
    signal: { message: "OpenClaw transport error: malformed_streaming_fragment" },
    expected: null,
  },
  {
    id: "http-provider-timeout",
    source: httpSource,
    signal: { message: "provider body timed out 50" },
    expected: reason("timeout"),
  },
  ...messageRows(billingSource, reason("overloaded"), [
    // FIXED(refactor-02): was timeout, now overloaded
    { id: "billing-status-503", message: "503 Service Unavailable" },
    // FIXED(refactor-02): was timeout, now overloaded
    { id: "billing-llm-service-unavailable", message: "LLM error: service unavailable" },
    // FIXED(refactor-02): was timeout, now overloaded
    {
      id: "billing-api-error-unavailable",
      message:
        '{"type":"error","error":{"type":"api_error","message":"Service temporarily unavailable"}}',
    },
  ]),
  ...messageRows(billingSource, reason("timeout"), [
    { id: "billing-status-499", message: "499 Client Closed Request" },
    { id: "billing-status-500", message: "500 Internal Server Error" },
    { id: "billing-status-502", message: "502 Bad Gateway" },
    { id: "billing-status-504", message: "504 Gateway Timeout" },
    { id: "billing-503-database", message: "503 Internal Database Error" },
    { id: "billing-stop-abort", message: "Unhandled stop reason: abort" },
    { id: "billing-stream-closed", message: "stream was closed" },
    { id: "billing-esockettimedout", message: "Error: connect ESOCKETTIMEDOUT 10.0.0.1:443" },
    { id: "billing-enetunreach", message: "Error: connect ENETUNREACH 10.0.0.1:443" },
    { id: "billing-enetreset", message: "Error: read ENETRESET" },
    { id: "billing-ehostdown", message: "Error: connect EHOSTDOWN 192.168.1.1:443" },
    {
      id: "billing-zai-network-stop",
      message: "Unhandled stop reason: network_error",
      provider: "zai",
    },
    { id: "billing-provider-abort", message: "Provider finish_reason: abort" },
    { id: "billing-provider-malformed", message: "Provider finish_reason: malformed_response" },
    { id: "billing-undici-terminated", message: "terminated" },
    { id: "billing-stream-read-error", message: "stream_read_error" },
    { id: "billing-undici-headers-timeout", message: "UND_ERR_HEADERS_TIMEOUT" },
    { id: "billing-undici-body-timeout", message: "UND_ERR_BODY_TIMEOUT" },
    { id: "billing-undici-aborted", message: "UND_ERR_ABORTED" },
    { id: "billing-undici-content-length", message: "UND_ERR_REQ_CONTENT_LENGTH_MISMATCH" },
    { id: "billing-request-failed", message: "Request failed" },
    {
      id: "billing-api-error-internal",
      message: '{"type":"error","error":{"type":"api_error","message":"Internal server error"}}',
    },
    {
      id: "billing-zhipu-network-json",
      message:
        '{"error":{"code":"1234","message":"网络错误,错误id:abc123,请联系客服。"},"request_id":"abc123"}',
      provider: "zai",
    },
    { id: "billing-chinese-connect-timeout", message: "连接超时" },
    { id: "billing-chinese-request-timeout", message: "请求超时,请重试" },
    { id: "billing-chinese-service-unavailable", message: "服务暂时不可用" },
    { id: "billing-chinese-connection-error", message: "连接错误" },
    { id: "billing-chinese-internal", message: "内部错误" },
    { id: "billing-chinese-server", message: "服务器错误" },
    { id: "billing-chinese-server-internal", message: "服务器内部错误" },
    { id: "billing-chinese-system-busy", message: "系统繁忙" },
    { id: "billing-chinese-system-abnormal", message: "系统异常" },
  ]),
  ...messageRows(retrySource, reason("overloaded"), [
    // FIXED(refactor-02): was timeout, now overloaded
    {
      id: "retry-billing-service",
      message: "503 billing service unavailable; please retry your request",
    },
    // FIXED(refactor-02): was timeout, now overloaded
    {
      id: "retry-subscription-service",
      message: "503 subscription service unavailable while checking quota",
    },
    // FIXED(refactor-02): was timeout, now overloaded
    { id: "retry-503-retry-after", message: "503 Service Unavailable; Retry-After: 120 seconds" },
  ]),
  ...messageRows(retrySource, reason("timeout"), [
    { id: "retry-http-500", message: "HTTP 500 temporary provider response" },
    { id: "retry-503", message: "503: temporary provider response" },
    { id: "retry-524", message: "524 status code (no body)" },
  ]),
  ...messageRows(patternsSource, reason("auth"), [
    {
      id: "patterns-cloudflare-challenge",
      status: 403,
      message:
        "<!doctype html><html><head><title>403 Forbidden</title></head><body>Enable JavaScript and cookies to continue.<p>Please stand by, while we are checking your browser...</p></body></html>",
    },
    {
      id: "patterns-cloudflare-cdn-cgi",
      status: 403,
      message:
        '<!doctype html><html><head><title>403 Forbidden</title></head><body><script src="/cdn-cgi/challenge-platform/h/g/orchestrate/chl_page"></script><p>Checking your browser...</p></body></html>',
    },
  ]),
  // Provider-completed server errors.
  ...failoverSignalRows(billingSource, reason("server_error"), [
    [
      "billing-openai-structured-server-error",
      {
        provider: "openai",
        message:
          'Codex error: {"type":"error","error":{"type":"server_error","code":"server_error","message":"An error occurred while processing your request."},"sequence_number":2}',
      },
    ],
    // #109218
    ["billing-provider-finish-error", { message: "Provider finish_reason: error" }],
  ]),
  {
    id: "matches-provider-finish-error",
    source: matchesSource,
    signal: { message: "Provider finish_reason: error" },
    expected: reason("server_error"),
  },
  {
    id: "openrouter-finish-error",
    source: openRouterSource,
    signal: { provider: "openrouter", message: "Provider finish_reason: error" },
    expected: reason("server_error"),
  },
  {
    id: "ollama-incomplete-stream",
    source: "extensions/ollama/index.test.ts",
    signal: { provider: "ollama", message: "Ollama API stream ended without a final response" },
    expected: null,
  },
  // Missing models and expired sessions.
  {
    id: "patterns-groq-deactivated",
    source: patternsSource,
    signal: { provider: "groq", message: "model_is_deactivated: this model has been deactivated" },
    expected: reason("model_not_found"),
  },
  {
    id: "openrouter-missing-model",
    source: openRouterSource,
    signal: {
      provider: "openrouter",
      status: 404,
      message: "No endpoints found for missing/model.",
    },
    expected: reason("model_not_found"),
  },
  ...failoverSignalRows(retrySource, reason("model_not_found"), [
    [
      "retry-mistral-model-not-found",
      { provider: "mistral", message: "Mistral API error (404): model not found" },
    ],
    // FIXED(refactor-02): was rate_limit, now model_not_found
    ["retry-gpt-preview-not-found", { message: "model gpt-5.5-preview-0429 not found" }],
    // FIXED(refactor-02): was null, now model_not_found
    ["retry-model-preview-not-found", { message: "model model-x-500-preview not found" }],
  ]),
  ...failoverSignalRows(billingSource, reason("session_expired"), [
    ["billing-session-not-found", { message: "HTTP 410: session not found" }],
    [
      "billing-claude-conversation-missing",
      { provider: "claude-cli", message: "No conversation found with session ID: abc123" },
    ],
  ]),
] satisfies readonly FailoverClassificationCorpusRow[];