Fail local Transformers turns cleanly when generate() raises #856
All Vouch review confidence checks passed
Residual risk 0.13 = Change Risk (0.40) × (1 − Review Confidence (0.68)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 379 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.35 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.355
Real PR Conversation Timeline
2 items
Approved
Good work, thank you!
<img src="https://static.klipy.com/ii/d7aec6f6f171607374b2065c836f92f4/09/02/31WAoDw9.gif"/>
andimarafioti
omkar-334
Refs #850. When
generate()raises on the worker thread, theTextIteratorStreamernever gets its end marker, so the local Transformers handlers keep waiting and the response never finishes. This stores the error, ends the streamer, and re-raises after streaming so the existing error path ends the response.Changes
_start_transformers_generationonBaseLanguageModelHandler. Both the text and vision handlers use it, replacing the duplicated_locked_pipeand_locked_generate.streamer.end()itself fails (it decodes the cached tokens, which can be what failed), the helper queues the stop marker directly, so the reader is still released._finish_transformers_generationre-raises the stored error as aRuntimeError. The existing handler inprocess()turns that into anEndOfResponsewith an error.Testing
tests/test_transformers_generation_failure.pyruns both handlers:Against the unmodified code 8 of these 10 fail by hanging. The 2 that pass are the cancel cases, which never hang.
Real model check with a tiny random Llama built locally and the trigger from the issue (
do_sample=True,temperature=0.0):| | Failing turn | Next turn |
|---|---|---|
| Before | never finished (15 s timeout) | not reached |
| After | ended in 0.97 s with the
temperature (=0.0)error | works |Checks: full suite 4037 passed, 13 skipped, 1 failed. The one failure is
tests/openai_realtime/test_webrtc.py::TestWebRTCLoopback::test_close_awaits_pending_ice_checks(aioice did not start a connectivity check), which fails the same way on untouchedmainin my environment.ruff check,ruff format --checkandmypy srcare clean.Not covered: a real downloaded model, GPU runs, and the MLX paths.
Behavior note
On a mid stream failure, sentences already sent stay sent. A partial sentence still buffered is dropped and the response ends with the error.