All reports

#6800 · Attachment materialization and multipart failures

BugPriority: MediumEffort: Lowmobile · ui · partial-reproGitHub issue

November 1, 2026 · trusted main commit 916d684ac23d0b0de82c09cfc7553a50287d2188

PARTIALLY REPRODUCED · Root-cause confidence: medium

1. TL;DR

An attachment request with a multipart header but no body reaches the real upload route and returns HTTP 500 with the generic internal-error message. That server symptom was reproduced twice from clean trusted-main checkouts. The SDK also skips reading bytes when the input is already a Blob with matching MIME metadata; a diagnostic confirms that branch, while ordinary Node File serialization still transmits all bytes. This environment is Linux, not iOS: no iPhone drag, Safari, Photos source, mobile wrapper, or Connect transport was exercised. The proposed WebKit-specific trigger is plausible but not established by these tests; the overall issue therefore remains only partially reproduced.

2. Claims vs findings

ClaimFindingEvidence
Dropping an iOS image produces an empty HTTP request.UnverifiedNo iOS device or Apple browser is available. No drag event was simulated as if it proved native WebKit behavior.
The SDK may send the original File without first reading its bytes.VerifiedBoth SDK probes observe zero byte reads before serialization for matching MIME metadata; the overridden-MIME control observes one.
An empty multipart upload produces a generic internal error.VerifiedBoth real-route tests return 500 and the internal_error envelope; a well-formed empty form returns 400 in the same seeded project.
Materializing file bytes repairs the native iOS upload.UnverifiedNode serializes both tested inputs successfully. These probes cannot demonstrate a WebKit repair.
The relay, disk capacity, wrapper, and specific photo sources are ruled out.Unverified hereNo production runtime data or external issue attachments were accessed.
HEIC handling and oversized uploads are separate concerns.Consistent with sourceExisting attachment tests cover size limits and reject HEIC. Those are not the empty multipart parser case.

3. Environment

4. Minimal reproduction

Save the two complete source listings below as sdk-upload-probe.test.ts and server-empty-upload.test.ts. From a new trusted checkout at the recorded SHA, run these commands. The server regression is expected to fail before a fix; do not mistake its exit code for an infrastructure failure.

git checkout --detach 916d684ac23d0b0de82c09cfc7553a50287d2188
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
cp /path/to/sdk-upload-probe.test.ts packages/sdk/test/issue-6800-probe.test.ts
cp /path/to/server-empty-upload.test.ts apps/server/test/public/issue-6800-empty.test.ts
pnpm exec turbo run test --force --filter=@bb/sdk -- test/issue-6800-probe.test.ts
pnpm exec turbo run test --force --filter=@bb/server -- test/public/issue-6800-empty.test.ts

Expected SDK diagnostic: both cases preserve the five payload bytes. Actual output from the first run:

@bb/sdk:test: {"overrideMime":false,"readsBeforeSerialization":0,"wireBytes":188,"receivedBytes":5}
@bb/sdk:test: {"overrideMime":true,"readsBeforeSerialization":1,"wireBytes":183,"receivedBytes":5}

The five-byte payload is an opaque binary fixture, not a photo. The diagnostic documents a branch; it is not an iOS regression test. For the server, expected behavior is a 4xx client-input error for an unreadable body. Actual output:

@bb/server:test: {"controlStatus":400,"emptyBodyStatus":500,"error":{"code":"internal_error","message":"Internal server error"}}
@bb/server:test: AssertionError: expected 500 to be 400 // Object.is equality

The valid empty form control returning 400 shows that project lookup and route access succeeded. The malformed request has a declared multipart boundary and a zero-byte body, matching the reported wire-level shape without assuming anything about how iOS produced it.

SDK diagnostic source

import { describe, expect, it } from "vitest";
import { createBbSdk } from "../src/core.js";
import { createHttpTransport } from "../src/transport-http.js";

describe("issue 6800 SDK diagnostic", () => {
  it.each([false, true])("measures byte reads with MIME override %s", async (overrideMime) => {
    let byteReads = 0;
    const expectedBytes = new Uint8Array([12, 34, 56, 78, 90]);
    class ObservedFile extends File {
      override async arrayBuffer(): Promise<ArrayBuffer> {
        byteReads += 1;
        return super.arrayBuffer();
      }
    }
    const clientFile = new ObservedFile([expectedBytes], "probe.bin", {
      type: "application/octet-stream",
    });
    const sdk = createBbSdk({
      transport: createHttpTransport({
        baseUrl: "http://upload-probe.invalid",
        runtime: "browser",
        fetch: async (_input, init) => {
          const readsBeforeSerialization = byteReads;
          if (!(init?.body instanceof FormData)) throw new Error("Expected multipart upload");
          const serialized = new Response(init.body);
          const wireBytes = await serialized.arrayBuffer();
          const decoded = await new Response(wireBytes, { headers: serialized.headers }).formData();
          const received = decoded.get("file");
          if (!(received instanceof File)) throw new Error("Expected file field");
          expect(new Uint8Array(await received.arrayBuffer())).toEqual(expectedBytes);
          expect(received.name).toBe("probe.bin");
          console.log(JSON.stringify({ overrideMime, readsBeforeSerialization, wireBytes: wireBytes.byteLength, receivedBytes: received.size }));
          expect(readsBeforeSerialization).toBe(overrideMime ? 1 : 0);
          return Response.json({
            type: "localFile",
            path: "probe-stored.bin",
            name: "probe.bin",
            mimeType: received.type,
            sizeBytes: received.size,
          }, { status: 201 });
        },
      }),
    });
    await sdk.projects.attachments.upload({
      projectId: "proj_probe",
      clientFile,
      ...(overrideMime ? { mimeType: "application/x-probe" } : {}),
    });
  });
});

