Skip to content

feat(server): execute guarded provider streams - #2434

Open
Pouyanpi wants to merge 4 commits into
developfrom
pouyanpi/transparent-proxy-streaming-kernel-1
Open

Pouyanpi wants to merge 4 commits into
developfrom
pouyanpi/transparent-proxy-streaming-kernel-1

Conversation

@Pouyanpi

@Pouyanpi Pouyanpi commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds provider-neutral SSE parsing, event classification, bounded buffering, and guarded stream execution. Content-bearing events are checked before release, and allowed events retain their original bytes.

What Changed

  • Declares stream roles, shape coverage, adapters, and declarative event classifiers.
  • Frames mixed SSE line endings incrementally, preserves raw bytes, and handles one initial BOM.
  • Rejects unfinished field blocks and drops unfinished comment tails; error hooks must encode complete SSE blocks.
  • Bounds events and unchecked pending bytes, verifies snapshots, and rejects modification requests.
  • Keeps the async-generator interface and closes upstream on iteration end or rejected arguments; callers own cleanup if iteration never starts.
  • Requires matching discriminator value types, consistent with buffered projections.

Review Notes

Review release ordering, ambiguity, bounds, byte preservation, and cancellation. HTTP dispatch, provider grammar, and request preparation are supplied by later PRs.

AI Assistance

  • No AI tools were used.
  • AI tools were used (Codex assisted with commit reconstruction, HTTP/error reconciliation, regression tests, and PR drafting). Human review of the new diff is pending.

Checklist

  • I've read the CONTRIBUTING guidelines.
  • This is maintainer-directed work.
  • The PR title follows the project commit convention.
  • Applicable declarations and tests are included.
  • Generated changelog files were not edited manually.
  • Automated and human review comments are addressed or answered.
  • The responsible reviewer or team is mentioned.

Stack Position

Part 1 of 4.

Stack Context

Adds OpenAI Chat streaming above #2414 in four parts: provider-neutral execution, typed OpenAI stream declarations and handwritten hooks, injected HTTP lifecycle handling, and integration with the buffered request pipeline.

The open chain is #2411 → #2413 → #2414 → #2434 → #2435 → #2436 → #2437. #2412 is closed; its provider provenance and boundary documentation are included in #2413.

Python declarations own field and event policy. Hooks are handwritten and created for each stream by the integration. The shared exporter currently emits buffered policy; streaming contract export remains separate work. Concrete outbound HTTP, deployment configuration, and replacement execution land separately.

Review each PR against its listed base branch.

Order PR Branch Base
1 #2434 pouyanpi/transparent-proxy-streaming-kernel-1 pouyanpi/openai-chat-buffered-integration-4
2 #2435 pouyanpi/openai-chat-streaming-contract-2 pouyanpi/transparent-proxy-streaming-kernel-1
3 #2436 pouyanpi/transparent-proxy-streaming-http-3 pouyanpi/openai-chat-streaming-contract-2
4 #2437 pouyanpi/openai-chat-streaming-integration-4 pouyanpi/transparent-proxy-streaming-http-3

Summary by CodeRabbit

  • New Features
    • Added support for inspecting provider-streamed responses before releasing buffered content, with configurable chunk and context sizes.
    • Unsafe or uninspectable streamed content can be withheld, while provider errors and stream-processing failures are handled as distinct outcomes.
    • Added support for parsing streamed events across varied chunk boundaries and validating provider event formats.

@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

@Pouyanpi
Pouyanpi force-pushed the pouyanpi/transparent-proxy-streaming-kernel-1 branch from 4ec5c7f to f4a6606 Compare October 6, 2026 11:05
@Pouyanpi Pouyanpi added this to the v0.25.0 milestone Oct 6, 2026
@Pouyanpi Pouyanpi self-assigned this Oct 6, 2026
@Pouyanpi Pouyanpi removed the status: needs triage New issues that have not yet been reviewed or categorized. label Oct 6, 2026
@Pouyanpi
Pouyanpi marked this pull request as ready for review October 6, 2026 11:06
@Pouyanpi Pouyanpi added status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile). and removed status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile). labels Oct 6, 2026
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge based on the reviewed stream behavior.

Summary

The PR adds provider-neutral SSE framing, stream-event classification, and guarded execution that checks buffered text before releasing its original provider bytes. Since the previous review, it also releases validated data-less keepalives promptly when no payload is pending and clarifies the input-context invariant. No new actionable issue was identified.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Provider bytes] --> B[SSE framing]
  B --> C[Classify and observe event]
  C -->|Data-less opaque event; nothing pending| D[Release original bytes]
  C -->|Guarded text| E[Buffer text window]
  E --> F[Output check]
  F -->|Allowed| G[Release original event bytes]
  F -->|Blocked or failed| H[Encode terminal outcome]
Loading

Reviews (6) · Last reviewed commit: "docs(server): state the single user inpu..." · Reviewed by Greptile

