Skip to content

[Bug]: Recovering a failed task can lose a pasted image that is still preparing #38030

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/mobile

Steps to reproduce

  1. In the mobile app, start a new task on a connected host where task creation fails.
  2. While the task is starting, type a follow-up in its composer.
  3. Paste a large image into the same composer.
  4. When the task creation error appears, tap Edit task before image preparation finishes.
  5. Inspect the recovered task draft after preparation finishes.

Expected behavior

The recovered draft includes the follow-up and the image once preparation finishes.

Actual behavior

If image preparation finishes while the recovery draft is being saved, the image is cleared from the old composer without being added to the recovered draft.

Impact

Major degradation or frequent failure. Mobile users recovering a failed task can lose an image when its pending paste finishes during recovery; this requires the preparation and recovery saves to overlap.

Version or commit

main at 17c142588b. The cause is at apps/mobile/src/state/recover-failed-thread-draft.ts:33.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

AssertionError: expected [] to deep equally contain
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/apps/mobile/src/state/threadOutboxDelivery.test.ts b/apps/mobile/src/state/threadOutboxDelivery.test.ts
index aa6e04c186..2e562a44ad 100644
--- a/apps/mobile/src/state/threadOutboxDelivery.test.ts
+++ b/apps/mobile/src/state/threadOutboxDelivery.test.ts
@@ -789,6 +789,60 @@ describe("thread outbox recovery rollback", () => {
     );
   });
 
+  it("keeps an attachment prepared while a failed task is being recovered", async () => {
+    const message: QueuedThreadMessage = {
+      ...queuedMessage({ messageId: "failed-late-attachment", text: "Original prompt" }),
+      modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
+      creation: {
+        projectId: ProjectId.make("project-1"),
+        workspaceMode: "local",
+        branch: null,
+        worktreePath: null,
+      },
+    };
+    const sourceKey = `${message.environmentId}:${message.threadId}`;
+    const targetKey = "new-task:restored-failed-late-attachment";
+    await composerDrafts.waitForComposerDraftsLoaded();
+    appAtomRegistry.set(composerDrafts.composerDraftsAtom, {
+      [targetKey]: { text: message.text, attachments: [] },
+      [sourceKey]: { text: "Please include tests", attachments: [] },
+    });
+    const saving = Promise.withResolvers<void>();
+    const resume = Promise.withResolvers<void>();
+    const write = harness.draftFile.File.prototype.write;
+    const writeSpy = vi
+      .spyOn(harness.draftFile.File.prototype, "write")
+      .mockImplementationOnce(async function (value) {
+        write(value);
+        saving.resolve();
+        await resume.promise;
+      });
+    const attachment = {
+      id: "late-paste",
+      type: "image" as const,
+      name: "pasted.png",
+      mimeType: "image/png",
+      sizeBytes: 1,
+      dataUrl: "data:image/png;base64,AA==",
+    };
+    try {
+      const recovering = recoverFailedThreadDraft(message);
+      await saving.promise;
+      composerDrafts.appendComposerDraftAttachments(sourceKey, [attachment], {
+        appendReference: true,
+      });
+      resume.resolve();
+      await recovering;
+      expect(composerDrafts.getComposerDraftSnapshot(targetKey).attachments).toContainEqual(
+        attachment,
+      );
+    } finally {
+      resume.resolve();
+      writeSpy.mockRestore();
+      await composerDrafts.flushComposerDrafts();
+    }
+  });
+
   it("keeps setup edits recoverable when saving their recovery draft fails", async () => {
     const message = queuedMessage({ messageId: "failed-save", text: "Original prompt" });
     const sourceKey = `${message.environmentId}:${message.threadId}`;
cd apps/mobile && pnpm exec vp test run src/state/threadOutboxDelivery.test.ts

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions