Skip to content
Toolkit

ADR-0126 — The archive says where its files were; the product says where they go

Status: Accepted · Date: 2026-08-30 · Track: 010 phase 02, second slice

Context

Phase 02's first slice judges an archive whole before a byte of it is stored (ADR-0125). This slice writes the accepted one out. That is the point in this track where a stranger's text has historically become a filesystem argument, and the charter's rule — nothing the artifact contains decides anything — has to survive contact with a write API that did not exist: FileStorage could save an upload under a name it minted and read one back, and had no way to write a second file belonging to the first.

The obvious API is SaveAt(path, bytes). Every unpacking CVE of the last thirty years is a variation on having had one.

Decision

An entry's own path is a label in the manifest, and never an argument to anything else.

  1. The write API accepts no name. SaveBundleEntry(prefix, reader) takes the bundle a byte belongs to and returns the key the backend chose. There is no method that takes a path, so the traversal such a method would be aimed at has nothing to arrive in. The leaf is randomHex(16) and carries no extension: an extension is a string whoever built the archive chose, and no reader downstream may take an instruction from one (ADR-0122).
  2. A prefix is a shape this product mints, bundles/<32 hex>, validated on every write and on the delete — the delete is RemoveAll, and it is guarded twice: the shape, then the resolved directory still being inside the storage root.
  3. The manifest is the only place the archive's own paths appear, mapping each cleaned path onto the key its bytes actually went to. Phase 03 resolves an asset by looking a request up in it. A lookup answers for what it holds; a path join answers for whatever the filesystem reaches, which is the difference the whole phase rests on.
  4. The manifest is written last. A prefix without one is an expansion that did not finish, and nothing will ever read it.
  5. Any failure removes the whole prefix — a refusal is the whole upload, and that now includes the failures a disk produces on its own. The keys written so far are handed to the delete rather than read back from a manifest that, at a refusal, does not exist.
  6. The expansion runs before the archive itself is stored, so a bundle that cannot be written out costs no row and no byte at all. The archive is kept beside its expansion rather than instead of it; phase 04 measures both.
  7. A refused cap is the uploader's business; a failed write is not. The sink's cap refusals are BundleRefusal and answer 400 naming the rule; a write failure is an ordinary error and answers 500, because telling a stranger their archive was wrong when the disk was full is a lie.
  8. A replacement frees what it replaces. The update path is what makes the old expansion unreachable, so it is what removes it. Freeing on DELETE is a different path and phase 04's.

The archive is read twice — once to judge, once to write — deliberately. A single pass would be a rule discovered while unpacking, which is a rule that has already spent the disk.

Consequences

  • zip-bundle stays unserved. Bytes are stored and nothing reads them, which is the honest state and the one the ledger records: an author who uploads a bundle still gets the 404 they got before. Only phase 03 may flip the row.
  • H3 widens, as it did for ADR-0125's limit half. An unserved row may now name its whole STORE half — the bound, the store, the tests and the hostile fixtures — and the gate holds those anchors; what unserved forbids is the SERVE half, a reader or a content type, because that is the claim the word makes. Naming a writer that exists is what makes deleting it fail the build.
  • The content type of an entry is not decided here. The local backend stores bytes and no type; S3 stores application/octet-stream. What a response calls an entry is phase 03's decision, from the product's own table, and the ledger's H7 holds it there.
  • BundleSink is a services-level interface, so the expansion depends on the narrow write API rather than on either backend, and the handler's FileStorage restates it.

Alternatives rejected

  • A SaveAt(path, …) API with a traversal check in front of it. The check becomes load-bearing, and the running-stack inversion in this slice's evidence shows what that costs when it is removed: ../../etc/passwd written two directories above the bundle, on a 201.
  • The manifest in links.settings. Two thousand entries in a JSONB column read on every redirect, to save one fetch on the asset path.
  • Storing the expansion instead of the archive. A format change would then have nothing to re-expand from.

Source: docs/decisions/0126-the-archive-says-where-its-files-were-and-the-product-says-where-they-go.md

Library