Skip to content

Desktop: chat timeline shows messages out of order with concurrent sessions (empty session_id in terminal events) #86890

Description

@yangchangjiang

Bug Report: Desktop chat timeline shows messages out of chronological order (concurrent sessions on same profile)

Environment

  • Hermes desktop app (Electron), Windows 10
  • Provider: DeepSeek (deepseek-v4-pro), profile: default
  • Multiple concurrent sessions on the same profile (main chat + other chat sessions + cron jobs)

Symptom

In the desktop chat view, messages appear out of chronological order. A message the user just sent appears ABOVE older messages ("刚才问的,怎么排在上面了"). The user reports this happens repeatedly ("老是时间线对不上"), and as a workaround they re-send messages — which produces duplicates in the DB.

Evidence gathered from state.db + logs (2026-08-15)

  1. Duplicate user messages from UI confusion: in one session (20260808_162500_414ff7), the same user message appears many times: 再次审计 x18, 报告发下 x5, 审计下carbrands x5. The user confirms they re-sent messages because the UI displayed them at wrong positions.

  2. Empty session_id in terminal events: desktop.log contains 2,305 JSON-RPC events of type agent.terminal.output with "session_id": "" (empty string). Terminal output from background processes is emitted without session attribution; if the renderer keys its message store by session_id, these events can land in whichever session view is active/rendered, causing messages from other sessions (and their tool outputs) to appear inside the current conversation.

  3. Concurrent interleaved sessions: at 17:16–18:00, three sessions were writing to the shared messages table simultaneously (20260623_233846_232bb8, 20260808_162500_414ff7, 20260708_225453_563966). One of them received a [CONTEXT COMPACTION] event at 17:16:53 while the user was chatting in another. The DB itself is correctly ordered by rowid/timestamp — the disorder is in the desktop renderer's view, not the store.

  4. The session in question (20260623_233846_232bb8) is a long-running session (June 23 → Aug 15) with multiple compactions; the wrong-order symptoms correlate with compaction events and concurrent session activity.

Likely root cause areas (to investigate)

  • agent.terminal.output events with empty session_id being dispatched to the active session view (or a shared store) instead of being dropped or routed by process_id.
  • Renderer re-sorting messages by timestamp where second-level precision ties are broken unstably (several message pairs share the same second: e.g. rows 282813/282814 at 18:05:40, 282815/282816 at 18:05:50).
  • Compaction notifications from one session triggering re-render/replay in another session's view.
  • Out-of-band user messages (delivered mid-turn while the agent is streaming) being re-inserted at the wrong index on history replay.

Impact

  • User cannot trust the conversation timeline; repeated re-sending pollutes sessions with duplicates.
  • Risk of the model answering based on a wrongly-ordered context (e.g. stale "PV不准" appearing before a later question), degrading multi-session workflows.

Repro steps (approximate)

  1. Open 2+ sessions on the same profile in the desktop app, one running long tool chains (background terminal processes emitting output).
  2. Let one session trigger a context compaction while the other is streaming.
  3. Send messages in quick succession (<1s apart) in the active session.
  4. Observe messages landing above older ones / tool output from the other session appearing in the wrong view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/sessionsSession lifecycle, resume, persistence, historycomp/desktopElectron desktop app (apps/desktop/*)sweeper:risk-session-stateSweeper risk: may lose/corrupt/mis-associate session or context statetype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions