claudecodeui icon indicating copy to clipboard operation
claudecodeui copied to clipboard

fix: dedupe realtime messages before render

Open CoderLuii opened this issue 7 months ago • 3 comments

Summary

  • upsert equivalent realtime messages instead of blindly appending them
  • dedupe realtime messages against persisted server messages when computing the merged session view

Testing

  • validated in HolyClaude integration flow while reproducing duplicate message and duplicate thinking-state rendering

Summary by CodeRabbit

  • Bug Fixes
    • Improved real-time message deduplication with a more robust equivalence comparator that accounts for multiple identifier types and fallback mechanisms, ensuring more reliable duplicate detection and message update handling across batches.

CoderLuii avatar Apr 04 '26 08:04 CoderLuii

📝 Walkthrough

Walkthrough

Updates message deduplication in the session store from simple ID equality to a sophisticated equivalence comparison that considers multiple identifier fields (id, rowid, sequence, requestId, toolId) with special handling for user messages and session creation events.

Changes

Cohort / File(s) Summary
Message Deduplication Logic
src/stores/useSessionStore.ts
Added isEquivalentNormalizedMessage() comparator supporting fallback matching via id, rowid+kind, sequence+kind, requestId+kind, and toolId+kind; implemented upsertRealtimeMessage() to replace existing equivalent messages or append new ones; refactored appendRealtime and appendRealtimeBatch to use upsert instead of simple append, enabling deduped batch processing.

Suggested reviewers

  • viper151
  • blackmammoth

Poem

🐰 Hops with glee through deduplicated streams, No more duplicate dreams in our message beams, With fallbacks so clever and comparisons deep, Your session store now keeps messages neat and unique! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: implementing deduplication of realtime messages before rendering, which matches the core objective of preventing duplicate message and thinking-state rendering.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Apr 04 '26 08:04 coderabbitai[bot]

Superseded by the refreshed PR update posted on June 15, 2026.

The old branch head in this comment was 7e75eb9. The PR has since been rebased against current main and replaced by 480e7d4.

Current update: https://github.com/siteboon/claudecodeui/pull/616#issuecomment-4711066243

CoderLuii avatar May 28 '26 09:05 CoderLuii

Hey @CoderLuii, there has been a ton of changes since this PR. Can you check if the PR is still relevant? If so, can you share a detailed reproduction step for the issue this PR attempts to fix.

blackmammoth avatar May 31 '26 11:05 blackmammoth

@blackmammoth yes, this is still relevant, and I refreshed the PR against current main.

Sorry for the earlier update being too thin and for leaving the noisy release-notes block in the PR body. I should have included the reproduction trail when I refreshed the branch.

This PR came from CoderLuii/HolyClaude#29, reported by @mikkelnl. The report was not that Claude answered twice. The UI rendered the same flow twice: each sent user message appeared twice with about a one-second timestamp gap, and the Thinking state appeared twice as two response blocks. The actual Claude response appeared once.

The reported setup was HolyClaude full/latest on a Raspberry Pi 5 ARM64 host, clean data directory, direct local IP access, Safari and Chrome both reproducing it. The reproduction was: deploy the image, open the web UI, create a CloudCLI account/session, send any message, then observe duplicate user rows and duplicate Thinking rows.

HolyClaude shipped the downstream fix in v1.1.9 because users were hitting it in the image. That release vendored a patched CloudCLI build and called out the realtime chat dedupe fix in the release notes. This PR now upstreams that same class of fix into claudecodeui.

What changed in this refresh:

I rebased the branch onto current main and removed the noisy release-notes block from the PR body.

The fix stays in the session store. Realtime messages now upsert against stable identities, and messages already represented by server history are skipped before they can count against the realtime buffer.

I also covered the weaker Thinking shape from the HolyClaude report: same-session, same-text Thinking rows about a second apart now collapse even when neither row has rowid or sequence. That fallback does not run when either row has rowid or sequence, and it stays away from broad requestId or toolId matching, so separate tool and permission events do not get collapsed.

I refreshed dependencies with npm ci, then ran typecheck, lint, build, and the targeted realtime/session-store check. The commands completed successfully.

The targeted check covers duplicate user rows, duplicate Thinking rows with and without row/sequence identity, older same-text Thinking rows staying separate, different-sequence Thinking rows staying separate, server-backed realtime rows being skipped before they count against the buffer, capped-buffer behavior, and distinct tool/permission events staying separate.

Current commit: 480e7d4

CoderLuii avatar Jun 15 '26 18:06 CoderLuii

Hey @CoderLuii, this should be fixed with the latest releases. Lmk if the issue is still recurrent tho.

blackmammoth avatar Jun 24 '26 07:06 blackmammoth