ADR 0028 — File transfers in parts (file store links)
Status: accepted · 2026-10-31 (owner request: files of 1 GB and more through the brokers and the file store links of ADR 0027).
Context
ADR 0027 moves a file as one action: upload takes it as one argument, download returns it as one reply. Every hop holds it whole (the args, the Zenoh query, the HTTP body to the store), so the links cap uploads at 64 MiB (the gateway’s POST /api/invoke body) and downloads at 16 MiB. A file of 1 GB would take several times its size in memory on a board with 2 GB, and one query of that size through a chain of brokers.
Decision
-
Uploads in parts, spooled on the link’s disk (
wyrm_filestore::parts). A folder’supload_begin {name, size, part_size?, content_type?, overwrite?, sha256?}(level write) answers{upload, part_size, parts}. The connection’supload_part {upload, index, data}writes one part at its offset into a sparse spool file (<data_dir>/uploads/c-<conn>/<id>.part, 0700; the prefix keeps a connection named.or..belowuploads). Parts may come in any order, and again after a cut;upload_status {upload}lists the missing ones (at most 1000).upload_commit {upload}answerscommittingat once and sends the spool file to the store in the background (a large file takes longer than a request may wait);upload_statusthen saysdonewith the Upload File answer, orfailedwith why.upload_abortdrops it. Parts are 64 KiB … 16 MiB (default 4 MiB); a file is at mostmax_file_mib(default 4 GiB, at most 1 TiB). -
To the store as it is read:
Backend::put_file(parent, name, src, size, …):- S3: CreateMultipartUpload, parts of
multipart_mib(default 16 MiB, at least 5 MiB, larger for files over 10 000 parts), CompleteMultipartUpload withIf-None-Match: *unless it overwrites, AbortMultipartUpload on a failure. - Drive: a resumable session (
uploadType=resumable, PATCH to replace), chunks ofupload_chunk_kib(a multiple of 256 KiB) withContent-Range, resumed from Drive’sRangeon 308. The session URL must be on the API’s origin. - WebDAV: one
PUTwhose body is streamed from the spool file (http::Request::file_body). - localfs: a copy from the spool file, through the same temporary file and rename as an overwrite.
One part (S3, Drive) or one 256 KiB read buffer (WebDAV, the HTTP client) is in memory at a time.
- S3: CreateMultipartUpload, parts of
-
Downloads in parts: a file’s
download_part {offset, length?}(level read, length ≤ 16 MiB, default 4 MiB) answers{data, offset, size, eof}, throughBackend::get_range: an HTTPRangerequest (S3, Drive, WebDAV; a store that ignoresRangefor an offset past 0 is refused rather than read whole), a seek and a read (localfs). -
Ownership and bounds. An upload belongs to the
ptoksubject that began it: another subject’s request answersnot_found. At most 4 uploads hold a spool file per connection (receiving, committing, or failed and kept for another commit; counted and taken under one lock), so the spool is at most 4 ×max_file_mib; parts, downloads and commits share the connection’s two transfer slots. An upload idle for an hour is dropped with its spool file; so are all of a connection’s when it stops or is edited, and all spool files on the link’s start. Asha256given at begin is checked before the file goes to the store. -
Same path through the brokers: each part is an ordinary action, so a chain of brokers carries it as any other (one query per part, at most 16 MiB). A client sends parts through the gateway’s
POST /api/invoke(a WebSocket frame holds 64 KiB).
Consequences
- Memory no longer grows with the file: a 512 MiB transfer in parts of 8 MiB (debug build, the link, the client and Zenoh in one process) peaked at 133 MiB of resident memory.
- The link’s disk holds a file in progress whole (sparse at first);
max_file_mibbounds it, andupload_beginrefuses a file larger than the free space of the spool’s disk minus 1 GiB (resource_exhausted), checked again at each part for the bytes still to come (ADR 0029, decision 11). - A connection’s uploads in progress are lost when it stops or the link restarts (the spool is not kept; the client begins again).
- Not done: presigned URLs (bytes past the brokers when a client can reach the store); a server-side copy between connections; a hash of a download (the client checks it against the store’s
etagwhere that is a digest).
Alternatives
- Parts straight to the store at each
upload_part(S3 parts, Drive chunks): no spool, but parts must come in order for Drive and WebDAV, S3 parts must be at least 5 MiB, and a retry from the client has to match the store’s rules. The spool takes parts in any order for every store. - A stream action for downloads: one request, but a stream reply cannot be resumed at an offset after a cut, and the gateway’s HTTP invoke returns the last item only.
Amendment 2026-11-15 — parts through the user gateway
Found live: a restore of a 5.8 MB backup from Studio failed with SocketException: Write failed (Broken pipe), nothing in the broker log. A part (4 MiB by default, never under 64 KiB for a file store) does not fit a gateway WebSocket frame (64 KiB), so the Dart client sends it by POST /api/invoke. The gateway takes that route only for an action with an editor: "file" parameter (ADR 0011), and restore_part (ADR 0048 §3) and upload_part declared none: every part was refused with 400 takes no file. The client never saw the refusal: the gateway read at most 64 KiB of the body and closed, and Dart’s HttpClient writes the whole body before it reads the answer.
Decided (ADR 0029):
- The marker stays
editor: "file"(spec 02 unchanged: the value is the contents of a local file, and a part is a piece of one). Everybinaryparameter that can be larger than a frame carries it:restore_part.data, a connection’supload_part.data, the flow engine’sput_artifact.bytes,sys/profiles ▸ put.profile, asinstall_zip,install_wasm,install_backup, a folder’suploadand storageimportalready did. A generic action form shows a file picker for it. The gateway rule is unchanged: a large body only for an action that declares such a parameter. Astringormapargument (a branchimport,import_dsa, a flowdef) cannot take the route and stays within a frame; rule for link authors indocs/links.md§1. - A refusal reaches the client. A declared
Content-Lengthover the limit (64 MiB + 64 KiB) is answered 413 before anything is read. Any other refusal before the body is read (key, file parameter, level, step-up, the user’s upload in progress, both upload permits in use) is answered after the gateway reads and drops the body: at most the limit, within 120 s, one chunk in memory, at most 4 at once; the refused request holds neither the user’s upload slot nor a permit. With all 4 in use, or when the client sentExpect: 100-continue(it reads the answer first), the body is not read. An unauthenticated request is not read either: a client whose session ended can still see a reset, and the Dart client then throws aWyrmException(disconnected, “the gateway closed the connection while <action> sent <n> bytes …”) instead of aSocketException. - Tests:
wyrm-gatewayhttp_invoke_takes_large_arguments(a 4 MiB refused body gives 400 and the text, 403 before 4 MiB are taken, a 4 MiB upload after them, 413 by the declared length),wyrmde2euploads_in_parts_through_the_gateway(a backup read through the gateway,restore_begin+restore_partbyPOST /api/invoke+restore_check;upload_begin+upload_part+upload_committo a localfs store), Dartbulk_invoke_test.dartand the gateway e2e case of a 4 MiB refusal.
Amendment 2026-11-15 (2) — the Rust client and large text arguments
After #99 the Rust client (wyrm-gateway-client: wyrm-agent, the MCP connector wyrm-mcp --gateway, wyr probe) still sent every invoke in a frame: an argument over 64 KiB closed its socket. Decided (ADR 0029):
- The Rust client takes the route as the Dart client does.
Conn::invokesends encodedargsover 60 KiB (MAX_FRAME_ARGS) byPOST /api/invokeon the endpoint and session of its login, with the same TLS roots, and smaller ones in a frame. It sendsExpect: 100-continueand the body only after100 Continue(or after 10 s without an interim answer, RFC 9110): the gateway checks the session, the key, the file parameter, the level and the step-up before it reads the body, so every refusal (also 401 for a session that ended, which the gateway never drains) comes back before the body goes, asError::Refused {status, message, http}with the gateway’s text. Timeouts: 15 s for the head, 125 s for the body, 185 s for the answer. Over 64 MiB + 64 KiB (MAX_INVOKE_BODY, the gateway’s value; a gateway test asserts both limits are the same) it refuses withError::TooLargebefore anything is sent. - No frame over 64 KiB leaves the client. A
set,check,historyor any other request overMAX_FRAMEisError::TooLargeat once: the gateway would close the socket and every stream on it. The MCP dry run does not ask the link’s check for such arguments (“not asked …; checked against ~meta only”); the call itself goes by the route. AConn::from_rawconnection (the gateway’s own/mcp, in process) has no HTTP route: an invoke over 60 KiB isTooLargethere. - A large
stringormapargument has no route; the limit stays. A branchimport {json},import_dsa {json}, a flowdef(deploy,validate,put_block) and a storagepublishvalue must fit 60 KiB. They are not markededitor: file: spec 02 makes that abinaryparameter with a file’s bytes, and none of them is one. They get no file form now: a large tree goes as several branches (exported and imported one connection or one device at a time), and storage values stop at 32 KiB. The gateway’s refusal says what to do: “<action> takes no file: invoke it over the WebSocket, with arguments under 60 KiB; only a parameter witheditor: filetakes more”. When a real case needs more, that action gets abinaryeditor: fileparameter beside the text one, as storageimport {data | file}has; the gateway and the clients need no change. wyrm-agent invoketakes--args-file <path>and--file <param>=<path>(the bytes of a file as a binary parameter, at most 64 MiB + 64 KiB).- Tests:
wyrm-gatewayrust_client_sends_large_arguments_by_http(frame and route give the same result up to 4 MiB; a non-file action’s 4 MiB refused with the text; 403 for a viewer;TooLargeover the limit and for aset/checkover a frame, the socket still open; 401 with “log in again” after the user is disabled),wyrm-mcpa_large_file_argument_goes_by_http(300 KiB$bytesover TLS with--gateway-ca, the dry run, a text argument refused),wyrmde2euploads_in_parts_through_the_gateway(nowrestore_partandupload_partby the Rust client, a 100 KiB storage value refused with the text),wyrm-agentinvoke_arguments_from_files.