[PR #365] [MERGED] Fix unstable message pagination cursor #4582

Closed
opened 2026-10-22 04:08:55 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/365
Author: @Xelvanis
Created: 5/3/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @SpicyMarinara

Base: main ← Head: fix/chat-branch-message-ordering


📝 Commits (1)

  • 7856e10 Fix unstable message pagination cursor

📊 Changes

4 files changed (+44 additions, -11 deletions)

View changed files

📝 packages/client/src/hooks/use-chats.ts (+5 -1)
📝 packages/client/src/hooks/use-generate.ts (+9 -5)
📝 packages/server/src/services/storage/chats.storage.ts (+28 -5)
📝 packages/shared/src/types/chat.ts (+2 -0)

📄 Description

When multiple messages share the same createdAt, using only the timestamp as a cursor can skip or duplicate messages. Include the message id as a tiebreaker in the cursor and add rowid-based ordering to keep pagination deterministic.

Linked issue

weh

Closes #

Why this change

  • Fixes unstable chat message ordering/pagination when multiple messages share the same createdAt timestamp, which could cause branch history pages to skip, duplicate, or misorder messages.

What changed

  • Changed chat message pagination cursors from timestamp-only to createdAt|id.
  • Added server-side cursor parsing and rowid tie-break ordering for stable message pagination.
  • Applied deterministic ordering to full message listing by sorting on createdAt plus rowid.
  • Re-sorted client-side optimistic and persisted generated message merges so newly inserted messages stay in chronological order.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Opened established chat with 47 messages, branched chats from #47, #45 and #15
  • All three confirmed to have correct message order and original timestamps from source chat.
  • Started fresh chat, exchanged messages until 20+ messages, branched from #23. All messages with correct order and timestamps.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced pagination stability when loading earlier messages in conversations.
    • Improved message ordering consistency throughout chat history.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/365 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/3/2026 **Status:** ✅ Merged **Merged:** 5/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `main` ← **Head:** `fix/chat-branch-message-ordering` --- ### 📝 Commits (1) - [`7856e10`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7856e108be2260d0855ed6c4e6ec5eef6046ea1f) Fix unstable message pagination cursor ### 📊 Changes **4 files changed** (+44 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/hooks/use-chats.ts` (+5 -1) 📝 `packages/client/src/hooks/use-generate.ts` (+9 -5) 📝 `packages/server/src/services/storage/chats.storage.ts` (+28 -5) 📝 `packages/shared/src/types/chat.ts` (+2 -0) </details> ### 📄 Description When multiple messages share the same `createdAt`, using only the timestamp as a cursor can skip or duplicate messages. Include the message id as a tiebreaker in the cursor and add `rowid`-based ordering to keep pagination deterministic. ## Linked issue weh Closes # ## Why this change - Fixes unstable chat message ordering/pagination when multiple messages share the same `createdAt` timestamp, which could cause branch history pages to skip, duplicate, or misorder messages. ## What changed - Changed chat message pagination cursors from timestamp-only to `createdAt|id`. - Added server-side cursor parsing and rowid tie-break ordering for stable message pagination. - Applied deterministic ordering to full message listing by sorting on `createdAt` plus `rowid`. - Re-sorted client-side optimistic and persisted generated message merges so newly inserted messages stay in chronological order. ## Validation - [X] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [X] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [X] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Opened established chat with 47 messages, branched chats from #47, #45 and #15 - All three confirmed to have correct message order and original timestamps from source chat. - Started fresh chat, exchanged messages until 20+ messages, branched from #23. All messages with correct order and timestamps. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) <!-- Add before/after screenshots or recordings for UI changes --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced pagination stability when loading earlier messages in conversations. * Improved message ordering consistency throughout chat history. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:08:55 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#4582
No description provided.