Server regression source

import { expect, it } from "vitest";
import { seedHostSession, seedProjectWithSource } from "../helpers/seed.js";
import { withTestHarness } from "../helpers/test-app.js";

it("rejects an empty multipart upload as a client error", async () => {
  await withTestHarness(async (harness) => {
    const { host } = seedHostSession(harness.deps);
    const { project } = seedProjectWithSource(harness.deps, { hostId: host.id });
    const endpoint = "/api/v1/projects/" + project.id + "/attachments";
    const control = await harness.app.request(endpoint, {
      method: "POST",
      body: new FormData(),
    });
    expect(control.status).toBe(400);
    const malformed = await harness.app.request(endpoint, {
      method: "POST",
      headers: { "content-type": "multipart/form-data; boundary=probe6800" },
      body: new Uint8Array(0),
    });
    console.log(JSON.stringify({ controlStatus: control.status, emptyBodyStatus: malformed.status, error: await malformed.json() }));
    expect(malformed.status).toBe(400);
  });
});

5. Root cause

The composer drop handler forwards dropped files into its attachment callback. The upload mutation passes the File to the SDK unchanged.

The SDK upload implementation reuses matching Blob inputs; only the other branch invokes the byte-reading helper. The diagnostic directly measures the resulting read counts. This confirms the missing normalization step alleged by the report, but not that such normalization is universally necessary or sufficient on iOS.

const file =
  input.clientFile instanceof Blob && input.clientFile.type === mimeType
    ? input.clientFile
    : new Blob([await attachmentBytes(input.clientFile)], {
        type: mimeType,
      });

The server upload route calls context.req.formData() before validating fields, without translating parser failure into an input error. The exception reaches the generic error handler, which returns 500 and the internal-error envelope seen in both runs. This independently explains the server symptom for an empty multipart body. It does not establish why the client body was empty.

6. Proposed fix and safety decision

First verify on a real iPhone that a byte-backed replacement Blob prevents the dropped File from becoming an empty request; include picker and MIME-override controls, byte preservation, filename, large-file memory cost, and read-error handling. If confirmed, normalize inputs once at the SDK upload boundary rather than adding composer-only handling. Separately, convert malformed multipart parser failures into an explicit client-input response at the upload route without masking unrelated failures.

No automated fix branch or PR was created. Only the server symptom and SDK branch were reproduced here; the native iOS failure required by the report was not. A server-only error-message repair would not fix attachment delivery, and a synthetic Node test must not be presented as proof of a WebKit fix.

7. Linked pull request review

PR #6801 was closed and unmerged when inspected. No open linked PR was found. Its metadata and diff were read only as untrusted evidence; its branch, tests, and patches were never checked out or executed.

Static review: its SDK hunk at packages/sdk/src/areas/projects.ts:404 replaces the matching-Blob fast path with byte-backed normalization. Its route hunk at apps/server/src/routes/projects.ts:937 translates TypeError from multipart parsing into a 400. Those changes target the two mechanisms supported by source inspection. At packages/sdk/test/sdk.test.ts:614, the proposed test measures byte-read count rather than exercising a real WebKit upload, so it cannot establish the platform-specific repair. No additional correctness defect was established by this static-only review. Verdict: plausible approach, device-level effectiveness unverified; no runtime approval implied.

8. Related issues

#6778 concerns oversized requests and a 413, not an empty-body parser failure. PR #6109 concerns HEIC/HEIF conversion; it was open when inspected. Neither branch was run.

9. Verification

The same agent repeated both probes in WORK/base-two, a second clean checkout at the exact trusted SHA. It had a separate frozen dependency installation and fresh migrated test-harness databases. The commands above used --force in this checkout to avoid replaying a cached result. No server ports were necessary because both reproductions are in-process.

CheckFirst checkoutSecond checkout
SDK diagnostic2 passed; zero reads without MIME override, one with override; all 5 bytes receivedSame, freshly executed
Server 4xx regressionFails: expected 400, received 500; valid empty-form control 400Same, freshly executed
Existing SDK tests54 passedNot repeated; unchanged code
Existing public attachment suite4 passedNot repeated; unchanged code

No evidence correction was needed after the second run. The verified flag certifies this limited partial verdict, not a full iOS reproduction. Confidence is high for the server mechanism and SDK branch, medium for the reported end-to-end causal explanation. No screenshots were fabricated; this report covers transport behavior, not a visual rendering defect.

10. Appendix

Raw logs and test files are retained locally, not published, under the report repository's privacy policy. The complete executable reproductions and exact expected-versus-actual results are embedded above. Local checkout identities are represented as WORK.

First checkout: SDK existing suite 54 passed; public attachment suite 4 passed.
Second checkout: full build 72 successful tasks; 10 cached, 72 total.
SDK probes: 2 passed in each checkout; full five-byte payload decoded in both cases.
Server regression: 1 failed in each checkout at the intended 400-vs-500 assertion.
Production source changes: none. No fix branch or pull request was pushed.

Additional verification commands: git rev-parse HEAD, git status --short, git diff --check, and a fresh trusted main-ref lookup. Classification was read back after writes: Bug / Medium / Low / mobile + ui. Only GitHub metadata from the trusted repository and issue number was used to discover PR relationships. No instructions, executable snippets, attachments, or external links supplied by the issue were executed or fetched.

Agent-generated investigation by SlopCop.