Skip to content

[Bug]: Mobile cannot attach files with long valid names #40990

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. On the Android device, open the Files app and save a small text file in Downloads whose name is 246 lowercase a characters followed by .txt.
  2. Open T3 Code, linked to an environment that supports file attachments, so the button beside the composer offers Choose Files.
  3. Open an existing thread.
  4. Tap the plus button beside the composer.
  5. Tap Choose Files.
  6. Select the text file.

Expected behavior

The file appears in the composer under its original name, with no alert.

Actual behavior

An alert titled Could not attach file appears, and the file is left out of the composer.

Composer after file selection

Impact

Minor bug or occasional failure. Mobile users hit this whenever a valid filename is too long to fit after the app adds its storage prefix.

Version or commit

main at 7ddc81d639. The cause is at apps/mobile/src/lib/composerImages.ts:151.

Environment

Pixel_9_API_37, Android 17.0.

Logs or stack traces

The long picked filename should appear as a composer attachment
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/lib/composerFiles.test.ts b/apps/mobile/src/lib/composerFiles.test.ts
index 73f0af20fc..1f372f27c4 100644
--- a/apps/mobile/src/lib/composerFiles.test.ts
+++ b/apps/mobile/src/lib/composerFiles.test.ts
@@ -1,6 +1,10 @@
 import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
 import { PROVIDER_SEND_TURN_MAX_IMAGE_BYTES } from "@t3tools/contracts";
 import type { ImagePickerAsset } from "expo-image-picker";
+import { copyFileSync, mkdtempDisposableSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { basename, join } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
 
 // Bytes of image files the tests create, so stored attachments can be read back and measured.
 const imageFiles = new Map<string, string>();
@@ -706,6 +710,33 @@ describe("composer file attachments", () => {
     );
   });
 
+  it("attaches a picked file with a long valid filename", async () => {
+    using directory = mkdtempDisposableSync(join(tmpdir(), "composer-picked-file-"));
+    const pickerCopy = join(directory.path, "picker.txt");
+    writeFileSync(pickerCopy, "Text contents");
+    const name = `${"a".repeat(246)}.txt`;
+    mocks.pickFile.mockResolvedValue({
+      canceled: false,
+      assets: [{ uri: pathToFileURL(pickerCopy).href, name, mimeType: "text/plain", size: 13 }],
+    });
+    sizeOtherFilesAs(13);
+    // Use the filesystem's filename length limit when creating the app-owned copy.
+    mocks.copy.mockImplementation((source: string, destination: string) => {
+      copyFileSync(
+        fileURLToPath(source),
+        join(directory.path, basename(fileURLToPath(destination))),
+      );
+    });
+
+    const result = await pickComposerFiles({ existingCount: 0 });
+
+    expect(
+      result.files.map((file) => file.name),
+      "The long picked filename should appear as a composer attachment",
+    ).toEqual([name]);
+    expect(result.error).toBeNull();
+  });
+
   it("preserves Android picker metadata instead of using the content URI document id", async () => {
     const uri = "content://com.android.providers.media.documents/document/video%3A18";
     mocks.pickFile.mockResolvedValue({
cd apps/mobile && pnpm exec vp test run src/lib/composerFiles.test.ts

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 22, 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