You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: handle top-level Responses API error events - #1835
When a Responses stream sends type: "error", the gateway forwards it but
keeps waiting. If upstream closes, Relay reports a missing final response
instead of the provider's error.
Handle these events like response.failed: forward them unchanged, then
report the provider's error on the next read, even if upstream stalls.
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
Preserve collected output, token usage, and first-final-response precedence.
Update the existing observability documentation and regression coverage.
Validation: Rust tests, Clippy, and formatting passed.
Where should the reviewer start?
ResponsesCompletionStream::poll_next in crates/core/src/codec/openai_responses.rs, followed by the Responses
stream tests and gateway regression.
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
OpenAI Responses streams now report standalone provider errors promptly, even when the stream would otherwise remain open. Error details are included when provided, and usage and output recorded before an error are retained.
Documentation
Updated OpenTelemetry guidance to describe how provider error events appear in client streams and tracing.
No actionable comments were generated in the recent review.
Walkthrough
The OpenAI Responses stream codec now handles standalone error events as provider failures. It forwards the event before reporting the error on the next poll. Tests and documentation cover stream validation, session outcomes, and stalled sources.
Changes
Responses Stream Error Handling
Layer / File(s)
Summary
Recognize and report provider error events crates/core/src/codec/openai_responses.rs, crates/core/tests/integration/stream_tests.rs, docs/configure-plugins/observability/opentelemetry.mdx
The codec extracts details from standalone error events and reports the saved error on the next poll. Integration tests cover completion validation and provider error details. The documentation describes the corresponding stream and observability behavior.
Verify session and stalled-stream outcomes crates/core/tests/integration/stream_tests.rs, crates/cli/tests/coverage/shared/gateway_tests.rs
Session tests check error outcomes while retaining usage and output evidence. A gateway test checks that response collection completes when the source remains pending after yielding an error event.
This change makes standalone provider error events in Responses streams surface as stream errors instead of being missed. No merge-blocking risk was found in the supplied changes, and tests cover the new behavior.
Security architecture risk: Low · up to 73a0e
A provider error now ends the affected stream without waiting for upstream to close. The main risk is that provider error text can also appear in configured traces, where it may be visible to a different audience than the original response.
Retained concerns
Low · security · inferred: A standalone provider error before the first final response can now place its free-form message and code in LLM span status. If those fields contain sensitive details and event sanitization does not remove them, configured trace recipients can see text previously forwarded to the caller but not copied into span status through this path.
Security review details
Security Blast Radius
inferred — The termination change is scoped to the affected Responses stream. The additional data exposure is to subscribers and configured trace destinations for that stream, if the provider text survives sanitization; the evidence does not establish who can read those traces in production.
Trust Boundaries and Controls
observed — Provider-controlled code and message become END-event status metadata. The runtime passes the event through its existing sanitizer dispatch, and the trace integration maps the resulting status description to the span.
Resilience and Maintainability Implications
observed — The managed stream terminalizes the source on error or cancellation. If the client disconnects before reading the saved error, the gateway guard cancels the stream and retains responsibility for session cleanup.
Hardening Proposals
proposed — Keep the provider event intact for the caller, but use a stable classification or redacted description in exported trace status by default. Apply the same policy to both standalone errors and response.failed.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title uses the allowed type "fix", a lowercase imperative summary, no trailing period, and is 48 characters long. It states the main change: the gateway now handles top-level Responses API error e…
Description check
The description follows the repository template. It has an Overview with both checklist items checked, a Details section describing preserved output, usage, and precedence plus validation results, a r…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title uses the allowed type "fix", a lowercase imperative summary, no trailing period, and is 48 characters long. It states the main change: the gateway now handles top-level Responses API error events. The title matches the raw summary and the PR objectives.
Full details: Description check
Explanation
The description follows the repository template. It has an Overview with both checklist items checked, a Details section describing preserved output, usage, and precedence plus validation results, a reviewer starting point naming ResponsesCompletionStream::poll_next, and a Related Issues section that uses the 'Relates to' keyword with #1807. The template's 'Closes' line is replaced by 'Relates to', which the template allows. Overall the description is complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
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...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bugissue describes bug; PR fixes buglang:rustPR changes/introduces Rust codesize:SPR is small
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
When a Responses stream sends
type: "error", the gateway forwards it butkeeps waiting. If upstream closes, Relay reports a missing final response
instead of the provider's error.
Handle these events like
response.failed: forward them unchanged, thenreport the provider's error on the next read, even if upstream stalls.
Details
Preserve collected output, token usage, and first-final-response precedence.
Update the existing observability documentation and regression coverage.
Validation: Rust tests, Clippy, and formatting passed.
Where should the reviewer start?
ResponsesCompletionStream::poll_nextincrates/core/src/codec/openai_responses.rs, followed by the Responsesstream tests and gateway regression.
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit