Skip to content

The agent that grows with you

fix(codex): keep Codex web searches in stored history as tool calls

h4ck2007114e0d63802380
diff --git a/agent/codex_runtime.py b/agent/codex_runtime.py
index b20faa31d42..f63254baf89 100644
--- a/agent/codex_runtime.py
+++ b/agent/codex_runtime.py
@@ -259,7 +259,7 @@ def _record_codex_app_server_compaction(agent, turn, *, approx_tokens: int | Non
# into the callbacks the standard runtime fires (tool_progress_callback, _fire_stream_delta, ...).
# Item types that project to a Hermes tool_call (keep in sync with agent/transports/codex_event_projector.py
-# so UI names match recorded names). webSearch is codex's built-in tool: no projector entry, still gets a bubble.
+# so UI names match recorded names). webSearch is codex's built-in tool; the projector records it under the same id.
_CODEX_TOOL_ITEM_TYPES = frozenset({"commandExecution", "fileChange", "mcpToolCall", "dynamicToolCall", "webSearch"})
# Text-delta notifications → the agent stream hook each one feeds. Single source for both the display
# handlers and the liveness set below, so a new delta method can't stream without refreshing activity (#118410).
diff --git a/agent/transports/codex_event_projector.py b/agent/transports/codex_event_projector.py
index 067f744b2c5..71b16316eb6 100644
--- a/agent/transports/codex_event_projector.py
+++ b/agent/transports/codex_event_projector.py
@@ -145,11 +145,19 @@ class CodexEventProjector:
)
return f"dyn_{tool}", tool, _dict_args(item.get("arguments")), content
+ @staticmethod
+ def _web_search_spec(item: dict) -> tuple[str, str, dict, str]:
+ # Codex ran the search itself; the result names it so a later non-Codex
+ # turn does not read this as a Hermes web_search call.
+ content = json.dumps({"provider": "codex", "status": item.get("status") or "completed"})
+ return "web_search", "web_search", {"query": item.get("query") or ""}, content
+
_TOOL_PROJECTIONS: dict[str, Callable[[dict], tuple[str, str, dict, str]]] = {
"commandExecution": _command_spec,
"fileChange": _file_change_spec,
"mcpToolCall": _mcp_tool_call_spec,
"dynamicToolCall": _dynamic_tool_call_spec,
+ "webSearch": _web_search_spec,
}
@staticmethod
diff --git a/tests/agent/transports/test_codex_event_projector.py b/tests/agent/transports/test_codex_event_projector.py
index 6f15277dfe0..05b0d6cbf19 100644
--- a/tests/agent/transports/test_codex_event_projector.py
+++ b/tests/agent/transports/test_codex_event_projector.py
@@ -245,6 +245,25 @@ class TestMcpToolCallProjection:
assert "error" in msgs[1]["content"]
+class TestWebSearchProjection:
+ def test_web_search_is_recorded_under_the_live_card_id(self) -> None:
+ # The live bubble and the stored history must share name + call id, or a
+ # refreshed transcript drops the card and shows a raw JSON note instead.
+ from agent.codex_runtime import _codex_item_to_tool_name, _stable_call_id
+
+ item = {"type": "webSearch", "id": "ws-1", "query": "Hermes Agent docs"}
+ result = CodexEventProjector().project({"method": "item/completed", "params": {"item": item}})
+
+ assert result.is_tool_iteration is True
+ assistant, tool = result.messages
+ call = assistant["tool_calls"][0]
+ live_name = _codex_item_to_tool_name(item)
+ assert call["function"]["name"] == live_name
+ assert call["id"] == tool["tool_call_id"] == _stable_call_id(item, live_name)
+ assert json.loads(call["function"]["arguments"]) == {"query": "Hermes Agent docs"}
+ assert json.loads(tool["content"]) == {"provider": "codex", "status": "completed"}
+
+
class TestUserAndOpaqueProjection:
def test_user_message_text_fragments_only(self) -> None:
item = {
@@ -309,6 +328,8 @@ class TestRoleAlternationInvariant:
{"type": "dynamicToolCall", "id": "d1", "tool": "x",
"arguments": {}, "status": "completed",
"contentItems": [], "success": True},
+ {"type": "webSearch", "id": "w1", "query": "x",
+ "status": "completed"},
],
)
def test_tool_items_emit_assistant_then_tool(self, item) -> None: