Skip to content

[Bug] An unsubmitted chat message is lost when the page reloads after the session expires #662

Closed

Description

@kayahk

Problem

A chat message that has been typed but not sent does not survive a page reload. When the browser session expires — Paca bounces the tab through sign-in and the user reloads — everything in the composer is gone, however long the message and however much context went into it. Only messages that were already sent survive, because those are persisted server-side; a new conversation whose first message was never submitted leaves no trace at all.

Reproduction, on any long-lived tab:

  1. Open a project's floating agent chat (or /conversations) and start a new conversation.
  2. Type a message, don't send it.
  3. Leave the tab open until the session lapses, then reload (or let the sign-in bounce do it).
  4. The composer is empty. Nothing of the draft remains.

This applies to every composer in the app — project floating chat, global floating chat, the new-conversation page and a conversation page — because they all render the same thread composer.

Why the reload is not the thing to fix

Paca already refreshes its own token silently: apps/web/src/lib/api-client.ts intercepts a 401, POSTs /auth/refresh, and replays the queued request, so an expired access token never reaches the user. What forces a full reload is the layer above that — an expired refresh token, or a deployment identity proxy / SSO session — and no SPA code can keep itself alive across a full-document sign-in redirect. So the reload cannot be made to not happen from inside Paca; it can be made non-destructive.

Proposal

Persist the composer's current text in sessionStorage and restore it when the composer mounts empty:

  • apps/web/src/lib/composer-draft.ts — key/load/save helpers, keyed by pathname. Storage access is wrapped: a disabled or full storage must never break the composer or sending.
  • apps/web/src/components/assistant-ui/thread.tsx — a useComposerDraft hook used by the thread composer, which every chat surface shares, so one place covers all four of them.
  • The draft is cleared as soon as the composer empties, i.e. after a successful send, so a sent message can't reappear as a ghost draft.

sessionStorage rather than localStorage: a draft only has to outlive a reload in this tab, and a prompt should not be left on disk after the tab is gone. Keying by pathname keeps each page's draft separate and makes the restore land on exactly the URL the re-auth bounce returns to.

Not covered

  • Attached context chips (annotation/mention badges) live in an in-memory store and are not restored; only the text is.
  • A floating panel's open conversation still resets on reload — the conversation itself is not lost (it stays in the Conversations list), only the panel's selection.

Acceptance criteria

  • Text typed into any chat composer is restored after reloading the same page.
  • Sending a message clears the stored draft; no ghost drafts reappear.
  • Emptying the composer manually clears it too.
  • Drafts on different pages stay separate.
  • Unavailable storage (private mode, policy) neither throws nor blocks sending.
  • A unit test covers the round-trip and the clear-on-empty case.

Activity

  1. pullfrog commented on Oct 29, 2026

    @pullfrog
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions