Skip to content

perf: reduce async waterfalls in chat sync/save path#45

Merged
charlesrhoward merged 1 commit intomainfrom
codex/feat-33-reduce-chat-sync-waterfalls
Feb 21, 2026
Merged

perf: reduce async waterfalls in chat sync/save path#45
charlesrhoward merged 1 commit intomainfrom
codex/feat-33-reduce-chat-sync-waterfalls

Conversation

@charlesrhoward
Copy link
Contributor

@charlesrhoward charlesrhoward commented Feb 21, 2026

Summary

  • parallelize independent title update calls during cloud history load
  • introduce per-session message signatures to track saved prefixes
  • use append-only cloud saves when history grows, with clear+rewrite fallback only when message history changes in place

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.

@vercel
Copy link

vercel bot commented Feb 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drawit Ready Ready Preview, Comment Feb 21, 2026 10:22pm

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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, [])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +238 to +242
} 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@cursor

This comment has been minimized.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issue.

@cursor
Copy link

cursor bot commented Feb 21, 2026

Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

  • ✅ Fixed: Fallback save failure causes duplicate messages on retry
    • On save failures we now mark the session for forced full resync so the next retry clears and rewrites messages instead of appending duplicates after partial commits.

@charlesrhoward charlesrhoward force-pushed the codex/feat-33-reduce-chat-sync-waterfalls branch from d05fbe4 to c97c56f Compare February 21, 2026 22:21
@charlesrhoward charlesrhoward merged commit 8706863 into main Feb 21, 2026
4 checks passed
@charlesrhoward charlesrhoward deleted the codex/feat-33-reduce-chat-sync-waterfalls branch February 21, 2026 22:30
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.

Performance: Reduce async waterfalls in chat sync/save path

1 participant