Skip to content

Add stream interruption support (truncateAfterChunks, disconnectAfterMs, AbortSignal)#24

Merged
jpr5 merged 9 commits intomainfrom
feat/streaming-interruption
Mar 11, 2026
Merged

Add stream interruption support (truncateAfterChunks, disconnectAfterMs, AbortSignal)#24
jpr5 merged 9 commits intomainfrom
feat/streaming-interruption

Conversation

@jpr5
Copy link
Contributor

@jpr5 jpr5 commented Mar 11, 2026

Summary

  • New truncateAfterChunks and disconnectAfterMs fixture fields to simulate mid-stream server disconnects
  • AbortSignal-based interruption primitives (createInterruptionSignal, signal-aware delay())
  • Backward-compatible writeSSEStream overload with StreamOptions returning completion status
  • Interruption threaded through all 7 streaming paths: HTTP SSE (completions, responses, messages, gemini) and WebSocket (responses, realtime, gemini-live)
  • destroy() method on WebSocketConnection for abrupt disconnect simulation
  • Journal records interrupted and interruptReason on interrupted streams
  • LLMock convenience API extended with interruption options
  • Completed streaming items removed from Future Direction

Test plan

  • 29 new tests across interruption, sse-writer, server, ws-responses, ws-realtime, ws-gemini-live
  • Red-green verified: broke code → tests fail → restored → tests pass
  • All 468 tests passing (was 429)
  • pnpm build clean
  • pnpm run format:check clean
  • pnpm run lint clean
  • Backward compatible — no breaking changes to existing API

🤖 Generated with Claude Code

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 11, 2026

Open in StackBlitz

npm i https://pkg.pr.new/CopilotKit/llmock/@copilotkit/llmock@24

commit: b58a4ad

@jpr5 jpr5 force-pushed the feat/streaming-interruption branch from 744b57a to 5ed8b5c Compare March 11, 2026 20:05
jpr5 added 6 commits March 11, 2026 13:46
Add InterruptionControl interface and createInterruptionSignal() for
truncateAfterChunks and disconnectAfterMs support. Update writeSSEStream
to accept StreamOptions with signal/onChunkSent and return boolean
indicating completion. Export shared delay() with AbortSignal support.
Plumb createInterruptionSignal through all HTTP SSE handlers (server.ts,
responses.ts, messages.ts, gemini.ts). Each provider's SSE writer now
accepts signal/onChunkSent and returns boolean. Extend LLMock convenience
API with truncateAfterChunks/disconnectAfterMs opts. Pass through new
fields in fixture-loader.
Add destroy() to WebSocketConnection for abrupt disconnects.
Thread interruption signals through all three WS handlers
(ws-responses, ws-realtime, ws-gemini-live) so truncateAfterChunks
and disconnectAfterMs work for WebSocket streams the same way
they do for HTTP SSE streams.
@jpr5 jpr5 force-pushed the feat/streaming-interruption branch from 5ed8b5c to dfb279e Compare March 11, 2026 20:47
jpr5 added 3 commits March 11, 2026 14:00
- truncateAfterChunks: 0 aborts on first tick
- disconnectAfterMs: 0 aborts promptly
- delay() with pre-aborted signal resolves immediately
- fixture-loader passes through interruption fields
- Tool call interruption via OpenAI /v1/chat/completions
- Claude /v1/messages with truncateAfterChunks and disconnectAfterMs
- Gemini streamGenerateContent with truncateAfterChunks
- Responses API /v1/responses with truncateAfterChunks
- WS Responses API tool call truncation
- WS Realtime API tool call truncation (nested arg chunking loop)
- WS Gemini Live tool call truncation (atomic frame)
@jpr5 jpr5 merged commit 47dfd64 into main Mar 11, 2026
8 checks passed
@jpr5 jpr5 deleted the feat/streaming-interruption branch March 11, 2026 21:02
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.

1 participant