Skip to content

Turn large pasted text into ordinary message attachments - #2

Open
aotd1 wants to merge 4 commits into
mainfrom
pasted-text-attachments
Open

aotd1 wants to merge 4 commits into
mainfrom
pasted-text-attachments

Conversation

@aotd1

@aotd1 aotd1 commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Human comments

What was wrong

The shared message editor handled large clipboard text as inline editor content. This expanded multi-megabyte pastes into the DOM and the main prompt instead of using BB's existing file attachment storage and execution-host delivery. Drafts had no recoverable state or undo operation for an automatically created text attachment.

What changed

This is a behavioral clone of the large-text Paste feature in the Codex Desktop app: paste a large text block, get a compact Pasted text.txt attachment, then type a short request. The agent receives access to the complete file.

  • Convert plain-text Paste events at 5,000 Unicode code points or more into ordinary Pasted text.txt attachments. Preserve the existing request, selection and focus; keep files/images on their existing path.
  • Add compact filename/byte-size/80-character preview cards, full-text links, loading/error states, retry and explicit Insert as text. Keep full recovery Blobs in IndexedDB and block sending unfinished attachments.
  • Integrate attachments with editor Undo/Redo and existing persisted drafts. Keep asynchronous uploads tied to the original draft; removal cannot be undone by a late upload. Redo/submission retries reuse prepared files.
  • Preserve original filenames and sizes in history, add-to-chat and message editing. Codex/Pi receive names alongside execution-host paths; Claude and ACP reuse their existing adapters. Add an ACP native resource-link contract test.
  • Reuse project attachment upload/storage and daemon staging before runtime startup. No daemon wire change or protocol bump; the server-to-client timeline has optional filename/size metadata.
  • Document the existing CLI --file and SDK upload equivalents and the implementation/verification report in docs/pasted-text-attachments.md.

The 5,000 boundary replaces the initially proposed >10,000 threshold after read-only inspection of the installed Codex application bundle (ChatGPT macOS 26.930.31730, build 12947). Codex uses UTF-16 string length; BB retains the requested code-point counting, so an emoji counts as one. The feature is in core because the current plugin API does not expose the required Paste and shared Undo hooks.

BB editor with a 3,638,577-byte / 75,151-line synthetic paste attached as a file and a short request:

BB editor showing Pasted text.txt as a compact attachment beside the request

How you verified

Turbo checks with dependency orchestration passed:

  • App editor/upload/recovery/draft/card tests: 200 passed.
  • App history/streaming/message actions: 82 passed; the edited attachment-only message scenario was also rerun.
  • Client-core prompt drafts: 19 passed; thread-view parsing/timeline: 90 passed; daemon thread dispatch/staging: 33 passed.
  • Codex provider suite: 333 passed. Pi provider suite: 183 passed, one existing skipped test.
  • Focused ACP resource-link delivery test: passed. Two existing Claude local-file description tests: passed.
  • App/client-core/server-contract/thread-view/Codex/Pi and ACP typechecks passed; app/Codex/Pi lint passed with existing repository warnings.

Manual QA used synthetic 3,638,577-byte / 75,151-line data in an isolated dev instance. The Paste event produced a compact card, kept the short request in the editor, survived reload, and downloaded without data changes. A real local Codex turn read the staged file with a tool and returned the exact byte/line counts. Sent history retained the original filename and download link after reload.

An ephemeral Linux container ran the actual BB staging function and Codex input adapter using a QA HTTP transport serving only that synthetic attachment. No client/server attachment directory was mounted. The container read all bytes from its own /tmp/bb-container-agent path; provider input was only 217 characters. The container and transport were cleaned up. A full model turn inside an enrolled container, a second physical host, and native mobile clipboard events were not manually exercised; daemon and adapter contracts are covered by tests. The editor screenshot is embedded above and stored with the implementation documentation. No user HAR, supplied Markdown file, or full generated fixture was added to Git.

