{
  "id": "llm/streaming-chunk-order-mismatch",
  "signature": "Error: streaming response chunk order mismatch - expected index 5 but got 7",
  "signature_zh": "错误：流式响应块顺序不匹配 - 期望索引 5 但收到 7",
  "regex": "streaming response chunk order mismatch",
  "domain": "llm",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "When using SSE streaming with parallel processing or load balancing, chunks may arrive out of order due to network latency or server-side concurrency, causing the client to reassemble the response incorrectly.",
  "root_cause_type": "generic",
  "root_cause_zh": "在使用 SSE 流式传输进行并行处理或负载均衡时，由于网络延迟或服务器端并发，块可能乱序到达，导致客户端错误地重新组装响应。",
  "versions": [
    {
      "version": "openai==1.23.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-4-turbo-2024-04-09",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "gpt-4o-2024-05-13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Timeout doesn't fix ordering; out-of-order chunks will still be out of order regardless of wait time.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This works as a workaround but defeats the purpose of streaming for real-time applications.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Implement a buffer that reorders chunks based on sequence numbers before assembly: `buffer[chunk.index] = chunk; while buffer[next_index] is not None: yield buffer[next_index]; next_index++`",
      "success_rate": 0.85,
      "how": "Implement a buffer that reorders chunks based on sequence numbers before assembly: `buffer[chunk.index] = chunk; while buffer[next_index] is not None: yield buffer[next_index]; next_index++`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a single-threaded SSE client or ensure the API endpoint is not behind a load balancer that reorders requests.",
      "success_rate": 0.7,
      "how": "Use a single-threaded SSE client or ensure the API endpoint is not behind a load balancer that reorders requests.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using a proxy or CDN, bypass it for streaming endpoints to reduce reordering risks.",
      "success_rate": 0.75,
      "how": "If using a proxy or CDN, bypass it for streaming endpoints to reduce reordering risks.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "实现一个缓冲区，根据序列号对块进行重新排序后组装：`buffer[chunk.index] = chunk; while buffer[next_index] is not None: yield buffer[next_index]; next_index++`",
    "使用单线程 SSE 客户端，或确保 API 端点不在会重新排序请求的负载均衡器后面。",
    "如果使用代理或 CDN，请绕过流式端点以减少重新排序的风险。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://platform.openai.com/docs/guides/streaming",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.75,
  "resolvable": "partial",
  "first_seen": "2024-05-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}