Skip to content

Studio: fit the MCP match search to the room left for a reply - #18624

Merged
danielhanchen merged 1 commit into
mainfrom
studio-mcp-match-room
Nov 20, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-mcp-match-room

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Follow-up to #18529.

Problem

  1. Near a full context window, a later MCP lookup message can now come back as an empty reply. Studio: keep the MCP tool list fixed per chat and add each message's matches as a search #18529 adds the message's matching tools after it as an mcp_tool_search exchange. That exchange sits next to the message, so truncation cannot remove it, and on a near-full window it takes the room the reply needed. Before Studio: keep the MCP tool list fixed per chat and add each message's matches as a search #18529 the same turn either answered or showed a clear "Message too long" error.
  2. Each request checks the MCP tools remembered from earlier searches one at a time at the start of the tool loop, and each check rebuilds the whole tool catalog. Since Studio: keep the MCP tool list fixed per chat and add each message's matches as a search #18529 every search card adds up to 5 names, so this grows over a chat: 200 remembered names against a 346-tool catalog took about 400 ms before the first model call.

Change

  • The match search gets at most the room left after the tool listing, the message, a reply reserve (the larger of 1024 tokens and a quarter of the window, as the knowledge-base whole-document budget uses) and a 512-token margin, capped at its existing 15% share. When nothing fits, no search is added. The tools stay reachable through mcp_tool_search.
  • Remembered tools are checked with the bulk _mcp_tool_specs lookup, one catalog build for all of them.

Results

Studio from current main vs main + this PR. unsloth/Qwen3-0.6B-GGUF Q4_K_M on CPU, 4096 window, a 96-tool MCP server. Second message = filler text + a document lookup:

second message main this PR
short lookup mcp_tool_search card added mcp_tool_search card added
~4,000 tokens (filler x186) empty reply answers, calls list_user
~4,140 tokens (filler x190) empty reply after 7.9 s "Message too long: 4142 tokens exceeds the 4096-token context window"

Controller setup with 200 remembered names and a 346-tool catalog: 398 ms on main, 6 ms with this PR.

Tests

  • test_a_message_that_fills_the_window_gets_no_search_after_it: fails on main (the exchange is added), passes here.
  • test_controller_checks_remembered_tools_with_one_catalog_build: fails on main (6 catalog builds), passes here.
  • MCP, llama.cpp and safetensors tool-loop, controller, external tool result and admission suites pass.

@danielhanchen danielhanchen self-assigned this Nov 20, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T12:56:47.809475Z 6fcb5ca Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 6fcb5cae6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 37326ea into main Nov 20, 2026
@danielhanchen
danielhanchen deleted the studio-mcp-match-room branch November 20, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant