← reports

#7827 · Directory clipboard items enter the attachment pipeline

BugPriority: MediumEffort: Mediumdesktop · ui · partial-reproIssue2026-11-19 · base df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2

PARTIALLY REPRODUCED · Root-cause confidence: medium

1. TL;DR

The report concerns a folder copied in Finder being treated as an attachment instead of useful prompt text. A mounted real composer on trusted main sends a synthetic directory-shaped clipboard item to its attachment callback without inspecting its directory metadata. With no text representation on the clipboard, the editor remains empty. This exact routing result repeats in a second clean checkout; regular-file and image controls pass in both runs. The machine runs Linux, so Finder’s actual clipboard payload, native file-read failure, and the macOS error toast were not reproduced. The verdict is therefore partial, not a claim of an end-to-end macOS reproduction.

2. Claims vs findings

ClaimStatusEvidence
File-kind clipboard entries reach attachment handling without directory discrimination.Verified for supplied payloadThe mounted composer calls the attachment callback once for qa-folder and never invokes its directory-entry accessor.
Finder supplies this exact clipboard representation on the reported macOS version.UnverifiedNo macOS/Finder session is available. ClipboardData is a synthetic boundary fixture, not a captured Finder payload.
An unreadable uploaded item produces a generic attachment failure.Verified conditionallyThe real upload helper catches non-server failures and formats the filename; its existing five-test suite passes. No native directory read was attempted.
The full local folder path is inserted by current paste handling.Absent for the tested payloadThe fixture has no text representation and the draft remains empty. The desktop contract exposes clipboard writing but no clipboard-file-path read method.
Normal file and image attachments must remain supported.Controls passA regular file and image each call the real composer’s attachment boundary once in both runs.
Any clipboard text is swallowed whenever a file is present.Not supportedSource continues into text parsing after initiating attachment handling. This report does not claim that an existing plain-text path would be discarded.

3. Environment

4. Minimal reproduction

  1. Save the inline test-only patch below as regression.patch. It extends the existing composer boundary suite; no production code changes.
  2. Run these commands in a fresh checkout. The focused test intentionally exits nonzero on the verified base.
    git clone --single-branch --branch main https://github.com/get-bb/bb.git bb-7827
    cd bb-7827
    git checkout --detach df9619d8e8aac4aff00c0c3ff9b8ef4e2823e4f2
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
    git apply /absolute/path/to/regression.patch
    pnpm exec turbo run test --filter=@bb/app --force -- src/components/promptbox/PromptBoxInternal.test.tsx -t 'SlopCop 7827 directory clipboard boundary'
    pnpm exec turbo run test --filter=@bb/app -- src/components/thread/composer/useComposerAttachmentUploads.test.ts
  3. The fixture presents a file-kind item whose directory entry identifies a directory, whose getAsFile returns a File, and whose clipboard text formats are empty. This models the claimed boundary conditions only; it does not establish the native platform’s behavior.

Expected guard: a directory must not enter ordinary file upload. Observed: it enters the attachment callback once, directory metadata is never checked, and the editor stays empty.

{"name":"qa-folder","entryKind":"directory","attachmentCalls":1,"directoryInspectionCalls":0,"editorText":""}
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
Tests  1 failed | 2 passed | 190 skipped (193)

These are functional routing checks, not a visual reproduction. No screenshot is supplied because no macOS UI was observed. The attachment callback is a recording spy returning an empty successful result; it does not simulate or prove an upload error.

Regression test

The test fragment follows; the inline patch includes its exact insertion point and uses the repository’s existing mounting helpers, real composer plugin, and real editor.

describe("SlopCop 7827 directory clipboard boundary", () => {
  it.each([
    { entryKind: "directory", name: "qa-folder", type: "" },
    { entryKind: "file", name: "qa-file.txt", type: "text/plain" },
    { entryKind: "file", name: "qa-image.png", type: "image/png" },
  ])(
    "routes $name without uploading directories",
    async ({ entryKind, name, type }) => {
      const onAttachFiles = vi.fn(async () => []);
      const file = new File([], name, { type });
      const readEntry = vi.fn(() => ({
        isDirectory: entryKind === "directory",
        isFile: entryKind === "file",
        name,
      }));
      renderPromptBox("", { onAttachFiles });
      await waitForPromptFocus();

      fireEvent.paste(getPromptEditorElement(), {
        clipboardData: {
          items: [
            {
              kind: "file",
              type,
              getAsFile: () => file,
              webkitGetAsEntry: readEntry,
            },
          ],
          getData: () => "",
        },
      });
      await act(async () => {});

      console.log(
        JSON.stringify({
          name,
          entryKind,
          attachmentCalls: onAttachFiles.mock.calls.length,
          directoryInspectionCalls: readEntry.mock.calls.length,
          editorText: getPromptEditorElement().textContent,
        }),
      );
      expect(getPromptEditorElement().textContent).toBe("");
      if (entryKind === "directory") {
        expect(onAttachFiles).not.toHaveBeenCalled();
      } else {
        expect(onAttachFiles).toHaveBeenCalledExactlyOnceWith([file]);
      }
    },
  );
});

