Skip to content

fix(sidebar): one new chat, retargeted — stop spawning empty chats per agent click#4474

Open
vibegui wants to merge 2 commits into
mainfrom
vibegui/one-new-chat
Open

fix(sidebar): one new chat, retargeted — stop spawning empty chats per agent click#4474
vibegui wants to merge 2 commits into
mainfrom
vibegui/one-new-chat

Conversation

@vibegui

@vibegui vibegui commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Problem

Clicking back and forth between agents in the sidebar spawned a new empty "New chat" every time — the list filled up with duplicates. Root cause: useNavigateToAgent mints a fresh taskId on every click and the destination route eagerly creates that thread row (useEnsureTask).

Fix

There is only ever one new chat. If you're already sitting in an empty "New chat", clicking a different agent re-points that same thread at the new recipient (swaps the ?virtualmcpid the composer/run sends to) instead of creating another empty thread. It only starts a fresh chat when you're not already in one.

  • handleOpenAgent: when the active thread is an empty "New chat", reuse its taskId and set the recipient to the clicked agent (setTaskId), else navigateToAgent as before.
  • Active-agent highlight now derives from the URL virtualmcpid (falling back to the thread row), so it stays correct after an in-place retarget.
  • Extracted the shared isThreadEmpty check (also used by the new-thread button).

The send path already targets the URL param agent (agent: { id: capturedVirtualMcpId }), so retargeting an unsent chat routes the first message to the right agent.

Testing

  • tsc --noEmit clean, bun run lint clean, client build passes.
  • Manual: verify clicking agents A→B→A while in a new chat keeps a single "New chat" row and updates the recipient; sending lands the message with the last-selected agent.

🤖 Generated with Claude Code


Summary by cubic

Stops creating duplicate empty "New chat" threads when switching agents. Reuses the current unsent chat, retargets its recipient, and updates the thread row’s agent icon so only one new chat exists.

  • Bug Fixes
    • If the active thread is an empty "New chat", keep its taskId, retarget the recipient on agent click, and persist the new agent to the row (setAgentCOLLECTION_THREADS_UPDATE) so the sidebar icon follows; otherwise navigate as before.
    • Read active agent from the URL virtualmcpid (fallback to thread) to keep the sidebar highlight correct after retargeting. Uses useSearch from @tanstack/react-router.
    • Added virtual_mcp_id to ThreadUpdateDataSchema and storage/update mappings, ThreadManagerStore.setAgent and useThreadActions.setAgent, plus a shared isThreadEmpty check to verify unsent chats.

Written for commit 455da2c. Summary will update on new commits.

Review in cubic

vibegui and others added 2 commits July 11, 2026 22:44
…ent click

Clicking between agents created a brand-new empty "New chat" every time
(navigateToAgent minted a fresh taskId and the route eagerly created the row),
piling up empties. Now there's only ever one new chat: if you're already in an
empty "New chat", clicking a different agent re-points that same thread at the
new recipient (swaps the ?virtualmcpid the composer sends to) instead of
creating another. Only starts a fresh chat when you're not already in one.

Also derive the active-agent highlight from the URL virtualmcpid (falling back
to the thread row) so it stays in sync after an in-place retarget, and factor
the empty-thread check shared with the new-thread button.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Re-pointing an empty new chat now persists the new agent onto the thread row
(optimistically + via COLLECTION_THREADS_UPDATE), so the sidebar row icon
follows the agent you clicked instead of showing the create-time agent.

Adds virtual_mcp_id to ThreadUpdateDataSchema + the update tool/storage mapping,
and a ThreadManagerStore.setAgent method. The UI only calls it for unsent "New
chat" threads (guarded in handleOpenAgent).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant