The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(codex): canonicalize fc_-only tool-result ids to match the call side
kshitijk4poor635232ec4ec7
diff --git a/agent/codex_responses_adapter.py b/agent/codex_responses_adapter.pyindex bd90e0ad919..01718fa4548 100644--- a/agent/codex_responses_adapter.py+++ b/agent/codex_responses_adapter.py@@ -742,9 +742,20 @@ def _chat_messages_to_responses_input(if role == "tool":raw_tool_call_id = msg.get("tool_call_id")- call_id, _ = _split_responses_tool_id(raw_tool_call_id)+ call_id, tool_response_item_id = _split_responses_tool_id(raw_tool_call_id)if not isinstance(call_id, str) or not call_id.strip():- if isinstance(raw_tool_call_id, str) and raw_tool_call_id.strip():+ # Legacy fc_-only stored ids: canonicalize to the same+ # ``call_<suffix>`` the assistant branch synthesizes above, so+ # a >64-char pair clamps to the SAME surrogate on both sides.+ # Hashing the raw ``fc_…`` here while the call side hashed+ # ``call_<suffix>`` would break the pairing and 400 the replay.+ if (+ isinstance(tool_response_item_id, str)+ and tool_response_item_id.startswith("fc_")+ and len(tool_response_item_id) > len("fc_")+ ):+ call_id = f"call_{tool_response_item_id[len('fc_'):]}"+ elif isinstance(raw_tool_call_id, str) and raw_tool_call_id.strip():call_id = raw_tool_call_id.strip()if not isinstance(call_id, str) or not call_id.strip():continuediff --git a/tests/agent/test_codex_responses_adapter.py b/tests/agent/test_codex_responses_adapter.pyindex 611f51ceb7d..2a65dabb8f0 100644--- a/tests/agent/test_codex_responses_adapter.py+++ b/tests/agent/test_codex_responses_adapter.py@@ -375,6 +375,37 @@ def test_chat_messages_to_responses_input_sanitizes_replayed_fn_name():assert call["call_id"] == output["call_id"] == "call_abc123"+def test_chat_messages_to_responses_input_canonicalizes_fc_only_pair():+ """A legacy fc_-only stored id must map the paired function_call and+ function_call_output to the SAME call_id — including the oversized case+ where both sides clamp to the same surrogate (#49224)."""+ for fc_id in ("fc_short123", "fc_" + "a" * 64):+ messages = [+ {+ "role": "assistant",+ "content": "",+ "tool_calls": [+ {+ "id": fc_id,+ "function": {"name": "web_search", "arguments": "{}"},+ }+ ],+ },+ {+ "role": "tool",+ "tool_call_id": fc_id,+ "content": "some result",+ },+ ]++ items = _chat_messages_to_responses_input(messages)++ call = next(i for i in items if i.get("type") == "function_call")+ output = next(i for i in items if i.get("type") == "function_call_output")+ assert call["call_id"] == output["call_id"]+ assert len(call["call_id"]) <= 64++def test_preflight_codex_input_items_sanitizes_replayed_fn_name():"""The preflight choke-point also coerces invalid replayed names(covers callers that build input items without the chat converter)."""