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: satisfy dashboard stats cache typing

Kayzobb5b676dd704
diff --git a/headroom/proxy/helpers.py b/headroom/proxy/helpers.py
index 9e0fed399..c75d8436f 100644
--- a/headroom/proxy/helpers.py
+++ b/headroom/proxy/helpers.py
@@ -14,7 +14,7 @@ import random
import threading
import time
from pathlib import Path
-from typing import TYPE_CHECKING, Any
+from typing import TYPE_CHECKING, Any, cast
from headroom import paths as _paths
@@ -133,7 +133,7 @@ def _get_rtk_stats() -> dict[str, Any] | None:
now = time.monotonic()
with _rtk_stats_cache_lock:
if _rtk_stats_cache["has_value"] and now < float(_rtk_stats_cache["expires_at"]):
- return _rtk_stats_cache["value"]
+ return cast(dict[str, Any] | None, _rtk_stats_cache["value"])
payload: dict[str, Any] | None
rtk_bin = shutil.which("rtk")
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 1f56173ff..8e3eb24f0 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -32,7 +32,7 @@ import sys
import time
from datetime import datetime, timezone
from pathlib import Path
-from typing import TYPE_CHECKING, Any, Literal
+from typing import TYPE_CHECKING, Any, Literal, cast
if TYPE_CHECKING:
from ..backends.base import Backend
@@ -1660,13 +1660,13 @@ def create_app(config: ProxyConfig | None = None) -> FastAPI:
async def _get_cached_stats_payload() -> dict[str, Any]:
"""Return a short-TTL cached `/stats` snapshot for dashboard polling."""
now = time.monotonic()
- cached_payload = _stats_snapshot.get("value")
+ cached_payload = cast(dict[str, Any] | None, _stats_snapshot.get("value"))
if cached_payload is not None and now < float(_stats_snapshot["expires_at"]):
return cached_payload
async with _stats_snapshot_lock:
now = time.monotonic()
- cached_payload = _stats_snapshot.get("value")
+ cached_payload = cast(dict[str, Any] | None, _stats_snapshot.get("value"))
if cached_payload is not None and now < float(_stats_snapshot["expires_at"]):
return cached_payload