fix: preserve chat input when a prompt fails to send (#214)#226
Merged
agegr merged 1 commit intoJul 25, 2026
Merged
Conversation
When sending a prompt fails because the event stream cannot be connected, useAgentSession already rolls back the optimistic user message, but the input box was cleared by ChatInput immediately after onSend, so the typed text was lost and had to be retyped after a retry. Restore the message text into the input on EventStreamConnectionError, mirroring the existing shell-command recovery in executeBash. insertIfEmpty is used so anything typed in the meantime is not clobbered. Fixes agegr#214
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
Fixes #214.
When a prompt fails to send because the agent event stream can't be connected, the UI shows a "connection error" notice and the typed message is lost — the user has to retype everything before retrying.
Root cause
In
ChatInput.handleSend, the input is cleared immediately after callingonSend(fire-and-forget):onSendultimately runsuseAgentSession.handleSend, which callsensureEventsConnected(...)before the prompt is dispatched. On failure it throwsEventStreamConnectionError, and the catch block already rolls back the optimistic user message — but by then the input has already been cleared, so the text is gone.Fix
Restore the message text into the input when the send fails with
EventStreamConnectionError, in the same block that rolls back the optimistic message. This mirrors the existing shell-command recovery path inexecuteBash, which already does:insertIfEmptyonly restores when the input is empty, so anything the user has typed since is never clobbered. The prompt genuinely never reached the agent in this path, so restoring is safe.Testing
tsc --noEmitpasseseslintpassesNotes / scope
Scoped intentionally to the connection-error rollback path that issue #214 describes. Restoring attached images is out of scope (the imperative handle only exposes text restore); only the text is preserved, which is what the issue asks for.