Skip to content

[D-26] Empty assistant message persists when stream is aborted before first token #39

@rz1989s

Description

@rz1989s

Discovered during Sprint 4.2b Chrome MCP verification (PR for #23 + #24).

Issue

When the user submits a query, useChat.ts:131-150 pushes BOTH the user message AND an empty assistant message into the conversation array BEFORE streaming starts. If the stream is then aborted (via the in-input stop button, or via switchConversation/deleteConversation), the empty assistant message stays in the conversation array forever.

Visible in production: opening any old chat shows orphan K avatars with no content beside them — one per aborted stream.

Repro

  1. Open https://kami.rectorspace.com
  2. Submit any query
  3. Click the stop button BEFORE the first token arrives (~2s window)
  4. Observe: the user message stays visible; an orphan K avatar persists alongside it
  5. Switch to another conversation and back — the orphan stays

Suggested fix (needs brainstorm)

Two reasonable approaches, neither obviously correct without more thought:

  • A: Delete the empty assistant message on abort. Simple but loses the breadcrumb that "the user asked X but it was interrupted."
  • B: Replace the empty content with a placeholder string (e.g., "Stream interrupted.") so the row remains visually meaningful. Slightly more work; preserves history.

Files

  • src/hooks/useChat.ts:131-150 (push empty assistant message)
  • src/hooks/useChat.ts:86-90 (switchConversation aborts)
  • src/hooks/useChat.ts:100-118 (deleteConversation aborts)
  • src/hooks/useChat.ts:300-303 (stopStreaming)

Effort

~1-2h once the brainstorm picks an approach.

Tracked by

Not part of the 2026-04-26 QA umbrella (#3) — discovered later. Stand-alone issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions