mirror of
https://github.com/mw00/project-maya.git
synced 2026-12-03 19:04:50 +07:00
[PR #626] serve: the tool-call parser resumes its </tool_call> search; TCP_NODELAY on streamed replies #634
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#634
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?
📋 Pull Request Information
Original PR: https://github.com/mw00/project-maya/pull/626
Author: @SeriousRising
Created: 10/28/2026
Status: 🔄 Open
Base:
main← Head:serve-parser-nodelay📝 Commits (1)
72aa0e6serve: the tool-call parser resumes its </tool_call> search; TCP_NODELAY on streamed replies📊 Changes
4 files changed (+74 additions, -1 deletions)
View changed files
📝
serve/frontend.py(+8 -1)📝
serve/server.py(+7 -0)📝
serve/test_server.py(+27 -0)📝
serve/test_tools.py(+32 -0)📄 Description
Two small serve changes on the streaming path; both leave the bytes sent unchanged.
1. The tool-call parser resumes its
</tool_call>searchProblem. While the model streams a long tool argument (an agent writing a file), the handler thread's CPU per token grows with the argument's length.
Cause.
serve/frontend.py:1350(v1.1.35), in call state:i = self.buf.find(CALL_END)searches from 0 on every piece, andbufholds the whole call so far: O(n²) over the call. #403 / #482 fixed what is emitted while a call streams; this is the search cost, which they did not touch.Fix. After a miss, keep
_call_resume = max(0, len(buf) - len(CALL_END) + 1)and search from there. That is sound because in call statebufonly grows (the one temporary swap forstream_toolsrestores it whole). The offset is reset on entering call state.Output: the same events.
serve/test_tools.pyCallEndRescanfeeds a call whose argument contains</tool_cal,</tool_callxand trailing partial fragments at piece sizes 1 / 2 / 3 / 5 / 11 / 64, and requires the whole-feed result each time;test_search_resume_advances_with_the_bodyerrors on v1.1.35'sfrontend.pyand passes with the fix.Measured (a 200K-char string argument in 20-char pieces through
OutputParser(stream_tools=True), the same 8 events):2. TCP_NODELAY on streamed replies
Problem. Streamed replies are small frames, often one token each. With Nagle on and the client's delayed ACK, a frame can wait for the ACK (classically ~40 ms) on a LAN hop, e.g. to a proxy in front of Maya.
Fix.
Handler._sse()(serve/server.py:4276, the one entry for every streaming path) setsIPPROTO_TCP / TCP_NODELAY = 1; anOSErroris ignored. The bytes are identical; only the packetization differs.Test:
serve/test_server.pyNoDelayStreaminguses a real loopback socket and checks the option goes 0 -> 1 through_sse(); it fails on v1.1.35'sserver.py. Not measured: we did not timestamp frame arrivals with and without it; the ~40 ms is the textbook Nagle / delayed-ACK interaction, not our measurement.No new settings.
Checks (as
.github/workflows/tests.yml):tools/check_hip_compat.pyOK; server tests 466 OK (12 skipped; v1.1.35 runs 463 - the new parser / NODELAY tests); installer and tools tests 584 OK (31 skipped).🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.