mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1624] [CLOSED] frontend: the tools in a canonical order #3568
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3568
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/Niko1221/Strata/pull/1624
Author: @XinacS
Created: 10/8/2026
Status: ❌ Closed
Base:
main← Head:f-tool-order📝 Commits (2)
156b6f3frontend: _tool_list returns the tools sorted by name - clients send them in the order their MCP servers finished registering, and the template renders the tool list before the system prompt, so one swap moves the shared prefix back thousands of tokens and the conversation is read again132ddb0frontend: "system_reminders": "tail" moves a client's system-reminder block out of a past turn onto the last user turn📊 Changes
3 files changed (+103 additions, -8 deletions)
View changed files
📝
serve/frontend.py(+47 -5)📝
serve/server.py(+8 -3)📝
serve/test_server.py(+48 -0)📄 Description
_tool_listreturns the tools sorted by name. Clients send them in the order their MCP servers finished registering, and the chat template renders the tool list before the system prompt, so one swap in that list moves the shared prefix back thousands of tokens and the whole conversation is read again. Sorted by name, the rendered tool region is identical on every request.Measured before (opencode with the
swift-iq3_xxsmulti config: parallel 3, 262144 context, 16 conversation slots): a request of 190283 tokens reused 81694 and read 108589, with the shared prefix ending at token 3977. The text at the cut was the tool list, withrbash_remote-bashandreadswapped between the two requests - a full conversation re-read caused by nothing the user did.opencode has the same finding and closed it as not planned: https://github.com/anomalyco/opencode/issues/23571 (MCP tool ordering changes after restart and breaks prompt caching). Sorting on the serving side fixes it for every client, not just opencode.
Measured after (same setup): warm requests reuse 98.4% of prompt tokens, 7 turns in a row at 98.2-99.9% (42990 = 42946 reused, 38643 = 38397 reused; cold conversation starts excluded). No 3977-prefix cut recurred.
Tests:
ToolOrderin serve/test_server.py - both request shapes (OpenAI{"type":"function","function":{...}}and Anthropic{"name":..,"input_schema":..}) come out sorted whatever order they arrive in. Full suite: 264 tests OK.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.