Skip to content

Chat history silently truncates when localStorage hits browser quota #4

Description

@zhaojingyu2

Hey, I ran into a confusing bug while playing with the agent chat UI. I had a long conversation going (maybe 50–60 turns with some image attachments), and at some point new messages started "disappearing" — they'd render briefly, then on refresh the latest few would be gone.

After poking around, I think I found the cause in Frontend/js/agent-chat/store.js:18:

function writeAll(list) {
    localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

When localStorage.setItem exceeds the per-origin quota (usually 5MB or 10MB depending on browser), it throws a QuotaExceededError. Since there's no try/catch around the call, the exception bubbles up — but in the React render path it may be caught and silently logged somewhere harmless. The result is that the in-memory state has the new message but the persisted state doesn't, so a refresh "loses" it.

A few things would help here:

  1. Wrap setItem in a try/catch and on quota errors, prune the oldest N messages and retry.
  2. Surface a user-visible warning ("conversation getting long, oldest messages may be dropped").
  3. Consider switching to IndexedDB for the chat history — it has a much larger quota and proper async semantics.

Happy to take a stab at (1) and (2) if maintainers agree. Not sure about appetite for (3).

Reproduction: open the chat UI, send messages with large image attachments until you hit ~5MB of serialized JSON.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions