mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 21:08:26 +07:00
[GH-ISSUE #403] DeepSeek: a long string tool argument is held until its closing tag, so clients time out while the model is still writing #156
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
mw00/project-maya#156
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @talisp on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/403
In short
The problem. When DeepSeek writes a long string argument in a tool call, for example the content of a file for a
writetool, Maya sends the call's name and its short arguments right away. The long value itself is held until its closing tag. While the model keeps generating, the client receives no data. A client with a stream-idle limit cancels a request that is working fine, then retries it.What it cost us. DeepSeek-V4.1-Flash wrote at ~16-18 tok/s on our card. DeepSeek Harness (pi-ai) gave up with
pi-ai stream idle timeout after 300000msafter about 5,000 tokens of the file, and retried. One agent step made 1 attempt + 5 retries over ~31 minutes and then failed. The prompt was reused from the cache each time, so the cost was the repeated generation, not prompt reading.Where it comes from. It is reproducible offline, without a server or GPU, with Maya's own parser:
How the sibling projects handle it.
KEEPALIVE_S).The proposal, in short:
string="true"values as they are generated, as the GLM path already does for string arguments.We raised the client's idle limit to 20 minutes as a workaround, but this only hides the problem. The technical details follow, for whoever implements or reviews this.
Technical notes
1. Versions and environment
451f9cb6a21ea65673bdde2e57b4a670ae2b885925deec505b525212e05faa58697d9d2b7d17fdb3serve/frontend.py85cb11fb2c6adcb8630aabe93c8aacb509bd3fec, identical in the deployment and in that maindeepseek-v4.1-flash, unsloth UD-Q8_K_XL,maya-ds4, 262,144 context2. The incident
The agent was writing a source file with a tool named
write; the file content was a string argument. The step began at 21:03:26 and failed at 21:34:15 local time, after 1 attempt + 5 retries. The server's monitor showed the following attempts:3. Offline reproduction (no server, model or GPU)
Save as
repro_maya_tool_argument_streaming.pyand run it with the project's venv. It loadsserve/frontend.pyonly.Results on v1.1.21 and on main
25deec5, with 20 pieces totalling 5,540 characters:openai_to_messages()openai_to_messages()OutputParserThe two controls explain how a naive test can make GLM look affected.
OutputParserexpects the normalized{name, parameters}dicts that the HTTP path produces, not the public{type, function}wrappers. With the server's normalization, GLM streams its string arguments.4. Where the value is held
Links are pinned to
25deec5.DsmlRewriter._plain(): whilein_paramis set, the text goes toparameter_textand the method returns"".DsmlRewriter._tag()releases the value at</|DSML| parameter>.string="true", it isjson.dumps(parameter_text)with<replaced by<, so that literal legacy delimiters survive the rewrite to GLM's form.OutputParsersetsschemas = {}in DSML mode, because DSML carries its own string-or-JSON flag. The scanner therefore cannot take the schema-driven string path that streams GLM strings, and a value can sit on itsrawpath until the terminator. A fix inDsmlRewriteralone may leave this second hold in place.serve/server.py:Service.run()passesstream_tools=True.openai_chunks()turnstool_start/tool_argsinto deltas.yield "ping") comes only from the engine's no-token beat. While tokens flow into a held value, nothing is written. When a heartbeat is written, it is the SSE comment: keep-alive.5. How the sibling projects handle it
stream_tools = Falsefor DSML: the whole call arrives at the endKEEPALIVE_S = 10.0inserve/server.py(0.2.1.x), "a held-back tool argument leaves the stream quiet: ping at least this often": keep-aliveRelated Strata reports:
chunkTimeout. The client aborts a healthy request and retries. PR #1953 proposed an emptychat.completion.chunkfor/v1/chat/completionsandevent: pingfor/v1/messages. It was closed without being merged. We have not checked whether pi-ai counts SSE comments; the timeout we saw is consistent with no data at all being written.QUEUE_BEAT_S. Maya's server already beats while queued.6. Possible fixes
A. Stream DSML string values (the real fix).
string="true"flag through the rewrite into the scanner, or emittool_argsevents directly from the DSML path. Then:json.dumps(piece, ensure_ascii=False)[1:-1], with<→<as today (per-piece JSON escaping is safe, since an escape never spans two characters);</|DSML| parameter>.feed()already has that "could still become a tag" check.string="false"values (JSON: numbers, booleans, null, objects, arrays) can stay whole-value, as Strata does for arrays and objects. They are rarely long.B. A keep-alive while a value is held (a safety net, independent of A).
KEEPALIVE_S. While tokens are being generated and the parser has returned no events for N seconds, yield a ping.chat.completion.chunk;event: pingon/v1/messages), per Strata #1951, rather than an SSE comment.7. Tests a fix should pass
string="true"/"false", strings that look like numbers or JSON, null, booleans, numbers, arrays and objects keep their meaning.finish_reason, cancellation, answers without tools, andfinish().test_ds41_conformance.py,test_tools.pyandtest_tool_images.pykeep passing.8. What we did and did not do
We can test a branch on the machine above and report the same timings.
@mw00 commented on GitHub (Oct 23, 2026):
Thanks for the clear write-up. Fixed in v1.1.26: a DeepSeek tool call's string arguments (
string="true", e.g. a file's content) now stream to the client as they are written instead of arriving at the closing tag, so clients with a stream-idle timeout keep receiving data. The streamed pieces join to exactly the same arguments as the final call (new test in serve/test_ds41_conformance.py).