Repository navigation
feat(server): execute guarded provider streams - #2434
Merged
Pouyanpi merged 16 commits intoOct 13, 2026
Merged
Conversation
This was referenced Oct 5, 2026
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Pouyanpi
force-pushed
the
pouyanpi/transparent-proxy-streaming-kernel-1
branch
from
October 6, 2026 11:05
4ec5c7f to
f4a6606
Compare
Pouyanpi
marked this pull request as ready for review
October 6, 2026 11:06
Contributor
|
Pouyanpi
force-pushed
the
pouyanpi/transparent-proxy-streaming-kernel-1
branch
2 times, most recently
from
October 8, 2026 17:52
9052700 to
cb9fb48
Compare
This was referenced Oct 8, 2026
Base automatically changed from
pouyanpi/openai-chat-buffered-integration-4
to
develop
October 9, 2026 13:16
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
force-pushed
the
pouyanpi/transparent-proxy-streaming-kernel-1
branch
from
October 9, 2026 13:22
cb9fb48 to
558d602
Compare
Contributor
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>
The SSE standard ignores one byte order mark at stream start. The parser treated a later line that starts with a BOM as an unknown field, so its event had no data and was released as opaque metadata without text checks. Some clients, including openai-node, strip a BOM at later line starts and read the line as a data field, so a provider could deliver text that output rails never inspected. Keep one stream-leading BOM. Reject any other line that starts with a BOM, including BOM-only lines and a second leading BOM, as an ambiguous event that fails the inspected stream closed. The check runs on complete lines, so it is independent of chunk boundaries and line endings. Uninspected relays are not parsed and are unaffected. Tests cover every chunk split, LF, CR, and CRLF endings, BOM-only lines, comments, unfinished tails, withheld events in the guarded stream, and a differential check that the OpenAI Python SDK decoder never yields data that this parser did not parse. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
JSON can encode an unpaired UTF-16 surrogate as an escape, and the JSON parser also accepts its CESU-8 bytes. Such text cannot be re-encoded as UTF-8, so the guarded stream failed with a generic processing error while counting text bytes. Treat guarded or snapshot text with an unpaired surrogate as an unsupported provider stream: no output check runs, pending events are withheld, and the error is rendered as a stream shape failure. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
A transparent proxy should not enforce Unicode validity that the provider and client do not. JSON escapes can produce lone surrogates, for example half of a pair split across deltas, and clients receive them as sent. The stream path now counts their bytes without failing, checks the text, and relays it unchanged. A checker that cannot handle such text still fails closed as a check failure. This replaces the earlier rejection. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
The Python SDK never strips a BOM, so comparing with it cannot catch the line-leading BOM differential. A small reader modelled on openai-node 7.31.0 strips a BOM at every line start; accepted streams must expose no data to it that this parser did not parse. Disabling the BOM rejection fails these cases. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
The classifier read guarded text from the validated projection, while the runner relays the original event bytes. A validator that changed, dropped or reordered the selected text would let the checker approve one string while the client received another. Text is now resolved from the raw payload before validation and compared afterwards; any difference fails closed. Null, missing and empty text keep their existing meaning. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Rule construction compared discriminators with Python equality, so rules for true and 1 were rejected as duplicates although runtime matching treats them as different values. Duplicate detection now uses the same exact type and value as matching. Array selection also stops treating a missing member as an explicit null. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
The guarded stream closed its source without a time limit, so a provider body whose close stalled could hang an otherwise complete response. Iterator and resource cleanup now share one helper: each attempt is shielded and bounded, and timeouts or ordinary close failures are logged instead of replacing the stream's outcome. Close failures were previously raised; this is deliberate, because cleanup must not mask a block, an upstream failure or a cancellation. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
…celled If closing the iterator raised cancellation, the separate resource closer was skipped and the upstream connection could stay open. The resource closer now runs in a finally block, so it is attempted however iterator cleanup ends. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
tgasser-nv
approved these changes
Oct 13, 2026
tgasser-nv
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, just a few items to address before merging:
- Could you add tests to get the patch coverage up?
- There are quite a few features the OpenAI Chat binding doesn't use.
StreamArraySelection,event_type_field,TEXT_SNAPSHOTwith the history check andmissing_text_value. Can you add tests to cover these while we're OpenAI only?
Stream failures reached the client as a native error event but left no record for operators. Each failure outcome is now logged once, where it is encoded: projection and framing rejections and unsupported modification requests as warnings with their stage and reason, upstream failures as warnings with the exception type, and checker or processing failures as errors with the exception attached. Blocks are ordinary checker decisions and are not logged here. Reasons describe shapes and never echo provider text. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
The OpenAI Chat binding exercises only part of the shared stream kernel. Synthetic rules now cover data-less events, the SSE event-type discriminator, exactly-one array selection, dotted match keys, missing text handling, text paths that do not reach a string, snapshot history beyond the verification limit, non-byte provider chunks, and every classifier definition and contract consistency check. No runtime behavior changes. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
Failure messages and tracebacks can carry provider or checked text, such as a duplicate JSON member name or a checker error. Log only the outcome type, stage and exception type. Signed-off-by: Pouyanpi <13303554+Pouyanpi@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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
Review Notes
Review release ordering, SSE ambiguity, bounds, byte preservation, and cancellation and cleanup. HTTP dispatch, provider grammar, and request preparation are supplied by later PRs.
AI Assistance
Checklist
Stack Position
Part 1 of 4.
developStack Context
Adds OpenAI Chat streaming above the merged buffered implementation on develop 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 develop → #2434 → #2435 → #2436 → #2437. The buffered foundation is merged; #2412 is closed.
Python declarations own field and event policy. Hooks are handwritten and created for each stream by the integration. The final PR exports the bound buffered and streaming policy for inspection; export never constructs runtime components. Concrete outbound HTTP, deployment configuration, and replacement execution land separately.
Review each PR against its listed base branch.
pouyanpi/transparent-proxy-streaming-kernel-1developpouyanpi/openai-chat-streaming-contract-2pouyanpi/transparent-proxy-streaming-kernel-1pouyanpi/transparent-proxy-streaming-http-3pouyanpi/openai-chat-streaming-contract-2pouyanpi/openai-chat-streaming-integration-4pouyanpi/transparent-proxy-streaming-http-3Summary by CodeRabbit