Skip to content

[BUG] Streaming "thought" events are mixed directly into visible message content #749

Description

@vipul674

Description of the Bug

In frontend/src/components/chat/ChatPanel.tsx, when the streaming endpoint sends a thought event type, the message content is appended directly to the visible chat bubble:

if (event.type === "thought") {
    setCurrentAnswer(prev => prev + `\n[thought] ${event.data}`);
}

When subsequent token events arrive (the actual answer), the thought text becomes permanently embedded within the visible response. The user sees something like:

[thought] The user is asking about the revenue figures from the Q3 report. I need to search the document for relevant data.
Based on the document, the Q3 revenue was $4.2 million...

This is confusing because:

  • The thought process should be visually distinct from the final answer
  • The [thought] prefix looks like a debug artifact
  • Thoughts can be lengthy (paragraphs of reasoning) and clutter the response
  • There is no way for the user to hide or expand thoughts

Steps to Reproduce

  1. Start a chat session and ask a complex question
  2. The streaming response includes intermediate thought steps
  3. Observe that thoughts and the final answer are mixed together in the same text bubble
  4. The [thought] prefix is displayed to the user as plain text

Expected Behavior

Thought events should be displayed separately from the answer, for example in:

  • A collapsible "Show reasoning" section above the answer
  • A separate UI element with a subtle style (smaller font, muted color)
  • A separate pane or drawer

Affected File

frontend/src/components/chat/ChatPanel.tsx (lines ~329-336)

Suggested Fix

Store thoughts in a separate field/state and render them distinctly:

// Separate states
const [thoughts, setThoughts] = useState<string[]>([]);
const [currentAnswer, setCurrentAnswer] = useState("");

// Handler
if (event.type === "thought") {
    setThoughts(prev => [...prev, event.data]);
} else if (event.type === "token") {
    setCurrentAnswer(prev => prev + event.data);
}

Render thoughts in a collapsible section above the answer.

GSSoC '26

  • Yes, I am participating in GirlScript Summer of Code and would like to fix this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssocGirlScript Summer of Code 2026 issue/PR

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions