Public: anyone can read this; the crew can change it.
Every hosted forge streams its SQLite and git to a bucket continuously and restores from it #16887
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16858-every-hosted-forge-streams-its-sqlite-an → main 0 commits fork
3 files
changed +30
−4
docs/features/hosted-stream.md +1 −1
| @@ -13,7 +13,7 @@ The nightly snapshot keeps each hosted forge once a day ([hosted-backup.md](host | ||
| 13 | 13 | |
| 14 | 14 | ## Where it is read |
| 15 | 15 | |
| 16 | `streamLag(dataDir)` in `src/snapshot/stream.ts` answers each forge's last whole pass, last failure and lag. /system's *Snapshot stream* section and its terminal screen (`src/tui/screens/system.ts`, `streamLines`) say it per hosted forge in `src/snapshot/stream_words.ts`'s words: how long ago the last whole pass finished and the last failure; a forge with no pass yet says the first is due within five minutes. Nothing is drawn when no forge is hosted. | |
| 16 | `streamLag(dataDir)` in `src/snapshot/stream.ts` answers each forge's last whole pass, last failure and lag. /system's *Snapshot stream* section and its terminal screen (`src/tui/screens/system.ts`, `streamLines`) say it per hosted forge in `src/snapshot/stream_words.ts`'s words: how long ago the last whole pass finished and the last failure; a forge with no pass yet says the first is due within five minutes. Nothing is drawn when no forge is hosted. The MCP `system` tool with `{ kind: "stream" }` (admin) answers the same rows, each with its sentence as `says`. | |
| 17 | 17 | |
| 18 | 18 | ## Restore a forge from the stream |
| 19 | 19 |
src/http/mcp/tools/system.ts +11 −3
Diff not shown — a line 3,394 characters wide (limit 2,000). +11 −3
View filetest/snapshot-stream.test.ts +18
| @@ -18,6 +18,8 @@ import { restoreHostedInto } from "../src/snapshot/restore.ts"; | ||
| 18 | 18 | import { startSnapshots } from "../src/snapshot/service.ts"; |
| 19 | 19 | import { pruneSnapshots, streamManifestKey, takeSnapshot } from "../src/snapshot/snapshot.ts"; |
| 20 | 20 | import { readStream, STREAM_LATE_MS, streamLag, streamPass } from "../src/snapshot/stream.ts"; |
| 21 | import type { Ctx } from "../src/http/context.ts"; | |
| 22 | import { tool as systemTool } from "../src/http/mcp/tools/system.ts"; | |
| 21 | 23 | import { pollUntil } from "./helpers/poll.ts"; |
| 22 | 24 | |
| 23 | 25 | const PASS = "correct horse battery staple"; |
| @@ -127,6 +129,22 @@ describe("the stream of hosted forges", () => { | ||
| 127 | 129 | expect((await restoreHostedInto(store, "stream", "kid", dir, { passphrase: PASS })).repos).toBe(1); |
| 128 | 130 | }); |
| 129 | 131 | |
| 132 | test("the MCP system tool's stream read gives an admin each forge's lag and refuses anyone else", async () => { | |
| 133 | const store = dirStore(join(root, `store-${n++}`)); | |
| 134 | await pass(store, new Date()); | |
| 135 | const make = async (username: string, isAdmin: boolean) => { | |
| 136 | const r = await createUser(parent.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", isAdmin }); | |
| 137 | if (!r.ok) throw new Error(r.error); | |
| 138 | return r.value; | |
| 139 | }; | |
| 140 | const ctx = { app: parent } as unknown as Ctx; | |
| 141 | const read = await systemTool.run(ctx, await make("stream-admin", true), { kind: "stream" }); | |
| 142 | expect(read).toMatchObject({ ok: true, value: { rows: [{ name: "kid", late: false }] } }); | |
| 143 | expect(JSON.stringify(read)).toContain("last whole pass"); | |
| 144 | const refused = await systemTool.run(ctx, await make("stream-member", false), { kind: "stream" }); | |
| 145 | expect(refused).toMatchObject({ ok: false, error: "forbidden" }); | |
| 146 | }); | |
| 147 | ||
| 130 | 148 | test("the service streams on its own timer and on request, never beside a snapshot", async () => { |
| 131 | 149 | const store = dirStore(join(root, `store-${n++}`)); |
| 132 | 150 | const handle = startSnapshots(parent, store, { version: "t", passphrase: PASS, streamEveryMs: 40, nightlyInMs: 3_600_000 }); |
new above
offline