# Error: streaming response chunk order mismatch - expected index 5 but got 7

- **ID:** `llm/streaming-chunk-order-mismatch`
- **Domain:** llm
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 75%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| openai==1.23.0 | active | — | — |
| gpt-4-turbo-2024-04-09 | active | — | — |
| gpt-4o-2024-05-13 | active | — | — |

## Workarounds

1. **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++`** (85% success)
   ```
   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++`
   ```
2. **Use a single-threaded SSE client or ensure the API endpoint is not behind a load balancer that reorders requests.** (70% success)
   ```
   Use a single-threaded SSE client or ensure the API endpoint is not behind a load balancer that reorders requests.
   ```
3. **If using a proxy or CDN, bypass it for streaming endpoints to reduce reordering risks.** (75% success)
   ```
   If using a proxy or CDN, bypass it for streaming endpoints to reduce reordering risks.
   ```

## Dead Ends

- **** — Timeout doesn't fix ordering; out-of-order chunks will still be out of order regardless of wait time. (60% fail)
- **** — This works as a workaround but defeats the purpose of streaming for real-time applications. (30% fail)
