perf: reduce async waterfalls in chat sync/save path#45
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7ee7175822
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| setMessages([]) | ||
| lastSavedMessagesRef.current = "" | ||
| if (chatSession) { | ||
| persistedMessageSignaturesRef.current.set(chatSession.id, []) |
There was a problem hiding this comment.
Defer signature reset until cloud clear succeeds
Setting the persisted signature cache to [] before chatService.clearMessages completes means a failed clear leaves old cloud rows intact but marks the session as empty locally. On the next save, the append-only path in useDebouncedCloudSave treats this as a new session and appends new messages without clearing, so previously cleared messages reappear in cloud history. This regression is triggered by transient Supabase failures during “Clear chat” and causes durable history corruption.
Useful? React with 👍 / 👎.
| } else if (previousSignatures.length === 0) { | ||
| // New session with no known cloud messages yet. | ||
| if (dbMessages.length > 0) { | ||
| await chatService.saveMessages(session.id, dbMessages) | ||
| didWrite = true |
There was a problem hiding this comment.
Treat uncached signatures as unknown cloud state
The previousSignatures.length === 0 branch assumes the cloud session has no persisted messages and performs append-only writes. That assumption is false when signature cache population was skipped (for example, getMessages fails after setChatSession during history load), so later saves can append a full local transcript onto an existing cloud transcript instead of replacing it. This introduces duplicate/out-of-order history after transient load failures.
Useful? React with 👍 / 👎.
This comment has been minimized.
This comment has been minimized.
|
Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.
|
d05fbe4 to
c97c56f
Compare
Summary
Closes #33
Note
Medium Risk
Changes the persistence algorithm for cloud chat messages; bugs could cause missed/duplicated writes or incorrect ordering across rapid edits/regenerations, though it retains a clear+rewrite fallback.
Overview
Reduces latency and write load in the chat sync/save path by tracking per-session message signatures and using them to append only new messages to Supabase when the conversation grows, falling back to
clearMessages+ full rewrite only when prior messages changed in-place.During cloud history load, session and diagram title updates are now queued and executed in parallel via
Promise.allSettled, and signature state is initialized/cleared on session load, new chat, and clear chat to keep incremental saves consistent across sessions.Written by Cursor Bugbot for commit c97c56f. This will update automatically on new commits. Configure here.