Skip to content

Fix Responses API background=true + stream=true panic (#1945)#2068

Closed
glaziermag wants to merge 1 commit into
EricLBuehler:masterfrom
glaziermag:fix-1945-responses-streaming
Closed

Fix Responses API background=true + stream=true panic (#1945)#2068
glaziermag wants to merge 1 commit into
EricLBuehler:masterfrom
glaziermag:fix-1945-responses-streaming

Conversation

@glaziermag

@glaziermag glaziermag commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #1945. Alternative to closed PR #1989.

Problem

The /v1/responses endpoint supports a background=true mode that spawns a Tokio task to process the request asynchronously. When stream=true was also set, the pipeline emitted a sequence of Response::Chunk(…) messages followed by a terminal Response::Done. The background receiver used a single match bg_rx.recv().await — it hit the first Chunk message, fell into the _ => catch-all, and marked the task as failed with "Unexpected response type".

Fix

Replace the single match with a while let Some(msg) = bg_rx.recv().await loop. Response::Chunk(_) arms continue to drain stream chunks; the terminal variants (Done, ModelError, ValidationError, InternalError) break the loop with the appropriate outcome.

Scope

This fix applies to background (background=true) chat completion requests. Non-background streaming requests go through a different path and are unaffected. Other response variants (CompletionDone, ImageGeneration, etc.) not applicable to this endpoint fall into the _ => arm as before — that is pre-existing behavior for endpoint misuse, not a regression.

Files changed

  • mistralrs-server-core/src/responses.rs

@glaziermag glaziermag force-pushed the fix-1945-responses-streaming branch from 1bf58be to 5cd2631 Compare April 6, 2026 23:47
@glaziermag glaziermag marked this pull request as ready for review April 6, 2026 23:50
@glaziermag glaziermag force-pushed the fix-1945-responses-streaming branch from 5cd2631 to ad592d6 Compare April 15, 2026 19:42
@github-actions

Copy link
Copy Markdown
Code Metrics Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language              Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 C Header                  5          305          210           52           43
 CSS                       2         1181         1036           34          111
 CUDA                     59        17706        13869         1637         2200
 Dockerfile                1           39           22            8            9
 HTML                      2          235          197           14           24
 JavaScript               16         3580         2702          486          392
 Jinja2                    7          694          656            5           33
 JSON                     21          409          406            0            3
 Makefile                  1            6            5            0            1
 Metal Shading Lan|       31        11647         9007         1064         1576
 PowerShell                1          300          227           30           43
 Python                  125         8316         6808          412         1096
 Shell                     2          485          329           95           61
 Plain Text                3         3723            0         2413         1310
 TOML                     27         1290         1124           35          131
 YAML                      3           25           23            2            0
─────────────────────────────────────────────────────────────────────────────────
 Jupyter Notebooks         3          122           83           23           16
 |- Markdown               1           60           30           22            8
 |- Python                 1          122          113            1            8
 (Total)                              304          226           46           32
─────────────────────────────────────────────────────────────────────────────────
 Markdown                105        11197            0         8067         3130
 |- BASH                  72          934          691          149           94
 |- Dockerfile             1            1            1            0            0
 |- JSON                  20          719          719            0            0
 |- PowerShell             3            3            3            0            0
 |- Python                23         1038          862           60          116
 |- Rust                  51         2048         1718           54          276
 |- TOML                   6          207          164            0           43
 |- YAML                   2            9            8            1            0
 (Total)                            16156         4166         8331         3659
─────────────────────────────────────────────────────────────────────────────────
 Rust                    547       236072       207590         6565        21917
 |- Markdown             361         8962          452         7385         1125
 (Total)                           245034       208042        13950        23042
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                   961       311435       249055        28614        33766
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

@glaziermag

Copy link
Copy Markdown
Contributor Author

Update (2026-04-15): Rebased onto origin/master. Branch was previously behind upstream by several commits. No code changes — the while let Some(msg) = bg_rx.recv().await fix with Response::Chunk(_) => continue is unchanged.

@glaziermag

Copy link
Copy Markdown
Contributor Author

Closing in favor of #2114, which is a clean reimplementation against current master with a minimal diff (no extraneous reindentation changes). The fix is the same: loop-drain Response::Chunk events in the background task handler.

@glaziermag glaziermag closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Responses API: background=true + stream=true fails with 'Unexpected response type'

1 participant