Repository navigation
Studio: search earlier turns for the user's question, not the tool loop's own notices - #16204
Merged
danielhanchen merged 3 commits intoNov 1, 2026
Conversation
…op's own notices (unslothai#16187) When a long tool turn compacts on a later pass, the automatic recall took its query from the last user-role message on the live branch. The loop adds its own user-role notices there (an identical call already ran, the tool call budget is spent), so recall searched the archive for that notice and the final answer pass, which cannot call search_conversation, got nothing back and told the user it had no earlier context. build_conversation_recall now takes query_messages, the client's own transcript, for the query; the live branch still filters what is returned. The llama.cpp loop (iteration fits and the final pass) and the MLX / managed-engine loop pass their request branch.
…nal provider path [skip ci]
Member
|
Review record for #16204, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#674. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
2 of 5 tasks
2 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #16187
What was wrong
In the second screenshot the turn runs 13 rounds of 2 tool calls, reaches the 25-call cap, and the context is compacted on the final "give your answer now" pass. That pass runs with
tool_choice: "none", sosearch_conversationcan't be called there; the only way back to earlier turns is the automatic recall that runs when a fit evicts something.That recall took its query from the last user-role message on the loop's live branch. The loop adds its own user-role notices to that branch (for example "an identical call had already completed successfully…" or the "You have used all available tool calls…" nudge when it rides a user turn). So the archive was searched for the notice text instead of the user's question, nothing relevant came back, and the model answered that it had no earlier context. These notices are long enough that the existing thin-query fallback ("continue" and the like) doesn't catch them.
The change
build_conversation_recalltakesquery_messages, the client's own transcript, and reads the query (and the thin-query anchor) from it. The live branch is still what filters the results, so tool results this request produced stay recallable._archive_and_recallpasses it through (only when given, so existing callers are unchanged)._request_branchon its per-iteration fit and on the final pass; the MLX / managed-engine loop (compact_chat_context) passes itsrequest_branch.Tests
test_recall_searches_the_users_question_not_the_loops_own_noticesdrives the real llama.cpp tool loop: repeated calls leave a duplicate-call notice as the last user turn, the final pass compacts, and the recall query must be the user's question. Before the fix it searched for the notice.test_conversation_recall_injection.pycoverquery_messagesinbuild_conversation_recalland_archive_and_recall.test_mlx_context_compaction.py: the existing re-prompt loop test also checks the query source.All three new tests fail on main and pass with the change.
Ran on Windows 11 (no GPU needed), compared against a clean copy of main:
test_conversation_recall_injection.py81 passed,test_mlx_context_compaction.py20 passed,test_conversation_archive.py187 passed,test_external_conversation_archive.py11 passed,test_conversation_search_safetensors_loop.py11 passed,test_conversation_recall_session.py8 passed,test_context_overflow_truncation.py78 passed.test_checkpoint_compaction.py: 168 passed, 1 failed, 14 errors, identical on clean main (/proc/self/fdand a Windows-only parametrize setup error).test_llama_cpp_tool_loop.py: the targeted tests pass; the full file hangs on this machine in a textual-fallback per-turn-limit test on clean main as well, so I couldn't get a full-file run here. CI should cover it.I don't have a Mac, so the MLX loop is covered only by the stubbed tests above.
External provider path
The API provider loop (
_fit_external_context) already searched for the user's question, but it filtered the recall to the client's request only. Tool results this turn produced and a fit evicted were archived and then filtered out, so the model still answered that it had no findings. The recall now filters on the loop's own conversation and takes its query from the client's request (query_messages), matching the llama.cpp loop.test_a_tool_result_this_turn_evicted_is_recalled_for_the_users_questionfails without this and passes with it.