Skip to content

Continuations reorder a round's reasoning around gateway-executed calls #482

Open

Description

@haoshan98

Description

When a model's response holds reasoning before a gateway-executed call (MCP, web search, or hosted tool search), a
previous_response_id continuation sends the model that call and its output before the reasoning that led to it.
The live round and a store: false replay of the public output keep the original order, so the continuation does not
share the live round's prompt prefix (no prompt-cache reuse), and a reasoning model reads its reasoning after the
action it produced.

Steps to reproduce

  1. Run the gateway against a reasoning model on vLLM (seen with Qwen/Qwen3.6-35B-A3B-FP8), with a logging proxy
    between the gateway and vLLM so the upstream request bodies can be read.
  2. POST /v1/responses with store: true, hosted tool search and one deferred function:
    {"model": "Qwen/Qwen3.6-35B-A3B-FP8", "store": true,
     "input": "What's the weather in Paris right now? The get_weather tool is deferred: first call tool_search with paths [\"get_weather\"] to load it, then call get_weather for Paris.",
     "tools": [{"type": "tool_search"},
               {"type": "function", "name": "get_weather", "description": "Get the current weather for a city",
                "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"],
                               "additionalProperties": false},
                "strict": true, "defer_loading": true}]}
    The response output is reasoning, tool_search_call, tool_search_output, reasoning, function_call(get_weather).
  3. Continue with previous_response_id set to that response and a function_call_output for get_weather.
  4. Compare the input of the upstream request for step 3 with the input of the live second round in step 2, and with
    a store: false request whose input is the user message, step 2's output and the same function_call_output.

Expected behavior

The continuation sends the stored history in the order it happened, the same as the live round and a store: false
replay: user, reasoning, function_call(tool_search), function_call_output, reasoning, function_call(get_weather), function_call_output.

Actual behavior

The continuation sends user, function_call(tool_search), function_call_output, reasoning, reasoning, function_call(get_weather), function_call_output: the gateway call and its output come before the reasoning that
preceded them.

Cause: without a session continuation lease (a first turn, or conversation mode), record_round_history
(executor/engine/agent_turn.rs) records only the gateway calls, append_gateway_results
(executor/gateway/history.rs) adds their outputs to new_input_items, and persistence writes new_input_items
before the round's output items, where the reasoning is. A response with a continuation lease (a WebSocket session)
records reasoning in place and is not affected.

Environment

Additional context

Activity

  1. added
    bug
    on Oct 26, 2026
  2. Than0316 commented on Nov 1, 2026

    @Than0316
    Contributor

    Hi @haoshan98, thanks for the detailed write-up. Are you planning to fix this yourself, or would a contribution be welcome?

    If it's open, I'd follow the direction in the issue: record each gateway call at its position in the round's output instead of after the request input, keep the is_already_in_history skip from #472, and add a test with reasoning before a call for each gateway tool. The test would check the continuation's input against the live round's order using the mock upstream, like hosted_tool_search_projection_test.rs. Happy to take a different approach if you prefer.

  3. GCSimba commented on Nov 6, 2026

    @GCSimba
    Contributor

    @Than0316 are you working on this? If not, I'd be glad to take it, following the direction in the issue: record each gateway call at its position in the round's output instead of after the request input, keep the is_already_in_history skip from #472, and add a continuation test where reasoning precedes a hosted tool search call. @haoshan98 does that match what you had in mind?

  4. Than0316 commented on Nov 12, 2026

    @Than0316
    Contributor

    Update: I re-checked on current main. #505 fixed this for tool search, web search and MCP (regression tests in #519), but file_search (added in #486 after #505) still sends the reasoning after the search on a previous_response_id continuation. I have a failing test for it.

    @franciscojavierarceo are you planning to fix the file_search case, or would you like me to? @GCSimba @haoshan98 for visibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions