CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.
Python agent-frameworkagent-harnessagent-runtimeagentic-aiai-agentsai-frameworkanthropicharnessharness-engineeringharness-frameworklanggraphlanggraph-alternativellmmcpopenaipi-agentpi-agent-corepythonpython-agent
fix(tracing): tolerate legacy (Provider, Model) tuples in extra_llm_calls
xf gong1c3632a1ae3f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 19d25d0..314b68c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -31,7 +31,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0of `Iterable[tuple[Provider, Model]]`. Third-party middleware overridingthis hook must update the return shape (see Migration). The recorderconsumer in `cubepi.tracing` was adapted in lock-step; built-in- `CompactionMiddleware` already updated.+ `CompactionMiddleware` already updated. The tracing recorder defensively+ skips legacy tuple entries with a `cubepi.tracing` logger warning so an+ un-migrated middleware degrades gracefully (its extra LLM call simply+ won't appear in the trace) instead of breaking attach for the whole+ agent.- **`cubepi.middleware.compaction.summarizer.summarize()` takes`model: BoundModel`** instead of separate `provider: Provider, model: Model`kwargs. Direct callers (rare — this is internal to `CompactionMiddleware`)diff --git a/cubepi/tracing/recorder.py b/cubepi/tracing/recorder.pyindex fd92904..975307a 100644--- a/cubepi/tracing/recorder.py+++ b/cubepi/tracing/recorder.py@@ -21,6 +21,7 @@ from __future__ import annotationsimport contextvarsimport hashlibimport json+import loggingimport timeimport tracebackimport uuid@@ -42,6 +43,7 @@ from cubepi.agent.types import (ToolExecutionStartEvent,)from cubepi.providers.base import (+ BoundModel,StreamEvent,ToolCall,ToolResultMessage,@@ -290,6 +292,25 @@ class Recorder:except Exception:extra = []for bound in extra:+ # Defensive: a third-party middleware that hasn't+ # migrated from the pre-BoundModel ``(provider, model)``+ # tuple contract would raise AttributeError on+ # ``bound.spec`` here, killing tracing attach for the+ # whole agent. Mirror the existing tolerance shown by+ # the ``except Exception`` above and the+ # ``_DuckMiddleware`` skip path: warn once per entry,+ # drop the bad item, keep the rest of attach working.+ if not isinstance(bound, BoundModel):+ logging.getLogger("cubepi.tracing").warning(+ "cubepi tracing: middleware %s returned a "+ "non-BoundModel entry (%s) from "+ "extra_llm_calls(); skipping. The "+ "(Provider, Model) tuple form was removed in "+ "this release — return a BoundModel instead.",+ type(mw).__name__,+ type(bound).__name__,+ )+ continuespec = bound.speckey = (spec.provider_id, spec.id)if key != agent_key:diff --git a/tests/tracing/test_recorder.py b/tests/tracing/test_recorder.pyindex 0382a33..0a3ca0a 100644--- a/tests/tracing/test_recorder.py+++ b/tests/tracing/test_recorder.py@@ -725,6 +725,44 @@ class TestMiddlewareProviders:await tracer.shutdown()assert any(s.name.startswith("chat ") for s in exporter.spans)+ async def test_middleware_extra_llm_calls_legacy_tuple_is_skipped(self, caplog):+ # A third-party middleware that hasn't migrated from the+ # pre-BoundModel ``(provider, model)`` tuple contract must not kill+ # tracing attach — the recorder skips the bad entry, logs a+ # warning, and continues. Same defensive philosophy as the raising+ # and duck-provider cases below.+ from cubepi.middleware.base import Middleware++ legacy_provider = FauxProvider()+ legacy_model = Model(id="legacy-m", provider_id="legacy")++ class _LegacyTupleMiddleware(Middleware):+ def extra_llm_calls(self):+ return [(legacy_provider, legacy_model)]++ provider = FauxProvider()+ agent = Agent(+ model=BoundModel(provider=provider, spec=MODEL),+ system_prompt="test",+ middleware=[_LegacyTupleMiddleware()],+ )+ exporter = InMemoryExporter()+ tracer = Tracer(+ service_name="test-svc",+ agent_name="test-agent",+ exporters=[exporter],+ )+ with caplog.at_level("WARNING", logger="cubepi.tracing"):+ tracer.attach(agent)+ provider.append_responses([faux_assistant_message("ok")])+ await agent.prompt("x")+ await agent.wait_for_idle()+ await tracer.shutdown()+ assert any(s.name.startswith("chat ") for s in exporter.spans)+ assert any("non-BoundModel" in record.message for record in caplog.records), (+ "expected a warning about the legacy tuple entry"+ )+async def test_middleware_extra_llm_calls_raising_is_swallowed(self):# If a middleware's ``extra_llm_calls()`` raises during attach the# recorder must keep going — the agent's own provider is the