Skip to content

fix: surface managed streaming failures to clients - #1652

Merged
willkill07 merged 1 commit into
NVIDIA:release/0.11from
willkill07:fix/1648-managed-stream-errors
Nov 4, 2026
Merged

willkill07 merged 1 commit into
NVIDIA:release/0.11from
willkill07:fix/1648-managed-stream-errors

Conversation

@willkill07

Copy link
Copy Markdown
Member

Overview

Managed streaming previously turned a provider connection failure after partial output into a clean EOF that OpenAI and Anthropic SDKs accepted as a successful-looking response. Emit an explicit SSE error so clients reject interrupted responses while valid HTTP framing preserves the assigned daemon worker route.

  • 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

  • Emit provider-compatible errors for OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages after streaming begins.
  • Include standard Responses error fields and the nested error object required for the reported OpenAI Python SDK to raise; continue the event sequence number.
  • Use a fixed client-facing message so underlying errors cannot expose private upstream URLs, credentials, or malformed payloads.
  • Preserve HTTP errors before the first event, partial output, session cleanup, and worker routing. Failed streams omit successful completion markers.
  • Add regression coverage for protocol errors, premature Responses EOF, middleware failures, and subsequent requests through the same worker; update the documented behavior.

Validation

  • just test-rust: 6,642 passed, four skipped.
  • Eight focused streaming and worker-route regression tests passed; the new regression failed against the unchanged release branch.
  • Reproduced before and after with openai==3.45.0 and anthropic==2.5.0: interrupted Chat and Responses streams now raise APIError; Anthropic Messages raises APIStatusError. Complete streams retain their normal finish reasons, and raw HTTP framing remains valid.
  • just docs: passed. The comparison against published redirects was skipped because FDR returned HTTP 403.
  • cargo fmt --all -- --check: passed.
  • uv run pre-commit run: passed, including Clippy, compilation, dependency audits, and documentation links.
  • After the test assertion iterator adjustment, both affected worker tests were rerun and passed.

Where should the reviewer start?

Start with client_sse_body and encode_sse_error_frame in crates/cli/src/gateway/mod.rs. The protocol and cleanup regression is streaming_response_reports_midstream_errors_in_the_provider_protocol in crates/cli/tests/coverage/shared/gateway_tests.rs. The extended daemon tests verify that application errors preserve the worker route and the next request.

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

@willkill07
willkill07 requested review from a team as code owners November 4, 2026 22:42
@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 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

@willkill07 willkill07 self-assigned this Nov 4, 2026
@willkill07 willkill07 added this to the 0.11 milestone Nov 4, 2026
@willkill07
willkill07 merged commit 4e731c7 into NVIDIA:release/0.11 Nov 4, 2026
44 checks passed
@bbednarski9 bbednarski9 mentioned this pull request Nov 5, 2026
2 tasks done
willkill07 added a commit that referenced this pull request Nov 6, 2026
#### Overview

Resolve the conflicts blocking the `release/0.11` → `main` forward merge
in #1650. The release fixes were written against the combined core
crate; main now separates types, codecs, runtime, and observability.
This branch places the fixes in those current crates while retaining the
original release commits.

