Skip to content

fix(translation): honor Chat streaming usage opt-in - #797

Closed
ajcasagrande wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ajcasagrande:ajc/agent-adapters-pr-04
Closed

ajcasagrande wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
ajcasagrande:ajc/agent-adapters-pr-04

Conversation

@ajcasagrande

@ajcasagrande ajcasagrande commented Sep 20, 2026

Copy link
Copy Markdown

What

Makes generated OpenAI Chat streaming usage opt-in through stream_options.include_usage. Requested usage now follows the finish chunk as one choices: [] frame at clean EOF. The relay test confirms hidden client output still emits answer-token telemetry.

Why

OpenAI Chat callers that omit usage opt-in must not receive generated usage frames. This keeps provider raw replay unchanged while preserving clean-EOF ordering and telemetry behavior.

Notes for reviewers

  • RED to GREEN contract tests cover omitted, false, non-boolean, true, missing backend usage, post-stop errors, and raw replay.
  • Full workspace tests passed. Focused relay tests, relay crate tests, scoped Clippy, formatting, and diff checks passed.
  • Fresh Graham review approved with zero findings.

Summary by CodeRabbit

  • New Features

    • OpenAI Chat streaming responses can now include a separate final usage-only chunk when explicitly requested.
    • Usage information is emitted after normal completion and remains available even when no backend usage data is returned.
  • Bug Fixes

    • Prevented usage data from being embedded in terminal message chunks.
    • Usage is no longer emitted for errored streams or when usage inclusion is not requested.
    • Ensured usage is emitted at most once and stream replay reaches the correct final state.

Signed-off-by: Anthony Casagrande <acasagrande@nvidia.com>
Signed-off-by: Anthony Casagrande <acasagrande@nvidia.com>
@ajcasagrande
ajcasagrande requested a review from a team as a code owner September 20, 2026 00:52
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: 8e6049e3-9f2c-4c7d-9b32-5fb383c5a2fc

📥 Commits

Reviewing files that changed from the base of the PR and between bfcd023 and 71ae90a.

📒 Files selected for processing (7)
  • crates/switchyard-nemo-relay-plugin/src/runtime.rs
  • crates/switchyard-server/src/lib.rs
  • crates/switchyard-translation/src/codecs/openai_chat/stream.rs
  • crates/switchyard-translation/src/codecs/stream.rs
  • crates/switchyard-translation/src/helpers.rs
  • crates/switchyard-translation/tests/response_translation.rs
  • crates/switchyard-translation/tests/stream_translation.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 9 remain after this review.


Walkthrough

Changes

OpenAI Chat streaming usage

Layer / File(s) Summary
Usage opt-in state and initialization
crates/switchyard-translation/src/codecs/stream.rs, crates/switchyard-translation/src/helpers.rs, crates/switchyard-server/src/lib.rs
Stream state records Chat usage opt-in and finalization. Usage generation requires stream_options.include_usage: true.
Chat stream replay and finalization
crates/switchyard-translation/src/codecs/openai_chat/stream.rs
Replay marks stopped streams as finalized. Usage updates state without immediate output. Successful finalization emits terminal and optional usage chunks separately.
Usage behavior validation
crates/switchyard-translation/helpers.rs, crates/switchyard-translation/tests/*, crates/switchyard-nemo-relay-plugin/src/runtime.rs
Tests cover opt-in, replay, errors, state-only usage, and updated stream termination behavior.

Priority: ⬇️ Low

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 31 functions across 7 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: honoring the OpenAI Chat streaming usage opt-in during translation.
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

A rabbit checks the streaming trail
Usage waits beyond the final tale
Opt-in opens one last small door
Errors leave no usage on the floor
Replay keeps the stream in score

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

@ajcasagrande

Copy link
Copy Markdown
Author

closing for now, while product alignment is conferred

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