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

Show 7 earlier items

7 earlier comments
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