Public: anyone can read this; the crew can change it.
Each hosted forge's state is written as one file to the parent's backup destination by the nightly, so one forge can be restored alone #13837
After each nightly snapshot, every hosted forge is now written as its own file to the same destination, so one forge can be restored without the others. The new test (test/snapshot-children.test.ts) passes along with the archive and snapshot-service suites, 86 tests across 9 files.
stopped parked by the crew deploy 59472b8
13 earlier comments · 1 event
After each nightly snapshot, every hosted forge is now written as its own file to the same destination, so one forge can be restored without the others. The new test (test/snapshot-children.test.ts) passes along with the archive and snapshot-service suites, 86 tests across 9 files. tsc --noEmit and scripts/gate.ts --fix are clean, and the gate's comment rewraps are committed.
- The copy (
src/spawn/nightly_copy.ts,copyForges): each finished hosted forge goes toforge-snapshots/<name>.tar.gzin the shape an archive has, so it holds the ledger and the data directory with its repositories and keys. The forge's own database is left out of the file read and itsVACUUM INTOcopy is added instead, so the database copy is consistent while the forge keeps running. UnlikearchiveForge, nothing is stopped and nothing is removed. The last copy is recorded in<data>/archive/nightly/<name>.json. - Upload size: each forge has one key, replaced each night, so the store stays bounded. A forge is not sent again when the sizes and times of all its files and its ledger match the last copy. Each copy is read back and its hash checked before the record is written.
- Too large: a forge over
ARCHIVE_MAX_BYTESis listed as skipped with its size ("<name> skipped: N MiB, over the 256.0 MiB one file holds"), and that line is logged as a warning. - Wiring (
src/snapshot/service.ts): the pass runs after the parent's snapshot is taken and verified, before the drill check. A failed forge copy is logged and never fails the parent's snapshot. - Restore (
src/spawn/archive.ts): the restore step is split out asrestoreRecord.restoreForgenow falls back to a forge's last nightly copy when there is no archive record, so the existing Restore by name in the web, MCP and terminal brings back a lost forge. The nightly record is kept after a restore; an archive's record is dropped, as before. A sharedholdingForgeguard stops an archive, a restore and a nightly copy of the same forge from running at once.
The test makes two hosted forges with accounts in their databases, runs a snapshot through startSnapshots, and checks both files are in the store. It then removes one forge, restores it alone and finds its account, while the other forge's database is untouched. It also checks that an unchanged forge is not sent again and that a forge over the cap is named with its size. It fails without the change because no nightly record exists.
Left out:
- A lost forge does not appear under "Archived" on /forges, so there is no button for it yet. Restore by name works through MCP; the web route and the terminal action need the name in their request.
- The night's outcome goes to the log only, not to the Backups page.
- The parent's own snapshot is unchanged.
- A tar read that comes back with an error but still leaves a file is accepted, so the rest of a busy forge's files may be a moment behind its database copy.
Tests not run here: scripts/fast.ts named 2046 files for this diff, so I picked the suites myself: the new test plus forge-archive, snapshot, snapshot-outcome, snapshot-one-core, mcp-snapshot-now, backup-retry, backup-truth and backup-lanes. The forge's check runs the rest.
Try it: bun test test/snapshot-children.test.ts
🤖 Generated with Claude Code
The nightly snapshot now writes each hosted forge to the snapshot destination as one file of its own, nightly/<name>.tar.gz. Restore can bring one lost forge back without touching the others. A forge that hasn't changed since its last copy is not written again. A copy that doesn't read back with the same bytes counts as a failure. A copy bigger than the archive size limit is skipped.
src/spawn/nightly_copy.ts makes each copy:
spawn/<name>.jsonand the forge'schildren/<bodyId>/directory are packed with tar, leaving out the liveforge.dbfiles.- A consistent copy of
forge.dbis then added under the same name. It is made withvacuumFile(src/snapshot/vacuum.ts), which runs in a Worker, the same one the forge's own snapshot uses. This keeps the copy from freezing requests the way it did in #8742, and that file no longer opens a database itself. - The tar file is compressed with
gzip -n -f. gzip's stderr is ignored: it was piped but never read. - The file is uploaded, read back and its checksum compared before it is recorded.
src/spawn/archive.ts gives this module its tar helper and the record of what was copied. src/snapshot/service.ts runs the copies after each nightly snapshot.
The gzip call is listed in test/spawn-sites.test.ts with what it runs on. I kept the gzip process rather than compressing in memory, so a large copy isn't held whole in memory.
test/snapshot-children.test.ts checks that a run writes one file per hosted forge and that one restores alone. The type check, the gate, that file and test/spawn-sites.test.ts, test/spawn-pipes.test.ts and test/worker-database-opens.test.ts pass here. The full suite runs in the forge's check on this push.
🤖 Generated with Claude Code
Request changes. The core copy works and the test is real, but the following need fixing in one round:
- Both doors: a lost forge's nightly copy has no entry on the page or in the terminal. /forges lists only archive records, so there is no button, and the terminal action needs the name typed. Restore from the nightly must be reachable from the page and from src/tui/ the way Restore is, not MCP only.
- No docs/features/<name>.md. Add the how-to there (what is copied, where the key lives, the size cap, how to restore one forge). Do not put it in README.
- The night's outcome goes to the log only. A forge skipped for size must be visible to a person (Backups page / resilience), not just a log.warn. Box 2 says 'named', and a log line nobody reads is close to silent.
- Box 1 says reuse archiveForge without its remove step. The pull writes a parallel tar+gzip path in nightly_copy.ts instead and exports tar/mib/BODY_ID from archive.ts. Reuse the archive pipeline (a keep-running option on archiveForge) rather than duplicating it.
- The restore record lives only in <data>/archive/nightly/<name>.json on the parent. If the parent's disk is the thing lost, restore-by-name finds no record even though forge-snapshots/<name>.tar.gz is in the store. Restore should be able to find the key from the store (list forge-snapshots/) and check retention does not sweep that prefix. Add a test for that.
- Dead/odd code: the
export { nightlyRecord, type NightlyRecord }re-export in nightly_copy.ts, the duplicated recordPath helpers, the unused recordPath-freeunchangedskip that never checks the key still exists in the store (a store wiped of the file reports 'unchanged' forever). Check store.get/head before skipping. - Accepting a tar that exited non-zero as long as a file exists can store a half-read forge. Distinguish exit 1 (changed file) from exit 2 and fail on the latter.
- Direction: this is a feature while the pipeline list is first; say in the pull why it goes ahead of it.
After the host's own nightly snapshot, each hosted forge is now written as one file to the same backup destination at forge-snapshots/<name>.tar.gz. Any one forge can then be restored alone, from the page, the terminal or MCP. This round answers every point in the review. The tests that cover the change pass (192), as do tsc, the gate and design-lint. scripts/fast.ts named 2394 files, which is too broad to run here, so I ran the snapshot, archive, backups, forges-page, MCP-forges and terminal-forges suites myself.
- Reuses the archive code (4, 6, 7): the nightly copy is now
archiveForgewith a newkeepRunning: { fingerprint }option (src/spawn/archive.ts).- With that option, the forge is not stopped or removed. Its database is copied consistently with VACUUM INTO, off the serving thread, and the key is replaced each night.
- The packing lives in one function,
packForge. Tar's exit 1 (a file changed while it was read) is accepted; any other failure fails that forge's copy and nothing is stored. nightly_copy.tsonly goes through the forges, skips the unchanged ones and keeps the outcome. "Unchanged" now first checks that the store still holds the copy: by listing on a normal store, by reading it on a sealed one, since a sealed store hides its key names.- The re-export, the second
recordPath,holdingForge, and the exportedtar/mib/BODY_IDare gone.
- Restore on the page and in the terminal (1): a new
restorableForgeslists the archives plus the nightly copies of forges that no longer exist here./forgeslists them under "Archived" with a Restore button, the terminal'srpicker offers them, and the MCP dry run lists the same set. - Restore when the host's disk is lost (5): if there is no record on this host, Restore reads
forge-snapshots/<name>.tar.gzstraight from the store and works out the forge's data directory from the file itself. Retention only sweepssnapshots/andchunks/, so it never removes these copies. A test covers both: prune, delete the local record, restore by name. - Outcome visible to a person (3): the night's result is saved to
<data>/archive/nightly-outcome.json. The Backups page has a "Hosted forges" block with the last night's summary, and every skipped or failed forge appears under a "Not copied" badge. - Docs (2):
docs/features/forge-nightly-copy.mdcovers what is copied, where the key lives, the 256 MiB cap, and how to restore one forge, including when the host's disk is lost. - Tests:
- A lost forge appears in the Restore list and a running one does not.
- The night's outcome is saved.
- A store wiped of a copy gets it again.
- Retention plus restore from the store alone works.
- An unreadable file in a forge's data fails the copy and stores nothing. This test is skipped when run as root.
Why ahead of the pipeline list (8): today a hosted forge can only come back by restoring the whole host, and that also rolls back every other forge. This copy runs inside the existing snapshot job, adds no new service, and is capped at one file per forge per night, so it closes a data-loss gap cheaply now.
Left out:
- No list of lost forges when the host's disk is gone: in that case the page and terminal show nothing to pick, because a sealed store cannot be listed by name. Restore by name works: MCP
forgeswithrestore: "<name>". - Double download: a restore from the store alone downloads the copy twice, once to find its directory and once to restore it (capped at 256 MiB).
To try it: send a forge, run a snapshot, remove the forge, open /forges and press Restore under "Archived". The Backups page shows what the night came to.
🤖 Generated with Claude Code
After the host's own nightly snapshot, each hosted forge is now written as one file to the same backup destination, at forge-snapshots/<name>.tar.gz. Any one forge can then be restored alone, from /forges, from the terminal, or through MCP. This push also merges main.
- Reuses the archive code: the nightly copy is
archiveForgewith a newkeepRunningoption (src/spawn/archive.ts). With it, the forge is not stopped or removed, its database is copied consistently while it runs, and the copy replaces the previous night's.- Tar's exit 1 (a file changed while it was read) is accepted. Any other tar failure fails that forge's copy, and nothing is stored for it.
src/spawn/nightly_copy.tsgoes through the forges and skips any whose files have not changed. It only skips when the store still holds the copy; a store that lost it gets it again.
- Restore entry on every door: a forge that no longer exists here but has a nightly copy is listed under "Archived" on
/forgeswith a Restore button. The terminal'srpicker on the Forges screen offers it, and the MCPforgesdry run lists the same set. - Restore when the host's disk is lost: if this host has no record of the copy, Restore by name reads
forge-snapshots/<name>.tar.gzfrom the store and works out the forge's data directory from the file itself. Snapshot retention only removessnapshots/andchunks/, so these copies are never pruned. - Night's result shown: the outcome is saved to
<data>/archive/nightly-outcome.json. The Backups page has a "Hosted forges" block that names every forge skipped for size or failed, with the reason. - Docs:
docs/features/forge-nightly-copy.mdcovers what is copied, where the key lives, the 256 MiB cap, and how to restore one forge. - Merge with
main: the only conflict was the description of the MCPforgestool. It keepsmain'ssizeoption andnot_founderror, plus this pull's wording thatrestorealso brings back a lost forge from its nightly copy.
Why this goes ahead of the pipeline list: today a hosted forge can only come back by restoring the whole host, which also rolls back every other forge. This closes that data-loss gap inside the existing snapshot job, with at most one file per forge per night.
Tests: the covering suites pass after the merge (147 tests: nightly copy, archive, MCP forges, terminal forges, Backups page), and tsc and the gate pass. scripts/fast.ts named too much to run here (2394 files), so I chose these suites myself. New tests check:
- A lost forge appears in the Restore list; a running one does not.
- The night's outcome is saved.
- A store wiped of a copy gets it again.
- Retention plus restore from the store alone works.
- An unreadable file fails the copy and stores nothing. This one is skipped when run as root.
Left out:
- When the host's disk is gone, the page and terminal have nothing to list, because an encrypted destination hides its key names. Restore by name works through MCP:
forgeswithrestore: "<name>". - A restore from the store alone downloads the copy twice (at most 256 MiB each time).
To try it: send a forge, run a snapshot, remove the forge, then open /forges and press Restore under "Archived". The Backups page shows what the night came to.
🤖 Generated with Claude Code
Each hosted forge now gets its own file every night, written to the backup destination right after the host's nightly snapshot. That means a single lost forge can be restored without restoring the whole host.
- The copy:
archiveForgeruns withkeepRunning(src/spawn/nightly_copy.ts,src/spawn/archive.ts). Nothing is stopped or removed. The forge's database is copied withVACUUM INTO, off the serving thread. If a forge's files and ledger haven't changed since its last copy, and the store still holds that copy, it isn't sent again. - Where it goes: one key per forge,
forge-snapshots/<name>.tar.gz, replaced each night. Snapshot retention only sweepssnapshots/andchunks/, so it never prunes these copies. - Restore: a lost forge is offered by Restore on
/forgesand in the terminal. If this host's own records of the copies are gone, the forge is found by reading the store. - Not copied: the Backups page has a "Hosted forges" block that says what the last night came to. It names every forge that was skipped (over the 256 MiB cap, with its size) or failed. The same words go to the log as a
snapshotswarning. - Docs: the note
docs/features/forge-nightly-copy.mdnow has its row under "Backups and moving" indocs/features/README.md. The missing row is what turned the last check red.
test/feature-orphans.test.ts passes, and bun scripts/gate.ts --fix changed no files. This last push only touches the docs index, so I did not re-run bun x tsc --noEmit or the other tests for it.
Left out: copies are not encrypted beyond what the backup destination itself provides, and nothing prunes a forge's copy after the forge is deleted.
To try it: stop a hosted forge and move its data away, open /forges, and press Restore on its nightly copy. The Backups page names any forge the night did not copy.
🤖 Generated with Claude Code
The nightly snapshot now also writes each hosted forge as one file of its own, to the same backup destination. That lets a single lost forge be restored without restoring the whole host.
- The copy:
archiveForgewithkeepRunning(src/spawn/nightly_copy.ts,src/spawn/archive.ts). Nothing is stopped or removed, and the running database is copied withVACUUM INTO. A forge that hasn't changed is not sent again, unless the store has lost its copy. - Where it goes: one key per forge,
forge-snapshots/<name>.tar.gz, replaced each night. Snapshot retention only sweepssnapshots/andchunks/, so it never prunes these copies. - Restore: a lost forge is offered by Restore on
/forgesand in the terminal. If this host's own records of the copies are gone, the forge is found by reading the store. - Not copied: the Backups page block "Hosted forges" names every forge the last night skipped (over the 256 MiB cap, with its size) or failed. The log carries the same words as a
snapshotswarning.
This push fixes the red check:
- Feature index: the merge with main brought in
docs/features/app-page-details.mdfrom #13804, which has no row indocs/features/README.md. That made the index test fail. It now has a row under "Your apps", and this pull's ownforge-nightly-copy.mdhas one under "Backups and moving". - Slow test: the nightly-copy test in
test/snapshot-children.test.tstook 2.22 s against the 2 s budget. It is now three tests, each checking one thing: one file per forge with a single restore; an unchanged forge not re-sent and an oversized one named; a wiped store sent the copy again. No assertion changed. - Preview quota test: the "live previews" quota test hit 420 s on one shard in the check. It passes here in 8 s and this pull doesn't touch it, so I made no change for it.
bun x tsc --noEmit and bun scripts/gate.ts --fix are clean. scripts/fast.ts named 2417 test files because of the merge, too broad to run here. I ran the 40 files covering snapshots, archive, backups, nightly and the features index instead: 219 pass, 0 fail.
Left out: copies get no encryption beyond what the destination provides, and nothing prunes a forge's copy after the forge is deleted.
To try it: stop a hosted forge and move its data away, open /forges, and press Restore on its nightly copy. The Backups page names any forge the night did not copy.
🤖 Generated with Claude Code
Every hosted forge's state is written as a nightly copy (src/spawn/nightly_copy.ts, src/spawn/archive.ts). The forges and backups pages, the terminal's forges screen and the MCP forges tool now show when each forge's copy was last taken. This push merges main again and fixes the two tests that failed the check:
- "the index is one note to a row, each named in words, each once": main added its own row for
app-page-details.mdtodocs/features/README.md, and the row an earlier merge on this branch added was still there, so the note was listed twice. The branch's row is gone and main's stays. This was the cause of the failure. - "a fast-forward applies the previewed id: a parent that moved after it is not taken": this one is timing-dependent. It passed five runs in a row here, both before and after merging main, so the failure was never reproduced. The likely cause is the setup's "Next" commit to
alice/ff: it starts the forge's own follow ofbob/ff, and nothing waits for that follow to finish. Under load it can movebob/ffwhile the test is still checking that the fork did not move. Intest/take-expect.test.tsthefffork is now set to not follow right after it is forked, before that commit.
To review: src/spawn/archive.ts, src/spawn/nightly_copy.ts and test/snapshot-children.test.ts. The feature is described in docs/features/forge-nightly-copy.md.
Run here, all green: bun scripts/gate.ts --fix, bun x tsc --noEmit, bun scripts/design-lint.ts, and bun test on test/feature-orphans.test.ts, test/take-expect.test.ts, test/snapshot-children.test.ts and test/spawn-sites.test.ts (19 pass). The gate names src/web/pages/backups.ts and src/web/pages/forges.ts as changed pages that need looks.
🤖 Generated with Claude Code
Declined: main now does the job of #13837 in another way (8282ca745, "Hosted forges are in no backup (#13839)"). Merging it in would leave the nightly copying every hosted forge twice, so I aborted the merge and pushed nothing. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m7hf9kb9a7s145kpmkazdsyw Left open: someone has spoken on this pull.
After each nightly snapshot, every hosted forge is now written as its own file to the same destination, so one forge can be restored without the others. The new test (
test/snapshot-children.test.ts) passes along with the archive and snapshot-service suites, 86 tests across 9 files.tsc --noEmitandscripts/gate.ts --fixare clean, and the gate's comment rewraps are committed.src/spawn/nightly_copy.ts,copyForges): each finished hosted forge goes toforge-snapshots/<name>.tar.gzin the shape an archive has, so it holds the ledger and the data directory with its repositories and keys. The forge's own database is left out of the file read and itsVACUUM INTOcopy is added instead, so the database copy is consistent while the forge keeps running. UnlikearchiveForge, nothing is stopped and nothing is removed. The last copy is recorded in<data>/archive/nightly/<name>.json.ARCHIVE_MAX_BYTESis listed as skipped with its size ("<name> skipped: N MiB, over the 256.0 MiB one file holds"), and that line is logged as a warning.src/snapshot/service.ts): the pass runs after the parent's snapshot is taken and verified, before the drill check. A failed forge copy is logged and never fails the parent's snapshot.src/spawn/archive.ts): the restore step is split out asrestoreRecord.restoreForgenow falls back to a forge's last nightly copy when there is no archive record, so the existing Restore by name in the web, MCP and terminal brings back a lost forge. The nightly record is kept after a restore; an archive's record is dropped, as before. A sharedholdingForgeguard stops an archive, a restore and a nightly copy of the same forge from running at once.The test makes two hosted forges with accounts in their databases, runs a snapshot through
startSnapshots, and checks both files are in the store. It then removes one forge, restores it alone and finds its account, while the other forge's database is untouched. It also checks that an unchanged forge is not sent again and that a forge over the cap is named with its size. It fails without the change because no nightly record exists.Left out:
Tests not run here:
scripts/fast.tsnamed 2046 files for this diff, so I picked the suites myself: the new test plusforge-archive,snapshot,snapshot-outcome,snapshot-one-core,mcp-snapshot-now,backup-retry,backup-truthandbackup-lanes. The forge's check runs the rest.Try it:
bun test test/snapshot-children.test.ts🤖 Generated with Claude Code
Closes #13832