The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): defer credential-warning onboarding to the first chat attempt
Teknium6bb8f60f5721
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.tsindex 67f13044c4f..a4439a7122a 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/submit.ts@@ -20,7 +20,7 @@ import {} from '@/store/composer'import { $hudMode } from '@/store/hud'import { clearNotifications, notify, notifyError } from '@/store/notifications'-import { requestDesktopOnboarding } from '@/store/onboarding'+import { consumePendingCredentialWarning, requestDesktopOnboarding } from '@/store/onboarding'import {$sessions,resolveComposerSessionKey,@@ -180,6 +180,23 @@ export function useSubmitPrompt(deps: SubmitPromptDeps) {stopVoicePlayback()}+ // The gateway already told us this profile has no usable provider (a+ // credential warning arrived with the session's runtime info, deferred+ // instead of popping onboarding on the mere profile switch). The user+ // is now actually trying to chat — THIS is the moment to open+ // onboarding, before a send the gateway said will fail. The draft+ // stays in the composer; once a provider is configured they just hit+ // Enter again.+ if (!options?.fromQueue) {+ const deferredCredentialWarning = consumePendingCredentialWarning()++ if (deferredCredentialWarning) {+ requestDesktopOnboarding(deferredCredentialWarning)++ return false+ }+ }+// Barged mid-speech (here or via the voice loop's VAD)? Flag the submit// so the backend notes the interruption to the model.const interrupted = takeVoicePlaybackInterrupted()diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.tsindex 79b6f41952c..d6dd5c85d2b 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts@@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'import { textWithoutReferenceLines, WIRE_REFERENCE_KINDS } from '@/components/assistant-ui/reference-kinds'import { type ChatMessage, type ChatMessagePart, chatMessageText } from '@/lib/chat-messages'import { $approvalModes, approvalModeForProfile } from '@/store/approval-mode'-import { $desktopOnboarding } from '@/store/onboarding'+import { $desktopOnboarding, consumePendingCredentialWarning } from '@/store/onboarding'import { $activeGatewayProfile } from '@/store/profile'import {$currentBranch,@@ -73,25 +73,41 @@ const initialOnboardingState = $desktopOnboarding.get()describe('applyRuntimeInfo credential warnings', () => {beforeEach(() => {+ consumePendingCredentialWarning()$desktopOnboarding.set({ ...initialOnboardingState, reason: null, requested: false })})afterEach(() => {+ consumePendingCredentialWarning()$desktopOnboarding.set(initialOnboardingState)})- it('requests setup for the exact empty-key warning returned by the server', () => {+ it('defers the empty-key warning to submit time instead of popping onboarding on switch', () => {const warning = "No API key configured for provider 'openrouter'. First message will fail."applyRuntimeInfo({ credential_warning: warning })- expect($desktopOnboarding.get()).toMatchObject({ reason: warning, requested: true })+ // Merely switching to (or activating a session on) the unconfigured+ // profile must NOT open the blocking overlay…+ expect($desktopOnboarding.get()).toMatchObject({ reason: null, requested: false })+ // …but the warning is staged for the submit path to consume.+ expect(consumePendingCredentialWarning()).toBe(warning)+ // Consuming clears it — the next submit doesn't double-fire.+ expect(consumePendingCredentialWarning()).toBeNull()+ })++ it('a warning-free session event clears the stash (profile healed or switched away)', () => {+ applyRuntimeInfo({ credential_warning: "No API key configured for provider 'openrouter'. First message will fail." })+ applyRuntimeInfo({ model: 'gpt-5' })++ expect(consumePendingCredentialWarning()).toBeNull()})it('ignores an auxiliary-provider warning', () => {applyRuntimeInfo({ credential_warning: 'OPENROUTER_API_KEY not set' })expect($desktopOnboarding.get()).toMatchObject({ reason: null, requested: false })+ expect(consumePendingCredentialWarning()).toBeNull()})})diff --git a/apps/desktop/src/store/onboarding.ts b/apps/desktop/src/store/onboarding.tsindex 3043d3245ef..3c40c543382 100644--- a/apps/desktop/src/store/onboarding.ts+++ b/apps/desktop/src/store/onboarding.ts@@ -390,14 +390,38 @@ export function requestDesktopOnboarding(reason = DEFAULT_ONBOARDING_REASON) {patch({ reason: reason.trim() || DEFAULT_ONBOARDING_REASON, requested: true })}+/** Credential warning delivered passively (session create/activate/resume+ * runtime info, stream heartbeats) — e.g. right after switching to a+ * profile that has no provider configured. Popping the blocking onboarding+ * overlay here punishes merely LOOKING at an unconfigured profile, so the+ * warning is deferred instead: stashed until the user actually tries to+ * chat, where the submit path consumes it and opens onboarding before the+ * doomed send. The latest warning wins; a session event without a warning+ * clears the stash (the profile became configured, or the user switched+ * back to a healthy one). */+let pendingCredentialWarning: null | string = null+export function requestDesktopOnboardingForCredentialWarning(reason: null | string | undefined) {const warning = reason?.trim()if (!warning || !isProviderSetupErrorMessage(warning)) {+ pendingCredentialWarning = null+return}- requestDesktopOnboarding(warning)+ pendingCredentialWarning = warning+}++/** Submit-time gate: returns the deferred credential warning (and clears it)+ * so the caller can open onboarding instead of sending a prompt that the+ * gateway already said will fail. Null when the active profile is healthy. */+export function consumePendingCredentialWarning(): null | string {+ const warning = pendingCredentialWarning++ pendingCredentialWarning = null++ return warning}// Open the onboarding provider selector on demand from an already-configured