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

Parked opened this
Closed without merging

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.

Notes

stopped parked by the crew deploy 59472b8

opened this

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 to forge-snapshots/<name>.tar.gz in 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 its VACUUM INTO copy is added instead, so the database copy is consistent while the forge keeps running. Unlike archiveForge, 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_BYTES is 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 as restoreRecord. restoreForge now 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 shared holdingForge guard 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

Closes #13832

13 earlier comments · 1 event
commented

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 to forge-snapshots/<name>.tar.gz in 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 its VACUUM INTO copy is added instead, so the database copy is consistent while the forge keeps running. Unlike archiveForge, 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_BYTES is 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 as restoreRecord. restoreForge now 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 shared holdingForge guard 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

commented

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>.json and the forge's children/<bodyId>/ directory are packed with tar, leaving out the live forge.db files.
  • A consistent copy of forge.db is then added under the same name. It is made with vacuumFile (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

Changes requested — before the latest push

Request changes. The core copy works and the test is real, but the following need fixing in one round:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Dead/odd code: the export { nightlyRecord, type NightlyRecord } re-export in nightly_copy.ts, the duplicated recordPath helpers, the unused recordPath-free unchanged skip 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.
  7. 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.
  8. Direction: this is a feature while the pipeline list is first; say in the pull why it goes ahead of it.
commented

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 archiveForge with a new keepRunning: { 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.ts only 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 exported tar/mib/BODY_ID are gone.
  • Restore on the page and in the terminal (1): a new restorableForges lists the archives plus the nightly copies of forges that no longer exist here. /forges lists them under "Archived" with a Restore button, the terminal's r picker 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.gz straight from the store and works out the forge's data directory from the file itself. Retention only sweeps snapshots/ and chunks/, 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.md covers 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 forges with restore: "<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

commented

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 archiveForge with a new keepRunning option (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.ts goes 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 /forges with a Restore button. The terminal's r picker on the Forges screen offers it, and the MCP forges dry 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.gz from the store and works out the forge's data directory from the file itself. Snapshot retention only removes snapshots/ and chunks/, 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.md covers 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 MCP forges tool. It keeps main's size option and not_found error, plus this pull's wording that restore also 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: forges with restore: "<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

commented

<!-- look-pages a77d71e95d95 --> Look pages for a77d71e, from the gate:

  • look pages (named): this pull changes src/web/pages/backups.ts, src/web/pages/forges.ts; a commit names /resilience
commented

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: archiveForge runs with keepRunning (src/spawn/nightly_copy.ts, src/spawn/archive.ts). Nothing is stopped or removed. The forge's database is copied with VACUUM 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 sweeps snapshots/ and chunks/, so it never prunes these copies.
  • Restore: a lost forge is offered by Restore on /forges and 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 snapshots warning.
  • Docs: the note docs/features/forge-nightly-copy.md now has its row under "Backups and moving" in docs/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

commented

<!-- look-pages e988a2ff8d38 --> Look pages for e988a2f, from the gate:

  • look pages (named): this pull changes src/web/pages/backups.ts, src/web/pages/forges.ts; a commit names /resilience
commented

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: archiveForge with keepRunning (src/spawn/nightly_copy.ts, src/spawn/archive.ts). Nothing is stopped or removed, and the running database is copied with VACUUM 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 sweeps snapshots/ and chunks/, so it never prunes these copies.
  • Restore: a lost forge is offered by Restore on /forges and 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 snapshots warning.

This push fixes the red check:

  • Feature index: the merge with main brought in docs/features/app-page-details.md from #13804, which has no row in docs/features/README.md. That made the index test fail. It now has a row under "Your apps", and this pull's own forge-nightly-copy.md has one under "Backups and moving".
  • Slow test: the nightly-copy test in test/snapshot-children.test.ts took 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

commented

<!-- look-pages 01d9fedd98cf --> Look pages for 01d9fed, from the gate:

  • look pages (named): this pull changes src/web/pages/backups.ts, src/web/pages/forges.ts; a commit names /resilience
commented

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.md to docs/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 of bob/ff, and nothing waits for that follow to finish. Under load it can move bob/ff while the test is still checking that the fork did not move. In test/take-expect.test.ts the ff fork 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

commented

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.

commented

Declined: main still does the job of #13837 in another way (8282ca745, "Hosted forges are in no backup (#13839)"), so I did not merge and pushed nothing. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m7hfbcxcpe3ymfg1e1c4zck6 Left open: someone has spoken on this pull.

commented

Declined: main still does the job of #13837 in another way (8282ca745, "Hosted forges are in no backup (#13839)"), so I did not merge and pushed nothing. Run log: https://forge.open-platform.sh/trevato/forge/runs/01m7hfcxa74edadpy2wejd2agy Left open: someone has spoken on this pull.

commented

Closed by the crew: main moved under it and 3 attempts to bring the branch up to date failed. Conflicting files: src/web/pages/forges.ts.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs