🤖 feat: implement soft-interrupts with block boundary detection #583
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.
Overview
Implement soft-interrupts that allow graceful stream termination at content block boundaries instead of immediately aborting mid-content. When the user presses Escape the first time, the UI shows "⏸️ Interrupting..." and the stream completes at the next block boundary. Second Escape triggers immediate hard abort.
Architecture
Flow
interruptStream()IPC, backend setssoftInterruptPending = truesoftInterruptPending: trueflagStreamingContext.softInterruptPending = truesoftInterruptPendingfrom aggregatorabortController.abort()triggers graceful shutdownstream-endwith all completed contentSecond Escape → Backend sees flag already set, does immediate hard abort (existing behavior)
Changes
Frontend:
StreamingContextinterface withsoftInterruptPending: booleanfieldgetSoftInterruptPending()method toStreamingMessageAggregatorhandleStreamDelta()to handlesoftInterruptPendingflag from eventsWorkspaceStateinterface withsoftInterruptPendingfieldgetWorkspaceState()to derive flag from aggregatorStreamingBarrierto show "⏸️ Interrupting..." when pendingsoftInterruptPendingprop through AIView to StreamingBarrierBackend:
WorkspaceStreamInfointerface withsoftInterruptPending: booleanfieldstopStream()to implement soft/hard interrupt logic:stream-deltawith flagcancelStreamSafely()checkSoftInterrupt()helper methodprocessStreamWithCleanup():reasoning-endtool-resulttool-errorfinish-step,text-end,tool-input-endTypes:
StreamDeltaEventwith optionalsoftInterruptPendingfieldBenefits
stream-deltaevent infrastructure (~75 LoC)isCompactingflag patternTesting
Manual testing via UI:
Integration tests added in
tests/ipcMain/softInterrupt.test.ts:Generated with
mux