Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(providers): use BaseException in _forward, fix callback type annotations

xf gong6b7bab46ca4d
diff --git a/cubepi/providers/fallback.py b/cubepi/providers/fallback.py
index f3ad8da..65289ad 100644
--- a/cubepi/providers/fallback.py
+++ b/cubepi/providers/fallback.py
@@ -149,7 +149,7 @@ class FallbackBoundModel:
async for ev in src:
out.push(ev)
out.set_result(await src_stream.result())
- except Exception as exc: # noqa: BLE001
+ except BaseException as exc: # noqa: BLE001
err_msg = AssistantMessage(
content=[],
stop_reason="error",
@@ -159,6 +159,8 @@ class FallbackBoundModel:
)
out.push(StreamEvent(type="error", error_message=str(exc)))
out.set_result(err_msg)
+ if not isinstance(exc, Exception):
+ raise
outer.attach_task(asyncio.create_task(_forward()))
return outer
diff --git a/tests/providers/test_fallback.py b/tests/providers/test_fallback.py
index a5d4da6..30322dc 100644
--- a/tests/providers/test_fallback.py
+++ b/tests/providers/test_fallback.py
@@ -123,9 +123,9 @@ async def test_stream_primary_raises_trigger_error_fallback_succeeds() -> None:
primary = _raising(rate_err)
fallback = _faux("fallback", "ok")
- failover_calls: list[tuple[BoundModel, BoundModel, Any]] = []
+ failover_calls: list[tuple[BoundModel, BoundModel | None, Any]] = []
- async def _cb(failed: BoundModel, nxt: BoundModel, err: Any) -> None:
+ async def _cb(failed: BoundModel, nxt: BoundModel | None, err: Any) -> None:
failover_calls.append((failed, nxt, err))
fbm = FallbackBoundModel(chain=(primary, fallback), on_failover=_cb)
@@ -190,7 +190,7 @@ async def test_stream_on_failover_callback_raises_is_swallowed() -> None:
primary = _raising(rate_err)
fallback = _faux("fallback", "ok")
- async def _bad_cb(failed: BoundModel, nxt: BoundModel, err: Any) -> None:
+ async def _bad_cb(failed: BoundModel, nxt: BoundModel | None, err: Any) -> None:
raise RuntimeError("callback is broken")
fbm = FallbackBoundModel(chain=(primary, fallback), on_failover=_bad_cb)