fix(openai): preserve legacy reasoning replay

Filter only v1 reasoning with an explicitly foreign provider.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This commit is contained in:
ccurmeandopen-swe[bot] committed 2026-10-02 20:04:20 +00:00
1 parent d3541af65e
commit 31e5b4115b
2 files changed
+25 -6

No files matched your search

@@ -5010,10 +5010,12 @@ def _construct_responses_api_input(
input_.append(new_item)
elif block_type == "reasoning":
if lc_msg.response_metadata.get(
"output_version"
) == "v1" and lc_msg.response_metadata.get(
"model_provider"
) == "openai" and (
store is not False or block.get("encrypted_content")
):
) not in (None, "openai"):
continue
if store is not False or block.get("encrypted_content"):
input_.append(_pop_index_and_sub_index(block))
elif block_type in (
"compaction",
@@ -3303,22 +3303,39 @@ def test__construct_responses_api_input_human_message_with_image_url_conversion(
@pytest.mark.parametrize("provider", ["openai", "anthropic", None])
@pytest.mark.parametrize("store", [None, True, False])
@pytest.mark.parametrize("output_version", ["v1", "responses/v1", None])
def test__construct_responses_api_input_reasoning_provider(
provider: str | None, store: bool | None
provider: str | None, store: bool | None, output_version: str | None
) -> None:
message = AIMessage(
content=[
{"type": "reasoning", "reasoning": "reasoning text"},
{"type": "text", "text": "answer"},
],
response_metadata={"model_provider": provider, "output_version": "v1"},
response_metadata={
"model_provider": provider,
"output_version": output_version,
},
)
result = _construct_responses_api_input([message], store=store)
reasoning = [item for item in result if item["type"] == "reasoning"]
assert bool(reasoning) == (provider == "openai" and store is not False)
assert bool(reasoning) == (
(output_version != "v1" or provider in (None, "openai")) and store is not False
)
assert result[-1]["content"][0]["text"] == "answer"
def test__construct_responses_api_input_legacy_reasoning() -> None:
message = AIMessage(
content=[{"type": "text", "text": "answer"}],
additional_kwargs={
"reasoning": {"type": "reasoning", "id": "rs_123", "summary": []},
},
)
result = _construct_responses_api_input([message])
assert {"type": "reasoning", "id": "rs_123", "summary": []} in result
def test__construct_responses_api_input_store_false_replays_stateless_history() -> None:
ai_message = AIMessage(
content=[