fix(native): name new chats instantly from the first message - #415
Merged
Conversation
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>
This was referenced Jul 1, 2026
claudiusthebot
added a commit
that referenced
this pull request
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:setSessionName, but the native chat registry's in-memorytitlewas not updated and nochat_updatedevent 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 thechat_updatedbroadcast that already follows pushes it live to every connected client.Changes
chats.ts: exportDEFAULT_CHAT_TITLEso the guard shares one constant.index.ts: addmaybeAutoTitle(), call it fromemitUser().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. Fulltsc --noEmitclean.π€ Generated with Claude Code