Skip to content

Commit d21ff4e

Browse files
fix(core): guard session auto-title against empty names
A persist without uiMessages (turn finalize / compaction) hit the "New Session" branch with an empty first-user-text, so the generated title was "" and permanently overwrote the default name. Skip empty/whitespace titles so the name stays "New Session" until a persist with real messages regenerates it. Also move resolveTextAdapter() inside the try/catch to avoid unhandled rejections.
1 parent d6cd5d3 commit d21ff4e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

packages/core/src/managers/services/session-service.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ export class SessionService {
8484
input: Pick<SessionPersistInput, "usage" | "resolveTextAdapter">
8585
): Promise<string> {
8686
const { usage, resolveTextAdapter } = input;
87-
const textAdapter = (await resolveTextAdapter?.()) ?? null;
88-
if (!textAdapter) return userMessage.slice(0, 50);
8987
try {
88+
const textAdapter = (await resolveTextAdapter?.()) ?? null;
89+
if (!textAdapter) return userMessage.slice(0, 50);
9090
const { text, usage: queryUsage } = await runSideTextQuery(textAdapter, {
9191
systemPrompt:
9292
"Generate a concise title (3-8 words) for a conversation that starts with the following message. Return ONLY the title, no quotes or punctuation.",
@@ -178,7 +178,12 @@ export class SessionService {
178178
const firstUserText = getFirstUserInput(uiMessages || []);
179179
this.generateSessionTitle(firstUserText, { usage, resolveTextAdapter }).then((title) => {
180180
if (this.data) {
181-
this.data.name = title;
181+
// Skip empty/whitespace titles (e.g. a no-uiMessages persist passes an
182+
// empty first user text) so the name stays "New Session" and a later
183+
// persist with real messages can regenerate it.
184+
const trimmed = title.trim();
185+
if (!trimmed) return;
186+
this.data.name = trimmed;
182187
// Reuse the unified save path so a title-write failure also emits
183188
// `session:save-error` (target "session-title").
184189
void this.saveToStore(emitEvent, "session-title");

0 commit comments

Comments
 (0)