Skip to content

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

fix(providers): guard stream-error classification to SDK-originated exceptions

xf gong90bf50411b17
diff --git a/cubepi/providers/openai.py b/cubepi/providers/openai.py
index 2b87bda..3afa5ad 100644
--- a/cubepi/providers/openai.py
+++ b/cubepi/providers/openai.py
@@ -510,15 +510,17 @@ class OpenAIProvider(BaseProvider):
except BaseException as e:
exc = e
# Classify SDK stream-level errors that the narrow create()
- # try/except didn't catch — async-for-chunk iteration errors
- # (mid-stream connection drops, timeouts) arrive here raw.
+ # try/except didn't catch. Only classify exceptions from the
+ # openai SDK module — local callback/processing exceptions
+ # (on_payload, on_response, assembly) must not be re-tagged.
if isinstance(e, Exception):
from cubepi.errors import classify_and_raise
- try:
- classify_and_raise(e, model=model, messages=messages)
- except Exception as _classified:
- exc = _classified
+ if type(e).__module__.startswith("openai"):
+ try:
+ classify_and_raise(e, model=model, messages=messages)
+ except Exception as _classified:
+ exc = _classified
err_text = self._error_message(exc, model)
error_msg = AssistantMessage(
content=[],
diff --git a/cubepi/providers/openai_responses.py b/cubepi/providers/openai_responses.py
index fac69e8..1fa7444 100644
--- a/cubepi/providers/openai_responses.py
+++ b/cubepi/providers/openai_responses.py
@@ -581,15 +581,17 @@ class OpenAIResponsesProvider(BaseProvider):
except BaseException as e:
exc = e
# Classify SDK stream-level errors that the narrow create()
- # try/except didn't catch — async-for-event iteration errors
- # arrive here raw.
+ # try/except didn't catch. Only classify exceptions from the
+ # openai SDK module — local callback/processing exceptions
+ # must not be re-tagged.
if isinstance(e, Exception):
from cubepi.errors import classify_and_raise
- try:
- classify_and_raise(e, model=model, messages=messages)
- except Exception as _classified:
- exc = _classified
+ if type(e).__module__.startswith("openai"):
+ try:
+ classify_and_raise(e, model=model, messages=messages)
+ except Exception as _classified:
+ exc = _classified
err_text = self._error_message(exc, model)
error_msg = AssistantMessage(
content=[],