Skip to content

fix: record Chat Completions in-stream errors as failed calls - #1808

Merged
willkill07 merged 3 commits into
NVIDIA:release/0.11from
mnajafian-nv:fix/chat-stream-error-status
Nov 23, 2026
Merged

willkill07 merged 3 commits into
NVIDIA:release/0.11from
mnajafian-nv:fix/chat-stream-error-status

Conversation

@mnajafian-nv

@mnajafian-nv mnajafian-nv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Overview

An OpenAI-compatible provider can return HTTP 200 and later send an error object inside a Chat Completions stream. The standalone gateway forwards it but can still record the call as OK. This change records ERROR with the provider's error details.

  • I confirm this contribution is my own work, or I have the right to submit it under this project's license.
  • I searched existing issues and open pull requests, and this does not duplicate existing work.

Details

Forward the original error chunk unchanged, then report the failure on the next read. A stalled connection or later transport error cannot hide it. Keep collected text and token usage, and handle missing error details.

Clients also receive Relay's existing SSE error payload instead of [DONE]. The existing observability guide documents this behavior.

This applies to the standalone gateway and Rust callers using the built-in Chat Completions validator. Daemon observation is unchanged.

Validation: Regression tests failed before the fix and passed afterward. The Rust suite, Clippy, formatting, and docs checks passed. Dependency-audit hooks still report findings in unchanged release dependencies.

Where should the reviewer start?

ChatCompletionStream::poll_next in crates/core/src/codec/openai_chat.rs, then the two Chat stream regressions in crates/core/tests/integration/stream_tests.rs.

Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)

Summary by CodeRabbit

  • Bug Fixes
    • Chat completion streams now forward provider error events before reporting a stream error on the next read. Error details use the provider’s code and message when available, with defaults otherwise.
    • Failed streams emit an error end event while preserving partial response text and usage; successful streams emit a success end event.
  • Documentation
    • Clarified how provider errors in streaming responses are surfaced in OpenTelemetry and affect the stream’s final event.

Recognize provider error objects inside successful HTTP streams instead of
letting the managed call finish as OK. Preserve the original chunk and
report its failure before polling the source again.

Signed-off-by: Maryam Najafian <[email protected]>
@github-actions github-actions Bot added size:S PR is small Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code labels Nov 23, 2026
@mnajafian-nv
mnajafian-nv requested review from a team as code owners November 23, 2026 00:47
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The OpenAI Chat streaming codec now forwards provider error events before returning a derived stream error on the next poll. Integration tests cover error details, termination, partial output, usage, and end-event metadata. OpenTelemetry documentation describes the behavior.

Changes

Chat stream error handling

Layer / File(s) Summary
Validate Chat completion streams
crates/core/src/codec/openai_chat.rs
validate_stream wraps the incoming stream. It forwards events and reports a FlowError::Internal on the next poll after an object-valued top-level error.
Verify and document stream outcomes
crates/core/tests/integration/stream_tests.rs, docs/configure-plugins/observability/opentelemetry.mdx
Integration tests cover error derivation, termination, partial output, usage, and end-event metadata. The OpenTelemetry documentation describes the provider error event and subsequent stream error.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • NVIDIA/NeMo-Relay#1781: This PR handles the issue’s noted Chat Completions case by recording in-stream error chunks as failed calls while forwarding the chunk and preserving partial text and usage. The reported Anthropic behavior remains unchanged.
Merge Risk: Minimal · up to d366b

Provider errors that arrive mid-stream on OpenAI-compatible Chat Completions are now recorded as failed calls, and the documentation matches the traced behavior. No outstanding merge-blocking issue was found.

Architecture risk: Low · up to d366b

The change affects 2 systems.

