Skip to content

Commit d2d6bf8

Browse files
author
balogh.adam@icloud.com
committed
test handling
1 parent 2cf22c2 commit d2d6bf8

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/opengradient/client/llm.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses import dataclass
66
from typing import AsyncGenerator, Awaitable, Callable, Dict, List, Optional, TypeVar, Union
77
import httpx
8+
import asyncio
89

910
from eth_account import Account
1011
from eth_account.account import LocalAccount
@@ -170,6 +171,8 @@ async def _call_with_tee_retry(
170171
return await call()
171172
except httpx.HTTPStatusError:
172173
raise
174+
except asyncio.CancelledError:
175+
raise
173176
except Exception as exc:
174177
logger.warning(
175178
"Connection failure during %s; refreshing TEE and retrying once: %s",
@@ -424,6 +427,8 @@ async def _chat_stream(self, params: _ChatParams, messages: List[Dict]) -> Async
424427
return
425428
except httpx.HTTPStatusError:
426429
raise
430+
except asyncio.CancelledError:
431+
raise
427432
except Exception as exc:
428433
if chunks_yielded:
429434
raise

src/opengradient/client/tee_connection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _resolve_tee(self):
133133
raise RuntimeError(f"Failed to fetch LLM TEE endpoint from registry: {e}") from e
134134

135135
if tee is None:
136-
raise ValueError("No active LLM proxy TEE found in the registry. Pass llm_server_url explicitly to override.")
136+
raise ValueError("No active LLM proxy TEE found in the registry.")
137137

138138
logger.info("Using TEE endpoint from registry: %s (teeId=%s)", tee.endpoint, tee.tee_id)
139139
return tee
@@ -155,10 +155,8 @@ def _connect(self) -> ActiveTEE:
155155
async def reconnect(self) -> None:
156156
"""Connect to a new TEE from the registry and rebuild the HTTP client."""
157157
async with self._refresh_lock:
158-
old_client = self._active.http_client
159-
self._active = self._connect()
160158
try:
161-
await old_client.aclose()
159+
self._active = self._connect()
162160
except Exception:
163161
logger.debug("Failed to close previous HTTP client during TEE refresh.", exc_info=True)
164162

@@ -188,6 +186,9 @@ async def _tee_refresh_loop(self) -> None:
188186
continue
189187
logger.info("Current TEE %s no longer active; switching to a new one.", self._active.tee_id)
190188
await self.reconnect()
189+
except asyncio.CancelledError:
190+
logger.debug("Background TEE health check cancelled; exiting loop.")
191+
raise
191192
except Exception:
192193
logger.warning("Background TEE health check failed; will retry next cycle.", exc_info=True)
193194

0 commit comments

Comments
 (0)