Repository navigation
[Fix] deepseekv32 detector: tolerate partial non-string param values raising MalformedJSON (stream tear-down) - #28684
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…that raise MalformedJSON The streaming partial-parameter branch in `_parse_parameters_from_xml` caught only `json.JSONDecodeError`, but `partial_json_parser` raises its own `MalformedJSON` -- a `ValueError` that does NOT subclass the stdlib `json.JSONDecodeError`. So a partial non-string-typed parameter whose streamed prefix is not yet valid JSON (e.g. an agentic code-exec argument like `python3 -c "...`) let the exception escape to the outer handler, which dumped the entire raw DSML buffer into `normal_text` and never cleared `_buffer` -- re-raising on every subsequent chunk and tearing down the stream. Broaden the except to `(json.JSONDecodeError, ValueError)`, matching the complete-value branch a few lines above, so a not-yet-valid partial value falls back to the raw string instead of crashing the stream. Adds a regression test asserting no raise, no DSML leak into `normal_text`, and that the tool name is still recovered.
3a3a875 to
e159c64
Compare
|
We independently hit this on DeepSeek-V4-Flash in production, triggered by array-valued tool arguments (e.g. an One downstream symptom worth flagging beyond the stream tear-down: in our traces the propagated error also surfaced the raw DSML markup in message We additionally added a fail-safe in |
|
Thanks, this is a great catch — we've added exactly the fail-safe you described. Confirmed your ballooning symptom on our side too: the outer Verified red→green on And yes please — I'd love the fixture. The guard I added forces a parse error mid-markup deterministically (monkeypatched |
|
@shanemort1982 — sounds like we're hitting the same problem from two sides: we're on DeepSeek-V4-Pro, you're on Flash, same root cause (yours via array-valued Also, credit where it's due: you independently reported this and proposed the exact fail-safe, so I'd like to add a |
|
@GavinZhu-GMI cheers for the credit, much appreciated. And yeah, confirmed: 62280c3 fixes our V4-Flash case too. Same behaviour on our side, normal_text stays empty, buffer is kept, and the invoke completes on a later chunk. For the trailers: Reported-by + Suggested-by on 62280c3 is the accurate one since you wrote that commit. Co-authored-by on the fixture commit is grand. Reported-by: shanemort1982 [email protected] Will share the fixture separately. Easier if I paste it here, or want a PR against the branch? |
62280c3 to
3bf9591
Compare
…r leaks raw DSML markup The outer except in parse_streaming_increment returned the raw buffer as normal_text on any error. Because _buffer is retained across increments, that both leaks the DSML markers into user-visible content and re-emits the whole buffer on every subsequent chunk -- ballooning the response to the output-token cap (tool_calls empty, finish_reason=stop). Reported independently on DeepSeek-V4-Flash, triggered by array-valued tool arguments rather than the code-string prefix the partial-value fix addresses; same root cause, one layer up. While the buffer still holds tool-call markup, emit empty normal_text and keep buffering so a still-arriving invoke can complete on a later chunk, instead of surfacing the markup. Adds a regression test forcing a parse error mid-markup and asserting no leak and a retained buffer. Co-authored-by: shanemort1982 <[email protected]>
3bf9591 to
2476acb
Compare
|
@shanemort1982 — please open the fixture as a PR against this branch ( I've also pushed the credit: the fail-safe commit ( Thanks again for the independent V4-Flash confirmation and the fail-safe suggestion. |
Add TestDeepSeekV32Detector.test_streaming_array_recipe_partial_value_chunked_1_7_64. Replays a complete tool call whose non-string `operations` parameter carries a spreadsheet-edit recipe emitted with Python-style single quotes, so its streamed prefix is not-yet-valid JSON and partial_json_parser raises MalformedJSON (a ValueError, not a stdlib json.JSONDecodeError). Feeding the payload at chunk sizes 1, 7 and 64 asserts no raise, no DSML-marker leak into normal_text, and that the tool name is still recovered. Fails on the unpatched detector at every chunk size; passes with the partial-value except widening plus the outer fail-safe on this branch.
…rray-recipe-fixture test(deepseekv32): streamed array-recipe fixture at chunk sizes 1/7/64
|
Heads-up: #34458 (5899674) landed and includes the exception fix from this PR — Not closing this, because the early-return guard you added is not in the merged version. I checked the case it targets and a partial DSML marker no longer reaches |
|
Thanks @GavinZhu-GMI. Closing this because it has had no updates in 91 days. Reopen it if the work is still relevant. Some directories moved recently, so an older branch may need retargeting: |
Motivation
The DeepSeek-V3.2 / V4 function-call detector tears down streaming responses on certain tool-call payloads. We hit this in production on agentic code-exec traffic (e.g. a tool argument like
python3 -c "..."), where the frontend logged a steady trickle of:Each error torn an in-flight stream → incomplete response.
Root cause: in
DeepSeekV32Detector._parse_parameters_from_xml, the partial-value branch catches onlyexcept json.JSONDecodeError. Butpartial_json_parserraises its ownMalformedJSON, which is aValueErrorand does not subclass the stdlibjson.JSONDecodeError. So when a non-string-typed parameter's streamed prefix is not yet valid JSON (bare text such aspython3 -c "...before any closing tag), the exception escapes the narrowexceptand propagates to the outerexcept Exceptionhandler inparse_streaming_increment, which:normal_text=current_text— dumping the raw DSML buffer (internal tool-call markers) into user-visible content, andself._buffer— so the same exception re-fires on every subsequent chunk, wedging/tearing the stream.Note the sibling complete-value branch a few lines above already catches
(json.JSONDecodeError, ValueError); this is just an asymmetry between the two branches.Modifications
python/sglang/srt/function_call/deepseekv32_detector.py: broaden the partial-valueexceptto(json.JSONDecodeError, ValueError), matching the complete-value branch, so a not-yet-valid partial value falls back to the raw string instead of crashing the stream.test/registered/unit/function_call/test_function_call_parser.py: addTestDeepSeekV32Detector.test_streaming_partial_non_string_param_does_not_throw— feeds the bare-text partial value across chunks and asserts no raise, no|DSML|leak intonormal_text, and that the tool name is still recovered. The test fails before the fix and passes after.This also affects DeepSeek-V4, whose detector inherits this method.
Accuracy Tests
N/A — no change to model/kernel forward code. Pure parser robustness fix on the streaming-detect path.
Speed Tests and Profiling
N/A — no hot-path or kernel change.
Checklist
CI States
Latest PR Test (Base): ❌ Run #27950909001
Latest PR Test (Extra): ❌ Run #27950908843