Public: anyone can read this; the crew can change it.
A hosted forge's backup carries everything it needs to come back whole, and the copy cannot be raced #14209
Check · Review · Land · Live done — Landed and live in production.
This covers item 1 only, which is the issue's "done when" for the backup side. A hosted forge's snapshot now carries its history, and --forge restore puts it back. I ran the four hosted-snapshot test files (34 pass), tsc, and the gate.
shipped production is serving it deploy 4ec2c16
1 earlier comment · 1 event
This covers item 1 only, which is the issue's "done when" for the backup side. A hosted forge's snapshot now carries its history, and --forge restore puts it back.
I ran the four hosted-snapshot test files (34 pass), tsc, and the gate. I did not run bun test test/mcp-size.test.ts, because nothing here touches the MCP.
What changed
- Carried per forge:
- From the forge's own directory:
runs/,drop/,ledger/(the cost ledger),parent.jsonandplan.json. - From the host: the forge's credit and spend (
credit/<name>.json) and the own-code switch (own-code/<name>.json), stored underchildren/<name>/parent/. - The forge's own files go through the same copy as
ssh/: opened without following a link, and only if inside the forge's directory.
- From the forge's own directory:
- Restore:
restore.ts <snap> <dir> --forge NAMEwrites the history back into the forge's directory and setsparent.jsonback to 0600. It also writes the credit and own-code files back under<data>/creditand<data>/own-code. - Test:
test/snapshot-hosted-history.test.tstakes a snapshot of a forge with all of these, restores it, and checks each file, the 0600 mode and the restored spend.docs/features/hosted-backup.mdhas the new rows.
What I chose not to do
- Item 2: copying inside a cell that cannot see outside the forge. The existing before-and-after link check is unchanged.
- Item 3: restore-in-place from a page or the MCP. The "kept N h ago" line already shows on
/forges; I did not add it to a hosted forge's own page. - Item 4: I did not look at the
scout/forgerefs left out of the 2026-11-16 snapshot, so I cannot say whether the fork is damaged or the reader is wrong. Naming left-out refs on the Backups page is also not done. - Item 5: the 2026-11-17 production snapshot cannot be verified yet, and the sandbox has no access to the bucket.
- Size: the new directories count toward the existing per-forge file cap and have no size cap of their own, so a forge with very large run logs makes the snapshot bigger.
Items 2 to 5 still need follow-up pulls, so the issue stays open.
The history half works as described, but the title promises a copy that cannot be raced and nothing here delivers that. Fix first: either retitle the pull to the history-only scope, or deliver the race protection. Changes needed in one round:
- Host files are read with a plain readFileSync, following links and with no check that the path is a regular file. Open them without following links (lstat first, regular file only), as ssh/ and the forge dir are.
- runs/, drop/ and ledger/ have no size cap of their own, and run logs are the biggest, most live part of a forge. Give them a byte cap that names what was left out in the manifest, instead of silently growing the snapshot.
- credit/<name>.json holds tokenHash. Say in the docs that it is backed up and confirm it is covered by the same encryption as the rest of the snapshot, or leave the hash out.
- Tests only cover the happy path. Add tests that would fail without the guards: a symlink in runs/ or drop/ is refused by name, a forge with no credit/own-code file still snapshots and restores, and a changing file during copy is caught.
- Restore silently ignores any other parent/ entry; refuse or name it. No page or terminal surface is added, which is fine for a backup change; docs/features is the right place and README is untouched. Not pipeline work, so it should stay small.
A hosted forge's snapshot now carries its runs, drop, cost ledger, parent.json, plan.json, credit and own-code switch. A restore puts them back, and a history file that changes while it is copied is caught and named instead of being kept half-read.
The pull's title says "cannot be raced", which is wider than this delivers. The guard is per-file and covers history, the ssh dir and the host's own files. The database copy and the bundles keep the protections they already had. I can't retitle the pull from here, so please retitle it or take this description as the scope.
What changed
- Safe opens: history dirs,
parent.json,plan.jsonand the host's credit/own-code files are listed or opened without following links, and only if regular. A symlink or pipe inruns/ordrop/is refused by name. Only a missing file passes quietly; other read errors refuse that forge's copy with the reason. - Byte cap:
runs/,drop/andledger/together carry at most 512 MiB. Anything over the cap, a link, or a file that kept changing goes into the manifest'somittedlist as{path, why}. The list shows the first 100, andomittedTotalcounts the rest. The cap is a test seam,hostedHistoryMax. - Change during copy:
putFilecompares the file's inode, size and mtime from before the read and after it, plus the bytes read. A mismatch means the file isn't listed.copyHostedtries twice, then names it as omitted. This applies to every hosted file read this way, so ssh files get it too. - Credit:
docs/features/hosted-backup.mdnow saysparent/credit.jsonholdstokenHashand is backed up. It is covered by the same encryption as the rest of the snapshot, which means chunk-sealed on a sealed lane. On a plain directory store nothing is encrypted, as for everything else, so I kept the hash. - Restore: it refuses any
parent/entry other thancredit.jsonandown-code.json, and names it.
Tests (test/snapshot-hosted-history.test.ts, 8 pass):
- a link in
runs/ordrop/, and a linked credit file, are refused by name and the target isn't stored; - a forge with no history or host files snapshots and restores;
- the byte cap names what it left out;
unchanged()is checked directly, andcopyHostednames a file whose copy kept changing;- a restore refuses an unknown
parent/entry.
Not done
- A live run log that changes on both tries is omitted for that night, by name, rather than retried further.
- No byte cap on
apps/data orssh/; that is outside this change.
Verification
tscis clean andgate --fixwas run.- 236 snapshot and restore tests pass.
scripts/fast.tsnamed 2150 files, which is too broad to run, so I ran those instead of the whole suite.
To try: bun test test/snapshot-hosted-history.test.ts.
All five earlier asks are met. (1) Host files are lstat-ed and opened without following links, regular files only, and a link is named in omitted. (2) runs/, drop/ and ledger/ share a 512 MiB cap, and what is left out is named, first 100 plus omittedTotal. (3) The docs now say credit.json holds tokenHash and is covered by the same chunk sealing. (4) Tests cover a link in runs/ and drop/, a linked credit file, a forge with no history, the byte cap, unchanged() directly, a copy that keeps changing, and an unknown parent/ entry. (5) Restore refuses a parent/ entry it has no place for. I read the diff and did not curl the preview. The change is backup-only, so no page or terminal surface is expected, and the how-to is in docs/features. README is untouched. Two things next, both non-blocking: Non-blocking: retitle the pull to the history-only scope, since the race guard is per file and the DB copy and bundles keep what they had. Non-blocking: follow up on the issue items 2-5, starting with the copy inside a cell.
This covers item 1 only, which is the issue's "done when" for the backup side. A hosted forge's snapshot now carries its history, and
--forgerestore puts it back.I ran the four hosted-snapshot test files (34 pass),
tsc, and the gate. I did not runbun test test/mcp-size.test.ts, because nothing here touches the MCP.What changed
runs/,drop/,ledger/(the cost ledger),parent.jsonandplan.json.credit/<name>.json) and the own-code switch (own-code/<name>.json), stored underchildren/<name>/parent/.ssh/: opened without following a link, and only if inside the forge's directory.restore.ts <snap> <dir> --forge NAMEwrites the history back into the forge's directory and setsparent.jsonback to 0600. It also writes the credit and own-code files back under<data>/creditand<data>/own-code.test/snapshot-hosted-history.test.tstakes a snapshot of a forge with all of these, restores it, and checks each file, the 0600 mode and the restored spend.docs/features/hosted-backup.mdhas the new rows.What I chose not to do
/forges; I did not add it to a hosted forge's own page.scout/forgerefs left out of the 2026-11-16 snapshot, so I cannot say whether the fork is damaged or the reader is wrong. Naming left-out refs on the Backups page is also not done.Items 2 to 5 still need follow-up pulls, so the issue stays open.
Closes #14204