@devries-cameron20 / t3code Mirror · read-only / commits / 7b4c4b423c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 14:30 UTC

refactor(web): the upload queue alone records finished file uploads on drafts (#26050)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 27, 2026 at 11:19 UTC 7b4c4b423c2fddfcc8bb829860df8eea69c0be08
3 files changed +33 -34
apps/web/src/components/chat/ChatComposer.tsx
-32
@@ -811,7 +811,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
811 const removeComposerDraftImage = useComposerDraftStore((store) => store.removeImage);
812 const addComposerDraftFiles = useComposerDraftStore((store) => store.addFiles);
813 const removeComposerDraftFile = useComposerDraftStore((store) => store.removeFile);
814 - const setComposerDraftFileUpload = useComposerDraftStore((store) => store.setFileUpload);
814 const insertComposerDraftTerminalContext = useComposerDraftStore(
815 (store) => store.insertTerminalContext,
816 );
@@ -880,37 +879,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
879 supportsAttachmentUploads,
880 ]);
881
883 - useEffect(() => {
884 - for (const file of composerFiles) {
885 - if (
886 - !attachmentUploadsCapabilityKnown ||
887 - !supportsAttachmentUploads ||
888 - maxFileAttachmentBytes === null ||
889 - file.sizeBytes > maxFileAttachmentBytes
890 - ) {
891 - continue;
892 - }
893 - const upload = uploadsByImageId[file.id];
894 - if (upload?.status === "ready" && upload.environmentId === environmentId) {
895 - setComposerDraftFileUpload(
896 - attachmentDraftTarget,
897 - file.id,
898 - environmentId,
899 - upload.attachmentId,
900 - );
901 - }
902 - }
903 - }, [
904 - attachmentUploadsCapabilityKnown,
905 - attachmentDraftTarget,
906 - composerFiles,
907 - environmentId,
908 - maxFileAttachmentBytes,
909 - setComposerDraftFileUpload,
910 - supportsAttachmentUploads,
911 - uploadsByImageId,
912 - ]);
913 -
882 const {
883 providerInstanceEntries,
884 selectedProviderEntry,
apps/web/src/lib/attachmentUploadQueue.test.ts
+26
@@ -379,6 +379,32 @@ describe("attachmentUploadQueue", () => {
379 }
380 });
381
382 + it("stamps a file that lands in a draft after its upload finished", async () => {
383 + const draftId = DraftId.make("draft-restored-upload");
384 + const file = makeFile("restored");
385 + try {
386 + startAttachmentUpload({ environmentId: firstEnvironment, image: file, draftTarget: draftId });
387 + await Promise.resolve();
388 + const settled = awaitAttachmentUploads([file.id]);
389 + TestXmlHttpRequest.requests[0]!.complete();
390 + await settled;
391 +
392 + useComposerDraftStore.getState().addFiles(draftId, [file]);
393 + startAttachmentUpload({ environmentId: firstEnvironment, image: file, draftTarget: draftId });
394 +
395 + expect(TestXmlHttpRequest.requests).toHaveLength(1);
396 + expect(useComposerDraftStore.getState().getComposerDraft(draftId)?.files).toMatchObject([
397 + {
398 + id: file.id,
399 + uploadedAttachmentId: "pending-environment-1-restored.pdf",
400 + uploadEnvironmentId: firstEnvironment,
401 + },
402 + ]);
403 + } finally {
404 + useComposerDraftStore.getState().clearComposerContent(draftId);
405 + }
406 + });
407 +
408 it("turns an expired persisted file into a marker that a re-pick can replace", async () => {
409 const draftId = DraftId.make("draft-expired-upload");
410 const file: ComposerFileAttachment = {
apps/web/src/lib/attachmentUploadQueue.ts
+7 -2
@@ -57,6 +57,8 @@ interface UploadJob {
57 stopWatchingConnection: () => void;
58 }
59
60 +type DraftFileOwner = Pick<UploadJob, "image" | "environmentId" | "draftTarget">;
61 +
62 const jobsByImageId = new Map<string, UploadJob>();
63 const queue: UploadJob[] = [];
64 const activeUploadsByEnvironment = new Map<EnvironmentId, number>();
@@ -82,7 +84,7 @@ export function readAttachmentUpload(imageId: string): AttachmentUploadState | u
84 return useAttachmentUploadStore.getState().uploadsByImageId[imageId];
85 }
86
85 -function resolveCurrentFileDraftTarget(job: UploadJob): ComposerThreadTarget | undefined {
87 +function resolveCurrentFileDraftTarget(job: DraftFileOwner): ComposerThreadTarget | undefined {
88 if (job.draftTarget === undefined || job.image.type !== "file") {
89 return undefined;
90 }
@@ -110,7 +112,7 @@ function resolveCurrentFileDraftTarget(job: UploadJob): ComposerThreadTarget | u
112 }
113
114 /** Persist background completions even when no composer is mounted. */
113 -function stampDraftFileUpload(job: UploadJob, attachmentId: string): void {
115 +function stampDraftFileUpload(job: DraftFileOwner, attachmentId: string): void {
116 const draftTarget = resolveCurrentFileDraftTarget(job);
117 if (draftTarget === undefined) {
118 return;
@@ -402,6 +404,9 @@ export function startAttachmentUpload(input: {
404
405 const existing = readAttachmentUpload(input.image.id);
406 if (existing?.status === "ready" && existing.environmentId === input.environmentId) {
407 + // A file restored into a draft after its upload finished (stash, failed send) missed the
408 + // completion stamp; stamping here keeps it from re-uploading after a reload.
409 + stampDraftFileUpload(input, existing.attachmentId);
410 return;
411 }
412 if (existing?.status === "failed" && existing.environmentId === input.environmentId) {