Skip to content

The agent that grows with you

fix(desktop): re-queued external sends keep their identity and land in the created session; billing card matches its provider

kshitijk4poorb1d7c5b296d4
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
index c43b4f8b98b..38039e5935f 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.test.tsx
@@ -293,9 +293,40 @@ describe('useComposerSubmit external request routing', () => {
expect(getQueuedPrompts('stored-session').map(({ text, attachments }) => ({ text, attachments }))).toEqual(
accepted ? [] : [{ text: 'continue', attachments: [] }]
)
+
+ if (!accepted) {
+ // Same message, same identity: the rejection may follow an uncertain delivery the owner dedupes by id.
+ const [, options] = onSubmit.mock.calls[0] as unknown as [string, { submission_id: string }]
+ expect(getQueuedPrompts('stored-session')[0]?.id).toBe(options.submission_id)
+ }
}
)
+ it('queues a rejected external request from a new chat under the session it was created in', async () => {
+ const { onSubmit } = renderSubmitHook({ busy: false, sessionKey: '__new__:fresh-draft' })
+
+ const submit = onSubmit as unknown as ReturnType<
+ typeof vi.fn<(text: string, options?: { onComposerScopeAssigned?: (scope: string) => void }) => Promise<boolean>>
+ >
+
+ submit.mockImplementation(async (_text, options) => {
+ options?.onComposerScopeAssigned?.('created-session')
+
+ return false
+ })
+
+ try {
+ await act(async () => {
+ expect(requestComposerSubmit('continue', { target: 'main' })).toBe(true)
+ })
+
+ await waitFor(() => expect(getQueuedPrompts('created-session').map(({ text }) => text)).toEqual(['continue']))
+ expect(getQueuedPrompts('__new__:fresh-draft')).toEqual([])
+ } finally {
+ clearQueuedPrompts('created-session')
+ }
+ })
+
it('does not fan out a main ship across keep-alives or other projects', async () => {
const visibleMain = renderSubmitHook({ sessionKey: 'session-a' })
const hiddenMain = renderSubmitHook({ sessionKey: 'session-b', visible: false })
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
index 351786d203a..c6551bc80ca 100644
--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.ts
@@ -133,7 +133,7 @@ export function useComposerSubmit({
attachments?: ComposerAttachment[],
displayKind?: 'hidden',
target?: Parameters<ChatBarProps['onSubmit']>[1],
- onRejected?: () => void
+ onRejected?: (scope: string | null, submissionId: string) => void
) => {
// A fresh chat's composer is keyed by its per-lifecycle fresh-draft key
// (`__new__:<uuid>`), but the submit contract spells "no session yet" as
@@ -184,7 +184,9 @@ export function useComposerSubmit({
// typed), so a rejection drops it instead of loading it into the draft. An
// external request brings its own (it never took the draft, so it must not
// overwrite it).
- const rejected = onRejected ?? (displayKind ? () => {} : restore)
+ // The callback gets the scope the send ended up in (a new chat's session.create may have
+ // re-homed it) and this send's identity, so a re-queued request is the same message.
+ const rejected = onRejected ? () => onRejected(restoreScope, submissionId) : displayKind ? () => {} : restore
// A synchronous throw takes the rejection path too: the caller has already cleared the
// composer, so a send that fails while it is being prepared must not take the words with it.
@@ -241,13 +243,26 @@ export function useComposerSubmit({
const queueKey = activeQueueSessionKeyRef.current
// External requests contain only text; the unsent draft and its attachments stay in the composer.
- const enqueue = () =>
- void enqueueQueuedPrompt(queueKey, { text, attachments: [], ...(displayKind ? { displayKind } : {}) })
+ const enqueue = (key: string | null = queueKey, id?: string) =>
+ void enqueueQueuedPrompt(key, {
+ text,
+ attachments: [],
+ ...(id ? { id } : {}),
+ ...(displayKind ? { displayKind } : {})
+ })
if (!current.busy) {
// Explicitly no attachments: the send must not pick up the draft's files. A rejected
- // visible request goes to the queue (sendable, editable), never over the user's draft.
- current.dispatchSubmit(text, [], displayKind, undefined, displayKind ? () => {} : enqueue)
+ // visible request goes to the queue (sendable, editable), never over the user's draft:
+ // under its own submission id (a rejection can follow an uncertain delivery, and the
+ // owner dedupes by id) and in the scope the send landed in.
+ current.dispatchSubmit(
+ text,
+ [],
+ displayKind,
+ undefined,
+ displayKind ? () => {} : (scope, id) => enqueue(scope ?? queueKey, id)
+ )
return
}
@@ -262,7 +277,7 @@ export function useComposerSubmit({
enqueue()
}
})
- .catch(enqueue)
+ .catch(() => enqueue())
} else {
enqueue()
}
@@ -282,7 +297,7 @@ export function useComposerSubmit({
enqueue()
}
})
- .catch(enqueue)
+ .catch(() => enqueue())
} else {
enqueue()
}
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
index 5cb36cb012e..0e35a6d5524 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.test.tsx
@@ -554,6 +554,37 @@ describe('error card layout (Error System Overhaul)', () => {
}
})
+ it('never retargets an older card at a later wall from another provider in the same chat', async () => {
+ openExternalLink.mockClear()
+ const { $activeSessionId } = await import('@/store/session')
+ const { clearBillingBlock, setBillingBlock } = await import('@/store/billing-block')
+ $activeSessionId.set('wall-session')
+ setBillingBlock('wall-session', {
+ billing_url: 'https://platform.openai.com/settings/organization/billing',
+ is_nous: false,
+ message: 'out of credits',
+ model: 'gpt-5',
+ provider: 'openai',
+ provider_label: 'OpenAI'
+ })
+
+ try {
+ render(
+ <MemoryRouter>
+ <Harness
+ assistant={failedMessage({ code: 'billing', layer: 'billing', provider: 'nous', retryable: false })}
+ />
+ </MemoryRouter>
+ )
+
+ fireEvent.click(await screen.findByRole('button', { name: en.assistant.thread.errorOpenBillingSettings }))
+ expect(openExternalLink).not.toHaveBeenCalled()
+ } finally {
+ clearBillingBlock()
+ $activeSessionId.set(null)
+ }
+ })
+
it("never sends a third-party provider's credit failure to Nous billing without its billing link", async () => {
render(
<MemoryRouter>
diff --git a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
index 3e25d491c22..a46dbc0ed92 100644
--- a/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
+++ b/apps/desktop/src/components/assistant-ui/thread/assistant-message.tsx
@@ -1098,6 +1098,9 @@ const textButton = (className: string, onClick: () => void, label: ReactNode) =>
// Out of credits runs the same recovery as the banner and toast: the failing provider's own
// billing page (Nous → Settings → Billing). A plan limit is Nous billing. Without this chat's
// billing descriptor Hermes doesn't know where a third-party provider bills, so no button.
+const sameProvider = (a?: string | null, b?: string | null) =>
+ Boolean(a && b && a.trim().toLowerCase() === b.trim().toLowerCase())
+
const OpenBillingAction: FC<{ className: string; label: string; surface?: ErrorSurface }> = ({
className,
label,
@@ -1105,7 +1108,16 @@ const OpenBillingAction: FC<{ className: string; label: string; surface?: ErrorS
}) => {
const runtimeId = useStore(useSessionView().$runtimeId)
const wall = useStore($billingBlock)
- const block = surface?.code !== 'usage_window' && wall?.sessionId === runtimeId ? wall.block : null
+
+ // This chat's wall, and only for the provider this card failed on: a later wall from another
+ // provider in the same chat must not retarget an older card.
+ const block =
+ surface?.code !== 'usage_window' &&
+ wall?.sessionId === runtimeId &&
+ sameProvider(wall.block.provider, surface?.provider)
+ ? wall.block
+ : null
+
const nousBilling = surface?.code === 'usage_window' || (surface?.provider || 'nous').toLowerCase() === 'nous'
if (!block && !nousBilling) {