Skip to content

The agent that grows with you

fix(desktop): never lose a refused or failed steer's text (#68927)

brooklyn!8228bc0a1ecf
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 fb31b3f7d79..735448354d6 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
@@ -357,6 +357,32 @@ describe('useComposerSubmit busy-turn routing', () => {
expect(onSubmit).not.toHaveBeenCalled()
})
+ it('puts a refused steer back in the composer when there is no queue to hold it', async () => {
+ // A brand-new chat is busy while its first session.create is in flight but
+ // has no queue key yet. The steer clears the draft first, so a refusal must
+ // restore the words rather than drop the only copy (#68927).
+ const { hook, loadIntoComposer, onSteer } = renderSubmitHook({ busy: true, sessionKey: null, text: 'keep me' })
+ onSteer.mockResolvedValueOnce(false)
+
+ act(() => {
+ hook.result.current.submitDraft()
+ })
+
+ await waitFor(() => expect(loadIntoComposer).toHaveBeenCalledWith('keep me', []))
+ })
+
+ it('queues a steer whose redirect RPC fails instead of losing it', async () => {
+ const { hook, onSteer } = renderSubmitHook({ busy: true, text: 'still here' })
+ onSteer.mockRejectedValueOnce(new Error('request timed out: session.redirect'))
+
+ act(() => {
+ hook.result.current.submitDraft()
+ })
+
+ await waitFor(() => expect(getQueuedPrompts('stored-session').map(({ text }) => text)).toEqual(['still here']))
+ clearQueuedPrompts('stored-session')
+ })
+
it('queues a plain-text follow-up while the active turn is compacting', () => {
const { hook, onCancel, onSteer, onSubmit, queueCurrentDraft } = renderSubmitHook({
busy: true,
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 7339409ec24..cfd7c5521c7 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
@@ -308,11 +308,24 @@ export function useComposerSubmit({
triggerHaptic('submit')
clearDraft()
- void Promise.resolve(onSteer(text)).then(accepted => {
- if (!accepted && activeQueueSessionKey) {
+ // The draft is already cleared, so a refused or failed redirect must keep
+ // the only copy: queue it for the next turn, or restore it when there is no
+ // queue yet (a new chat is busy before its first session exists).
+ const keep = () => {
+ if (activeQueueSessionKey) {
enqueueQueuedPrompt(activeQueueSessionKey, { text, attachments: [] })
+ } else {
+ loadIntoComposer(text, [])
}
- })
+ }
+
+ void Promise.resolve(onSteer(text))
+ .then(accepted => {
+ if (!accepted) {
+ keep()
+ }
+ })
+ .catch(keep)
}
const queueDraft = () => {