Changed systems: crates, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/core/src/codec/openai_chat.rs: Added future, pinning, task-polling, Stream, and streaming runtime imports used by the stream-validation wrapper; the runtime import now includes LlmJsonStream and LlmStreamInner.
  • observed — Modified behavior in crates/core/src/codec/openai_chat.rs: Added documentation directing callers to StreamingCodec::validate_stream for reporting provider errors carried in top-level error objects.
  • observed — Modified behavior in crates/core/src/codec/openai_chat.rs: Added validate_stream, which wraps the incoming LlmJsonStream in ChatCompletionStream with no pending provider error and an active state.
  • observed — Modified behavior in crates/core/src/codec/openai_chat.rs: Added a stream wrapper that forwards events and, after forwarding an event with an object-valued top-level error, emits the derived FlowError::Internal on the next poll. It derives the error code from string or numeric code, falling back to string type or "error", and the message from string message or "stream failed". It then ends; ordinary stream completion or inner errors also end it. terminalize and close mark it ended and delegate to the inner stream.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title uses the Conventional Commits format with the allowed type "fix", lowercase, no trailing period, and 61 characters, which is under the 72-character limit. It states the main change: Chat Com…
Description check Passed The description follows the repository template. It includes the Overview with both checklist items marked, the Details section explaining the forwarding and next-read failure behavior, the reviewer s…
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.
Full details: Title check

Explanation

The title uses the Conventional Commits format with the allowed type "fix", lowercase, no trailing period, and 61 characters, which is under the 72-character limit. It states the main change: Chat Completions in-stream errors are recorded as failed calls. The changeset adds a ChatCompletionStream wrapper that surfaces provider error events as FlowError::Internal and records ERROR end events, so the title matches the change.

Full details: Description check

Explanation

The description follows the repository template. It includes the Overview with both checklist items marked, the Details section explaining the forwarding and next-read failure behavior, the reviewer starting points (ChatCompletionStream::poll_next and the two stream regressions), and the Related Issues section using the 'Relates to' keyword with #1781 and #1782. It also gives validation results. The Related Issues entry does not use the Closes/Fixes/Resolves keyword, which is acceptable because the author chose 'Relates to' from the allowed list.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4bda6b3 and d366b7d.

Files selected for processing: 2

  • crates/core/tests/integration/stream_tests.rs
  • docs/configure-plugins/observability/opentelemetry.mdx

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

Recent review details

Context from checks skipped due to timeout: 45

  • GitHub Check: CodeRabbit
  • GitHub Check: Python / Package (linux-arm64)
  • GitHub Check: Python / Test (linux-amd64)
  • GitHub Check: Node.js / Package (windows-amd64)
  • GitHub Check: Python / Package (linux-musl-amd64)
  • GitHub Check: Node.js / Package (linux-musl-amd64)
  • GitHub Check: Rust / Test (windows-amd64)
  • GitHub Check: Node.js / Package (linux-musl-arm64)
  • GitHub Check: Node.js / Package (windows-arm64)
  • GitHub Check: Python / Package (macos-arm64)
  • GitHub Check: Python / Test (windows-amd64)
  • GitHub Check: Python / Test (macos-arm64)
  • GitHub Check: Python / Package (windows-arm64)
  • GitHub Check: Python / Package (linux-amd64)
  • GitHub Check: Node.js / Package (linux-amd64)
  • GitHub Check: Python / Package (windows-amd64)
  • GitHub Check: Node.js / Package (linux-arm64)
  • GitHub Check: Python / Package (linux-musl-arm64)
  • GitHub Check: Python / Test (windows-arm64)
  • GitHub Check: Node.js / Package (macos-arm64)
  • GitHub Check: Node.js / Test (windows-amd64)
  • GitHub Check: Node.js / Test (linux-amd64)
  • GitHub Check: Node.js / Test (macos-arm64)
  • GitHub Check: Rust / Package (windows-amd64)
  • GitHub Check: Python / Test (linux-arm64)
  • GitHub Check: Rust / Package (windows-arm64)
  • GitHub Check: Rust / Package (macos-arm64)
  • GitHub Check: Node.js / Test (linux-arm64)
  • GitHub Check: Node.js / Test (windows-arm64)
  • GitHub Check: Rust / Package (linux-amd64)
  • GitHub Check: Rust / Package (linux-musl-amd64)
  • GitHub Check: Rust / Package (linux-musl-arm64)
  • GitHub Check: Rust / Test (linux-arm64)
  • GitHub Check: Rust / Package (linux-arm64)
  • GitHub Check: Go / Test (windows-amd64)
  • GitHub Check: Go / Test (macos-arm64)
  • GitHub Check: Go / Test (windows-arm64)
  • GitHub Check: Go / Test (linux-amd64)
  • GitHub Check: Node.js / Package OpenClaw plugin
  • GitHub Check: Go / Test (linux-arm64)
  • GitHub Check: Rust / Test (macos-arm64)
  • GitHub Check: Rust / Test (linux-amd64)
  • GitHub Check: Rust / Test (windows-arm64)
  • GitHub Check: Check / Run
  • GitHub Check: Preview docs
