feat: continue interrupted generation streams - #1339
Open
pjb157 wants to merge 3 commits into
Open
Conversation
Deploying control-layer with
|
| Latest commit: |
9b36fe0
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://17650663.control-layer.pages.dev |
| Branch Preview URL: | https://peter-stream-continuation.control-layer.pages.dev |
pjb157
force-pushed
the
peter/stream-continuation
branch
from
July 22, 2026 13:02
2c74d9c to
98027be
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in “stream continuation” mechanism to Onwards so interrupted SSE text-generation streams (Completions, Chat Completions, Responses) can be resumed by issuing a follow-up request (prefix-based) to another provider in the same pool, while preserving protocol identity and keeping retries bounded and configurable.
Changes:
- Introduces
stream_continuationconfiguration under poolfallback, including conservative defaults and eligibility checks by exact endpoint path. - Adds a checked SSE framer (
CheckedSseStream) plus parsing helpers to reliably frame events across mixed line endings and fragmentation, and to surface framing failures distinctly where needed. - Updates routing/handler logic to support post-header continuation, composite response policy, and sanitization adjustments (including legacy completion streaming sanitization).
Reviewed changes
Copilot reviewed 13 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| onwards/src/target.rs | Adds StreamContinuationConfig and wires it into FallbackConfig; merges response headers across pool/provider. |
| onwards/src/strict/handlers.rs | Routes strict endpoints through continuation-capable handler; updates SSE “data:” parsing tolerance and sanitization skip when preserving encoded streams. |
| onwards/src/stream_continuation.rs | Implements core continuation state machine: eligibility, event observation/rewrites, and composite stream retry loop. |
| onwards/src/sse.rs | Introduces CheckedSseStream, framing errors, and parse_sse_event for structured SSE parsing. |
| onwards/src/response_sanitizer.rs | Tightens event-stream content-type detection; adds legacy completion streaming sanitizer preserving choices[].text. |
| onwards/src/response_loop.rs | Minor cleanup in SSE event JSON parsing for loop deltas. |
| onwards/src/main.rs | Refactors tracer shutdown into a single if let ... && let Err(...) block. |
| onwards/src/load_balancer.rs | Adds reusable SelectionState and ProviderPool::select_next for caller-owned selection state. |
| onwards/src/handlers.rs | Adds continuation-aware forwarding core, composite response policy, canonical path metadata, SSE peek updates, and continuation body wrapping. |
| onwards/README.md | Documents stream continuation behavior, configuration, and limitations. |
| onwards/CHANGELOG.md | Notes new feature and the FallbackConfig API change. |
| onwards/Cargo.toml | Adds mime dependency. |
| dwctl/src/sync/onwards_config/mod.rs | Updates config conversion to set stream_continuation: None for the new field. |
| Cargo.lock | Lockfile update for mime. |
Comment on lines
+107
to
+111
| let data = match crate::sse::parse_sse_event(chunk) { | ||
| crate::sse::ParsedSseEvent::Comment => return SseEventKind::Comment, | ||
| crate::sse::ParsedSseEvent::Data { data, .. } => data, | ||
| crate::sse::ParsedSseEvent::Invalid => return SseEventKind::Data, | ||
| }; |
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
Testing
cargo test -p onwards --all-featurescargo clippy -p onwards --all-targets --all-features -- -D warningscargo fmt --all -- --checkcargo check -p dwctl --libcargo test -p dwctl sync::onwards_config --libmdbook build onwards/docs