Skip to content

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

fix(fallback): reject empty chain in FallbackBoundModel.__post_init__

xf gongcfa11cb4303f
diff --git a/cubepi/providers/fallback.py b/cubepi/providers/fallback.py
index bdefa10..a269aa9 100644
--- a/cubepi/providers/fallback.py
+++ b/cubepi/providers/fallback.py
@@ -69,6 +69,15 @@ class FallbackBoundModel:
| None
) = None
+ def __post_init__(self) -> None:
+ # An empty chain is a configuration mistake: provider/spec proxy,
+ # stream(), and generate() would all IndexError or silently exhaust
+ # without ever attempting a call. Fail fast at construction time.
+ if not self.chain:
+ raise ValueError(
+ "FallbackBoundModel.chain must contain at least one BoundModel"
+ )
+
@property
def provider(self) -> Provider:
return self.chain[0].provider
diff --git a/tests/providers/test_fallback.py b/tests/providers/test_fallback.py
index b9c97de..b8b18d2 100644
--- a/tests/providers/test_fallback.py
+++ b/tests/providers/test_fallback.py
@@ -95,6 +95,12 @@ def test_default_trigger_errors_composition() -> None:
assert ProviderBadRequest not in DEFAULT_TRIGGER_ERRORS
+def test_empty_chain_raises_value_error() -> None:
+ """FallbackBoundModel rejects an empty chain at construction time."""
+ with pytest.raises(ValueError, match="must contain at least one"):
+ FallbackBoundModel(chain=())
+
+
# ---------------------------------------------------------------------------
# stream() tests
# ---------------------------------------------------------------------------