Skip to content

fix(chat): render floating chat messages in insertion order instead of timestamp sort#5647

Merged
waleedlatif1 merged 1 commit into
stagingfrom
worktree-canvas-chat-message-order
Jul 13, 2026
Merged

fix(chat): render floating chat messages in insertion order instead of timestamp sort#5647
waleedlatif1 merged 1 commit into
stagingfrom
worktree-canvas-chat-message-order

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes the canvas chat showing model output above the user message (regression from feat(platform): settings permissions, admin, billing attribution/concurrency lims #5545, which moved the user-message insert after handleRunWorkflow — both messages then landed in the same millisecond and the timestamp sort's tie-break rendered them reversed)
  • Chat store now appends messages so insertion order is conversation order; renderer and CSV export drop the wall-clock timestamp sort entirely
  • Persist bumped to v1 with a migration that reverses legacy newest-first arrays (also corrects pairs saved in the wrong order during the bug window)
  • Added store tests covering same-timestamp ordering, the 50-message cap, and the v0→v1 migration

Type of Change

  • Bug fix

Testing

Unit tests for store ordering, cap trimming, and persist migration; existing floating chat tests pass; typecheck clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 13, 2026 10:34pm

Request Review

@cursor

cursor Bot commented Jul 13, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Localized chat store ordering and UI display logic; migration only reverses persisted message arrays for existing users.

Overview
Fixes floating canvas chat showing the model reply above the user message when both messages share the same millisecond timestamp.

The chat store now appends new messages and trims with slice(-MAX_MESSAGES) so array order is conversation order. Persist is bumped to v1 with a migration that reverses legacy newest-first arrays in localStorage. The floating chat UI and CSV export no longer sort by timestamp—they rely on store order. Vitest coverage was added for same-timestamp ordering, the 50-message cap, and the v0→v1 migration.

Reviewed by Cursor Bugbot for commit abe6f50. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR changes floating chat history to use store insertion order. The main changes are:

  • Chat rendering now filters by workflow without timestamp sorting.
  • The chat store now appends new messages and trims the oldest entries.
  • CSV export now preserves the stored message order.
  • Persisted v0 chat history is migrated by reversing legacy newest-first arrays.
  • Store tests cover migration, same-timestamp ordering, and cap trimming.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The store write path, migration, renderer, and CSV export now follow the same ordering contract.
  • The new tests cover the main ordering and trimming cases introduced by the change.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/chat/chat.tsx Removes timestamp sorting from the workflow message selector so rendering follows store order.
apps/sim/stores/chat/store.ts Changes message insertion and trimming to chronological store order, updates CSV export, and adds the persisted-state migration.
apps/sim/stores/chat/store.test.ts Adds tests for legacy migration, same-timestamp insertion order, and the 50-message cap.

Reviews (1): Last reviewed commit: "fix(chat): render floating chat messages..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 8e5dc40 into staging Jul 13, 2026
18 checks passed
@waleedlatif1 waleedlatif1 deleted the worktree-canvas-chat-message-order branch July 13, 2026 22:45
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.

1 participant