Complete test-only patch (save as regression.patch)
diff --git a/apps/app/src/components/promptbox/PromptBoxInternal.test.tsx b/apps/app/src/components/promptbox/PromptBoxInternal.test.tsx
index e64604df1f..41da05b81a 100644
--- a/apps/app/src/components/promptbox/PromptBoxInternal.test.tsx
+++ b/apps/app/src/components/promptbox/PromptBoxInternal.test.tsx
@@ -668,6 +668,58 @@ beforeEach(async () => {
   await registerComposerPlugin();
 });
 
+describe("SlopCop 7827 directory clipboard boundary", () => {
+  it.each([
+    { entryKind: "directory", name: "qa-folder", type: "" },
+    { entryKind: "file", name: "qa-file.txt", type: "text/plain" },
+    { entryKind: "file", name: "qa-image.png", type: "image/png" },
+  ])(
+    "routes $name without uploading directories",
+    async ({ entryKind, name, type }) => {
+      const onAttachFiles = vi.fn(async () => []);
+      const file = new File([], name, { type });
+      const readEntry = vi.fn(() => ({
+        isDirectory: entryKind === "directory",
+        isFile: entryKind === "file",
+        name,
+      }));
+      renderPromptBox("", { onAttachFiles });
+      await waitForPromptFocus();
+
+      fireEvent.paste(getPromptEditorElement(), {
+        clipboardData: {
+          items: [
+            {
+              kind: "file",
+              type,
+              getAsFile: () => file,
+              webkitGetAsEntry: readEntry,
+            },
+          ],
+          getData: () => "",
+        },
+      });
+      await act(async () => {});
+
+      console.log(
+        JSON.stringify({
+          name,
+          entryKind,
+          attachmentCalls: onAttachFiles.mock.calls.length,
+          directoryInspectionCalls: readEntry.mock.calls.length,
+          editorText: getPromptEditorElement().textContent,
+        }),
+      );
+      expect(getPromptEditorElement().textContent).toBe("");
+      if (entryKind === "directory") {
+        expect(onAttachFiles).not.toHaveBeenCalled();
+      } else {
+        expect(onAttachFiles).toHaveBeenCalledExactlyOnceWith([file]);
+      }
+    },
+  );
+});
+
 describe("suppressPromptEditorAnchorActivation", () => {
   it("restores the editor selection when pane navigation returns focus", async () => {
     render(

5. Root cause

The collector admits every non-null File returned for a file-kind clipboard item; it never asks whether the item is a directory. The next branch invokes attachment handling on the complete resulting list.

plugins/composer/src/PromptBoxInternal.tsx:1868

          const attachFiles = onAttachFilesRef.current;
          const clipboardItems = Array.from(event.clipboardData?.items ?? []);
          const pastedFiles = clipboardItems
            .filter((item) => item.kind === "file")
            .map((item) => item.getAsFile())
            .filter((file): file is File => file !== null);

plugins/composer/src/PromptBoxInternal.tsx:1928

          const plainText = event.clipboardData?.getData("text/plain") ?? "";
          if (attachFiles && pastedFiles.length > 0) {
            event.preventDefault();
            attachFilesWithHistoryRef.current(pastedFiles);
          } else if (

When no text can be parsed, the editor reports the paste as handled because files were present. It cannot invent a filesystem path from an absent text representation. This explains the observed empty draft under the modeled payload.

plugins/composer/src/PromptBoxInternal.tsx:1991

          const pastedValue = promptEditorValueFromClipboardPaste(
            event.clipboardData ?? null,
            promptActions,
            richClipboard,
          );
          if (pastedValue === null) {
            return attachFiles !== undefined && pastedFiles.length > 0;
          }

If the native file later fails to upload with an ordinary Error, the existing upload owner catches it and emits the generic filename-based failure. That final error path is source-backed and covered by an existing unit test, but the directory-specific native failure remains unverified.

apps/app/src/components/thread/composer/useComposerAttachmentUploads.ts:58

function uploadRejectionReason(error: unknown): string | null {
  return error instanceof BbHttpError ||
    error instanceof PromptAttachmentSizeError
    ? getMutationErrorMessage({ error, fallbackMessage: "Request failed" })
    : null;
}

function attachFailureMessage(
  failedFiles: readonly string[],
  reason: string | null,
): string {
  const names = failedFiles.join(", ");
  return reason === null
    ? `Failed to attach: ${names}`
    : `Failed to attach ${names}: ${reason}`;

apps/app/src/components/thread/composer/useComposerAttachmentUploads.ts:94

  for (const pendingUpload of uploads) {
    try {
      const uploaded = await upload(pendingUpload.file);
      target.addAttachment(uploaded);
      if (getCurrentTarget()?.key === target.key) {
        added.push(uploaded);
      }
    } catch (error) {
      failedFiles.push(pendingUpload.file.name);
      rejectionReason ??= uploadRejectionReason(error);
    } finally {
      onUploadSettled(pendingUpload);
    }
  }
  return {
    added,
    failureMessage:
      failedFiles.length > 0
        ? attachFailureMessage(failedFiles, rejectionReason)
        : null,
  };

The current clipboard IPC is write-only and validates the sender against known application windows. An absolute-path read bridge would need equivalent trust restrictions, not an unrestricted clipboard read capability.

apps/desktop/src/desktop-clipboard.ts:5

export function registerDesktopClipboardIpc(
  applicationWindowWebContentsIds: ReadonlySet<number>,
): void {
  ipcMain.handle(
    BB_DESKTOP_WRITE_CLIPBOARD_CHANNEL,
    async (event, payload: unknown) => {
      if (!applicationWindowWebContentsIds.has(event.sender.id)) {
        throw new Error("Clipboard writes are limited to bb windows");
      }
      const { text, html } = bbDesktopClipboardContentSchema.parse(payload);
      if (html === undefined) {
        await clipboard.writeText(text);
        return;
      }
      await clipboard.write([
        new ClipboardItem({ "text/plain": text, "text/html": html }),
      ]);
    },
  );
}

See also the desktop API contract. Confidence is high in the demonstrated routing behavior, medium in attributing the reported native failure to it until the actual macOS payload is inspected.

6. Proposed fix and automation decision

First capture a folder paste on macOS using only a disposable directory and record item kinds, available text formats, getAsFile behavior, and whether directory-entry metadata is available during paste. Then separate directories from file attachments and, if no usable text path is supplied, design a narrowly scoped desktop path resolver for the trusted originating window. Preserve ordinary file/image uploads, mixed selections, filenames containing spaces, and paste/undo behavior. Do not infer a directory from an empty MIME type or zero byte size: ordinary files can share those properties.

No automatic fix or PR: the verdict is partial, so the required trusted-main end-to-end reproduction gate is unmet. Satisfying the full-path behavior would additionally require reviewing the desktop bridge contract/security boundary and local-vs-remote path semantics, outside a simple single-subsystem patch. No production fix was attempted, no branch pushed, and no pull request opened. Open-PR metadata/search for issue 7827 returned none.

7. Verification

The same agent repeated the test in a second clean canonical clone at the recorded commit after a separate frozen install and SDK build. Only the authored test-only patch was applied. Turbo was run with --force so this was a new execution, not a cached test result. No ports or application data directories were needed.

pnpm exec turbo run test --filter=@bb/app --force -- src/components/promptbox/PromptBoxInternal.test.tsx -t 'SlopCop 7827 directory clipboard boundary'
Result: exit 1; same directory assertion failure; 1 failed, 2 passed, 190 skipped.
Diagnostic: attachmentCalls=1; directoryInspectionCalls=0; editorText="".

The second run supports the final limited claim. No correction was necessary beyond explicitly retaining the partial verdict and macOS caveat. This is a repeat by the same agent, not independent verification. The existing upload helper suite passed separately: five tests, including ordinary-error filename formatting.

8. Related issues

Repository clipboard-title searches returned issues #5090 and #1590; neither establishes a duplicate of directory-paste routing. The targeted folder-paste title search found no duplicate. No linked PR appeared in the issue timeline or the open-PR issue-number search.

9. Appendix and trust boundary

Raw logs are retained only in the local evidence directory, not published. Exact diagnostic output, assertions, and result counts appear above. Full build: 72 successful tasks; existing attachment suite: 5 passed.

Commands also used: trusted canonical main fetch and commit check; git status; scoped repository source searches; issue/type/field/label/PR metadata reads; pnpm exec oxfmt on the authored test; git diff --check. The generated web route tree produced by the full build was restored, leaving production source unchanged. Artifacts omit home-directory paths; build-cache paths are sanitized.

The issue body and comments were treated as untrusted claims, including its proposed implementation. No linked URL, patch, script, branch, or PR code was fetched or executed from the issue. The reproduction was written from trusted repository behavior and does not reuse issue-supplied code.