From 310f1d344ad10667f9738d3e459092cb9d52f1dd Mon Sep 17 00:00:00 2001 From: Raj Rasane Date: Thu, 2 Apr 2026 10:26:06 +0530 Subject: [PATCH] fix: provide local session title fallback for 3P providers When using non-Anthropic providers (Ollama, Gemini, Codex), the underlying call to queryHaiku for session title generation fails. Previously, this caused the catch block to return null, leaving the terminal tab permanently stuck on 'Claude Code'. Now, when the API call fails, we gracefully derive a title locally from the user's first message (first 7 words, sentence-cased), ensuring users still see a meaningful session title in their terminal tab. --- src/utils/sessionTitle.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/utils/sessionTitle.ts b/src/utils/sessionTitle.ts index 5a722c88..72ae8054 100644 --- a/src/utils/sessionTitle.ts +++ b/src/utils/sessionTitle.ts @@ -124,6 +124,29 @@ export async function generateSessionTitle( level: 'error', }) logEvent('tengu_session_title_generated', { success: false }) - return null + + // Fallback: derive a title locally from the user's first message. + // This ensures 3P providers (Ollama, Gemini, OpenAI) still get + // meaningful terminal titles when the Haiku API call is unavailable. + return localFallbackTitle(trimmed) } } + +/** + * Fallback local title generator for when the Haiku API is unavailable + * (e.g. when using third-party providers without an Anthropic API key). + */ +function localFallbackTitle(text: string): string | null { + const words = text.split(/\s+/).slice(0, 7) + if (words.length === 0) return null + + // Create a sentence-case string + let fallback = words.join(' ') + if (fallback.length > 50) { + fallback = fallback.substring(0, 49) + '…' + } + + if (fallback.length <= 3) return null + + return fallback.charAt(0).toUpperCase() + fallback.slice(1) +}