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): classify cancelled relay tasks correctly in termination cause

Adryan Eka Vandra6ae0fcd8b52f
diff --git a/headroom/proxy/handlers/openai.py b/headroom/proxy/handlers/openai.py
index b34afa977..54aaa95f9 100644
--- a/headroom/proxy/handlers/openai.py
+++ b/headroom/proxy/handlers/openai.py
@@ -1949,8 +1949,19 @@ class OpenAIHandlerMixin:
# (e.g. server shutdown).
for t in done:
exc = None
- with contextlib.suppress(Exception):
- exc = t.exception()
+ # Cancelled tasks raise CancelledError from
+ # .exception(); surface it explicitly so the
+ # downstream ``isinstance(exc, CancelledError)``
+ # branches actually run. For any other
+ # unexpected state (``InvalidStateError`` if
+ # the task somehow isn't done — shouldn't
+ # happen post-gather but defensive), we
+ # suppress and leave ``exc`` as ``None``.
+ if t.cancelled():
+ exc = asyncio.CancelledError()
+ else:
+ with contextlib.suppress(asyncio.InvalidStateError):
+ exc = t.exception()
task_name = t.get_name() or ""
if t is client_task:
if client_relay_error is not None: