Blobs
Big, immutable things go to one store, src/blob/store.ts (step 2 of
#4481). Its keys are paths and its contents are bytes; it has no other
idea of structure. The refs and metadata that name those bytes stay in
the database.
Two shapes, one store
Storeis the small shape snapshots were written against: put, get, list, names, delete. Snapshots, the mirror and the drill still take exactly this, unchanged (docs/SNAPSHOT.md).BlobStoreis the same store, with what a large file needs:put(key, Blob): aBun.fileis streamed from disk, never read whole into memory. It can be retried, because it is read anew each time.putStream(key, stream): a body of unknown length. A bucket takes it multipart. A directory writes it under a temporary name and renames it into place, so a reader never sees half of it. It is tried only once, because a stream cannot be replayed.size(key),getRange(key, { start, end })andgetStream(key, range?).endis exclusive. A range past the end of the object is empty, and an absent key isundefined, the same answer on a bucket as on a directory.presign(key, { method: "GET" | "PUT", expiresInS }): a URL straight to the bucket, signed locally with no request. A directory has none, so its caller serves the bytes itself.- A storage-class hint on every put:
hot(the default, which sends nothing),infrequent(STANDARD_IA, which R2 and S3 accept) orarchive(DEEP_ARCHIVE, S3 only). It is the fourth argument ofput(key, body, signal?, options?): the third is the abort signal snapshots already pass, so their calls are unchanged.
s3Store (any S3-compatible endpoint: R2, S3, B2) and dirStore are both
BlobStores. withRetries keeps one a BlobStore: sizes, ranges and
opening a stream are retried the way a get is, and a Blob put gets a
deadline that follows its size.
At the boundary
A key with .. or . segments, a leading / or a control byte is
refused. So is a range that is not whole, non-negative bytes in order, and
a presign that is not a GET or PUT valid for 1 s to 7 days. The bucket's
secret never appears in a presigned URL; only its signature does.
Big git blobs
Blobs over a size policy are copied here by object id after a push and served by presigned URL: docs/features/large-files.md.
A person's attached looks
A picture a person attaches to a pull (src/looks/archive.ts) is written with put(key, blob) under
looks/<app>/<env>/<sha256>.<w>x<h>.<ext> and its row's path is blob:<key>. The forge's own
looks stay files under the data dir. The store is the bucket when S3_* is set, else
<data>/look-blobs. The forge serves it after mayFetchLook; on a bucket it then redirects to a
60 s presigned GET, never signing for someone the app does not let in. deleteLooksAndObjects
removes the objects with the rows, keeping one another row still names (same bytes, one object).
Attachments from before this stay on the disk and are served from there; they are not migrated.
Not here yet
Attachments and the cold-tier lifecycle are later steps of #4481, each with its own issue.
Run logs (#4545)
src/runs/archive.ts. Once a run is finished, the hourly sweep (crew/dispatch.ts, before the prune) puts runs/<id>.log to the store as runs/<id>.log, streamed from disk, class infrequent. The store is the bucket when S3_* is set, else <data>/run-archive. A put that fails leaves the file local for the next sweep; a local log is evicted only once the store holds the same number of bytes and it has been idle a day. The run page, the REST log and the MCP run_log bring an evicted finished log back from the store before reading it; a run in progress is never archived or restored, and its live tail is unchanged.
Packs: the repository in the bucket
src/blob/packs.ts (#4491, step 4 of #4481; the write path and the rebuild, the first slice). Inside pre-receive, after the forge's own checks pass and before git moves a ref, a push's new objects are written to the store as one pack (packs/<owner>/<name>/pending/<hash>/<seq>.pack). A store that fails, or gives no answer in 60 s, refuses the push with a 503 and nothing moves, so the pusher is acked only for a push the store holds. The record of its ref updates (<seq>.json) is written in post-receive, after git applied them: a push git then refused leaves a pack no record names, which a rebuild never reads. The first time the store is used for a repository that already has refs, its history is written first as a base record (0000000000000-base.json and base.pack), so a rebuild has what the first push's old values name.
bun scripts/rebuild-repo.ts <data-dir> <owner> <name> <empty-target-dir> makes a bare repository from nothing: it indexes each record's pack in order and replays its updates with update-ref <ref> <new> <old>, so a record that does not fit stops the rebuild and is named. The target must have no refs. A repository whose refs moved outside receive-pack (the web editor, merges) stops a rebuild at the first record whose old value they changed.
On when the forge has a bucket (S3_*) or FORGE_PACK_STORE=dir (a directory under the data directory); FORGE_PACK_STORE=off turns it off. Not done yet: pushes that skip receive-pack (web editor, merges), refs kept in the database, rebuilding on a missing repository at boot, evicting idle repositories, clearing packs no record names, and the scheduled repack and compaction on the primary.