[GH-ISSUE #2963] [Issue]: Swipe counter briefly shows wrong values (e.g. 3/2, or number leads the text) after regenerate or switch #1541

Closed
opened 2026-10-21 05:38:41 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2963

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The swipe counter can briefly show wrong values right after a regenerate or a swipe switch. Two transient, self-correcting glitches with the same flavor (the counter updates before the rest catches up):

  • After regenerating, the counter can flash a wrong total like 3/2 (the active index advanced, the total hasn't yet) before the background refetch fixes it to 3/3.
  • After switching swipes, the counter jumps instantly but the body text / reaction chips / thinking still show the previous swipe until the server round-trips — so on a slow backend the number leads the content.

Neither loses data, but both look broken, and during the 3/2 window the right-arrow can kick off another generation.

How to reproduce (try it yourself)

Wrong total after regen:

  1. Have an assistant message with 2 swipes (counter 2/2).
  2. Click Regenerate (or the "generate next swipe" arrow).
  3. Watch the counter the instant streaming finishes, before the background refetch lands.
    You'll see: it briefly shows 3/2, then self-corrects to 3/3.

Number leads body on switch:

  1. Have a message with multiple swipes whose contents differ.
  2. Throttle the network (or use a remote/slow backend).
  3. Click the next-swipe arrow.
    You'll see: the counter jumps to 2/3 instantly, but the body/reactions/thinking stay on swipe 1 for a moment before snapping over.
    Expected (both): the counter and the content/total change together.

Where it is

  • Wrong total: packages/server/src/services/storage/chats.storage.ts getMessage() (~705-708) returns no swipeCount (only getMessages/listMessagesPaginated decorate it); the regenerate snapshot is built via getMessage (generate.routes.ts:6958-6959), and the client merges {...existing, ...incoming} in mergeCachedGeneratedMessage (use-generate.ts ~419), so incoming (no swipeCount) leaves the stale total until refreshMessagesInBackground reconciles. SwipeJumpControl.tsx renders activeSwipeIndex + 1 against that stale total.
  • Number leads body: packages/client/src/hooks/use-chats.ts useSetActiveSwipe.onMutate (~1187-1189) spreads only { ...msg, activeSwipeIndex: index }; the swapped content/extra only arrive in onSuccess (~1199-1201). The body reads message.content/extra, so number and body desync until the PUT returns.

What's happening

Both are optimistic-update gaps: the index is advanced locally without the matching total (regen) or without the matching content/extra (switch), and the truth only lands on the server round-trip / background refetch.

Suggested fix

  • Decorate the message_saved snapshot with the current swipe count (e.g. swipeCount = (await getSwipes(id)).length) on the regen/swipe paths, or have getMessage() compute swipeCount like getMessages() does, so the merge updates the total.
  • In useSetActiveSwipe.onMutate, swap content + extra optimistically from the useSwipes cache, or defer the counter advance until onSuccess, so the number and body move together.

AI-investigated against v2.0.6; both optimistic paths read. Transient/no-data-loss; please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2963 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The swipe counter can briefly show wrong values right after a regenerate or a swipe switch. Two transient, self-correcting glitches with the same flavor (the counter updates before the rest catches up): - After **regenerating**, the counter can flash a wrong total like `3/2` (the active index advanced, the total hasn't yet) before the background refetch fixes it to `3/3`. - After **switching** swipes, the counter jumps instantly but the body text / reaction chips / thinking still show the previous swipe until the server round-trips — so on a slow backend the number leads the content. Neither loses data, but both look broken, and during the `3/2` window the right-arrow can kick off another generation. **How to reproduce (try it yourself)** Wrong total after regen: 1. Have an assistant message with 2 swipes (counter `2/2`). 2. Click Regenerate (or the "generate next swipe" arrow). 3. Watch the counter the instant streaming finishes, before the background refetch lands. **You'll see:** it briefly shows `3/2`, then self-corrects to `3/3`. Number leads body on switch: 1. Have a message with multiple swipes whose contents differ. 2. Throttle the network (or use a remote/slow backend). 3. Click the next-swipe arrow. **You'll see:** the counter jumps to `2/3` instantly, but the body/reactions/thinking stay on swipe 1 for a moment before snapping over. **Expected (both):** the counter and the content/total change together. **Where it is** - Wrong total: `packages/server/src/services/storage/chats.storage.ts` `getMessage()` (~705-708) returns no `swipeCount` (only `getMessages`/`listMessagesPaginated` decorate it); the regenerate snapshot is built via `getMessage` (`generate.routes.ts:6958-6959`), and the client merges `{...existing, ...incoming}` in `mergeCachedGeneratedMessage` (`use-generate.ts` ~419), so `incoming` (no `swipeCount`) leaves the stale total until `refreshMessagesInBackground` reconciles. `SwipeJumpControl.tsx` renders `activeSwipeIndex + 1` against that stale total. - Number leads body: `packages/client/src/hooks/use-chats.ts` `useSetActiveSwipe.onMutate` (~1187-1189) spreads only `{ ...msg, activeSwipeIndex: index }`; the swapped content/extra only arrive in `onSuccess` (~1199-1201). The body reads `message.content`/`extra`, so number and body desync until the PUT returns. **What's happening** Both are optimistic-update gaps: the index is advanced locally without the matching total (regen) or without the matching content/extra (switch), and the truth only lands on the server round-trip / background refetch. **Suggested fix** - Decorate the `message_saved` snapshot with the current swipe count (e.g. `swipeCount = (await getSwipes(id)).length`) on the regen/swipe paths, or have `getMessage()` compute `swipeCount` like `getMessages()` does, so the merge updates the total. - In `useSetActiveSwipe.onMutate`, swap `content` + `extra` optimistically from the `useSwipes` cache, or defer the counter advance until `onSuccess`, so the number and body move together. --- *AI-investigated against v2.0.6; both optimistic paths read. Transient/no-data-loss; please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in staging: optimistic swipe switches now move cached content/extra with the active index, and regenerated SSE merges preserve a sane swipe count. Validated with pnpm check and pnpm regression:prompt.

<!-- gh-comment-id:4830957649 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in staging: optimistic swipe switches now move cached content/extra with the active index, and regenerated SSE merges preserve a sane swipe count. Validated with pnpm check and pnpm regression:prompt.
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#1541
No description provided.