Skip to content

fix(native): name new chats instantly from the first message - #415

Merged
claudiusthebot merged 1 commit into
mainfrom
fix/companion-instant-chat-title
Jul 1, 2026
Merged

fix(native): name new chats instantly from the first message#415
claudiusthebot merged 1 commit into
mainfrom
fix/companion-instant-chat-title

Conversation

@claudiusthebot

Copy link
Copy Markdown
Collaborator

Problem

New chats stayed on the "New chat" placeholder for a long time (Dylan flagged this from the companion app β€” chats "get stuck on being called New chat for quite some time").

Root cause

The session name is already derived for free β€” extractSessionName() just trims the first user message, no model call. But it was:

  1. Set too late β€” only at the end of the first turn, inside the backend handler.
  2. Never propagated β€” written to storage via setSessionName, but the native chat registry's in-memory title was not updated and no chat_updated event fired. Connected clients kept showing "New chat" until a restart re-hydrated the persisted name from storage.

Fix

Derive the title the instant the first user message lands (in emitUser): update the in-memory entry + persist via the existing rename path, then the chat_updated broadcast that already follows pushes it live to every connected client.

  • Guarded so it only fires while the chat still carries the placeholder β€” a user's manual rename is never clobbered.
  • Still zero model usage β€” this is the cheapest possible path (no Haiku/GPT-mini call needed for the baseline title; a nicer LLM-generated short title can land as a separate follow-up).

Changes

  • chats.ts: export DEFAULT_CHAT_TITLE so the guard shares one constant.
  • index.ts: add maybeAutoTitle(), call it from emitUser().
  • native-frontend.test.ts: cover the placeholder-only guard and the no-usable-text (sticker/attachment) case.

Test

npx vitest run src/__tests__/native-frontend.test.ts β†’ 13 passed. Full tsc --noEmit clean.

πŸ€– Generated with Claude Code

New chats sat on the "New chat" placeholder for far too long. The
session name was only derived (a free trim of the first user message β€”
no model call) at the *end* of the first turn inside the backend
handler, written straight to storage. The native chat registry's
in-memory title was never updated and no chat_updated event fired, so
connected clients kept showing "New chat" until a restart re-hydrated
the persisted name.

Derive the title the moment the first user message lands, in emitUser:
update the in-memory entry and persist via the existing rename path,
then the chat_updated broadcast that already follows propagates it live
to every client. Guarded so it only fires while the chat still carries
the placeholder, so a user's manual rename is never clobbered. Still
zero model usage.

- chats.ts: export DEFAULT_CHAT_TITLE so the guard shares one constant
- index.ts: add maybeAutoTitle(), call it from emitUser()
- tests: cover the placeholder-only guard and the no-usable-text case

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