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): keep health probes and the Codex attestation out of the proxy log (#4611)

gglucass78736a16bc46
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 2e97c8404..9346e2333 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -487,6 +487,9 @@ logging.basicConfig(
)
logger = logging.getLogger("headroom.proxy")
+# Liveness/readiness probe routes: auth-exempt, and logged at DEBUG.
+_HEALTH_PROBE_PATHS = frozenset({"/health", "/livez", "/readyz"})
+
def _output_reduction_payload(shaper_active: bool, est: Any = None) -> dict[str, Any]:
"""/stats payload for the output-shaping layer.
@@ -4042,7 +4045,13 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
safe_headers = redact_for_wire_debug(headers)
except Exception:
safe_headers = {"redaction_error": True}
- logger.info(
+ # A desktop or orchestrator polls these every few seconds; at INFO they
+ # filled half of an idle proxy log and cut a busy one's history to hours.
+ line_level = (
+ logging.DEBUG if method == "GET" and path in _HEALTH_PROBE_PATHS else logging.INFO
+ )
+ logger.log(
+ line_level,
"event=proxy_inbound_request id=%s method=%s path=%s query=%s client=%s "
"content_length=%s headers=%s",
inbound_id,
@@ -4096,7 +4105,8 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
proxy.metrics.record_inbound_response(status_code=response.status_code)
except Exception:
logger.debug("record_inbound_response failed", exc_info=True)
- logger.info(
+ logger.log(
+ line_level,
"event=proxy_inbound_response id=%s method=%s path=%s status=%s "
"duration_ms=%.2f response_content_length=%s",
inbound_id,
@@ -4140,7 +4150,7 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
# Anything else on these paths falls through to the catch-all passthrough
# relay (FastAPI's @app.get does not register HEAD), so exempting it would
# let an unauthenticated caller relay arbitrary requests upstream.
- _AUTH_EXEMPT_PATHS = frozenset({"/health", "/livez", "/readyz"})
+ _AUTH_EXEMPT_PATHS = _HEALTH_PROBE_PATHS
# A non-loopback bind with no token is the exact shape (``--host 0.0.0.0``
# from any launcher) that exposes the unauthenticated /v1/* relay to the
diff --git a/headroom/proxy/wire_debug_redaction_policy.py b/headroom/proxy/wire_debug_redaction_policy.py
index 28fe89533..8387e0281 100644
--- a/headroom/proxy/wire_debug_redaction_policy.py
+++ b/headroom/proxy/wire_debug_redaction_policy.py
@@ -16,6 +16,8 @@ WIRE_DEBUG_SECRET_KEYS = (
"x-api-key",
"openai-api-key",
"anthropic-api-key",
+ # Codex's signed device attestation, sent with every request.
+ "x-oai-attestation",
"access_token",
"refresh_token",
"id_token",
diff --git a/tests/test_proxy/test_inbound_response_size.py b/tests/test_proxy/test_inbound_response_size.py
index 9e58e9edd..44c3b2f44 100644
--- a/tests/test_proxy/test_inbound_response_size.py
+++ b/tests/test_proxy/test_inbound_response_size.py
@@ -114,3 +114,22 @@ def test_streaming_response_no_content_length(capture_logs):
m = re.search(r"response_content_length=(\S*)", line)
assert m, f"expected response_content_length field in: {line}"
assert m.group(1) in ("", '""'), f"expected empty for streaming, got: {m.group(1)}"
+
+
+def test_health_probes_log_at_debug_and_traffic_at_info(capture_logs):
+ """A desktop polls /readyz every few seconds: at INFO it filled half the log."""
+ app = create_app(_make_config())
+ with TestClient(app) as client:
+ client.app.state.proxy.handle_anthropic_messages = _json_handler
+ client.get("/readyz")
+ client.get("/livez")
+ client.post("/v1/messages", json={"model": "glm-5.2", "messages": []})
+
+ levels = {}
+ for r in capture_logs:
+ m = re.search(r"event=proxy_inbound_(?:request|response) .*?path=(\S+)", r.getMessage())
+ if m:
+ levels.setdefault(m.group(1), set()).add(r.levelno)
+ assert levels["/readyz"] == {logging.DEBUG}
+ assert levels["/livez"] == {logging.DEBUG}
+ assert levels["/v1/messages"] == {logging.INFO}
diff --git a/tests/test_wire_debug_redaction_policy.py b/tests/test_wire_debug_redaction_policy.py
index 4d6e4ed9c..0a103e36c 100644
--- a/tests/test_wire_debug_redaction_policy.py
+++ b/tests/test_wire_debug_redaction_policy.py
@@ -81,3 +81,13 @@ def test_wire_debug_keeps_token_usage_counters_visible() -> None:
"token_count",
):
assert not should_redact_key(key), key
+
+
+def test_wire_debug_redacts_codex_attestation_header() -> None:
+ # The inbound request log line runs every header through this policy, so
+ # without it each Codex request wrote the ~4 KB signed attestation to proxy.log.
+ redacted = redact_for_wire_debug(
+ {"x-oai-attestation": '{"v":1,"s":1,"t":"signed"}', "x-codex-window-id": "w:1"}
+ )
+
+ assert redacted == {"x-oai-attestation": WIRE_DEBUG_REDACTED, "x-codex-window-id": "w:1"}