Pull requests / #1624
#1624 frontend: the tools in a canonical order
open · @XinacS · 0 comments · View on GitHub
Setup & installServer & APIModels & quants
Description
`_tool_list` returns 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_xxs` multi 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, with `rbash_remote-bash` and `read` swapped 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:** `ToolOrder` in 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.
Related on strata.com
Editorial links to help you install, pick models, or read release notes — not part of the upstream thread.