The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a restored send keeps its id after a reload and on the Steer action
Tekniuma681f7c7303a
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.tsindex c4a98411bb4..c51ea3544e5 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-draft.ts@@ -21,6 +21,7 @@ import {import {type ComposerDraftRetry,draftRetryTextMatches,+ loadedDraftRetry,matchingDraftRetry,readDraftRetry,retryAttachmentIds,@@ -693,6 +694,7 @@ export function useComposerDraft({const { attachments, text } = takeSessionDraft(activeQueueSessionKey)savedDraftRef.current = savedDraft(text, attachments)+ draftRetryRef.current = loadedDraftRetry(draftRetryRef.current, text, attachments)loadIntoComposer(text, attachments, true)// Takes back a draft that is still exactly `retry`'s send under its identity.@@ -771,9 +773,9 @@ export function useComposerDraft({}reloadPersistedDrafts()- draftRetryRef.current = readDraftRetry(draftScopeRef.current)const stashed = takeSessionDraft(draftScopeRef.current)savedDraftRef.current = savedDraft(stashed.text, stashed.attachments)+ draftRetryRef.current = loadedDraftRetry(readDraftRetry(draftScopeRef.current), stashed.text, stashed.attachments)loadIntoComposer(stashed.text, stashed.attachments)}diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsxindex 028e49a6063..7554f2a920e 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-submit.send-then-close.test.tsx@@ -263,6 +263,28 @@ it('an interrupted send with attachments comes back once, under its id, even wheawait waitFor(() => expect(outboxKeys()).toEqual([]))await act(async () => {})expect(handles.editor()).toBe('')+ closeWindow()+ window.localStorage.clear()++ // A send whose outcome is unknown (timed out) is given back with its id; after a reload the saved+ // draft has its words but not its attachment, and Enter on it still retries that send.+ saveDraft('unknown words')++ const timedOut = vi.fn<ChatBarProps['onSubmit']>(async () => {+ throw new Error('request timed out')+ })++ await openPage(timedOut)+ act(() => handles.attach('example.com/b'))+ await act(async () => handles.submitDraft())+ await waitFor(() => expect(handles.editor()).toBe('unknown words'))+ closeWindow()++ const retried = vi.fn<ChatBarProps['onSubmit']>(async () => true)+ await openPage(retried)+ expect(handles.editor()).toBe('unknown words')+ await act(async () => handles.submitDraft())+ expect(retried.mock.calls[0][1]?.submission_id).toBe(timedOut.mock.calls[0][1]?.submission_id)})it('a restored send retried while a turn runs is queued under its id, never steered as a new message', async () => {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.tsindex d7619d9e143..58ea5e56f58 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@@ -535,6 +535,14 @@ export function useComposerSubmit({// tool boundary. If the turn already ended, queue the words instead.const steerDraft = (mode: 'interrupt' | 'steer' = 'interrupt') => {const text = draftRef.current.trim()+ // The Steer action on a restored send: queued under its id like a busy Enter (see queueRetry).+ const retry = attachments.length ? undefined : takeDraftRetry?.(draftRef.current, [])++ if (retry) {+ queueRetry(retry)++ return+ }// Guard on live editor state, not the render-lagged `canSteer`: a redirect// fired on a fast Enter must not be dropped because state hasn't synced.diff --git a/apps/desktop/src/store/composer-draft-retry.ts b/apps/desktop/src/store/composer-draft-retry.tsindex 77e70c72cfd..d26e93a8e49 100644--- a/apps/desktop/src/store/composer-draft-retry.ts+++ b/apps/desktop/src/store/composer-draft-retry.ts@@ -40,6 +40,19 @@ export function matchingDraftRetry(: undefined}+/** The identity a loaded draft carries. The draft store persists text only, so a draft that comes+ * back after the page died has lost its attachments: its identity then names exactly what is+ * offered (the words), and Enter on it is still the explicit retry instead of a new message. */+export function loadedDraftRetry(+ retry: ComposerDraftRetry | undefined,+ text: string,+ attachments: ComposerAttachment[]+): ComposerDraftRetry | undefined {+ return retry && attachments.length === 0 && retry.attachmentIds.length > 0 && draftRetryTextMatches(retry, text)+ ? { ...retry, attachmentIds: [] }+ : retry+}+/** The storage key of a draft scope, the same resolution the draft stash uses. */const scopeKey = (scope: string | null | undefined) => scope?.trim() || freshDraftScope()