Skip to content

[Feature] Notify on connection failure and retry #39

Description

@b-re-w

Issue 1: Connection failures aren’t surfaced to users

When the WebSocket connect call fails, the client updates internal state with ChatState.Error, but the UI never displays this information, leaving users unaware of connection issues and without any retry path

Surface connection errors with a retry option

  • ChatViewModel (app/src/commonMain/kotlin/gemstone/framework/ui/viewmodel/ChatViewModel.kt)

    • Add a lastMessage: String? field to remember the most recent message.
    • Store lastMessage before each send attempt and add a retryLastMessage() function that reuses it.
  • ChatScreen (app/src/commonMain/kotlin/gemstone/framework/ui/compose/screen/chat/ChatScreen.kt)

    • Observe uiState.error; when non‑null, display a Snackbar or AlertDialog showing the error message.
    • Include a “Retry” button that calls ChatViewModel.retryLastMessage() and clears the error via ChatViewModel.clearError().
    • Provide a dismiss/close action to clear the error without retrying.

Issue 2: No user feedback on disconnection

ChatUiState tracks isConnected, and ChatViewModel updates it on ChatState.Disconnected, but the UI ignores this flag. Users receive no notice when the connection drops, so their inputs may fail silently

Notify users when disconnected and allow manual reconnection

  • ChatScreen (app/src/commonMain/kotlin/gemstone/framework/ui/compose/screen/chat/ChatScreen.kt)

    • Monitor uiState.isConnected; when false, show a persistent banner or Snackbar stating “Disconnected from server.”
    • Provide a “Reconnect” button that triggers ChatViewModel.retryLastMessage() or a new reconnect() method.
  • ChatViewModel (app/src/commonMain/kotlin/gemstone/framework/ui/viewmodel/ChatViewModel.kt)

    • Implement reconnect() to reinitialize the WebSocket session and resend lastMessage if present.
    • Clear the disconnection notice once ChatState.Connected is observed.

Testing

After implementing the above, verify that connection failures trigger the UI alert with a working retry button.

Disconnect the server to confirm the disconnection banner appears and that reconnecting restores functionality.

Notes

The retry logic assumes the last message can safely be resent; adjust as needed for idempotency or multi-step conversations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions