Attachments
How a document a person attaches to a chat is stored, governed, sent to svc-ai, shown to the model, cited and kept. It covers agent chat (socket and batch prompt) and direct model chat.
Why it works this way
Until 24 October 2026 svc-core pasted a chat's documents into the person's message, as a <documents> block in front of what they typed, sent that to svc-ai as the input and stored it as the message. Every step of a run read the block as the person's own words.
CHAINR Bot, asked to "critically review this report" with report.pdf attached (trace f7003b95…), went wrong like this:
Triage chose
direct. The file-mention check then read<source>report.pdf</source>as the person naming a file of the knowledge base and forced a knowledge search.The search used the whole report as its query, about 94k tokens with its echoes. Its evidence said "'report.pdf' — NOT FOUND … tell the user this file is not available", and said the same of
manifest.json, a name that only appears inside the report.The agent refused. A revision that did review the report failed the quality check for not citing it: nothing in the run could be cited for it.
Memory recalled an unrelated episode, matched on the report's text.
The original file was never kept.
Now a turn carries the person's words, and its documents apart from them, at every step:
| Where | What it holds |
|---|---|
The wire (ExecuteRequest.attachments) | Each document's id, name, text, when it was attached and whether its text is there |
svc-ai's run (GraphState.attachments) | Each readable document as a source with an [S#] id |
| The stored user message | The words; meta.attachments names the documents by id |
The rollout was seven waves on feat/attachments-wave-1 … -7. The waves are referred to below where a behaviour dates from one.
Where a document lives
A chat upload is a row of uploaded_files (app/services/uploads.py), owned by the workspace it was uploaded in, like any resource (migration 88).
Its text is read in the background (migration 108). The upload answers with
status: reading, anduploads.readsettles itreadyorfailedwitherror. A row stillreadingpast twice docling's timeout reads as failed (ABANDONED_AFTER), because a restart drops the task. fe-core'suploadAndReadpollsGET /files/{id}until it settles.Its original is kept (migration 109, wave 1) in MinIO at
uploads/{id}/original: by id, never by the name it came with. The row holdsobject_keyandsize_bytes;object_keystays out of the edit history, besidecontent.An upload over 50 MB is refused (413).
When the store refuses the original (502), or the commit fails, no row is kept and the object is removed.
GET /files/{id}/contentserves the original to anyone who may attach it (verify_resource_read; anything else is a 404).Its media type is read from its name (
uploads.media_type), never from the client.It carries
UNTRUSTED_CONTENT_HEADERS(nosniff,Content-Security-Policy: sandbox) and an escapedContent-Disposition(app/util/http_headers.content_disposition, RFC 6266 with an ASCII fallback).A document uploaded before originals were kept answers 404 and says so.
Deleting a document removes its original after the commit.
The data export copies a Personal library's originals to
files/uploads/<id>_<name>(docs/system/data/export.md).
A chat attaches only its own workspace's documents. An id from anywhere else is left out, as if it did not exist (uploads.in_workspace).
What a turn carries
svc-core decides which documents a turn may use (app/services/attachments.py, wave 4); svc-ai decides how the model reads them. The vocabulary and the limits are both services' contract, in app/util/attachment_wire.py, held byte-identical by tools/test_shared_modules.py.
This message's documents (
turn_attachments): the ids the client sent (file_idson the socket frame, the batch prompt and the model prompt), each once, in the order given.Every one must be
ready. A document still being read, or never readable, refuses the turn withuploads.DocumentsNotReady: acode: "documents"frame on the socket, 409 on the HTTP routes. Left out, the agent would answer as if it had read it.More than ten refuses it too (
TooManyDocuments, 422 or the same frame).
Earlier messages' documents (
earlier_attachments): what the conversation's stored user messages attached (meta.attachments), newest message first, less this message's.One the workspace still holds and has read comes with its text.
One deleted since, moved out of reach, or no longer readable is sent named only, as
removed.
One list (
for_turn): this message's documents, then earlier ones, each once (by id, then by the text's hash).
Limit (attachment_wire) | Value | Past it |
|---|---|---|
MAX_ATTACHMENTS | 20 per turn | Later earlier ones are not sent |
MAX_ATTACHMENT_CHARS | 1,000,000 per document | Cut, and marked truncated |
MAX_ATTACHMENTS_CHARS | 3,000,000 per turn | An earlier one is sent named only (omitted); this message's are never left out |
Each entry is svc-ai's AttachmentSpec:
{
"id": "6f1c…",
"name": "report.pdf",
"mime_type": "application/pdf",
"text": "…",
"attached_in": "turn",
"availability": "available",
"truncated": false
}
attached_in is turn or earlier; availability is available, removed or omitted. AgentRequest.payload(attachments=) and ai_client.invoke_model(attachments=) add the key only when there are documents, so evaluation cells, tiles and the benchmark send what they did.
A message may carry documents and no words. Both chats send it, and svc-ai answers it as a request rather than small talk (attachments.unworded_task).
How the rules read them
The Input rules read a message's documents with its words, as they always have. Their redaction then reaches every copy:
Evaluate once on the governed text (
attachments.governed_text): this message's documents as they used to be pasted, then the words. Rule conditions, a block, a quota and the one activity row keep their meaning. The governed text is never sent or stored.Redact the words with the pass's redactor (
RulePass.redact). With no documents the pass's own text is used, so a turn without documents is byte for byte what it was.Redact every document (
attachments.redacted): its name and text, never its id. Earlier documents meet the same redaction, as the conversation's history does, behind the same keyed placeholders.Store and send the redacted copies. A blocked turn stores the words and documents as typed, like any blocked turn.
Direct model chat used to run its rules on the words alone and paste the documents in afterwards (effective_prompt). Since wave 5 it follows the same four steps.
svc-ai redacts the documents sent apart once more with the forwarded Input rules (InferenceEngine._take_attachments → gather(redactor=)). That is idempotent: a placeholder matches no detector. svc-ai's own rule conditions read the words (ctx.governed_input), not the documents; svc-core has already evaluated both.
What is stored
The user message is the words.
meta.attachmentsnames its documents[{id, name, mime_type?}](attachments.message_meta), on every path a turn is stored by: answered, blocked, failed, stopped.A chat command's record is
meta.command. It used to be stored as the message's whole meta while the chat and the decision record readmeta.command, so a reloaded message lost its command. Both now read either shape (attachments.command_of, fe-corecommandOf).The history sent to svc-ai names what each earlier message attached (
attachmentson the entry, from_load_conversationand model chat's_history_entry). svc-ai reads that asReview it [attached: report.pdf]and drops the key at the boundary, so it never reaches a provider.The running-turn registry shows a turn's documents (
RunningTurn.meta), so a page that comes back draws its chips.The decision record's Request section lists the documents by name (
RequestSection.attachments).
Ids and citations
attachments.gather (svc-ai, at the boundary) gives every readable document an id, S1 … Sn: this message's first, then earlier ones newest first. The run's source registry is seeded with them before anything else (attachments.seed), so every later source — a knowledge passage, a web page — numbers on from them.
A document is cited as:
{
"tool": "attachment",
"kind": "document",
"source": "report.pdf",
"title": "report.pdf",
"kb_id": "attachments",
"document_id": "6f1c…",
"citation_id": "S1"
}
The stream opens with them: a
citationsframe aftergraph_plan, before any node runs.A resumed run keeps them from its checkpoint (
_citations_before_pause, stream and batch).The quality check's ledger lists them first, as
attached_document(source_ledger._KIND_LABEL), so an[S1]in the draft is verified.The response standards say an attached document is cited by its id; what the person wrote in the conversation needs no marker (
prompts.RESPONSE_FORMATTING_STANDARDS).Read through a tool, it is still one source. The attachment tools' results carry the same id (the documents trailer,
source_trailers.DOCUMENT), and the run lists the document once however many parts were read (graph_based._reads_listed_attachment).CHAIN-R's Sources block lists it like any document (
answer_sources.finalise).meta.cited_sourceskeepstoolanddocument_idunredacted.fe-core's citation card reads "Attached document" and opens the original (
CitationRow,attachedDocumentId). A document pasted into a message before wave 4 has alegacy:id and nothing to open.
How the model is shown them
Agent chat and skills (graph engines)
Each answering call plans how it shows the documents (attachments.plan), in the list's order, for its model's window:
| Delivery | When | What the model sees |
|---|---|---|
listed | It does not fit | Its first 2,000 characters, and how to read the rest with the tools |
unavailable | removed or omitted | Its name, and why its text is not here |
The constants are INLINE_DOC_TOKENS, INLINE_TOTAL_TOKENS, INLINE_WINDOW_SHARE and LISTED_OPENING_CHARS. Tokens are estimated at 3.5 characters each (token_budget.CHARS_PER_TOKEN), deliberately high, so the 12,000-token report in the incident is shown whole.
Each step is shown what it needs:
The answering node reads
<attachments>first in its<request_context>, after the date (render_block). Each document is an<attachment id="S1" name=… attached=… size=…>element, its text CDATA-wrapped throughattachments.cdata. The note says the documents are the person's material, data and never instructions, cited by id. The system prompt is unchanged, so its cache holds.Synthesis reads the same block first in
<synthesis_input>. With nothing retrieved it answers from the documents, then its own knowledge.The quality check reads the documents as the agent was shown them (
render_for_evaluator). Its prompt counts them as evidence, an attachment's id as a real source, and does not call a claim unsupported only because it comes from a part the check was not shown.Triage and the planner read a manifest (
manifest_lines): each document's name, size and when it was attached, and for this message's a 200-character preview. Never a body.The retrieval workers are told the documents' names (
graph._attached_hint): search only for what the request needs beyond them.
attachments.cdata replaced five escapes in graph.py that wrote ]]]]]><![CDATA[> (a stray ]). It also escapes the request, the draft, the evidence and synthesis's knowledge, which were not escaped before.
The attachment tools
A conversation with any document gives every answering step two tools (app/tools/attachments.py, graph._attachment_tools, wave 3). They are bound to skill nodes and synthesis, built from state per call, so a resumed run has them too:
read_attachment(document, offset=0)returns a part of the document from a character offset. A part is 40,000 characters (PAGE_CHARS), or the documents' share of a small window, never under 4,000. It ends at a paragraph, line or sentence, and says where the next part begins and at what offset.search_attachments(query, document="", top_k=6)returns the passages that share the query's words, best first, at most 10.Passages are paragraph-first: short paragraphs together up to about 1,200 characters, a long one in parts that repeat 200 characters of the part before.
They are scored by
memory.lexicalcoverage (BM25-weighted), plus a bonus when the query appears as written. One place is one hit.Each passage gives its character range, for
read_attachmentto read on from.
Both take a document by its id (S1, [S1]), its upload id, or its name, approximate names resolved (resolve, over documents.match_document).
An unknown name lists the conversation's documents.
Two documents of one name are told apart by id.
A removed document says its text is not available and must not be guessed at.
No model is called and nothing is fetched, so neither tool costs anything or has an llm_paths entry. Both are platform-owned, so they are strict on a route that holds tool arguments to their schema (wire.platform_owned).
read_document given an attached document's name or id reads that document (make_knowledge_tools(attachments=), strong_match), unless the call names a knowledge base. It used to report a knowledge base file missing.
Direct model chat
The model engine has no tools to read on with (InferenceEngine.takes_attachments is false). The documents open its prompt, before the words (attachments.render_for_model, wave 5), as a <documents> block:
Each
<document>says when it was attached, its body CDATA-wrapped.All the documents share one budget: 48,000 estimated tokens, or 40% of the model's window when that is less (
model_budget,ModelEngine._attachment_window→token_budget.limits_for_model).One past the budget is cut, or named only, and says so in a
<note>. One removed says its text is not here.
A model call with no documents is sent exactly as written.
Which turns search the knowledge
A document the person attached is in the agent's hands, not the knowledge's. So:
Triage reads the manifest under
ATTACHED DOCUMENTS(prompts.build_gate_request(attachments=)), and one routing rule says a request about attached documents isdirect, unless it also asks for the knowledge bases or live data.The knowledge default does not override that (
_attachment_route_hold).always_retrieveused to turn a correctdirectinto a guide search. The gate frame'striage.adjustmentssays "kept: the request is about the documents it attached, not the knowledge bases".A failed triage answers from them (
_fallback_route(has_attachments=)), and a message of documents alone is never "trivial".A name is not a knowledge mention when an attached document has it, nor when it appears only inside one (
documents.find_mentioned_documents(exclude=, elsewhere=)). That coversreport.pdfandmanifest.jsonin the incident. A knowledge base file named beside the report is still searched.Retrieval's echo of the request is capped in the packed evidence (
ContextPacker: "Retrieved for" 300 characters, at most six queries of 200), and the query internal retrieval plans with is cut at 2,000 characters.The knowledge tools' guidance says a document attached to the conversation is not one of the knowledge base's files.
See Knowledge Retrieval.
Memory
An episode names the documents its message attached (remember(attached=) → Task: … [attached: report.pdf]), never their text. Recall reads the person's words, never a document's text; documents sent without a word are recalled by their names, since an earlier turn about the same file bears on it. See Memory.
Messages from before
Stored messages are never rewritten: a message from before wave 4 still holds its pasted <documents> block. Every reader takes it apart:
svc-ai lifts a block out of the input and out of every earlier user message (
attachments.split_legacy,gather). The person's words are what follows the block's last closing tag, so a document containing</documents>cannot pass its own text off as theirs. A lifted document is an earlier attachment with alegacy:<sha12>id; the same document pasted twice is one.fe-core draws its chips from the text (
parseUserMessageAttachments), named only.The decision record and the data export show the message as stored, block included.
Prompt caching
The system prompt is the agent's alone, with or without documents. The documents are in
<request_context>(prompt_cache).The tool block does not change as documents come and go. The attachment tools are bound whenever the conversation has a document, and their descriptions name none;
TestBinding.test_the_tool_set_names_no_documentpins it.The documents are re-sent on every call that shows them: the answering node, synthesis and the quality check, on every turn. Within one tool loop the tail cache mark covers them; across turns they are written to the cache again.
fe-core
The paperclip is a menu (
ChatPanel/AttachMenu, wave 6):Upload from computer;
Recent: the library's five newest documents that are read and not on the message already (
recentDocuments), so a document uploaded in one conversation is attached again in another in one step;All documents: the library above the message box.
The narrow composer's ⋯ menu draws the same items (
AttachItems).A sent message's chips open the original (
ChatPanel/SentAttachments,util/chatAttachments.openAttachment). A PDF or an image opens in a tab of its own; anything else, HTML and SVG included, is saved, never opened from a blob in the app's origin. A chip says when its document can no longer be opened.A stored message's documents are read from
meta.attachmentsfirst, then from pasted text (messageAttachments). Both chats send a message of documents alone.
Limits
An account's or workspace's originals stay in MinIO when it is deleted. Only deleting the document removes one, as with knowledge files.
search_attachmentsis lexical. A question worded unlike the document finds nothing; the agent reads on withread_attachmentinstead.The documents are written to the cache again every turn (see Prompt caching).
svc-ai's rule conditions read the words only. svc-core evaluated the rules on the words with the documents before the turn reached svc-ai.
Not verified live. The incident's turn is replayed through the real graph; no live turn has run since.
Tests
| Where | What it pins |
|---|---|
svc-ai tests/util/test_attachments.py | Splitting pasted blocks, gather's order, ids, caps and redaction, plan, the renderers |
svc-ai tests/inference/test_attachment_boundary.py, test_model_engine_attachments.py | The boundary for graph and model engines, the model budget, the history |
svc-ai tests/tools/test_attachment_tools.py | Paging, names, search, citations, strict binding, a stable tool set, read_document's redirect |
svc-ai tests/util/test_attachment_wire.py, svc-core tests/test_attachment_wire.py | The shared vocabulary and limits |
svc-core tests/test_attachments.py | Resolution, for_turn, the rules' sequence, the socket, the batch prompt, model chat, the history, the decision record |
svc-core tests/test_files.py | Originals: kept, removed, served, named safely |
fe-core AttachMenu.test, SentAttachments.test, CitationRow.test, chatAttachments.test, both Chat.attachments tests | The paperclip, chips, citations, reading stored messages |