**An authorized admin must land this manual forward merge using “Create
a Merge Commit”; do not squash or rebase. Keep #1650 open.** This
repository disables the auto-merger, so `/merge nosquash` does not apply
here. After this resolution lands in main, the forward-merger should
reconcile the original PR. See the [repository bot’s merge
instructions](#1650 (comment)).

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

#### Details

- Preserve the six pending release fixes: Responses request history
(#1643), tool ownership hints (#1645), managed streaming errors (#1652),
worker upstream errors (#1664), free-form tool-call evidence (#1644),
and interrupted LangGraph tool attempts (#1667).
- Keep provider-specific telemetry interpretation in codecs. The runtime
supplies portable request and tool-call views through the existing
normalizer/observability host contracts. Exporters consume these views
without adding a production dependency from observability to codecs or
runtime.
- Preserve the original provider annotations for encoding, invocation
IDs for result correlation, and free-form tool input as text.
- Retain the standalone exporter fallback. An explicitly empty supplied
call list overrides raw fallback data; malformed entries do not discard
neighboring valid calls or renumber positional fallback IDs.
- Move provider-aware exporter tests into plugin-host integration
coverage and share the raw-response field selectors across the provider
and fallback paths.

No dependency manifests or lockfiles change. The PR history contains the
six original release commits followed by one signed and signed-off
resolution merge commit (`dd4e167`). The branch includes main at
`72cc0ebe3` and release/0.11 at `74e432155`.

The consolidated merge retains the previously reviewed production
changes. It also includes two test-only review fixes: parse SSE
assertions by event delimiters instead of body chunks, and preserve
explicitly empty call lists in the telemetry test accessor while
checking both empty and populated results.

**Validation**

- `just test-rust`: 6,743 passed, 4 skipped after the test-only review
fixes.
- Focused SSE and telemetry regressions: 8 passed, including the ATIF
authoritative-empty-list regression.
- `just test-python`: 81 native binding tests, 1,531 package tests, and
24 example tests passed; 1 skipped after the latest release merge.
- `just test-python-langchain`: 402 passed, including LangGraph
interrupt/resume regressions.
- `just test-node`: 10 native binding tests, 551 package tests, and 26
example tests passed on the initial resolution. Node and shared runtime
sources were unchanged by the subsequent refresh, so this suite was not
repeated.
- Repository pre-commit hooks passed before each commit, with the
complete staged file lists explicitly supplied during merges. Applicable
checks included Clippy, compilation, formatting, Python typing,
documentation links, and dependency audits.
- Verified the signature, sign-off, clean worktree, unchanged original
release commit IDs, and exactly one merge commit. The review fixes
changed only three test-related files; binding suites were not repeated
for this test-only revision.

#### Where should the reviewer start?

Start with `TelemetryToolCall` and the optional `LlmNormalizer`
telemetry methods in `crates/types/src/codec/normalization.rs`, then the
provider views in `crates/codecs/src/telemetry.rs` and their consumption
in `crates/observability/src/normalization.rs`.

The exporter regressions are under
`crates/plugin-host/tests/integration/observability/`. The standalone
fallback regression is in
`crates/observability/tests/unit/atif_projection_tests.rs`.

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

- Relates to #1650


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* OpenAI Responses custom tool calls and results are supported,
preserving call IDs and free-form input across processing and
observability exports.
* LangGraph tool execution handles approval interrupts consistently in
synchronous and asynchronous workflows.
* **Bug Fixes**
* Managed streams return protocol-compatible error events when execution
fails after streaming begins, retaining already-sent content and
omitting successful completion markers.
* Tool-call telemetry better preserves provider details and skips
malformed entries without losing valid calls.
* **Documentation**
  * Clarified error behavior in managed streaming responses.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
willkill07 pushed a commit that referenced this pull request Nov 23, 2026
…1782)

#### Overview

Adds a `validate_stream` wrapper to the Anthropic streaming codec, so a
stream that carries an Anthropic `error` event (for example
`overloaded_error`) ends with an error and is recorded as `ERROR`,
instead of `OK` with partial output.

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

#### Details

- `crates/core/src/codec/anthropic.rs`:
`AnthropicMessagesStreamingCodec::validate_stream` wraps the source in
`AnthropicCompletionStream`, which forwards every event unchanged and,
after forwarding an `error` event, returns
`FlowError::Internal("Anthropic stream reported <type>: <message>")` on
the next poll, before polling the source again, so a stalled source or a
later transport error cannot delay or replace it. `terminalize` and
`close` are forwarded, as the trait requires.
- The wrapper detects the error from the events it forwards, not from
collector state, so the check does not depend on when the collector runs
(the ordering issue described in #1757).
- It uses `FlowError::Internal`, like the Responses completion check,
rather than `FlowError::Upstream`: the gateway's retry-aware routing
acts on `Upstream` failures, and a retry after partial output has
reached the client could duplicate output.
- Unknown event types are still ignored; the `observe` comment now notes
that `validate_stream` reports `error` events.
- The gateway is the caller of `validate_stream`
(`crates/cli/src/gateway/mod.rs`), so this covers the gateway path where
#1781 was reproduced.
- Side effect: after Anthropic's `error` event, the gateway also sends
its generic `event: error` (#1652), because the stream now ends with an
error. The Anthropic SDK raises on in-stream `error` events (as noted in
#1648), so it raises on `overloaded_error` first; a client reading the
raw stream sees both. Happy to adjust if you'd prefer to suppress the
second event.
- Out of scope: the Responses wrapper treats `response.failed` as a
normal terminal event.
- No breaking changes.

Tested on macOS, on `release/0.11` at `56965db4`:
- New
`anthropic_stream_validation_reports_error_events_and_preserves_close`:
normal, unknown-event, and `error` streams, plus upstream-error and
close forwarding. New
`anthropic_stream_validation_reports_error_events_before_polling_the_source_again`:
a source that stalls after the `error` event, and one that then returns
a transport error. New
`anthropic_sessions_record_in_stream_error_events_as_errors`: the end
event is `ERROR` with the provider's error type, partial output is kept,
and a normal stream stays `OK`. The first and third failed on
`release/0.11` without the fix; the second failed on the previous
revision of this PR. All pass now.
- `cargo nextest run -p nemo-relay -E 'test(~anthropic) |
test(~stream)'`: 298 passed.
- `just test-rust`: 6746 passed, 4 skipped (with `ulimit -n 4096`).
- `cargo fmt --all -- --check` and `cargo clippy -p nemo-relay
--all-targets -- -D warnings` pass.
- End to end through `nemo-relay --bind` with the mock from #1781: on
`main` (`23f05206`) the call was recorded `OK`; with this branch it is
`ERROR` (`Anthropic stream reported overloaded_error: Overloaded`), the
partial output is kept, and the client receives `overloaded_error`
first.
- Pre-commit hooks pass, except `npm audit` and `uv audit`, which I
skipped; this change touches no lockfiles. On the last commit, I also
skipped the docs link check, which failed on an unreachable external
link in an unrelated page; this change touches no docs.

Not tested on Linux or Windows; CI covers those.

#### Where should the reviewer start?

`AnthropicCompletionStream` in `crates/core/src/codec/anthropic.rs`.

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

Closes #1781

---------

Signed-off-by: Sakshi Tapkir <[email protected]>
Co-authored-by: Maryam Najafian <[email protected]>

This branch was previously deployed

1 inactive deployment
fern — 98d3d6a2 Deployed Nov 4, 2026 by willkill07 via Clean up docs preview #7041
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