Additional context used

Code guidelines: 4

.agents/skills/contribute-docs/SKILL.md — configured
.agents/skills/maintain-observability/SKILL.md — configured
AGENTS.md — configured
.agents/skills/review-doc-style/SKILL.md — configured
Path-based instructions: 7

Review documentation for technical accuracy against the current API, command correctness, and consistency across language bindings.

CodeRabbit configuration file

Files:

  • docs/configure-plugins/observability/opentelemetry.mdx
Tests should cover the behavior promised by the changed API surface, including error paths and cross-request isolation where relevant.

CodeRabbit configuration file

Files:

  • crates/core/tests/integration/stream_tests.rs
Review the Rust runtime for async correctness, scope isolation, middleware ordering, and event lifecycle regressions.

CodeRabbit configuration file

Files:

  • crates/core/tests/integration/stream_tests.rs
Source excerpt: In MDX files, top-of-file comments must use JSX comment delimiters: `{/*` to open and `*/}` to close.

CodeRabbit inference engine (.agents/skills/contribute-docs/SKILL.md)

Files:

  • docs/configure-plugins/observability/opentelemetry.mdx
Source excerpt: Core event model and emitted fields `crates/core/src/observability/atif.rs` `crates/core/src/observability/otel.rs` `crates/core/src/observability/openinference.rs` FFI and binding-native wrappers where the config or lifecyc...

CodeRabbit inference engine (.agents/skills/maintain-observability/SKILL.md)

Files:

  • docs/configure-plugins/observability/opentelemetry.mdx
Source excerpt: Update public documentation and examples when public behavior, package names, supported bindings, or documented workflows change.

CodeRabbit inference engine (AGENTS.md)

Files:

  • docs/configure-plugins/observability/opentelemetry.mdx
Source excerpt: Verify MDX files use JSX delimiters for top-of-file SPDX comments.

CodeRabbit inference engine (.agents/skills/review-doc-style/SKILL.md)

Files:

  • docs/configure-plugins/observability/opentelemetry.mdx
Additional comments: 2

docs/configure-plugins/observability/opentelemetry.mdx: 2

1308-1308: Data Integrity & Integration

The documented behavior is accurate. After a forwarded Chat chunk, a later stream error makes the gateway send its error frame and skip data: [DONE]. The doc sentence does not need a correction, and the review concern is answered by the inspected code.

1307-1307: Data Integrity & Integration

The documented behavior holds. For a provider error object with a numeric code and a message, the LLM span status description contains both values, for example OpenAI Chat stream reported 502: failed. The documentation's "when supplied" wording matches the fallback behavior in the codec.

@github-actions

Copy link
Copy Markdown

@willkill07 willkill07 added this to the 0.11 milestone Nov 23, 2026
@willkill07
willkill07 merged commit b1bded1 into NVIDIA:release/0.11 Nov 23, 2026
97 checks passed

This branch was previously deployed

1 inactive deployment
fern — d366b7d6 Deployed Nov 23, 2026 by willkill07 via Clean up docs preview #7651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug issue describes bug; PR fixes bug lang:rust PR changes/introduces Rust code size:S PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants