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: tolerate stubbed memory handlers on shutdown

JerrettDavis2b549c5c5972
diff --git a/headroom/proxy/server.py b/headroom/proxy/server.py
index 3f3813633..d8837fbaa 100644
--- a/headroom/proxy/server.py
+++ b/headroom/proxy/server.py
@@ -643,7 +643,7 @@ class HeadroomProxy(
await self.http_client.aclose()
self.http_client = None
- if self.memory_handler:
+ if self.memory_handler and hasattr(self.memory_handler, "close"):
await self.memory_handler.close()
# Print final stats
diff --git a/tests/test_proxy_healthchecks.py b/tests/test_proxy_healthchecks.py
index f9c75b1de..d517f24f2 100644
--- a/tests/test_proxy_healthchecks.py
+++ b/tests/test_proxy_healthchecks.py
@@ -1,3 +1,5 @@
+from types import SimpleNamespace
+
import pytest
pytest.importorskip("fastapi")
@@ -127,3 +129,27 @@ def test_readyz_initializes_qdrant_memory_backend(monkeypatch):
assert data["checks"]["memory"]["status"] == "healthy"
assert data["checks"]["memory"]["backend"] == "qdrant-neo4j"
assert data["checks"]["memory"]["initialized"] is True
+
+
+def test_shutdown_tolerates_stubbed_memory_handler():
+ config = ProxyConfig(
+ optimize=False,
+ cache_enabled=False,
+ rate_limit_enabled=False,
+ cost_tracking_enabled=False,
+ )
+ app = create_app(config)
+
+ with TestClient(app) as client:
+ client.app.state.proxy.memory_handler = SimpleNamespace(
+ health_status=lambda: {
+ "enabled": False,
+ "backend": None,
+ "initialized": False,
+ "native_tool": False,
+ "bridge_enabled": False,
+ }
+ )
+ response = client.get("/health")
+
+ assert response.status_code == 200