Skip to content

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

fix(tracing): don't reuse _close_open_spans for oneshot — only close chat_span

xf gongbbbe2cd7a5be
diff --git a/cubepi/tracing/tracer.py b/cubepi/tracing/tracer.py
index 5ddc00d..9a11e17 100644
--- a/cubepi/tracing/tracer.py
+++ b/cubepi/tracing/tracer.py
@@ -514,9 +514,22 @@ class Tracer:
d()
except Exception:
pass
- # Close any chat span left open by a cancelled/timed-out stream
- # (mirrors Recorder._close_open_spans for the agent detach path).
- recorder._close_open_spans(run)
+ # Close any chat span left open by a cancelled/timed-out stream.
+ # We don't reuse Recorder._close_open_spans because that helper
+ # also walks turn_span / agent_span — both of which point at
+ # root_span here, so it would mark a successful one-shot's root
+ # as aborted before we end it normally below. Tool spans don't
+ # exist for one-shot (no tool execution path).
+ if run.chat_span is not None:
+ try:
+ from cubepi.tracing.schema import CUBEPI_ABORTED, ERROR_TYPE
+
+ run.chat_span.set_attribute(CUBEPI_ABORTED, True)
+ run.chat_span.set_attribute(ERROR_TYPE, "cubepi.aborted")
+ run.chat_span.end()
+ except Exception:
+ pass
+ run.chat_span = None
recorder._run = None
root_span.end()
# Best-effort flush — tracing must never break the caller's work.
diff --git a/tests/tracing/test_oneshot.py b/tests/tracing/test_oneshot.py
index 8ae8a0f..c7d98e9 100644
--- a/tests/tracing/test_oneshot.py
+++ b/tests/tracing/test_oneshot.py
@@ -94,6 +94,9 @@ async def test_oneshot_produces_root_and_chat_spans() -> None:
assert attrs.get("cubepi.metadata.conversation_id") == "conv-123"
assert attrs.get("cubepi.metadata.user_id") == "usr-456"
assert "cubepi.run_id" in attrs
+ # Successful one-shot must NOT be marked aborted by the cleanup sweeper.
+ assert attrs.get("cubepi.aborted") is None
+ assert attrs.get("error.type") is None
chat = by_name[f"chat {MODEL.id}"]
# chat span must be a child of root