Skip to content

fix: preserve chat input when a prompt fails to send (#214)#226

Merged
agegr merged 1 commit into
agegr:mainfrom
shani-singh1:fix/214-preserve-input-on-connection-error
Jul 25, 2026
Merged

fix: preserve chat input when a prompt fails to send (#214)#226
agegr merged 1 commit into
agegr:mainfrom
shani-singh1:fix/214-preserve-input-on-connection-error

Conversation

@shani-singh1

Copy link
Copy Markdown
Contributor

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 calling onSend (fire-and-forget):

onSend(msg, attachedImages.length ? attachedImages : undefined);
clearInput();

onSend ultimately runs useAgentSession.handleSend, which calls ensureEventsConnected(...) before the prompt is dispatched. On failure it throws EventStreamConnectionError, 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 in executeBash, which already does:

opts.chatInputRef?.current?.insertIfEmpty(inputText);

insertIfEmpty only 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 --noEmit passes
  • eslint passes
  • Manual: trigger a prompt while the event stream can't connect → the "connection error" notice appears and the typed text remains in the input, ready to resend.

Notes / 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.

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
@agegr
agegr merged commit fdaf992 into agegr:main Jul 25, 2026
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.

After prompting and press enter, it says connection error and all the texts are gone

2 participants