Public: anyone can read this; the crew can change it.
/system lists the child forges the host adopted after a restart, with when, and the terminal's system screen the same #14377
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14368-system-lists-the-child-forges-the-host-a → main 8 commits fork 5 threads · 5 unresolved
docs/MCP.md +1 −1
| @@ -229,7 +229,7 @@ bytes in `tools/list`. After changing a tool run `bun scripts/mcp-table.ts`; | ||
| 229 | 229 | | `subscription_wake` | — | Admin: wake a resting subscription | 168 | |
| 230 | 230 | | `subscriptions` | — | Claude accounts: scopes, budgets | 158 | |
| 231 | 231 | | `sync` | — | Sync a mirror now; `originId` reconnects it | 197 | |
| 232 | | `system` | `pause`, `resume`, `csp`, `routes`, `bottleneck`, `footing`, `offsite`, `size`, `maintenance`, `growth` | The forge machine now: CPU, memory, disk, network | 475 | | |
| 232 | | `system` | `pause`, `resume`, `csp`, `routes`, `bottleneck`, `footing`, `offsite`, `size`, `maintenance`, `growth`, `adopted` | The forge machine now: CPU, memory, disk, network | 485 | | |
| 233 | 233 | | `take_back` | — | Open the pull that undoes a shipped pull | 219 | |
| 234 | 234 | | `take_updates` | — | Take the parent forge's updates into a fork | 268 | |
| 235 | 235 | | `teams` | — | Crew teams for person admins: charter, dial (0–100) and member agents | 338 | |
docs/features/cells-outlive.md +3 −1
| @@ -12,4 +12,6 @@ On when the host boots (#13750), so a production release leaves a hosted forge's | ||
| 12 | 12 | - the port must answer. A cell that is its supervisor's but silent is stopped and its record cleared, since nothing else would reap it; |
| 13 | 13 | - otherwise the cell is held in the registry as if this host had started it. A start for the same body waits for adoption to finish and finds the adopted cell, never a second one. The record is cleared when the cell goes. |
| 14 | 14 | |
| 15 | Not yet: the beat door still runs in the host, egress bytes of an outliving cell are not in the host's gauges (#13921), and there is no terminal view of adopted cells; they appear in the registry and the log (`child forge adopted`). | |
| 15 | Not yet: the beat door still runs in the host, egress bytes of an outliving cell are not in the host's gauges (#13921). | |
| 16 | ||
| 17 | **What the host did is shown.** For this host's life it keeps each cell it adopted or dropped at boot (`spawn/adopted.ts`: name, pid, when, why). /system lists them under "Child forges across the restart" ("kept running across the restart", "stopped: did not answer"), and nothing when there were none; the MCP `system` tool (`kind: adopted`) and the terminal's System screen read the same rows. |
src/http/mcp/tools/system.ts +8 −3
| @@ -10,6 +10,7 @@ import { liveOf } from "../../../perf/live.ts"; | ||
| 10 | 10 | import { LAG_BAR_MS, overBar } from "../../../perf/lag_minutes.ts"; |
| 11 | 11 | import { slowestRoutes } from "../../../perf/watch.ts"; |
| 12 | 12 | import { readBottleneck } from "../../../system/bottleneck.ts"; |
| 13 | import { adoptionsOf } from "../../../spawn/cell.ts"; | |
| 13 | 14 | import { live } from "../../../system/live.ts"; |
| 14 | 15 | import { footing, riskLines } from "../../../system/footing.ts"; |
| 15 | 16 | import { laneWords, readOffsiteLane } from "../../../snapshot/offsite_lane.ts"; |
| @@ -26,10 +27,10 @@ import { good, bad, repoArg, isAnswer, REPO_ARG, type Tool } from "../shared.ts" | ||
| 26 | 27 | |
| 27 | 28 | export const tool: Tool = { |
| 28 | 29 | name: "system", |
| 29 | doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"bottleneck\" }`: what limits the forge now, as /system/bottleneck: `{ says, limited, rows: [{ id, label, now, ceiling, fraction, detail, lever }], unseen }`; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine, and `outside`, what still waits on a hand outside the forge (empty when nothing does); a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line; with `action` pause (`until`: UTC time within a year, or `chapter: true`: until the open chapter closes, refused with no open chapter; else until switched on) or resume, the planner's switch: a preview, and `confirm:true` does it; the repository's owner, never an agent", | |
| 30 | doc: "the machine the forge runs on, now: CPU, load, memory, disk, network, processes, `largestDirs`: the five largest directories under the forge's data as {at, dirs: [{name, bytes}]} (null while first measured; at most once a minute), `stalls`: the last hour's main-thread stalls by route (`<route> (in flight)` when still running at the wake), or `job:<name>`, as {cause, ms, count}, `readings`: the last 20 minutes' worst loop lag as {at, ms, what} beside `barMs` (100) and `over`, and `readers`: who polls the telemetry and how fast, `{ kind: \"routes\" }`: the 10 slowest budgeted routes as {route, p95Ms, budgetMs, n, slowestPhase}, over budget first; a forge admin, or an agent granted `telemetry:read`. `{ kind: \"csp\" }`: the last 24 h of Content-Security-Policy violations browsers reported, `{ directive, n, newest }` per directive (`newest` the blocked host last counted), most first, counted per UTC hour from `since`, and `scriptErrors` `{ page, where, message, n, last }`, as the security page reads them; a forge admin only. `{ kind: \"bottleneck\" }`: what limits the forge now, as /system/bottleneck: `{ says, limited, rows: [{ id, label, now, ceiling, fraction, detail, lever }], unseen }`; a forge admin only. `{ kind: \"footing\" }`: what the forge stands on (#11685), as /system's \"What the forge stands on\": `forgeNode`, and per piece `{ id, need, what, machine, seen, risk, ifDies, issues }` read from the live cluster, with `risks`, one line per piece not on the forge's machine, and `outside`, what still waits on a hand outside the forge (empty when nothing does); a forge admin only. `{ kind: \"offsite\" }`: the off-site backup lane (#11805), as /system's \"Off-site backup\" and the terminal's: `{ health, says, where, sealed, lastSuccess, newest, error, backupFailure: { cause, bytes, seconds, says } | null, drill: { at, verdict, from, offSite, reason } | null }`; a forge admin only. `{ kind: \"size\" }`: the database's size (#12010), as /system's \"Database size\": `{ fileBytes, walBytes, growth: { perDay, days, readings: [{day, bytes}] }, walk: { at, pageSize, freeBytes, tables: [{name, bytes, rows}], indexes: [{name, table, bytes}] } | null }`, ten of each, largest first, the walk at most an hour old (null while the first runs); a forge admin, or an agent granted `telemetry:read`. `{ kind: \"maintenance\" }`: one row per maintenance worker, 7 days, `{ name, found, acted, last }` (`last` null: not yet run); admin or `telemetry:read`. `{ kind: \"adopted\" }`: the child forges found running at this host's boot, `{ rows: [{ name, pid, at, outcome: kept|dropped, says }] }`, as /system lists them; a forge admin only. `{ kind: \"growth\", repo }`: {openIssues, openPulls, openedToday, closedToday, openedWeek, closedWeek}, as /next's line; with `action` pause (`until`: UTC time within a year, or `chapter: true`: until the open chapter closes, refused with no open chapter; else until switched on) or resume, the planner's switch: a preview, and `confirm:true` does it; the repository's owner, never an agent", | |
| 30 | 31 | description: |
| 31 | 32 | "The forge machine now: CPU, memory, disk, network. Admin or telemetry:read; `kind: csp`: 24 h of CSP violations (admin).", |
| 32 | inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "bottleneck", "footing", "offsite", "size", "maintenance", "growth"] }, repo: REPO_ARG, action: { type: "string", enum: ["pause", "resume"] }, until: { type: "string" }, chapter: { type: "boolean" }, confirm: { type: "boolean" } } }, | |
| 33 | inputSchema: { type: "object", properties: { kind: { type: "string", enum: ["csp", "routes", "bottleneck", "footing", "offsite", "size", "maintenance", "growth", "adopted"] }, repo: REPO_ARG, action: { type: "string", enum: ["pause", "resume"] }, until: { type: "string" }, chapter: { type: "boolean" }, confirm: { type: "boolean" } } }, | |
| 33 | 34 | writes: true, |
| 34 | 35 | readsWhen: (args) => args["action"] === undefined || args["confirm"] !== true, |
| 35 | 36 | async run(ctx, user, args) { |
| @@ -82,6 +83,10 @@ export const tool: Tool = { | ||
| 82 | 83 | noteRead(ctx.app, user, reader, "system"); |
| 83 | 84 | return good({ workers: weekRows(ctx.app.db, duties.map((d) => d.name)).map((w) => ({ ...w, says: resultWords(w) })) }); |
| 84 | 85 | } |
| 86 | if (args["kind"] === "adopted") { | |
| 87 | if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its child forges across a restart"); | |
| 88 | return good({ rows: adoptionsOf(ctx.app) }); | |
| 89 | } | |
| 85 | 90 | if (args["kind"] === "footing") { |
| 86 | 91 | if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads what it stands on"); |
| 87 | 92 | const f = await footing.read(); |
| @@ -92,7 +97,7 @@ export const tool: Tool = { | ||
| 92 | 97 | const lane = readOffsiteLane(ctx.app.config.dataDir, ctx.app.db); |
| 93 | 98 | return good({ ...lane, says: laneWords(lane) }); |
| 94 | 99 | } |
| 95 | if (args["kind"] !== "csp") return bad("invalid", "kind is csp, routes, footing, offsite, size, maintenance, growth, or absent for the machine"); | |
| 100 | if (args["kind"] !== "csp") return bad("invalid", "kind is csp, routes, adopted, footing, offsite, size, maintenance, growth, or absent for the machine"); | |
| 96 | 101 | if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its CSP violations"); |
| 97 | 102 | const now = new Date(); |
| 98 | 103 | return good({ hours: 24, since: windowStart(24, now).toISOString(), directives: violationsByDirective(ctx.app.db, 24, now), scriptErrors: scriptErrorCounts(ctx.app.db, 24, now) }); |
src/spawn/adopted.ts added +33
| @@ -0,0 +1,33 @@ | ||
| 1 | /** | |
| 2 | * What this host did with each cell a previous host left running, for this host's life: kept | |
| 3 | * (adopted) or dropped, and why. Plain data; `cell.ts` writes it at boot, and /system, the MCP | |
| 4 | * `system` tool and the terminal's System screen read the same rows through `adoptionRows`. | |
| 5 | */ | |
| 6 | ||
| 7 | export interface Adoption { | |
| 8 | readonly name: string; | |
| 9 | readonly pid: number; | |
| 10 | /** When the host decided, ms since the epoch. */ | |
| 11 | readonly at: number; | |
| 12 | readonly outcome: "kept" | "dropped"; | |
| 13 | /** Why a dropped one was dropped; null for a kept one. */ | |
| 14 | readonly why: "silent" | "not-its-cell" | null; | |
| 15 | } | |
| 16 | ||
| 17 | export interface AdoptionRow { | |
| 18 | readonly name: string; | |
| 19 | readonly pid: number; | |
| 20 | readonly at: string; | |
| 21 | readonly outcome: "kept" | "dropped"; | |
| 22 | readonly says: string; | |
| 23 | } | |
| 24 | ||
| 25 | /** The sentence for one row, in plain words. */ | |
| 26 | export function adoptionWords(a: Adoption): string { | |
| 27 | if (a.outcome === "kept") return "kept running across the restart"; | |
| 28 | return a.why === "silent" ? "stopped: did not answer" : "gone: its process had already ended"; | |
"gone: its process had already ended" is also what a reused pid produces (supervisor no longer names it). Use plain, accurate words (docs/WRITING.md): "gone: no longer running as that child forge". |
||
| 29 | } | |
| 30 | ||
| 31 | /** The rows, oldest first, as the page, the MCP tool and the terminal all say them. */ | |
| 32 | export const adoptionRows = (list: readonly Adoption[]): AdoptionRow[] => | |
| 33 | [...list].sort((a, b) => a.at - b.at || a.name.localeCompare(b.name)).map((a) => ({ name: a.name, pid: a.pid, at: new Date(a.at).toISOString(), outcome: a.outcome, says: adoptionWords(a) })); |
src/spawn/cell.ts +13
| @@ -28,6 +28,7 @@ import { liveChildDisk, type ChildDisk } from "./disk_mount.ts"; | ||
| 28 | 28 | import { oneAtATime, sourcesFor, startFailure, startFirstThatWorks, useTree, type CodeSource } from "./own_code.ts"; |
| 29 | 29 | import { childGate, type ChildGate } from "./child_reach.ts"; |
| 30 | 30 | import { files, readPid } from "./supervisor.ts"; |
| 31 | import { adoptionRows, type Adoption, type AdoptionRow } from "./adopted.ts"; | |
| 31 | 32 | import { clearRecord, leaveRecord, readRecords, type CellRecord } from "./cell_record.ts"; |
| 32 | 33 | |
| 33 | 34 | /** |
| @@ -286,6 +287,10 @@ export interface CellChildren { | ||
| 286 | 287 | list(): readonly CellChild[]; |
| 287 | 288 | /** Settles once the cells a previous host left running have been probed, adopted or dropped. */ |
| 288 | 289 | readonly adopted: Promise<void>; |
| 290 | /** | |
| 291 | * Each cell adopted or dropped at this host's boot, as /system, the MCP and the terminal say it. | |
| 292 | */ | |
| 293 | adoptions(): AdoptionRow[]; | |
| 289 | 294 | /** |
| 290 | 295 | * Mark a request under way for this child; the returned function ends it. A child with one is not |
| 291 | 296 | * put to sleep. |
| @@ -314,6 +319,9 @@ export const SLEEP_AT_ONCE = 8; | ||
| 314 | 319 | |
| 315 | 320 | const registries = new WeakMap<App, CellChildren>(); |
| 316 | 321 | |
| 322 | /** What this host did with the cells it found at boot; none when no registry was made. */ | |
| 323 | export const adoptionsOf = (parent: App): AdoptionRow[] => registries.get(parent)?.adoptions() ?? []; | |
| 324 | ||
| 317 | 325 | /** |
| 318 | 326 | * The parent's one registry of child cells. `launcher` stands in for the cell launch the first time |
| 319 | 327 | * the registry is made (tests); later calls ignore it. |
| @@ -453,17 +461,20 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren { | ||
| 453 | 461 | /** |
| 454 | 462 | * A cell a previous host left running: its pid is watched, since this process did not start it. |
| 455 | 463 | */ |
| 464 | const boot: Adoption[] = []; | |
| 456 | 465 | const adopt = async (record: CellRecord, dir: string): Promise<void> => { |
| 457 | 466 | // The pid alone can be another process's by now: it is the cell only when its supervisor |
| 458 | 467 | // still names it (pid and start time, `readPid`). A pid that fails this is never signalled. |
| 459 | 468 | const isCell = (): boolean => alive(record.pid) && readPid(files(record.supervisor).cell) === record.pid; |
| 460 | 469 | if (!isCell()) { |
| 470 | boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "dropped", why: "not-its-cell" }); | |
| 461 | 471 | clearRecord(dir); |
| 462 | 472 | return; |
| 463 | 473 | } |
| 464 | 474 | if (!(await answers(record.port, Promise.resolve(), 3))) { |
| 465 | 475 | // Ours and silent: nobody would reap it, so it goes now, as its supervisor's cell. |
| 466 | 476 | if (isCell()) killTree(record.pid); |
| 477 | boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "dropped", why: "silent" }); | |
| 467 | 478 | parent.log.warn("child forge left by a previous host did not answer; stopped", { name: record.name, pid: record.pid }); |
| 468 | 479 | clearRecord(dir); |
| 469 | 480 | return; |
| @@ -481,6 +492,7 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren { | ||
| 481 | 492 | held.set(record.bodyId, child); |
| 482 | 493 | seen.set(record.bodyId, Date.now()); |
| 483 | 494 | startedAt.set(record.bodyId, record.startedAt); |
| 495 | boot.push({ name: record.name, pid: record.pid, at: Date.now(), outcome: "kept", why: null }); | |
| 484 | 496 | parent.log.info("child forge adopted", { name: record.name, pid: record.pid }); |
| 485 | 497 | void gone.then(() => { |
| 486 | 498 | clearRecord(dir); |
| @@ -601,6 +613,7 @@ export function makeRegistry(parent: App, launcher?: Launcher): CellChildren { | ||
| 601 | 613 | |
| 602 | 614 | return { |
| 603 | 615 | adopted, |
| 616 | adoptions: () => adoptionRows(boot), | |
| 604 | 617 | start(input) { |
| 605 | 618 | // A cell a previous host left running is found before a second is started beside it. |
| 606 | 619 | if (!adoptionOver) return adopted.then(() => this.start(input)); |
src/tui/screens/system.ts +13
| @@ -63,6 +63,8 @@ import { featureHealth } from "../../system/feature_health.ts"; | ||
| 63 | 63 | import { readerPaces } from "../../system/telemetry_reads.ts"; |
| 64 | 64 | import { live as liveMachine } from "../../system/live.ts"; |
| 65 | 65 | import { childDirOf, listChildrenNow } from "../../actions/spawn.ts"; |
| 66 | import { adoptionsOf } from "../../spawn/cell.ts"; | |
| 67 | import type { AdoptionRow } from "../../spawn/adopted.ts"; | |
| 66 | 68 | import { childrenUse, realSelf, selfUse, sizeWords, useWords, type ChildUseRow, type SelfUse } from "../../spawn/usage.ts"; |
| 67 | 69 | |
| 68 | 70 | const WIDTH = 72; |
| @@ -503,6 +505,15 @@ export function childLines(rows: readonly ChildUseRow[], inner = WIDTH - 6): str | ||
| 503 | 505 | ]; |
| 504 | 506 | } |
| 505 | 507 | |
| 508 | /** | |
| 509 | * Each child forge found running after the restart, a line each, as /system's "across the restart" | |
| 510 | * says it. | |
| 511 | */ | |
| 512 | export function adoptedLines(rows: readonly AdoptionRow[], inner = WIDTH - 6): string[] { | |
| 513 | if (rows.length === 0) return []; | |
| 514 | return ["Child forges across the restart", ...rows.map((r) => truncate(`${pad(r.name, 16)} ${r.says}`, inner))]; | |
| 515 | } | |
| 516 | ||
| 506 | 517 | /** The egress fault, one line, as /system says it; nothing when egress is enforced. */ |
| 507 | 518 | export function egressLines(session: Session): string[] { |
| 508 | 519 | const said = egressReportedLine(session.db); |
| @@ -524,6 +535,7 @@ export const entry: PaletteEntry = { | ||
| 524 | 535 | run: (session, ctx) => { |
| 525 | 536 | const self = selfLines(selfUse(realSelf(session.app.config.dataDir))); |
| 526 | 537 | const kids = childLines(childrenUse(listChildrenNow(session.app), (bodyId) => childDirOf(session.app, bodyId))); |
| 538 | const left = adoptedLines(adoptionsOf(session.app)); | |
| 527 | 539 | const who = askingLines(session); |
| 528 | 540 | ctx.push(systemScreen(ctx, [ |
| 529 | 541 | ...forgeLines(readHealth(session.app, session.user)), |
| @@ -533,6 +545,7 @@ export const entry: PaletteEntry = { | ||
| 533 | 545 | ...engineLines(session.app.config.engine), |
| 534 | 546 | ...(self.length === 0 ? [] : ["", ...self]), |
| 535 | 547 | ...(kids.length === 0 ? [] : ["", ...kids]), |
| 548 | ...(left.length === 0 ? [] : ["", ...left]), | |
| 536 | 549 | "", |
| 537 | 550 | ...systemLines(liveMachine().read()), |
| 538 | 551 | ], session)); |
src/web/pages/system.ts +15
| @@ -67,6 +67,8 @@ import { DB_FILE_CAP, DB_GROWTH_MAX, TOP, dbSize, dbSizeNeed, type DbSize } from | ||
| 67 | 67 | import { resultWords, weekRows, weekWords, type WeekRow } from "../../maintain/week_line.ts"; |
| 68 | 68 | import { duties } from "../../maintain/registry.ts"; |
| 69 | 69 | import { childDirOf, listChildren } from "../../actions/spawn.ts"; |
| 70 | import { adoptionsOf } from "../../spawn/cell.ts"; | |
| 71 | import type { AdoptionRow } from "../../spawn/adopted.ts"; | |
| 70 | 72 | import { childrenUse, mibWords, realSelf, selfUse, shareOf, sizeWords, useWords, type ChildUseRow, type SelfUse } from "../../spawn/usage.ts"; |
| 71 | 73 | |
| 72 | 74 | /** A group's memory, and a cell's beside its cap and who holds the cap. */ |
| @@ -223,6 +225,18 @@ export function childrenSection(rows: readonly ChildUseRow[]): Html { | ||
| 223 | 225 | })}</ul></section>`; |
| 224 | 226 | } |
| 225 | 227 | |
| 228 | /** | |
| 229 | * The child forges this host found running after its restart, kept or stopped; nothing when there | |
| 230 | * were none. | |
| 231 | */ | |
| 232 | export function adoptedSection(rows: readonly AdoptionRow[]): Html { | |
| 233 | if (rows.length === 0) return html``; | |
| 234 | return html`<section class="settings-block" id="sys-adopted"><h2>Child forges across the restart</h2> | |
| 235 | <ul class="list" aria-label="Each child forge this host found running when it started">${rows.map((r) => | |
| 236 | row({ title: r.name, titleAttr: r.name, meta: html`<span class="mono small">${r.says}</span>`, trail: html`<span class="mono small">${r.at.slice(0, 16).replace("T", " ")} UTC</span>`, data: { adopted: r.name, outcome: r.outcome } }), | |
| 237 | )}</ul></section>`; | |
| 238 | } | |
| 239 | ||
| 226 | 240 | /** |
| 227 | 241 | * The forges that run inside this process and what each took of its one serving thread in the last |
| 228 | 242 | * hour (`perf/child_time.ts`): nothing when none is open here and none was. A forge in a cell is |
| @@ -693,6 +707,7 @@ export async function systemPage(ctx: Ctx): Promise<Response> { | ||
| 693 | 707 | ${selfSection(self)} |
| 694 | 708 | ${engineSection(ctx.app.config.engine)} |
| 695 | 709 | ${childrenSection(children)} |
| 710 | ${adoptedSection(owner ? adoptionsOf(ctx.app) : [])} | |
The |
||
| 696 | 711 | ${inProcessSection(inProcess)} |
| 697 | 712 | <section class="settings-block"><h2>Disks and network</h2> |
| 698 | 713 | <ul class="list" id="sys-disks">${at("sys-disks")}</ul></section> |
test/cell-adopted-on-start.test.ts +69
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | import type { Ctx } from "../src/http/context.ts"; | |
| 2 | 3 | import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; |
| 3 | 4 | import { tmpdir } from "node:os"; |
| 4 | 5 | import { join } from "node:path"; |
| @@ -161,3 +162,71 @@ test("an adopted cell dropped on its death clears its record, and start waits fo | ||
| 161 | 162 | app.close(); |
| 162 | 163 | } |
| 163 | 164 | }); |
| 165 | ||
| 166 | test("the rows say which cells were kept and which stopped, the page and the terminal alike", async () => { | |
| 167 | const { adoptedLines } = await import("../src/tui/screens/system.ts"); | |
| 168 | const { adoptedSection } = await import("../src/web/pages/system.ts"); | |
| 169 | const { adoptionsOf } = await import("../src/spawn/cell.ts"); | |
| 170 | const { app, childDir, dir } = setup(); | |
| 171 | const server = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("ok") }); | |
| 172 | const quiet = Bun.spawn(["sleep", "30"]); | |
| 173 | const closed = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("") }); | |
| 174 | const closedPort = closed.port as number; | |
| 175 | closed.stop(true); | |
| 176 | try { | |
| 177 | const ctl = join(dir, "ctl"); | |
| 178 | supervised(ctl, process.pid); | |
| 179 | writeRecord(childDir("cell-a"), recordFor({ port: server.port as number, supervisor: ctl })); | |
| 180 | const ctlQuiet = join(dir, "ctl-quiet"); | |
| 181 | supervised(ctlQuiet, quiet.pid); | |
| 182 | writeRecord(childDir("cell-q"), recordFor({ bodyId: "cell-q", name: "q", pid: quiet.pid, port: closedPort, supervisor: ctlQuiet })); | |
| 183 | const cells = makeRegistry(app); | |
| 184 | await cells.adopted; | |
| 185 | const rows = cells.adoptions(); | |
| 186 | expect(rows.map((r) => [r.name, r.outcome, r.says])).toEqual([ | |
| 187 | ["a", "kept", "kept running across the restart"], | |
| 188 | ["q", "dropped", "stopped: did not answer"], | |
| 189 | ]); | |
| 190 | expect(rows[0]?.pid).toBe(process.pid); | |
| 191 | expect(Number.isNaN(Date.parse(rows[0]!.at))).toBe(false); | |
| 192 | expect(adoptedLines(rows).join("\n")).toContain("q"); | |
| 193 | expect(adoptedLines(rows)[2]).toContain("stopped: did not answer"); | |
| 194 | expect(String(adoptedSection(rows))).toContain("kept running across the restart"); | |
| 195 | expect(adoptedLines([])).toEqual([]); | |
| 196 | expect(String(adoptedSection([]))).toBe(""); | |
| 197 | expect(adoptionsOf(app)).toEqual([]); | |
Only the pure renderers are asserted. Add the non-owner page case and the terminal |
||
| 198 | } finally { | |
| 199 | quiet.kill(); | |
| 200 | server.stop(true); | |
| 201 | app.close(); | |
| 202 | } | |
| 203 | }); | |
| 204 | ||
| 205 | test("the MCP system tool's adopted read gives an admin the rows and refuses anyone else", async () => { | |
| 206 | const { tool } = await import("../src/http/mcp/tools/system.ts"); | |
| 207 | const { cellChildren } = await import("../src/spawn/cell.ts"); | |
| 208 | const { createUser } = await import("../src/core/users.ts"); | |
| 209 | const { app, childDir, dir } = setup(); | |
| 210 | const server = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("ok") }); | |
| 211 | try { | |
| 212 | const ctl = join(dir, "ctl"); | |
| 213 | supervised(ctl, process.pid); | |
| 214 | writeRecord(childDir("cell-a"), recordFor({ port: server.port as number, supervisor: ctl })); | |
| 215 | await cellChildren(app).adopted; | |
| 216 | const person = async (username: string, isAdmin: boolean) => { | |
| 217 | const r = await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", isAdmin }); | |
| 218 | if (!r.ok) throw new Error(r.error); | |
| 219 | return r.value; | |
| 220 | }; | |
| 221 | const admin = await person("adopt-admin", true); | |
| 222 | const member = await person("adopt-member", false); | |
| 223 | const read = await tool.run({ app } as unknown as Ctx, admin, { kind: "adopted" }); | |
| 224 | expect(read).toMatchObject({ ok: true, value: { rows: [{ name: "a", outcome: "kept", says: "kept running across the restart" }] } }); | |
| 225 | const refused = await tool.run({ app } as unknown as Ctx, member, { kind: "adopted" }); | |
| 226 | expect(refused).toMatchObject({ ok: false, error: "forbidden" }); | |
| 227 | expect(JSON.stringify(refused)).not.toContain("kept running"); | |
| 228 | } finally { | |
| 229 | server.stop(true); | |
| 230 | app.close(); | |
| 231 | } | |
| 232 | }); |
New admin-gated read with no test. Add one for admin (rows returned) and non-admin (forbidden).