AGENT GENERATED

aotd1 pushed a commit that referenced this pull request Nov 2, 2026
## Human comments

## What was wrong

Several cache owners wrote a server reply or the thread-detail bootstrap
straight into the React Query cache with `setQueryData` while a fetch of
the same key could still be in flight. React Query writes fetch results
without checking whether they're older than what's cached (query-core
`query.ts`), so the older fetch landed last and put stale data back.
Effects included: an environment or host status that stayed stale after
opening a thread, a plugin settings form resetting its draft to the old
value, a cancelled plugin install flipping back to running, new plugin
update jobs dropping out of the list, an `idle` app update phase
switching off the progress poll, and the AI service selection flickering
back. These are items #2–get-bb#10 from the direct cache write audit
(@thread:thr_fjr5x8dzaz). #1 (thread tabs) is fixed separately in get-bb#6611.

## What changed

Two fixes, depending on whether the data has a version field:

- **Environment and Host keep the newer copy by `updatedAt`** (#2, #3,
get-bb#10). The bootstrap ingest (`thread-detail-cache-owner.ts`), the rename
reply (`applyEnvironmentUpdateResult`), and the
`useEnvironment`/`useHosts` fetches all compare `updatedAt`. The
fetch-side check is what catches a fetch that started before the write
and lands after it. To make it testable, those fetches now live in
`environmentQueryOptions` and `hostsQueryOptions`. Host `status` comes
from live daemon sessions and a disconnect doesn't change `updatedAt`,
so on a tie the cached copy wins over the bootstrap. The bootstrap only
fills an empty cache or replaces strictly older data. Rename replies and
fetch results still win ties.
- **`setQueryDataOverInFlightFetch`** (`cache-effect-utils.ts`) for data
with no version (get-bb#4–get-bb#9): it writes the value, and if a fetch of the key
is in flight it cancels that fetch (the cache keeps the written value)
and refetches. With nothing in flight it's a plain write. Used by
`applyPluginSettingsView`, `applyPluginInstallJob`,
`applyPluginUpdateJob`, `hydrateAppUpdateStatus`,
`hydrateSystemVersionCache` and `writeCachedAiServices`, so every caller
gets the fix. Where the audit suggested an unconditional
cancel-write-invalidate (get-bb#7) or a cancel before the write (get-bb#8, get-bb#9), this
helper refetches only when a fetch was actually in flight. That avoids
an extra request on every write. Forced version and app-update checks
update the server's cache, so the trailing unforced refetch returns the
forced result.

No wire, CLI or plugin API changes.

Not covered here: audit items get-bb#11 (plugin safe mode) and get-bb#12 (prompt
history), both low risk. Also not covered: a lint rule restricting
direct `setQueryData` calls to the helper, which would stop new call
sites from bringing the race back.

## How you verified

- New tests use real `QueryClient`/`QueryObserver` instances: start a
fetch that resolves late with older data, do the write, let the fetch
land, then check that the newer value survives (and, for the helper,
that the trailing refetch runs).
- `thread-detail-cache-owner.test.ts` (new): late environment and
host-list fetches after a bootstrap, an older bootstrap over a newer
cache, and the equal-`updatedAt` host status case.
- `environment-workspace-cache-owner.test.ts`: a late environment fetch
after a rename, and an older rename reply over a newer cache.
- `in-flight-fetch-writes.test.ts` (new): one row per cache-owner write
for get-bb#4–get-bb#9, plus helper tests for the no-fetch case (no extra request)
and a fetch of an unobserved query.
- With each source change reverted, every race test failed on the stale
data and passed once the fix was restored.
- `pnpm exec turbo run typecheck lint test --filter=@bb/app`: passed
(647 files, 6515 tests; 0 lint errors, no new warnings). After rebasing
onto `0472409243` I re-ran the three changed test files (21 tests
passed).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

> AGENT GENERATED

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant