Skip to content

Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.

fix(proxy): resolve Codex custom_tool_call names for Responses tool exclusion (#3755)

donjor55c78deaa817
diff --git a/headroom/proxy/handlers/openai.py b/headroom/proxy/handlers/openai.py
index 9b44decce..6fc152f75 100644
--- a/headroom/proxy/handlers/openai.py
+++ b/headroom/proxy/handlers/openai.py
@@ -2103,13 +2103,14 @@ class OpenAIHandlerMixin:
# excluded tools (HEADROOM_EXCLUDE_TOOLS) can be protected from
# compression. The chat/Anthropic paths get this via
# ContentRouter._build_tool_name_map; the Responses payload carries the
- # name on the `function_call` item and the originating call_id on the
- # matching `function_call_output`, so we correlate them here.
+ # name on the `function_call` (or Codex `custom_tool_call`) item and
+ # the originating call_id on the matching output, so we correlate
+ # them here.
function_name_by_call_id: dict[str, str] = {}
for item in items:
if not isinstance(item, dict):
continue
- if item.get("type") != "function_call":
+ if item.get("type") not in ("function_call", "custom_tool_call"):
continue
name = item.get("name")
call_id = item.get("call_id")
diff --git a/tests/test_openai_responses_compression_units.py b/tests/test_openai_responses_compression_units.py
index 264fdfe68..4b6d54705 100644
--- a/tests/test_openai_responses_compression_units.py
+++ b/tests/test_openai_responses_compression_units.py
@@ -1194,3 +1194,109 @@ def test_openai_responses_adapter_floors_when_aggregate_below_threshold():
assert saved == 0
assert units_by_category == {"size_floor": len(outputs)}
assert new_payload == payload
+
+
+def test_openai_responses_adapter_preserves_excluded_custom_tool_outputs():
+ """Codex freeform tools pair ``custom_tool_call`` with its output by call_id.
+
+ The exclude check must resolve their names exactly like ``function_call``.
+ """
+ router = ContentRouter()
+ router.config.exclude_tools = {"serena.find_symbol", "find_symbol"}
+
+ def compress(self, content: str, **_kwargs):
+ return RouterCompressionResult(
+ compressed="should not be used",
+ original=content,
+ strategy_used=CompressionStrategy.KOMPRESS,
+ )
+
+ router.compress = MethodType(compress, router)
+ handler = _handler_with_router(router)
+ output = " ".join(f"sym{i}" for i in range(180))
+ payload = {
+ "model": "gpt-5",
+ "input": [
+ {
+ "type": "custom_tool_call",
+ "call_id": "call_1",
+ "name": "serena.find_symbol",
+ "input": "find_symbol main",
+ },
+ {
+ "type": "custom_tool_call_output",
+ "call_id": "call_1",
+ "output": output,
+ },
+ ],
+ }
+
+ new_payload, modified, saved, transforms, _units, _chain, _attempted = (
+ handler._compress_openai_responses_live_text_units_with_router(
+ payload,
+ model="gpt-5",
+ request_id="req_test",
+ )
+ )
+
+ assert modified is False
+ assert saved == 0
+ assert transforms == []
+ assert new_payload == payload
+
+
+def test_openai_responses_adapter_excludes_custom_tool_beside_compressed_function_call():
+ """An excluded custom tool stays raw while a non-excluded function call compresses."""
+ router = ContentRouter()
+ router.config.exclude_tools = {"exec"}
+
+ def compress(self, content: str, **_kwargs):
+ return RouterCompressionResult(
+ compressed="compressed tool output",
+ original=content,
+ strategy_used=CompressionStrategy.KOMPRESS,
+ )
+
+ router.compress = MethodType(compress, router)
+ handler = _handler_with_router(router)
+ excluded_output = " ".join(f"line{i}" for i in range(180))
+ other_output = " ".join(f"word{i}" for i in range(180))
+ payload = {
+ "model": "gpt-5",
+ "input": [
+ {
+ "type": "custom_tool_call",
+ "call_id": "call_exec",
+ "name": "exec",
+ "input": "cat build.log",
+ },
+ {
+ "type": "custom_tool_call_output",
+ "call_id": "call_exec",
+ "output": excluded_output,
+ },
+ {
+ "type": "function_call",
+ "call_id": "call_other",
+ "name": "some.other_tool",
+ "arguments": "{}",
+ },
+ {
+ "type": "function_call_output",
+ "call_id": "call_other",
+ "output": other_output,
+ },
+ ],
+ }
+
+ new_payload, modified, _saved, _transforms, _units, _chain, _attempted = (
+ handler._compress_openai_responses_live_text_units_with_router(
+ payload,
+ model="gpt-5",
+ request_id="req_test",
+ )
+ )
+
+ assert modified is True
+ assert new_payload["input"][1]["output"] == excluded_output
+ assert new_payload["input"][3]["output"] == "compressed tool output"