Skip to content

fix(translation): stream Chat abort, error and repetition finish reasons as errors - #962

Open
joshuacox wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
joshuacox:fix/876-streamed-finish-reasons
Open

joshuacox wants to merge 1 commit into
NVIDIA-NeMo:mainfrom
joshuacox:fix/876-streamed-finish-reasons

Conversation

@joshuacox

@joshuacox joshuacox commented Oct 9, 2026 •

Copy link
Copy Markdown

What

In decode_openai_chat_stream, a finish_reason of abort, error or repetition now decodes to a stream error carrying the message provider finished with finish_reason "<reason>" instead of a message stop. Each encoder already renders a stream error as its terminal error event: an error event for Anthropic clients, {"type": "error"} for Responses clients, and an {"error": ...} chunk for Chat clients.

Why

Related to #876. That issue covers non-streaming, and #884 fixes the buffered path with the same message and the same three reasons. The streamed path has the same hole: the Chat stream decoder passes the finish reason through as a stop, so a generation that did not complete reaches Anthropic clients as end_turn and Responses clients as response.completed.

This started as an addendum PR into the branch behind #884. Colin suggested targeting main directly instead, so it is a standalone PR here and the addendum is closed.

Tests

  • New test failed_finish_reasons_stream_as_errors in stream_translation.rs: for each of the three reasons, Anthropic clients get an error event and no message_delta, and Responses clients get an error event and no response.completed. It fails on unmodified main and passes with the change.
  • cargo test --workspace: 961 passed, 0 failed
  • cargo clippy --workspace --all-targets -- -D warnings: clean
  • cargo fmt --all --check: clean

Summary by CodeRabbit

  • Bug Fixes
    • Chat streams ending with an abort, error, or repetition now report a stream error that identifies the finish reason, rather than emitting a normal completion event.

…ons as errors

Signed-off-by: Josh Cox <6137404+joshuacox@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA-NeMo/Switchyard/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 482cb5d2-4dd7-4aac-bfc8-bced6e9401d1

📥 Commits

Reviewing files that changed from the base of the PR and between 9eb962f and 9f862bf.


📒 Files selected for processing (2)
  • crates/switchyard-translation/src/codecs/openai_chat/stream.rs
  • crates/switchyard-translation/tests/stream_translation.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.



Walkthrough

The OpenAI Chat stream decoder now emits a stream error for abort, error, and repetition finish reasons. Tests check these errors and confirm that Anthropic Messages and OpenAI Responses do not emit their normal terminal events.

Changes

Stream finish errors

Layer / File(s) Summary
Finish reason handling and translation coverage
crates/switchyard-translation/src/codecs/openai_chat/stream.rs, crates/switchyard-translation/tests/stream_translation.rs
The decoder emits StreamError for abort, error, and repetition instead of normal finish handling. Tests verify the reason appears in the error and that the target output omits its normal terminal event.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 9f862

The changed finish reasons produce stream errors, and no merge-blocking issue is established. The PR is ready for normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: translating Chat abort, error, and repetition finish reasons into stream errors.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


  • Fix all pre-merge checks with AI
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit watched the stream flow by
Three finish reasons caught its eye
An error came; the stop was gone
No usual ending carried on
The rabbit nibbled clover green
And sent the tests hopping clean

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

1 participant