FIX: Sending Queued Messages Lost When Clicking "Send Now" During Streaming #126
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
SESSION_EXPIREDerror) that occurred when aborting a stream and immediately starting a new message — the backend was resuming with an invalidated session ID saved by the cleanup handlerarePropsEqualinChatInputAreamissingqueueLength,firstQueueItemId, andonSendFromQueue, causing stale closures when queue state changedChanges
active-chat.tsxwaitForStreamingReady()helper that subscribes to Zustand store instead of polling withsetTimeout— includes a 30s safety timeout to prevent indefinite hangshandleSendFromQueuein try-catch; on failure, requeue the item viaprependItemso it is never losthandleForceSendsend call in try-catch; on failure, restore editor content viasetValueso the user can retrysetTimeoutpolling loops in bothhandleSendFromQueueandhandleForceSendwith the event-drivenwaitForStreamingReadyfetch('/api/agents/chat')DELETE calls fromhandleStopand keyboard handler (no REST server exists in Electron)ipc-chat-transport.tssessionInvalidatedflag set on abort to prevent the transport from reading a stalesessionIdfrom the last assistant message's metadataAgentMessageMetadatacast instead ofas anyfor metadata accesscancel.mutate()from abort handler — session cleanup is now handled server-sideclaude.tssessionIdfrom DB on abort (sessionId: abortController.signal.aborted ? null : metadata.sessionId) in both the error catch block and normal save blocksessionIdin the cleanup handler (unsubscribe callback) — only clearstreamIdsessionIdfrom DB when no active controller exists (handles the case where cleanup already removed fromactiveSessions)chat-input-area.tsxqueueLength,firstQueueItemId, andonSendFromQueuetoarePropsEqualto prevent stale closuresTest plan
SESSION_EXPIREDerror appears after the new message starts