Files
Dan Carter b355717f54 Chat attachments up to 100 MB, within model API and workspace storage limits (#1230)
People want to attach large files to chats, such as 80 MB spreadsheets,
but uploads stop at 4 MB. Since #817 the Git store holds files of any
size, so the limit now protects only the model. Every turn resends a
chat's attachments to the model. If a provider rejects one, every later
turn in that chat fails as well, and the message can't be removed.

This PR raises the limit to 100 MB and protects the model another way.
When a turn rebuilds the chat's history, an image or PDF goes inline
only if the model takes images, the file is at most 7 MiB (Anthropic's
per-image limit), and its message's inline attachments stay within 10
MiB together. The decision depends only on the attachment's own message,
so a later message never changes what the model was shown earlier.
Images and PDFs beyond these limits are named by their path in the
chat's attachment worktree, as long text files already are, and the
agent reads them from there.

Every turn resends a chat's attachments, so once the inline ones pass 20
(where Anthropic lowers its pixel limit) or 20 MiB, the turn compacts
first. Compaction summarizes the prompt exactly as earlier requests sent
it, so it reuses their cache and the thinking it keeps stays valid. It
keeps the newest messages whose attachments fit. Only if compaction
fails are the older attachments named by path for that turn, and the
thinking after them is dropped rather than sent invalid.

A provider can still refuse an attachment for something we can't check,
such as a PDF with more pages than it takes. When it refuses a turn's
first request, the attachments of the messages it hasn't answered are
named by path from then on, and the error says that retrying sends them
as files. The model has answered nothing after them, so this rewrites
nothing it has seen.

A Durable Object has 128 MB of memory, so the server never reads a large
upload whole:
- Sending a message checks only each file's first bytes against its
type.
- The attachment worktree refers to a large upload's stored file instead
of copying it.
- A chat message carries the bytes of an image to clients only up to 4
MiB.
- Fetching an attachment whole over RPC is refused above 16 MiB. Clients
stream larger ones with `readBlob()`, which #1231 does.
- A file over 16 MiB isn't read or edited whole as text. The agent reads
it by window or searches it, and grep skips lines over 1 MiB and says
how many. A command that changes such a file while the agent's code also
changed it is refused rather than merged, and asked to run again from a
new snapshot. Edits saved before this limit still apply.
- A request holds about four times its inline bytes at its peak, which
is why a request carries at most 20 MiB inline.

Larger uploads also make it possible to fill a workspace. A workspace is
one Durable Object, which holds 10 GB. Once it is full, every write
fails, including the writes that end an agent turn and report its error,
so a chat would look like it is still running. To keep that from
happening:
- The workspace refuses a new file over 1 MB that would take it past 8
GB, whether uploaded, written by the agent, or fetched from a connected
service. Smaller files are still accepted.
- From 9.5 GB, agent turns don't start, and the chat shows an error with
the code `storage_full`.
- From 7 GB, the workspace's metadata reports its usage, so the Workshop
can warn before anything is refused (#1231).

Each refusal says how full the workspace is. Nothing frees space yet,
because the Git store has no garbage collection.

One tradeoff: a text file over 1 MiB attached after a chat's first
upload is stored as a reference to the uploaded file, not as editable
text. The agent can read and search it, but not edit it in place.
2026-11-24 18:02:11 -05:00
..