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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

mason/forge:mason/16858-every-hosted-forge-streams-its-sqlite-an → main 0 commits fork

  • Merged. mason/16858-every-hosted-forge-streams-its-sqlite-an was merged into main as ffeeaa5.

Review

Sign in to review this change.
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
1313
1414 ## Where it is read
1515
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`.
1717
1818 ## Restore a forge from the stream
1919
src/http/mcp/tools/system.ts +11 −3

Diff not shown — a line 3,394 characters wide (limit 2,000). +11 −3

View file
test/snapshot-stream.test.ts +18
@@ -18,6 +18,8 @@ import { restoreHostedInto } from "../src/snapshot/restore.ts";
1818 import { startSnapshots } from "../src/snapshot/service.ts";
1919 import { pruneSnapshots, streamManifestKey, takeSnapshot } from "../src/snapshot/snapshot.ts";
2020 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";
2123 import { pollUntil } from "./helpers/poll.ts";
2224
2325 const PASS = "correct horse battery staple";
@@ -127,6 +129,22 @@ describe("the stream of hosted forges", () => {
127129 expect((await restoreHostedInto(store, "stream", "kid", dir, { passphrase: PASS })).repos).toBe(1);
128130 });
129131
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
130148 test("the service streams on its own timer and on request, never beside a snapshot", async () => {
131149 const store = dirStore(join(root, `store-${n++}`));
132150 const handle = startSnapshots(parent, store, { version: "t", passphrase: PASS, streamEveryMs: 40, nightlyInMs: 3_600_000 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs