Add stream interruption support (truncateAfterChunks, disconnectAfterMs, AbortSignal)#24
Merged
Add stream interruption support (truncateAfterChunks, disconnectAfterMs, AbortSignal)#24
Conversation
commit: |
744b57a to
5ed8b5c
Compare
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.
5ed8b5c to
dfb279e
Compare
- 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)
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
truncateAfterChunksanddisconnectAfterMsfixture fields to simulate mid-stream server disconnectscreateInterruptionSignal, signal-awaredelay())writeSSEStreamoverload withStreamOptionsreturning completion statusdestroy()method onWebSocketConnectionfor abrupt disconnect simulationinterruptedandinterruptReasonon interrupted streamsTest plan
pnpm buildcleanpnpm run format:checkcleanpnpm run lintclean🤖 Generated with Claude Code