Comment thread nemoguardrails/server/experimental/provider/sse.py Outdated
Comment thread nemoguardrails/server/experimental/provider/sse.py Outdated
Comment thread nemoguardrails/server/experimental/_guarded_stream.py Outdated
@Pouyanpi
Pouyanpi force-pushed the pouyanpi/transparent-proxy-streaming-kernel-1 branch 2 times, most recently from 9052700 to cb9fb48 Compare October 8, 2026 17:52
Base automatically changed from pouyanpi/openai-chat-buffered-integration-4 to develop October 9, 2026 13:16
@Pouyanpi
Pouyanpi added this pull request to stack #2445 October 9, 2026 13:16
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Parse inspected streams line by line so mixed CR, LF, and CRLF endings
and terminators split across chunks frame correctly in linear time.
Strip one initial BOM for field parsing while keeping it in raw bytes.
Release complete SSE blocks only, drop unfinished comment tails, and
reject unfinished field blocks as truncated provider streams.

Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
@Pouyanpi
Pouyanpi force-pushed the pouyanpi/transparent-proxy-streaming-kernel-1 branch from cb9fb48 to 558d602 Compare October 9, 2026 13:22
@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA-NeMo/Guardrails/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 78bd4143-092c-4fcc-818f-56da00e60ccc

📥 Commits

Reviewing files that changed from the base of the PR and between 4512d08 and 558d602.


📒 Files selected for processing (9)
  • nemoguardrails/server/experimental/_content_checker.py
  • nemoguardrails/server/experimental/_guarded_stream.py
  • nemoguardrails/server/experimental/provider/sse.py
  • nemoguardrails/server/experimental/provider/stream.py
  • nemoguardrails/server/experimental/provider/stream_classifier.py
  • tests/server/experimental/test_content_checker.py
  • tests/server/experimental/test_guarded_stream.py
  • tests/server/experimental/test_sse.py
  • tests/server/experimental/test_stream_classifier.py

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



📝 Walkthrough

Walkthrough

This change adds configuration for buffering provider streams, parses and classifies server-sent events, and checks buffered text before releasing its original events. It also adds validation for stream contracts, limits, snapshots, failure outcomes, and source cleanup.

Changes

Guarded provider stream inspection

Layer / File(s) Summary
Stream buffering policy
nemoguardrails/server/experimental/_content_checker.py, tests/server/experimental/test_content_checker.py
Adds validated chunk and context sizes, a release setting, and optional buffering configuration on ContentInspectionPolicy. Tests cover valid and invalid policy values.
Byte-preserving SSE parsing
nemoguardrails/server/experimental/provider/sse.py, tests/server/experimental/test_sse.py
Adds event framing across byte chunks, preserves raw event bytes, exposes parsed data and event fields, and handles size limits and truncated input. Tests cover line endings, BOMs, comments, and large inputs.
Provider stream contracts and classification
nemoguardrails/server/experimental/provider/stream.py, nemoguardrails/server/experimental/provider/stream_classifier.py, tests/server/experimental/test_stream_classifier.py
Adds event roles, projection contracts, adapter protocols, and rule-based classification. Tests cover recognized events, text selection, discriminator types, and contract mismatches.
Guarded stream buffering and release
nemoguardrails/server/experimental/_guarded_stream.py, tests/server/experimental/test_guarded_stream.py
Adds event validation, buffered text-window checks, snapshot history checks, and outcome rendering. Tests cover event release, blocked output, error handling, limits, and source closure.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Source as Async byte source
  participant Guard as guard_provider_stream
  participant Parser as iter_sse_events
  participant Adapter as ProviderStreamAdapter
  participant Checker as ContentChecker
  participant Renderer as StreamOutcomeRenderer
  Source->>Guard: yield byte chunks
  Guard->>Parser: pass source chunks
  Parser-->>Guard: return parsed SSE events
  Guard->>Adapter: classify and validate events
  Adapter-->>Guard: return guarded stream events
  Guard->>Checker: check buffered text windows
  Checker-->>Guard: return check result
  Guard->>Renderer: render blocked or failed outcome
  Guard-->>Source: close async source
Loading

Merge Risk: ⚪ Minimal · up to 558d6

This change adds experimental guarded stream parsing and release logic that nothing yet uses, and no concrete merge-blocking issue was found.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.24% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 103 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Test Results For Major Changes Passed The PR contains major new stream execution and parsing features, but the description includes testing information: it states that applicable tests are included and notes that regression tests were par…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the main change: adding guarded provider-stream execution. It is concise and directly related to the pull request objectives and implementation.


  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Output checks receive one projected user input subject as context in both
buffered and streaming execution. Document that this is a provider-neutral
execution invariant rather than a restriction on provider conversation
roles, and that relaxing it needs matching bindings, checker semantics, and
execution tests, not only provider or profile declarations.

Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: XL status: triaged Triaged by a maintainer; eligible for automated review (CodeRabbit/Greptile).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant