Skip to content

Handle duplicate message UUIDs in Svelte MessageList #137

Description

@DrumRobot

Problem

A fatal Svelte runtime error occurs when viewing certain sessions in the Web UI:
Uncaught Error: https://svelte.dev/e/each_key_duplicate

This happens at MessageList.svelte because the Svelte {#each} block uses msg.uuid as the uniqueness key:

{#each messages as msg, i (msg.uuid ?? `idx-${i}`)}

When the underlying .jsonl session file contains multiple records with the same uuid (which can happen with file synchronization conflicts, repeated history appends, or edits across sessions), Svelte encounters duplicate keys and crashes the page (white screen).

Proposed Changes

Phase 1: UI Hotfix (Immediate Stability)

  • Modify MessageList.svelte to guarantee unique keys (final implementation: O(n) Set-based first-occurrence keying — preserves stable Svelte identity for the no-duplicate case, only deduplicates true duplicates) — merged in PR fix(web): prevent each_key_duplicate when JSONL has duplicate uuids #183 (commit 29876ad):
    {#each messages as msg, i (msg.uuid ? `${msg.uuid}-${i}` : `idx-${i}`)}

Phase 2: UI Duplicate Warning (Visibility)

  • In SessionViewer.svelte or MessageList.svelte, proactively scan the messages array for duplicate uuids.
  • If duplicates are found, render a non-intrusive warning banner at the top of the session view:

    Warning: This session file contains duplicate message entries. Please check the raw .jsonl file or run session repair.

Phase 3: Backend Deduplication (Data Integrity)

Verification

  • Construct a test fixture .jsonl with intentionally duplicated lines (same uuid).
  • Verify the Web UI loads normally without throwing each_key_duplicate.
  • Verify the backend deduplication correctly filters out the duplicated messages from the array returned by readSession.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions