Repository navigation
Preserve prompt cache during deferred MCP tool search - #16546
Conversation
…ation mcp_tool_search injected the matched tool schemas into the declared tools array mid-turn. The chat template renders tools at the top of the prompt, so the next continuation diverged from the first tokens and llama-server re-evaluated the whole conversation; on hybrid/recurrent models without a checkpoint at the divergence that is a full prefill (unslothai#16538), and a discovered-but-unused tool dropped from the next turn's listing repeated the storm on every later search. The search result now carries the full schemas it already budgets with _MCP_TOOL_LOAD_SHARE, and the controller only opens its call gate for the found catalog names, leaving the declared tools - and the cached prompt prefix - untouched. Tools a thread runs are still recorded and listed on its later turns. Refs unslothai#16538
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe90003866
ℹ️ 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".
| if _fit_result_to_room(candidate, MCP_TOOL_SEARCH_NAME) == candidate: | ||
| fitted.append(spec) |
There was a problem hiding this comment.
Enable the schemas actually admitted by the budgeted search
On the GGUF path, execute_tool() sets _REQUEST_RESULT_BUDGET inside stream_tool_execution()'s copied worker context, but ToolLoopController.record_result() recomputes mcp_tool_search_specs() in the parent context, where the result room is still None. This new context-dependent check can therefore select different schemas: a large first match rejected by the worker's result cap can be accepted during recomputation and consume enough load share to exclude a smaller match that the worker actually returned. The next llama.cpp decoding grammar then lacks the tool reported as loaded, preventing its native call. Carry the admitted schemas back from execution, or recompute using the same result budget.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d02daa8: build the decoding catalog from the schemas in the completed search result instead of recomputing under the parent context. A real worker-thread regression returns ping but previously enabled large; it fails before this change and passes after. Python documents that copied-context changes remain isolated: https://docs.python.org/3/library/contextvars.html
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Fixes #16538. Keep searched MCP schemas out of the local model’s cached prompt declaration and return them in tool results. For llama.cpp, supply discovered schemas to its decoding grammar separately from the template’s tools. External providers retain normal tool declarations because they cannot separate the two.
Search admits only complete schemas within the response budget, without charging rejected matches against smaller tools. Deferred calls retain the existing schema-identifier filtering and argument coercion.
Continues Shreesh-Sree’s #16539, preserving the original commits. That PR and its source fork became unavailable during review. Includes fixes for four Codex findings from the review mirror, plus the external-provider compatibility regression.
Live validation:
mcp__demo__ping,n=7)./apply-templateconfirms byte-identical rendered prompts.MCP/controller/external-loop tests: 317 passed. The updated llama-loop regression and seven llama MCP tests pass. Pre-commit passes. Regression cases fail on their respective baselines. The broader backend run was interrupted after stalling with 415 tests passed; it is not a full-suite pass.
Final Codex review found no major issues at
d9570c4ffa.