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.
This commit is contained in:
Raj Rasane
2026-04-02 10:26:06 +05:30
parent 9590066b5b
commit 310f1d344a

View File

@@ -124,6 +124,29 @@ export async function generateSessionTitle(
level: 'error', level: 'error',
}) })
logEvent('tengu_session_title_generated', { success: false }) 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)
}