A hostile file kills a worker, not the runtime.
Between November 16 and 20 we moved file conversion out of the runtime's process, then taught it to read a whole book library
1. Where we left off
In October we wrote about the earlier step: "From a scanned page and a recording to a searchable document". loomcycle learned to import DOCX, XLSX, PPTX and PDF, to read scanned pages with OCR, and to turn a recording into text. That made a document-based reference system we are building possible at all. Its inputs come from mail attachments, archives and scans, which means we do not choose the files. Somebody else does.
That is fine when the somebody is friendly. It is a problem when they are not, or when a file is simply broken. This post is about what we did in the week of November 16 to make a bad file cheap, and what we added once it was cheap.
2. Why one file could hurt everyone
File conversion is the one kind of work in loomcycle whose memory use is decided by what someone put inside a file. Our own docs put a number on the ordinary case: one Office document at every extraction cap can take about 700 MiB. A hostile file is written to take more.
Think of three files a beginner might not suspect:
- A zip bomb. A small archive whose contents expand to something enormous when you open it.
- A malformed PDF. A file whose internal structure points in loops, or claims sizes it does not have, so the reader keeps allocating.
- A huge recording. A long voice note that has to be converted before speech-to-text can read it.
Until this release, conversion on a default install ran inside the runtime's own process. If one of those files exhausted memory, the operating system killed that process, and the process was the runtime. Every run on that replica went down with it: the agent reading the bad file, and every other agent doing unrelated work.
A concrete case from our own fixes shows how easy this is. Before v1.154.1, an encrypted PDF was read whole before we noticed it was encrypted. A 22 MB encrypted PDF took 390 MiB. Nothing malicious, just a file we could not use, costing roughly eighteen times its size in memory.
3. What we changed: conversion runs in workers
In v1.153.0 we shipped conversion workers, off by default. In v1.154.0 we turned them on by default for Linux.
A conversion worker is the same loomcycle binary, started as loomcycle worker. The runtime starts its children, supervises them and restarts them. Every conversion goes to them: text extraction, PDF page cuts and page rendering for OCR, a recording's conversion for speech-to-text, speech encoding, and the re-encoding of an image a vision model needs scaled.
A worker is handed bytes and returns bytes. It is never handed a path, a tenant, a run or a credential.
That sentence from our worker guide is the whole design. The worker holds no provider key, opens no store connection and mounts no volume. The runtime keeps every grant check, every fence, the run's inbox and every model call. The worker only converts.
Each child has its own memory limit. On Linux each child also raises its own out-of-memory score, so when memory runs short in a shared container, the kernel kills a worker before it kills the runtime.
4. What happens now when a bad file arrives
Here is the same story as before, with workers in place:
- An agent asks to extract a file. The runtime sends the file's bytes to a free worker.
- The file blows past the worker's memory limit. The worker dies.
- The runtime answers that one tool call with an error saying the file crashed the converter. The run that asked gets the error and can decide what to do next.
- The file is quarantined. For
quarantine_ttl_s, an hour by default, the same file is refused instead of being sent to the next worker to kill that one too. - The dead child is started again with backoff, from 1 second doubling up to 30 seconds.
Every other run keeps going. They never noticed.
Two more behaviours matter. When every worker is busy, a call waits queue_wait_s and is then answered as a busy server, which the model may retry. And when no worker is attached at all, the call is refused. The runtime never quietly falls back to converting in its own process, because that fallback would undo the point.
5. How to set it
The setting is conversion.mode. With nothing written, it means local on Linux and inprocess everywhere else. These are the keys and defaults as our configuration reference states them:
conversion:
mode: local # local (default on Linux) | inprocess (default elsewhere) | remote | local+remote
queue_wait_s: 60 # how long a conversion waits for a free worker before a busy answer
quarantine_ttl_s: 3600 # how long a file that killed a worker is refused
local:
workers: 2 # children kept running (1-64)
memory_limit_mb: 1024 # each child's GOMEMLIMIT (at least 128)
The four modes, in short:
inprocesskeeps the old behaviour. Write it if you want conversions back in the runtime on Linux, for example on a single-user install where you accept the risk.localruns children of the runtime on the same host or container. Nothing else to deploy.remotesends conversions to workers you run as their own containers, for hard memory limits, no shared filesystem, and workers on other hosts.local+remoteuses both kinds in one pool.
Remote workers need a shared LOOMCYCLE_WORKER_TOKEN of at least 32 characters, and TLS when the endpoint is off the loopback, unless you explicitly mark the network as private with insecure: true. A remote worker runs only its own helper commands, set in its own environment. A job says what to convert, never what to run.
6. Smaller images, and helpers where they belong
Moving conversion out of the runtime let us clean up the images. The runtime images are distroless again. The loomcycle-media image, which existed to carry ffmpeg and pdftoppm next to the runtime, is no longer published; its last tag is 1.153.0. Those programs now live in the loomcycle-worker image, which is built, signed and attested on every release tag, patches included.
The cloud example and the TrueNAS app now run two conversion-worker containers in remote mode. One thing to know before upgrading: in a distroless runtime image the local children have no ffmpeg or pdftoppm either, so voice-note conversion, speech encoding and OCR page rendering fail with "the program is not installed where the workers run". For those, run remote workers from the loomcycle-worker image.
7. Refusing what we cannot use, early
The encrypted PDF from section 2 got its own fix in v1.154.1. The runtime now reads only the first and last 64 KiB of a PDF and refuses a file whose trailer, or cross-reference stream, names both /Encrypt and /Root. The check after full parsing stays in place for anything the early check misses.
The same instinct runs through the new readers below. A book with DRM is refused. A Word file that is encrypted or obfuscated is refused by name. An encrypted or multi-volume RAR is refused. An indirect DjVu, or one that includes other files, is refused before any helper program runs.
8. With the floor in place, a whole book library
Once a bad file could only cost one worker, we were comfortable opening the door much wider. Between v1.160.0 and v1.162.0, File op=extract learned to read:
- EPUB 2 and 3, chapters in reading order, footnotes as
[n]under Notes. - FB2, and a
.fb2.zipholding one book, read as a stream in its declared legacy encoding. - RTF, also one saved as
.doc, through a bounded pure-Go tokenizer. - DjVu: the text layer through DjVuLibre, and in v1.162.0 OCR of scanned DjVu pages, rendered one picture per page within the run's page budget. The book itself is never sent to a vision model.
- MOBI, AZW3 and PalmDOC, in pure Go, with footnotes and contents labels.
- Word 97 to 2003 DOC, in pure Go from the old compound file format: text, heading styles, tables, footnotes and document properties.
- CHM compiled help files, in pure Go with an LZX decoder written from the published specification.
Every book now reports what it says about itself as metadata: title, authors, language, publisher, series, identifiers and more. Every value is bounded and treated as untrusted text.
Old files bring old encodings. In v1.163.0 a CHM help file whose Russian pages name no encoding is read correctly, even when the file claims to be English because it was compiled on English Windows. That case came from a field sample of v1.162.0 run on a real book library. In v1.165.0, plain text and HTML in windows-1251, KOI8-R, CP866 or Latin-1 that name no encoding are detected and decoded, and a conversion worker never sends invalid UTF-8.
Three smaller tools round it out:
- Sampling.
File op=extracttakespages(PDF only, such as1-10) to parse only those pages, andmax_charsto stop at a character limit and report where it cut. An agent can look at a book before committing to all of it. - Unpacking.
File op=unpackcopies the files out of a ZIP or RAR 4/5 archive into the run's inbox. By default it takes the formatsextractreads plus nested archives, which are written but never opened.dry_runlists without writing. - An agent's own OCR model.
transcription.ocr_modellets one agent be held to, say, a local vision model while the rest of the deployment reads scans elsewhere.
9. Workers are the floor, not the only wall
Workers make a crash cheap. They do not make it acceptable to crash often. So the new readers carry their own limits, each with a test that fails without it: decompression per record and per book, compound-file chain loops and directory cycles, LZX table and expansion limits, and for unpack, entry counts, sizes, expansion ratio and total size. That last list is the plain answer to the zip bomb. The book readers' fuzz targets run in CI.
The layering is the point. A reader that refuses a bad file early costs a few kilobytes. A reader that misses it costs one worker and one failed call. Neither costs the runtime.
For a document-based reference system, the input you cannot choose is the input you have to plan for. Mail attachments, old archives and scanned books will keep arriving in shapes nobody tested. What changed this week is the price of a bad one: an error on one call instead of an outage for everyone.
If you run loomcycle on Linux, you already have local workers after upgrading to v1.154.0 or later. If you run a distroless image and need recordings, speech or OCR page rendering, add loomcycle-worker containers; the worker guide in the repository walks through it.