Skip to content

feat(switchyard-translation): add neutral-IR encode/decode helpers#77

Merged
messiaen merged 3 commits into
mainfrom
grclark/translation-helpers
Jul 17, 2026
Merged

feat(switchyard-translation): add neutral-IR encode/decode helpers#77
messiaen merged 3 commits into
mainfrom
grclark/translation-helpers

Conversation

@messiaen

@messiaen messiaen commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds convenience helpers to switchyard-translation for translating between provider wire
formats and the neutral IR without threading an engine/policy through every call.

Base: libsy-lib-proto-cleanup

Changes

  • helpers.rs — free functions over a shared default engine: decode_request,
    encode_request, decode_buffered_response, encode_buffered_response, encode_stream,
    and a byte-based decode_stream (Stream<Item = Result<Vec<u8>, _>> → IR chunks — no HTTP
    client types), plus the RawEventStream type for unframed wire-event streams.
  • sse.rs — a minimal SSE frame parser backing decode_stream.
  • lib.rs — wires in the two modules and re-exports the helpers from the crate root.
  • Cargo.toml — adds futures + async-stream for the streaming helpers.

Tests

Unit tests for every helper (request/response round-trips, buffered & stream encode/decode)
and the SSE parser. Full workspace builds clean, clippy at zero.

Checklist

  • One class per file; filename = snake_case of the primary class.
  • New public symbols exported from switchyard/__init__.py.__all__ if intended for downstream use.
  • Unit tests added for new components / bug fixes.
  • README / --help updated if customer-facing surface changed.
  • Commits signed off (Signed-off-by: Your Name <email>) per the DCO.

Notes for reviewers

Anything reviewers should pay extra attention to — risky paths, follow-up tickets, intentional trade-offs.

Summary by CodeRabbit

  • New Features
    • Added convenient request and response translation between supported wire formats.
    • Added streaming translation for real-time responses, including SSE event encoding and decoding.
    • Added support for buffering partial stream frames and recognizing stream completion markers.
    • Preserved model information when encoding buffered responses.
  • Bug Fixes
    • Improved handling of incomplete UTF-8 data and non-standard streams that omit a final separator.

@messiaen messiaen self-assigned this Jul 16, 2026
@messiaen
messiaen requested a review from a team as a code owner July 16, 2026 17:09
@messiaen
messiaen force-pushed the grclark/libsy-lib-proto-cleanup branch 3 times, most recently from f2fc719 to 57c015d Compare July 16, 2026 23:13
Base automatically changed from grclark/libsy-lib-proto-cleanup to main July 16, 2026 23:27
@messiaen
messiaen force-pushed the grclark/translation-helpers branch from fcf75d3 to de9ddbe Compare July 16, 2026 23:39
@messiaen messiaen changed the title feat(switchyard-translation): add neutral-IR encode/decode helpers an… feat(switchyard-translation): add neutral-IR encode/decode helpers Jul 17, 2026
Comment thread crates/switchyard-translation/src/helpers.rs Outdated
Comment thread crates/switchyard-translation/src/helpers.rs Outdated
Comment thread crates/switchyard-translation/src/helpers.rs Outdated
Comment thread crates/switchyard-translation/src/helpers.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Comment thread crates/switchyard-translation/src/sse.rs Outdated
Signed-off-by: Greg Clark <grclark@nvidia.com>
@messiaen
messiaen force-pushed the grclark/translation-helpers branch from de9ddbe to bb40d0f Compare July 17, 2026 16:52
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Changes

The translation crate adds buffered request/response helpers, streaming encode/decode APIs, SSE frame parsing, associated tests, public re-exports, and futures-based runtime dependencies.

Translation streaming

Layer / File(s) Summary
SSE frame parsing
crates/switchyard-translation/src/sse.rs
Adds buffered SSE boundary detection, UTF-8 decoding, JSON and terminal-frame parsing, and parser tests.
Buffered and streaming translation helpers
crates/switchyard-translation/src/helpers.rs
Adds request/response wrappers and stream conversion helpers that preserve translation state, handle terminal events, and support incomplete trailing frames with tests.
Crate integration and runtime support
crates/switchyard-translation/src/lib.rs, crates/switchyard-translation/Cargo.toml
Registers the new modules, re-exports helper APIs, and adds futures and async-stream dependencies.

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

Poem

A rabbit hops through streams of light,
Translating chunks from day to night.
SSE frames neatly fall in line,
JSON carrots taste just fine.
“Done!” I twitch—then rest my ear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding neutral-IR encode/decode helpers for switchyard-translation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/switchyard-translation/src/helpers.rs`:
- Around line 146-159: Bound the pending SSE data in the streaming loop around
`buffer` and `sse::drain_next_sse_frame`: after draining all complete frames
from each chunk, reject the request when the remaining incomplete buffer exceeds
the configured maximum frame size. Add a multi-chunk test that omits the frame
delimiter and verifies the oversized pending frame is rejected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c3a2bb39-46ff-4a53-980b-a40929104739

📥 Commits

Reviewing files that changed from the base of the PR and between 93f0e3e and bb40d0f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock, !Cargo.lock
📒 Files selected for processing (4)
  • crates/switchyard-translation/Cargo.toml
  • crates/switchyard-translation/src/helpers.rs
  • crates/switchyard-translation/src/lib.rs
  • crates/switchyard-translation/src/sse.rs

Comment thread crates/switchyard-translation/src/helpers.rs Outdated
Signed-off-by: Greg Clark <grclark@nvidia.com>
@nachiketb-nvidia

Copy link
Copy Markdown
Contributor

nothing extra to add apart from Graham, just an additional pass checking if there are more idiomatic or standard ways of doing anything in this PR would be good

Signed-off-by: Greg Clark <grclark@nvidia.com>
@messiaen
messiaen requested a review from grahamking July 17, 2026 20:30
@messiaen
messiaen merged commit 8b8dad8 into main Jul 17, 2026
14 checks passed
@messiaen
messiaen deleted the grclark/translation-helpers branch July 17, 2026 20:51
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.

3 participants