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.

chore(proxy): announce pre-upstream concurrency; clean dead RequestLog fields and debug helpers

Adryan Eka Vandra55f59fad775c
diff --git a/headroom/proxy/debug_introspection.py b/headroom/proxy/debug_introspection.py
index 2ad60a883..80e284ed9 100644
--- a/headroom/proxy/debug_introspection.py
+++ b/headroom/proxy/debug_introspection.py
@@ -36,13 +36,10 @@ import time
from typing import TYPE_CHECKING, Any
if TYPE_CHECKING:
- from headroom.proxy.warmup import WarmupRegistry
from headroom.proxy.ws_session_registry import WebSocketSessionRegistry
__all__ = [
"collect_tasks",
- "collect_ws_sessions",
- "collect_warmup",
]
@@ -162,19 +159,3 @@ def collect_tasks(
entries.sort(key=_sort_key)
return entries
-
-
-def collect_ws_sessions(
- registry: WebSocketSessionRegistry | None,
-) -> list[dict[str, Any]]:
- """Return the registry snapshot, or an empty list if no registry."""
- if registry is None:
- return []
- return registry.snapshot()
-
-
-def collect_warmup(registry: WarmupRegistry | None) -> dict[str, Any]:
- """Return the warmup registry dict, or an empty dict if none."""
- if registry is None:
- return {}
- return registry.to_dict()
diff --git a/headroom/proxy/models.py b/headroom/proxy/models.py
index f9ba15ba8..8a8c9e114 100644
--- a/headroom/proxy/models.py
+++ b/headroom/proxy/models.py
@@ -48,22 +48,13 @@ class RequestLog:
response_content: str | None = None
error: str | None = None
- # Per-stage timings (Unit 2 — Codex WS + Anthropic HTTP paths)
- # Populated from ``StageTimer.summary()``. Keys are stage names
- # (e.g. ``accept``, ``upstream_connect``, ``memory_context``);
- # values are durations in milliseconds. Absent when the handler did
- # not thread a timer through (backward-compatible default).
- stage_timings: dict[str, float] | None = None
-
- # Session id — a UUID generated at WS accept / HTTP request start,
- # paired with ``request_id`` so multi-turn sessions can be
- # correlated. Optional for backward compatibility.
- session_id: str | None = None
-
- # Path key under which stage timings were recorded (e.g.
- # ``openai_responses_ws`` or ``anthropic_messages``). Used by the
- # Prometheus histogram series.
- stage_timings_path: str | None = None
+ # NOTE (Unit 2 follow-up): stage timings and session_id were briefly
+ # added here but are now emitted exclusively through
+ # ``emit_stage_timings_log`` (structured log line) and Prometheus.
+ # They were never populated on ``RequestLog`` instances, so the
+ # fields were removed to avoid confusing readers who expect
+ # them to be set. If a JSONL consumer needs them, have the consumer
+ # merge ``stage_timings`` log lines by ``request_id``.
@dataclass
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 74edfb640..61f6e8765 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -655,6 +655,23 @@ class HeadroomProxy(
f"http2={'ENABLED' if self.config.http2 else 'DISABLED'}"
)
+ # Unit 4 pre-upstream concurrency announcement. Report the resolved
+ # value (auto-detected vs. explicit) so operators can correlate
+ # ``pre_upstream_wait_ms`` log lines with the configured cap.
+ if self.anthropic_pre_upstream_sem is None:
+ logger.info(
+ "Anthropic pre-upstream concurrency: unbounded "
+ "(explicitly disabled)"
+ )
+ else:
+ _explicit = self.config.anthropic_pre_upstream_concurrency
+ _origin = "auto-detected" if _explicit is None else "explicit"
+ logger.info(
+ "Anthropic pre-upstream concurrency: %d (%s)",
+ self.anthropic_pre_upstream_concurrency,
+ _origin,
+ )
+
# Smart routing status
if self.config.smart_routing:
logger.info("Smart Routing: ENABLED (intelligent content detection)")
@@ -1315,12 +1332,6 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
from headroom.proxy.debug_introspection import (
collect_tasks as _collect_tasks,
)
- from headroom.proxy.debug_introspection import (
- collect_warmup as _collect_warmup,
- )
- from headroom.proxy.debug_introspection import (
- collect_ws_sessions as _collect_ws_sessions,
- )
from headroom.proxy.loopback_guard import require_loopback as _require_loopback
@app.get("/debug/tasks", dependencies=[Depends(_require_loopback)])
@@ -1331,12 +1342,14 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
@app.get("/debug/ws-sessions", dependencies=[Depends(_require_loopback)])
async def debug_ws_sessions():
ws_registry = getattr(proxy, "ws_sessions", None)
- return JSONResponse(status_code=200, content=_collect_ws_sessions(ws_registry))
+ snapshot = ws_registry.snapshot() if ws_registry is not None else []
+ return JSONResponse(status_code=200, content=snapshot)
@app.get("/debug/warmup", dependencies=[Depends(_require_loopback)])
async def debug_warmup():
warmup_registry = getattr(proxy, "warmup", None)
- return JSONResponse(status_code=200, content=_collect_warmup(warmup_registry))
+ payload = warmup_registry.to_dict() if warmup_registry is not None else {}
+ return JSONResponse(status_code=200, content=payload)
@app.get("/dashboard", response_class=HTMLResponse)
async def dashboard():
diff --git a/tests/test_proxy_debug_endpoints.py b/tests/test_proxy_debug_endpoints.py
index 7bd24e662..f7b1e1ec2 100644
--- a/tests/test_proxy_debug_endpoints.py
+++ b/tests/test_proxy_debug_endpoints.py
@@ -14,8 +14,6 @@ from fastapi.testclient import TestClient
from headroom.proxy.debug_introspection import (
collect_tasks,
- collect_warmup,
- collect_ws_sessions,
)
from headroom.proxy.loopback_guard import (
LOOPBACK_HOSTS,
@@ -147,16 +145,18 @@ def test_require_loopback_accepts_loopback_client():
# ---------------------------------------------------------------------------
-def test_collect_warmup_handles_none_registry():
- assert collect_warmup(None) == {}
+def test_warmup_registry_to_dict_returns_registry_shape():
+ """Serializer equivalent of the old collect_warmup helper.
-
-def test_collect_warmup_returns_registry_shape():
+ The helper was inlined at the /debug/warmup route handler in server.py
+ (``registry.to_dict() if registry else {}``); this test preserves
+ coverage of the registry's own serializer contract.
+ """
registry = WarmupRegistry()
registry.kompress.mark_loaded(handle=object(), source_status="enabled")
registry.memory_backend.mark_error("boom")
- payload = collect_warmup(registry)
+ payload = registry.to_dict()
assert payload["kompress"]["status"] == "loaded"
assert payload["memory_backend"]["status"] == "error"
@@ -165,11 +165,8 @@ def test_collect_warmup_returns_registry_shape():
assert "handle" not in payload["kompress"]
-def test_collect_ws_sessions_handles_none_registry():
- assert collect_ws_sessions(None) == []
-
-
-def test_collect_ws_sessions_returns_snapshot():
+def test_ws_session_registry_snapshot_returns_registered_entries():
+ """Serializer equivalent of the old collect_ws_sessions helper."""
reg = WebSocketSessionRegistry()
handle = WSSessionHandle(
session_id="sess-debug-1",
@@ -179,7 +176,7 @@ def test_collect_ws_sessions_returns_snapshot():
)
reg.register(handle)
- payload = collect_ws_sessions(reg)
+ payload = reg.snapshot()
assert len(payload) == 1
assert payload[0]["session_id"] == "sess-debug-1"
assert payload[0]["request_id"] == "req-debug-1"