The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a file removed from a given-back draft drops its retry identity
Tekniumd79513a395d7
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 8318a7b84b5..a53f6f5d604 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@@ -533,6 +533,29 @@ export function useComposerDraft({}, DRAFT_PERSIST_DEBOUNCE_MS)}+ // A file removed from (or added to) a restored draft makes it a new message too. Dropping the+ // identity here, not at the next load, matters: a reload legitimately loses a draft's files, so a+ // later load cannot tell a removal from that and would resend the removed file under the old id.+ useEffect(+ () =>+ attachmentScope.$attachments.listen(attachments => {+ const retry = draftRetryRef.current++ if (+ !retry ||+ queueEditRef.current ||+ isBrowsingHistory(sessionIdRef.current) ||+ retry.attachmentIds.join('\n') === retryAttachmentIds(attachments).join('\n')+ ) {+ return+ }++ draftRetryRef.current = undefined+ writeDraftRetry(draftScopeRef.current, undefined)+ }),+ [attachmentScope, queueEditRef]+ )+const scheduleDraftPersistRef = useRef(scheduleDraftPersist)scheduleDraftPersistRef.current = scheduleDraftPersistdiff --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 3e039bc0db8..252f21dc62e 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@@ -55,6 +55,7 @@ vi.mock('@assistant-ui/react', () => ({interface Handles {attach: (id: string) => void+ detach: (id: string) => voideditor: () => stringsubmitDraft: () => void}@@ -111,6 +112,7 @@ async function openPage(onSubmit: ChatBarProps['onSubmit'], pending: unknown[] =useLayoutEffect(() => {handles = {attach: id => mainComposerScope.add({ id, kind: 'url', label: id, refText: `@url:${id}` }),+ detach: id => mainComposerScope.remove(id),editor: () => composerPlainText(draft.editorRef.current!).trim(),submitDraft: submit.submitDraft}@@ -375,3 +377,24 @@ it('equal words typed again after an interrupted send are a new message, never tawait act(async () => handles.submitDraft())expect(reopened.mock.calls[0][1]?.submission_id).not.toBe(firstId)}, 30_000)++it('a file removed from a given-back draft is never resent under the old send', async () => {+ saveDraft('trimmed words')++ const timedOut = vi.fn<ChatBarProps['onSubmit']>(async () => {+ throw new Error('request timed out')+ })++ await openPage(timedOut)+ act(() => handles.attach('example.com/c'))+ await act(async () => handles.submitDraft())+ await waitFor(() => expect(handles.editor()).toBe('trimmed words'))+ act(() => handles.detach('example.com/c'))+ closeWindow()++ const reopened = vi.fn<ChatBarProps['onSubmit']>(async () => true)+ await openPage(reopened)+ await act(async () => handles.submitDraft())+ expect(reopened.mock.calls[0][1]?.submission_id).not.toBe(timedOut.mock.calls[0][1]?.submission_id)+ expect(await attachmentsNotice()).toBeUndefined()+}, 30_000)