Skip to content

Raise StreamDisconnectedError on SSE error frames#596

Open
mistralai-nfau wants to merge 7 commits into
mainfrom
nicolasfaurie/wfl-1679-python-sdk-raise-streamdisconnectederror-on-sse-error-frames
Open

Raise StreamDisconnectedError on SSE error frames#596
mistralai-nfau wants to merge 7 commits into
mainfrom
nicolasfaurie/wfl-1679-python-sdk-raise-streamdisconnectederror-on-sse-error-frames

Conversation

@mistralai-nfau

@mistralai-nfau mistralai-nfau commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Adds an AfterSuccess hook that turns a workflow SSE event: error frame into a raised StreamDisconnectedError (with reason + error), so consumers can wrap stream iteration in try / except instead of inspecting every event.

Import: from mistralai.extra.exceptions import StreamDisconnectedError

Refs WFL-1679.

Adds an AfterSuccess hook that converts a workflow SSE `event: error` frame into a raised StreamDisconnectedError (reason + error), so consumers use try/except around stream iteration instead of inspecting each event.
@mistralai-nfau
mistralai-nfau requested a review from anth2o July 22, 2026 12:47

@anth2o anth2o left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly nit suggestions and test case additions, otherwise LGTM

Comment thread src/mistralai/extra/workflows/stream_error_hook.py Outdated
Comment thread src/mistralai/extra/workflows/stream_error_hook.py Outdated
Comment thread src/mistralai/extra/workflows/stream_error_hook.py Outdated
Comment thread src/mistralai/client/_hooks/stream_error_hook.py Outdated
Comment thread src/mistralai/client/_hooks/stream_error_hook.py Outdated
Comment thread src/mistralai/client/_hooks/stream_error_hook.py
Comment thread src/mistralai/client/_hooks/registration.py
…s streams

- Move WorkflowStreamErrorHook to client/_hooks alongside the other hooks
- Cover deployment + execution logs SSE streams (same error-frame contract)
- Derive valid reasons from the StreamDisconnectReason Literal
- Add tests: error frame without trailing boundary; all stream operations
- Error hook forwards the raw stream unchanged, so it must keep Content-Encoding (httpx decodes downstream); removes duplication with workflow_encoding_hook
- Add test that the encoding hook + stream error hook compose correctly
Use json.loads(strict=False) so a value spanning several data: lines (rejoined with a literal newline per the SSE spec) still yields reason/error instead of silently falling back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants