[PR #482] [CLOSED] DSML: a partial closing-tag prefix in a streamed string argument swallows the rest of the call (v1.1.26 #403 follow-up) #555

Closed
opened 2026-10-29 21:26:47 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/482
Author: @catonooka
Created: 10/25/2026
Status: ❌ Closed

Base: main ← Head: fix/dsml-streamed-arg-closer-prefix


📝 Commits (2)

  • 6ddb89d DSML: inside a parameter value, only the complete closing tag is structural
  • fb2a9d1 drop CI workflow from the PR branch (repo-scope token cannot push workflow changes; CI runs on upstream's tree anyway)

📊 Changes

3 files changed (+78 additions, -44 deletions)

View changed files

➖ .github/workflows/tests.yml (+0 -39)
📝 serve/frontend.py (+37 -5)
📝 serve/test_ds41_conformance.py (+41 -0)

📄 Description

The bug

The v1.1.26 fix for #403 (a long string argument streams as it is written) scans for < inside a parameter value (DsmlRewriter.feed). But inside a value, only the complete closing tag is structural — the reference decoder reads until that exact token (parse_tool_calls in serve/ds41_encoding.py).

When a string value ends with a partial closing tag — e.g. a file documenting DSML itself, whose last line is </|DSML| para — the prefix glues onto the real closing tag: the opener scan matches, then find(">") lands inside the real closer, and the whole rest of the tool call (the real closing tag, </|DSML| invoke>, everything after) is emitted as argument data. The call's arguments are silently corrupted; nothing errors.

Reproducer on v1.1.27 (char-by-char or whole feed, same result):

from serve.frontend import OutputParser
parser = OutputParser(thinking=False, tools=None, stream_tools=True, dsml=True)
text = (
    '\n\n<|DSML| calls>\n<|DSML| invoke name="write">\n'
    '<|DSML| parameter name="content" string="true">'
    'a tutorial about DSML tags, ending mid-tag with </|DSML| para'
    '</|DSML| parameter>\n</|DSML| invoke>\n</|DSML| calls>'
)
for i in range(len(text)):
    events = parser.feed(text[i])
events += parser.finish()
call = next(e for e in events if e.kind == "tool_call")
print(call.arguments)
# expected: {'content': 'a tutorial about DSML tags, ending mid-tag with </|DSML| para'}
# actual:   {'content': 'a tutorial about DSML tags, ending mid-tag with </|DSML| para'
#            '</|DSML| parameter>\n</|DSML| invoke>\n</|DSML| calls>'}

The fix

Inside in_param, feed now looks only for the complete closing token and holds back a suffix that could still grow into it (the same hold the parser uses for tags split across deltas). Streaming behavior is unchanged: an 8k-char value still emits more than half its bytes before the closing tag (asserted by the new test). The closing-tag handling moved to a _close() helper; raw (string="false") values still arrive whole, as before.

Tests

Three new cases in serve/test_ds41_conformance.py:

  • a streamed string argument's deltas must arrive before the final tool_call event (index-compared against the event list — not just concat-and-compare, which is exactly how the buffering bug passed the original #403 test)
  • a partial closer prefix at a value's end stays argument data (the case above)
  • string="false" values keep arriving whole

serve.test_ds41_conformance: 35/35 green. Full suite: the same 13 pre-existing test-isolation failures as stock main, nothing new.

Found while serving DeepSeek-V4.1-Flash-1017 on a 2x RTX 3090 rig with a pi-ai client (the same streamIdleTimeoutMs=300000 class of failures as #403); our measurements from the original fix are in catonooka/maya-s24-turbo, dsv41-3090/deepseek-campaign-1024/FIX-dsml-tool-args-stream.md.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/mw00/project-maya/pull/482 **Author:** [@catonooka](https://github.com/catonooka) **Created:** 10/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/dsml-streamed-arg-closer-prefix` --- ### 📝 Commits (2) - [`6ddb89d`](https://github.com/mw00/project-maya/commit/6ddb89d4c82d8b7514edffcd6ddc71fc4058b237) DSML: inside a parameter value, only the complete closing tag is structural - [`fb2a9d1`](https://github.com/mw00/project-maya/commit/fb2a9d1643db4919be243b51eaf159685cc58bf0) drop CI workflow from the PR branch (repo-scope token cannot push workflow changes; CI runs on upstream's tree anyway) ### 📊 Changes **3 files changed** (+78 additions, -44 deletions) <details> <summary>View changed files</summary> ➖ `.github/workflows/tests.yml` (+0 -39) 📝 `serve/frontend.py` (+37 -5) 📝 `serve/test_ds41_conformance.py` (+41 -0) </details> ### 📄 Description ## The bug The v1.1.26 fix for #403 (a long string argument streams as it is written) scans for `<` **inside a parameter value** (`DsmlRewriter.feed`). But inside a value, only the complete closing tag is structural — the reference decoder reads until that exact token (`parse_tool_calls` in `serve/ds41_encoding.py`). When a string value ends with a **partial** closing tag — e.g. a file documenting DSML itself, whose last line is `</|DSML| para` — the prefix glues onto the real closing tag: the opener scan matches, then `find(">")` lands inside the real closer, and the whole rest of the tool call (the real closing tag, `</|DSML| invoke>`, everything after) is emitted as argument data. The call's arguments are silently corrupted; nothing errors. Reproducer on v1.1.27 (char-by-char or whole feed, same result): ```python from serve.frontend import OutputParser parser = OutputParser(thinking=False, tools=None, stream_tools=True, dsml=True) text = ( '\n\n<|DSML| calls>\n<|DSML| invoke name="write">\n' '<|DSML| parameter name="content" string="true">' 'a tutorial about DSML tags, ending mid-tag with </|DSML| para' '</|DSML| parameter>\n</|DSML| invoke>\n</|DSML| calls>' ) for i in range(len(text)): events = parser.feed(text[i]) events += parser.finish() call = next(e for e in events if e.kind == "tool_call") print(call.arguments) # expected: {'content': 'a tutorial about DSML tags, ending mid-tag with </|DSML| para'} # actual: {'content': 'a tutorial about DSML tags, ending mid-tag with </|DSML| para' # '</|DSML| parameter>\n</|DSML| invoke>\n</|DSML| calls>'} ``` ## The fix Inside `in_param`, `feed` now looks only for the complete closing token and holds back a suffix that could still grow into it (the same hold the parser uses for tags split across deltas). Streaming behavior is unchanged: an 8k-char value still emits more than half its bytes before the closing tag (asserted by the new test). The closing-tag handling moved to a `_close()` helper; raw (`string="false"`) values still arrive whole, as before. ## Tests Three new cases in `serve/test_ds41_conformance.py`: - a streamed string argument's deltas must arrive **before** the final `tool_call` event (index-compared against the event list — not just concat-and-compare, which is exactly how the buffering bug passed the original #403 test) - a partial closer prefix at a value's end stays argument data (the case above) - `string="false"` values keep arriving whole `serve.test_ds41_conformance`: 35/35 green. Full suite: the same 13 pre-existing test-isolation failures as stock main, nothing new. Found while serving DeepSeek-V4.1-Flash-1017 on a 2x RTX 3090 rig with a pi-ai client (the same streamIdleTimeoutMs=300000 class of failures as #403); our measurements from the original fix are in [catonooka/maya-s24-turbo](https://github.com/catonooka/maya-s24-turbo), `dsv41-3090/deepseek-campaign-1024/FIX-dsml-tool-args-stream.md`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:47 +07:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#555
No description provided.