Skip to content

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

fix(providers): drop loguru, fix FallbackBoundModel failover log placeholders

xf gongc25946e119ef
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc0b4dc..b368e9e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -86,8 +86,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
removed. Existing middlewares that return `None` after one injection are
unaffected. This enables evaluation loops like `GoalMiddleware`.
+### Changed
+
+- **Internal logging now uses stdlib `logging` exclusively.** Previously
+ `FallbackBoundModel` and the provider listener-exception path tried to
+ import `loguru` first and fell back to stdlib. The loguru path was
+ silently incorrect — loguru does not perform `%s` argument substitution,
+ so failover warnings rendered literal `%s` placeholders instead of the
+ resolved labels. cubepi has never declared loguru as a dependency; hosts
+ that prefer loguru should intercept stdlib logging records into it. No
+ public API change.
+
### Fixed
+- **`FallbackBoundModel` failover log line now substitutes its placeholders.**
+ Before the loguru removal above, the WARNING emitted on every failover
+ read `failed=%s → next=%s reason=%s attempt=%s/%s` literally because
+ the loguru-backed logger ignored the positional args. Now renders as
+ `failed=anthropic/claude-opus-4-5 → next=openai/gpt-5 reason=… attempt=1/2`.
+
- **`Recorder.attach()` and `Meter.attach()` now subscribe to every provider in
a `FallbackBoundModel` chain** (closes #167). Previously they only listened
to `chain[0].provider`, so post-failover calls executed against `chain[1..]`
diff --git a/cubepi/providers/base.py b/cubepi/providers/base.py
index cbaad54..5963098 100644
--- a/cubepi/providers/base.py
+++ b/cubepi/providers/base.py
@@ -3,6 +3,7 @@ from __future__ import annotations
import asyncio
import copy
import inspect
+import logging
from dataclasses import dataclass, field
from typing import (
Any,
@@ -555,18 +556,9 @@ async def _safe_run_coroutine(cb: Callable, coro: Any) -> None:
def _log_listener_exception(cb: Callable, exc: BaseException) -> None:
- try:
- from loguru import logger
-
- logger.opt(exception=exc).warning(
- "cubepi provider listener {} raised; swallowed", cb
- )
- except ImportError:
- import logging
-
- logging.getLogger("cubepi.providers").warning(
- "cubepi provider listener %r raised; swallowed", cb, exc_info=exc
- )
+ logging.getLogger("cubepi.providers").warning(
+ "cubepi provider listener %r raised; swallowed", cb, exc_info=exc
+ )
def _detach(listeners: list, cb: Callable) -> None:
@@ -967,8 +959,6 @@ def chain_providers(model: object) -> list["BaseProvider"]:
fallback chain so post-failover provider events land in the trace /
metric stream.
"""
- import logging
-
if model is None:
return []
chain = getattr(model, "chain", None)
diff --git a/cubepi/providers/fallback.py b/cubepi/providers/fallback.py
index b3579b3..76a6b71 100644
--- a/cubepi/providers/fallback.py
+++ b/cubepi/providers/fallback.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import asyncio
import inspect
+import logging
import time
from dataclasses import dataclass
from typing import Any, Awaitable, Callable
@@ -29,12 +30,7 @@ from cubepi.providers.base import (
chain_providers, # re-exported for back-compat; canonical home is base.py
)
-try:
- from loguru import logger as _log
-except ImportError: # pragma: no cover
- import logging as _logging
-
- _log = _logging.getLogger("cubepi.providers.fallback")
+_log = logging.getLogger("cubepi.providers.fallback")
DEFAULT_TRIGGER_ERRORS: frozenset[type[ProviderError]] = frozenset(