Skip to content

feat: continue interrupted generation streams - #1339

Open
pjb157 wants to merge 3 commits into
mainfrom
peter/stream-continuation
Open

feat: continue interrupted generation streams#1339
pjb157 wants to merge 3 commits into
mainfrom
peter/stream-continuation

Conversation

@pjb157

@pjb157 pjb157 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add opt-in post-response continuation for interrupted Completions, Chat Completions, and Responses streams
  • preserve protocol identity, sanitization, provider selection, and bounded retry state across continuation attempts
  • document configuration and operational limits while keeping generated deployment configs disabled by default

Testing

  • cargo test -p onwards --all-features
  • cargo clippy -p onwards --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • cargo check -p dwctl --lib
  • cargo test -p dwctl sync::onwards_config --lib
  • mdbook build onwards/docs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploying control-layer with  Cloudflare Pages  Cloudflare Pages

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

View logs

@pjb157
pjb157 force-pushed the peter/stream-continuation branch from 2c74d9c to 98027be Compare July 22, 2026 13:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_continuation configuration under pool fallback, 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 thread onwards/src/handlers.rs
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,
};
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.

2 participants