Skip to content

Studio: let search_conversation find this turn's results on API providers - #16666

Merged
danielhanchen merged 1 commit into
mainfrom
studio-search-conversation-this-turn
Nov 4, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-search-conversation-this-turn

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Fixes #16602

What was wrong

On API providers (OpenRouter, OpenAI-compatible custom servers and so on), Studio runs the tool loop itself and refits the context before every provider call. When a refit pushes out a tool result from the current turn, that result is archived, and search_conversation is meant to get it back later in the same turn.

The archive only returns chunks that are on the branch the tool is given. The external loop gave the tool the client's messages as they were when the turn started, so a result produced during this turn was never on that branch. It was archived and then filtered out of every search. The model saw "the conversation search came back empty" and answered that it had no earlier findings.

The local llama.cpp loop already passes a branch that grows as the loop goes (_extend_live_branch), so GGUF models were not affected.

The change

stream_with_studio_tools keeps the same kind of growing branch: the request's messages plus every message the loop adds. search_conversation gets a snapshot of it on each call. Nothing else reads the old frozen copy.

Tests

  • test_search_conversation_branch_holds_this_turns_tool_results (tests/test_external_tool_edge_cases.py): one web_search call, then a search_conversation call, checking that the branch handed to the tool holds the web_search result. It fails on main and passes with the change.
  • End to end, CPU only, with the real archive (sqlite-vec) and stub embeddings: a custom provider on a thread that already compacted once. In one turn it makes 8 rounds of 2 web_search calls, the context refits 10 times, and then it calls search_conversation for a finding from round 1. On main the chunk is in the archive, but the tool returns only older saved turns. With the change the finding comes back.
  • These suites all pass: test_studio_tool_loop.py, test_external_tool_edge_cases.py, test_external_conversation_archive.py, test_external_auto_compaction.py, test_conversation_recall_injection.py, test_conversation_recall_session.py, test_conversation_archive.py, test_external_tool_refusal_gates.py, test_external_mcp_delta_provenance.py, test_external_preserve_thinking.py, test_external_tool_call_id_replay.py, test_tool_loop_controller.py (637 passed).

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

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T13:59:02.445311Z c0b1a0e 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. More of your lovely PRs please.

Reviewed commit: c0b1a0e054

ℹ️ 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".

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.

[Bug] search_conversation tool totally disappeared (2nd time)

1 participant