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.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(ccr): log the exception type when a CCR continuation call fails (#3137)
Abhay Singh9f75f91dc566
diff --git a/headroom/ccr/response_handler.py b/headroom/ccr/response_handler.pyindex a4acfeb3d..06081baf7 100644--- a/headroom/ccr/response_handler.py+++ b/headroom/ccr/response_handler.py@@ -531,7 +531,12 @@ class CCRResponseHandler:try:current_response = await api_call_fn(current_messages, tools)except Exception as e:- logger.error(f"CCR: Continuation API call failed: {e}")+ # Log the type and repr, not just str(e): many exceptions+ # (httpx.TimeoutException(''), a bare Exception(), a connect+ # error with no message) have an empty str(), which produced a+ # log line with nothing after the colon and lost the cause+ # entirely (#3129).+ logger.error("CCR: Continuation API call failed: %s: %r", type(e).__name__, e)# Return the response we had (with unhandled CCR calls)# The client will see the tool_use and might handle it differentlybreakdiff --git a/tests/test_ccr_response_handler.py b/tests/test_ccr_response_handler.pyindex d7278b9ab..9621efacc 100644--- a/tests/test_ccr_response_handler.py+++ b/tests/test_ccr_response_handler.py@@ -418,6 +418,53 @@ class TestCCRResponseHandling:# Should return final responseassert result == final_response+ @pytest.mark.asyncio+ async def test_continuation_failure_logs_cause_for_empty_str_exception(self, caplog):+ """A continuation exception whose str() is empty (e.g.+ httpx.TimeoutException(''), a bare Exception()) must still log its+ cause. Interpolating str(e) alone produced a log line with nothing+ after the colon, losing the type entirely (#3129)."""+ store = get_compression_store()+ hash_key = store.store(+ original=json.dumps([{"id": i} for i in range(50)]),+ compressed="[]",+ original_item_count=50,+ )++ handler = CCRResponseHandler()+ initial_response = {+ "content": [+ {"type": "text", "text": "Let me get that data."},+ {+ "type": "tool_use",+ "id": "tool_123",+ "name": CCR_TOOL_NAME,+ "input": {"hash": hash_key},+ },+ ]+ }++ async def failing_api_call(messages, tools):+ raise Exception("") # empty str(e), non-empty repr()++ with caplog.at_level("ERROR", logger="headroom.ccr.response_handler"):+ result = await handler.handle_response(+ initial_response,+ [{"role": "user", "content": "Get me the data"}],+ None,+ failing_api_call,+ "anthropic",+ )++ # Degrades to the current response rather than raising.+ assert result == initial_response+ # The cause survives: the type name appears even though str(e) is "".+ failure_logs = [r.getMessage() for r in caplog.records if "Continuation" in r.getMessage()]+ assert failure_logs+ assert "Exception" in failure_logs[0]+ # Regression guard: never a bare "...failed: " with nothing after it.+ assert not failure_logs[0].rstrip().endswith("failed:")+@pytest.mark.asyncioasync def test_handle_response_max_rounds(self):"""Respects max retrieval rounds limit."""