Public: anyone can read this; the crew can change it.

The browser forge's own button: checkpoint, upload to /forges/move-in, start the shared forge #17397

opened this

Merged 47h 46m ago, live in production

mason/forge:mason/17377-the-browser-forge-s-own-button-checkpoin → main 0 commits fork

  • Merged. mason/17377-the-browser-forge-s-own-button-checkpoin was merged into main as 5ec7388.

Review

Sign in to review this change.
3 files changed +14 −3
docs/features/browser-forge-move.md +2 −1
@@ -8,8 +8,9 @@ A forge that runs in a browser tab lives on that device and stops when the tab c
88
99 - **The page.** `/forges/move-in` (a link on `/forges`, admins who are people only) says first what it costs: the shared plan's price a month from `src/billing/density.ts`, the 50 MiB of disk it holds and the 32 MiB the form takes, that it sleeps and wakes on the next visit, that its address is new, and that the browser's copy stays. Choose a name, the database, and (optionally) the repositories as a `.tar.gz` of the `repos/` directory; the button is the only step.
1010 - **The checks, before anything is kept.** A name this forge can give; the files together within the shared share; the database is a SQLite file whose integrity check says `ok` and holds a forge's tables; the git tar holds only plain files and folders with relative names, and expands (from its listing) to no more than the shared share less the database. A file that fails keeps nothing and says why. The database must be checkpointed (no `-wal` beside it); the browser forge does that before it sends.
11 - **The start.** The move starts the shared forge's process at once (`bootHostedChild`, the start a new forge gets), so the receipt says "It is running now." and the first visit finds it awake; where a start is refused (below the disk floor, at the awake ceiling) it says it wakes on the first visit (#17377).
1112 - **The receipt.** The files go under `children/<bodyId>`; the shared forge's own reader is then asked its counts (issues, pulls, repositories, people) and they must equal what the file said, or everything is removed. The page shows them, and one `forge.moved_in` event keeps the name, byte counts, SHA-256 of each file and the counts.
1213 - **The terminal.** Key `i` on the Forges screen (`src/tui/screens/forges.ts`) shows the same cost rows (`moveInCost`) and where to send the files. The terminal is read-only for this feature: it cannot move a forge, because the upload is a browser's file form.
13 - **Not done.** Files past 32 MiB together (the form is read whole to check it; a streamed upload would lift it toward the shared forge's 50 MiB); a start of the process at once (the first visit wakes it); carrying the browser forge's own sign-in sessions to the new address; the browser forge's side of the button (the in-browser forge is not in this repository yet: the form is what its button posts); an API or MCP route (a file does not go through a tool call); charging at a payment provider (the plan is the shared plan, billed as other shared forges are).
14 - **Not done.** Files past 32 MiB together (the form is read whole to check it; a streamed upload would lift it toward the shared forge's 50 MiB); carrying the browser forge's own sign-in sessions to the new address; the browser forge's side of the button (checkpoint the WAL, tar `repos/`, post the form): this repository holds only the tab forge's storage worker (`src/web/tabforge`), with no page, no git data and no tar writer for a tab to run it from, so the form is what that button will post (#17377); an API or MCP route (a file does not go through a tool call); charging at a payment provider (the plan is the shared plan, billed as other shared forges are).
1415
1516 Code: `src/spawn/move_in.ts`, `src/web/pages/forge_move_in.ts`, `recordMovedIn` in `src/actions/spawn.ts`, the `moveIn` cap in `src/kernel/body_caps.ts`. Test: `test/move-in.test.ts`.
src/spawn/move_in.ts +8 −2
@@ -13,7 +13,8 @@
1313 *
1414 * Not done: the browser forge's own sign-in sessions are not carried (the file holds them, so
1515 * they work, but the address is new); a database still in WAL mode must be checkpointed first (the
16 * browser forge does this before it sends); the process starts at the first visit's wake.
16 * browser forge does this before it sends); the process is started at once (`bootHostedChild`), and
17 * wakes on a visit where it could not.
1718 */
1819
1920 import { Database } from "bun:sqlite";
@@ -31,6 +32,7 @@ import { BODY_CAPS } from "../kernel/body_caps.ts";
3132 import { sha256 } from "../kernel/hash.ts";
3233 import { writePrivate } from "../kernel/file_modes.ts";
3334 import { randomBytes } from "node:crypto";
35 import { bootHostedChild, isAwakeBody } from "./host.ts";
3436 import { CHILD_NAME } from "./placement.ts";
3537 import { tar } from "./archive.ts";
3638 import { childCounts, type ChildCounts } from "./child_db.ts";
@@ -213,8 +215,12 @@ export async function moveIn(app: App, actor: User | undefined, b: Bundle): Prom
213215 actorId: (actor as User).id,
214216 payload: { name: b.name, dbBytes: b.db.length, dbSha256: sha256(b.db), gitBytes: b.git?.length ?? 0, gitSha256: b.git === undefined ? "" : sha256(b.git), issues: read.issues, pulls: read.pulls, repos: read.repos },
215217 });
218 // Started now, so the first visit finds it awake; where it may not start (below the disk floor,
219 // the awake ceiling) it stays asleep and wakes on the first visit, as any shared forge does.
220 await bootHostedChild(app, b.name);
221 const awake = isAwakeBody(app, bodyId);
216222 const url = liveChildUrl(app, b.name);
217 const says = `${b.name} is a shared forge now at ${url}: ${read.issues} issues, ${read.pulls} pulls and ${read.repos} repositories, read back from the copied file (database ${sha256(b.db).slice(0, 12)}). ${usdPerMonthWords(c.plan.priceUsd)}, from today. It wakes on the first visit.`;
223 const says = `${b.name} is a shared forge now at ${url}: ${read.issues} issues, ${read.pulls} pulls and ${read.repos} repositories, read back from the copied file (database ${sha256(b.db).slice(0, 12)}). ${usdPerMonthWords(c.plan.priceUsd)}, from today. ${awake ? "It is running now." : "It wakes on the first visit."}`;
218224 return { ok: true, says, plan: c.plan, counts: read, url };
219225 } finally {
220226 busy.delete(b.name);
test/move-in.test.ts +4
@@ -16,6 +16,7 @@ import { createRepo } from "../src/core/repos.ts";
1616 import { getUserById, type User } from "../src/core/users.ts";
1717 import { serve, type Servers } from "../src/http/server.ts";
1818 import { childCounts, closeChildDb } from "../src/spawn/child_db.ts";
19 import { isAwakeBody } from "../src/spawn/host.ts";
1920 import { tar } from "../src/spawn/archive.ts";
2021 import { moveIn, moveInCost, planMoveIn, type Bundle } from "../src/spawn/move_in.ts";
2122 import { clientRows } from "../src/spawn/clients.ts";
@@ -96,6 +97,9 @@ test("the files are copied as they are and the shared forge shows the same issue
9697 const event = server.db.query<{ payload: string }, []>("SELECT payload FROM event WHERE kind = 'forge.moved_in'").get();
9798 expect(JSON.parse(event!.payload)).toMatchObject({ name: "moved", issues: 3, dbBytes: files.db.length });
9899 expect(done.says).toContain("3 issues");
100 // The shared process is started by the move itself, not left to the first visit (#17377).
101 expect(isAwakeBody(server, child!.bodyId)).toBe(true);
102 expect(done.says).toContain("It is running now.");
99103 // A second move of the name is refused and keeps nothing more.
100104 const before = kept().length;
101105 const again = await moveIn(server, admin, bundle("moved"));

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

Keyboard shortcuts

Docs