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

A machine agent that does not check in after its update goes back to the version before, and the forge says so #18483

opened this

Merged 4h 53m ago, live in production

mason/forge:mason/18464-a-machine-agent-that-does-not-check-in-a → main 0 commits fork 2 threads · 2 unresolved

  • Merged. mason/18464-a-machine-agent-that-does-not-check-in-a was merged into main as 49c1b5a.

Review

Sign in to review this change.
5 files changed +126 −6
docs/features/infra.md +1 −1
@@ -114,7 +114,7 @@ Every DigitalOcean and Hetzner account is read into provider ▸ account ▸ pro
114114 - **Changed with the shared language:** `!web` and `!machine:i-111` negate and a leading `"` quotes (both were part of the word); `sort:`, `group:` and `created:` were text; `cost:=10`, `cost:>10,=20` and `cost:>10,<5` were refused; a sign left out and a long line's rest are now said; over MCP `cost:abc` and `cost:none` listed everything and are refused. `test/cloud-filter-lines.test.ts` holds each, and every line that kept its rows.
115115 - **A resource** is at `/infra/-/<cloud>/<account>/<project>/<id>`, beside the tree, or full width on a phone: cost, state, what it is attached to and what it holds (an address its balancer, NAT gateway or task; an ECS service its balancer and cluster; a balancer the services known behind it, "Shared by" when there are several; a link AWS does not state is not drawn, which does not mean nothing uses it), an AWS list price's day, what it leaves out and whose file it is (or why there is none), the app an AWS resource is part of and how that is known (nothing when it is not), what it was made from, who made it, when it was created, when it was read, and Ask about this (a talk with those facts, fenced as data).
116116 - **Created.** An EC2 instance's is when its primary network interface was attached, which is its first launch: AWS's `launchTime` is its last start and is not shown. "not known" when the cloud does not state a date, or the forge does not read one (an AWS address, function, table, cluster or zone). An S3 bucket's is "Created, or last changed", because AWS moves it when the bucket changes, its policy for one; a filter by `created:` uses that date all the same.
117 - **Containers.** A machine that is a game box opens into its containers (`src/cloud/containers.ts`), at `/infra/-/<cloud>/<account>/<project>/machine:<id>/container:<name>`: state, health, CPU, memory, how long it has been up, its image (the box owner's only) and a link to its page under /games, where it is changed. It is what the box's last full sync wrote, and nothing is asked of the box. The sync carries `upSince`, `memLimitMiB` and `cpuLimit` for each service, from one `docker inspect` that asks for those fields by name and never the whole answer, which holds the env (`services` in `src/games/agent.sh`): a limit of 0 is "no limit set", and one left out (an older agent) is "not known", as is a value out of its range. Without `upSince` the uptime is the diagnosis' word. "not known" is also said of figures the box could not measure, and of everything once the box is silent for two minutes ("not known: running 3 hours ago"). A container is in no count and no sum. The machine is the one the box's own row names, never found by name. Who sees which follows the games roles, and nobody sees the waker. A held box (docs/features/games.md) says so on its machine: in its row, and first in its facts with the next step. A machine's pane lists its containers as one table, on the page and in the terminal alike (`CONTAINER_COLUMNS`, `containerCell`): name (a link to the container), state, CPU limit, memory limit and started, as an ago. A value not known, or no limit set, is an em dash, never 0.
117 - **Containers.** A machine that is a game box opens into its containers (`src/cloud/containers.ts`), at `/infra/-/<cloud>/<account>/<project>/machine:<id>/container:<name>`: state, health, CPU, memory, how long it has been up, its image (the box owner's only) and a link to its page under /games, where it is changed. It is what the box's last full sync wrote, and nothing is asked of the box. The sync carries `upSince`, `memLimitMiB` and `cpuLimit` for each service, from one `docker inspect` that asks for those fields by name and never the whole answer, which holds the env (`services` in `src/games/agent.sh`): a limit of 0 is "no limit set", and one left out (an older agent) is "not known", as is a value out of its range. Without `upSince` the uptime is the diagnosis' word. "not known" is also said of figures the box could not measure, and of everything once the box is silent for two minutes ("not known: running 3 hours ago"). A container is in no count and no sum. The machine is the one the box's own row names, never found by name. Who sees which follows the games roles, and nobody sees the waker. A held box (docs/features/games.md) says so on its machine: in its row, and first in its facts with the next step. A box whose agent update was put back to the one before (docs/features/games.md, the agent's trial) says so there too: its row reads "On its old agent:" and the agent's own reason, in the terminal's Infra the same words after the row's place, and in the `infra` tool's list as the machine's `agentBack`; a box whose agent is fine has no such field. A machine's pane lists its containers as one table, on the page and in the terminal alike (`CONTAINER_COLUMNS`, `containerCell`): name (a link to the container), state, CPU limit, memory limit and started, as an ago. A value not known, or no limit set, is an em dash, never 0.
118118 - **Logs.** A game box's container has a Logs tab with the same live reader and console as its service's page on `/games/<box>/<service>`, with Restart, and Stop and Start under More, for an operator of it (they ask first when someone is on, as there). Someone with no role on the box is told so (`containerConsole` in `src/web/pages/games.ts`).
119119 - **File.** A machine has two tabs, Facts and File (`?tab=file`; `[` and `]` in the terminal); a container has a third, Logs (`?tab=logs`): on the page, for someone with a role on its box, the live reader below; otherwise, in the terminal and in the `infra` tool, its newest 200 lines as its box last synced them (nothing is fetched from the box; control characters are dropped, the page escapes the rest), or a sentence saying none were synced and when the box last did. The `infra` tool returns the same lines as `logs` for a container. Only an admin sees the tree. File says which lines of which file declare the thing, links to them, and says whether that agrees with what the forge knows (`src/cloud/declared_in.ts`, `declared_read.ts`). Two kinds of file are read: an app's `infra.json`, against the forge's own record of the machine (the cloud is not asked), and a game box's compose file, against the commit the box last said it runs. When the branch is at another commit the tab says so, since its lines may not be what runs; a silent box is "not known". Of a service it shows the image, ports, volumes and the names of its environment, never a value. A thing in neither file is "in no file the forge reads", one that is part of a stack is "not known", and one in a repository the reader may not read is "in a file you cannot read", with nothing of it shown. The join goes through the forge's own rows and never by a resource's name. On the branch that is followed, the file's own page says to a forge admin "Declares 3: …" with a link to each node; to anyone else it is as before. Nothing is written.
120120 - **Keys.** j and k move, Enter opens, h and l (or the arrows) close and open, `/` filters and Enter goes to the first match.
src/actions/infra.ts +17 −2
@@ -70,6 +70,15 @@ export interface Meter {
7070 readonly budget: Standing;
7171 }
7272
73 /**
74 * A game box's agent update that was put back, as the row's own field; nothing for any other
75 * machine.
76 */
77 const agentBack = (box: { readonly diag: { readonly rolledBack?: string } } | undefined): { agentBack?: string } => {
78 const why = (box?.diag.rolledBack ?? "").trim();
79 return why === "" ? {} : { agentBack: why.slice(0, 300) };
80 };
81
7382 /** One machine that bills, as every door shows it. */
7483 export interface Running {
7584 readonly name: string;
@@ -98,6 +107,11 @@ export interface Running {
98107 readonly offer: string;
99108 /** A game box (`games/store.ts`): Docker and the game agent, not a forge. */
100109 readonly game?: true;
110 /**
111 * A game box whose agent update was put back (#18464): why, in the agent's own words. Absent
112 * otherwise.
113 */
114 readonly agentBack?: string;
101115 }
102116
103117 /** One managed Postgres database, as every door shows it. */
@@ -236,7 +250,7 @@ function reckon(app: App, now: Date): { view: InfraView; rows: Map<string, Runni
236250 .map((r) => [r.name, r.at]),
237251 );
238252 const pinned = listPinned(db);
239 const games = new Set(listBoxes(db).map((g) => g.name));
253 const boxes = new Map(listBoxes(db).map((g) => [g.name, g]));
240254 for (const p of pinned) {
241255 const monthlyCents = cents.get(p.name) ?? 0;
242256 // A machine still being made is the build tray's, not a row yet.
@@ -258,7 +272,8 @@ function reckon(app: App, now: Date): { view: InfraView; rows: Map<string, Runni
258272 atProvider: existsAtProvider(p),
259273 clear: p.state === "failed" && !existsAtProvider(p) ? `nothing exists at ${isProvider(p.target) ? LABEL[p.target] : p.target}; clear this row` : "",
260274 offer: snapshotOffer(app, p),
261 ...(games.has(p.name) ? { game: true as const } : {}),
275 ...(boxes.has(p.name) ? { game: true as const } : {}),
276 ...agentBack(boxes.get(p.name)),
262277 };
263278 rows.set(p.name, r);
264279 if (p.state === "retired") {
src/tui/screens/infra.ts +1 −1
@@ -447,7 +447,7 @@ function infraWithCompose(f: Session, ctx: Ctx): { screen: Screen; compose: (par
447447 ...v.value.groups.flatMap((g) =>
448448 g.machines.map((m) => ({
449449 title: `${m.name} · ${month(m.monthlyCents)}`,
450 secondary: `${g.title} · ${m.where} · ${m.clear !== "" ? m.clear : m.endsAt === null ? "no end" : `ends ${m.ends}`}${m.state === "running" ? "" : ` · ${m.state}`}`,
450 secondary: `${g.title} · ${m.where} · ${m.clear !== "" ? m.clear : m.endsAt === null ? "no end" : `ends ${m.ends}`}${m.state === "running" ? "" : ` · ${m.state}`}${m.agentBack === undefined ? "" : ` · on its old agent: ${m.agentBack.length > 80 ? `${m.agentBack.slice(0, 79)}…` : m.agentBack}`}`,
outdated

The terminal text on its old agent: ... has no test. The reason can be 300 characters on one secondary line, which will wrap or cut on a narrow terminal. Truncate it for this line or put it on its own line, and test it.

451451 meta: m.account,
452452 })),
453453 ),
src/web/pages/infra.ts +2 −2
@@ -186,9 +186,9 @@ function machineRow(r: Running, cloud: { label: string; value: string } | undefi
186186 ...(cloud === undefined ? {} : { facts: [cloud] }),
187187 id: `machine-${r.name}`,
188188 title: html`<span class="mono">${r.name}</span>`,
189 meta: r.clear !== ""
189 meta: html`${r.clear !== ""
190190 ? html`<span data-where>${r.where} · ${r.state}</span><span>${r.clear}</span>`
191 : html`<span data-where>${r.where}${r.state === "running" ? null : html` · ${r.state}`}</span><span data-ends>${ends}</span>`,
191 : html`<span data-where>${r.where}${r.state === "running" ? null : html` · ${r.state}`}</span><span data-ends>${ends}</span>`}${r.agentBack === undefined ? null : html`<span data-agent-back>On its old agent: ${r.agentBack}</span>`}`,
outdated

Two things. The data-agent-back span is only in the non-clear branch, so a failed box that is being cleared shows no old-agent reason, while the terminal does. Move it outside the ternary. No test renders this span, so removing it would pass bun test. Add a page-level test.

192192 trail: html`<span>${money(r.monthlyCents)}<span class="muted"> a month</span></span>`,
193193 after: machineActions(r),
194194 data: { state: r.state },
test/infra-agent-back.test.ts added +105
@@ -0,0 +1,105 @@
1 /**
2 * A machine whose game agent was put back to the one before (#18464) says so on its /infra row, in
3 * the terminal's Infra and in the `infra` tool's list, with the agent's own reason; one whose agent
4 * is fine says nothing. A recorded cloud.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { addAccount, allowWrite, net as cloudNet } from "../src/actions/cloud.ts";
12 import { infraOf } from "../src/actions/infra.ts";
13 import { deployPinned, net } from "../src/actions/pinned.ts";
14 import { readPlaces } from "../src/cloud/places_read.ts";
15 import { createUser, type User } from "../src/core/users.ts";
16 import { setBaseDomain } from "../src/settings/pinned_domain.ts";
17 import { seedPlaces } from "./helpers/places-fixture.ts";
18 import { recordCloud } from "./helpers/recorded-cloud.ts";
19 import { runningRegion } from "../src/web/pages/infra.ts";
20 import { infraScreen } from "../src/tui/screens/infra.ts";
21 import { quietCtx, screenText, sessionFor } from "./helpers/tui-text.ts";
22 import { quietLogs } from "./helpers/globals.ts";
23
24 quietLogs();
25
26 const WHY = "agent update rolled back: the new agent exited 3 times within 600 s";
27 const saved = { cloud: cloudNet.fetch, fetch: net.fetch, resolve: net.resolve };
28 let dir = "";
29 let app: App;
30 let admin: User;
31 const cloud = recordCloud();
32
33 beforeAll(async () => {
34 dir = await mkdtemp(join(tmpdir(), "forge-agent-back-"));
35 app = createApp({ dataDir: dir, port: 0, url: "https://forge.example" });
36 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
37 if (!made.ok) throw new Error(made.error);
38 admin = made.value;
39 await seedPlaces(app.db);
40 const json = (o: unknown): Response => new Response(JSON.stringify(o), { status: 200 });
41 const sizes = [{ slug: "s-4vcpu-8gb", memory: 8192, vcpus: 4, disk: 160, transfer: 5, price_monthly: 10, available: true, regions: ["nyc3"] }];
42 await readPlaces(app.db, "digitalocean", async (url) => json(String(url).includes("/sizes") ? { sizes } : { regions: [{ slug: "nyc3", available: true }] }), "t");
43 cloudNet.fetch = async (url) =>
44 String(url).includes("cloudflare") ? json({ success: true, result: [{ id: "a".repeat(32), name: "example.com" }] }) : json({ account: { email: "[email protected]", status: "active" } });
45 for (const [provider, key] of [["digitalocean", "dop_v1_9Zq4TxLm7Kp2Vb8nWcR5"], ["cloudflare", "cf-token-0123456789abcdef0123456789abcdef"]] as const) {
46 const added = await addAccount(app, admin, provider, "main", key);
47 if (!added.ok) throw new Error(String(added.error));
48 }
49 allowWrite(app, admin, "digitalocean", "main", true);
50 setBaseDomain(app.db, "forges.example.net", admin.id);
51 net.fetch = cloud.fetch;
52 net.resolve = async () => [];
53 const box = await deployPinned(app, admin, {
54 name: "mc", host: "", target: "digitalocean", account: "main", app: "alice/mc", boots: "game",
55 source: "https://forge.example/alice/forge.git", version: "a".repeat(40), place: "digitalocean:nyc3:s-4vcpu-8gb",
56 });
57 if (!box.ok) throw new Error(String(box.error));
58 }, 30_000);
59 afterAll(async () => {
60 cloudNet.fetch = saved.cloud;
61 net.fetch = saved.fetch;
62 net.resolve = saved.resolve;
63 app.close();
64 await rm(dir, { recursive: true, force: true });
65 });
66
67 const row = () => {
68 const v = infraOf(app, admin);
69 if (!v.ok) throw new Error(v.error);
70 return v.value.groups.flatMap((p) => p.machines).find((m) => m.name === "mc")!;
71 };
72
73 test("a box whose agent is fine says nothing of it", () => {
74 expect(row().game).toBe(true);
75 expect(row().agentBack).toBeUndefined();
76 });
77
78 test("a box whose agent was put back says why on its row", () => {
79 app.db.query("UPDATE game_box SET diag_json = ?1 WHERE name = 'mc'").run(JSON.stringify({ rolledBack: WHY }));
80 expect(row().agentBack).toBe(WHY);
81 });
82
83 test("the page's row says it, and not for a healthy box", () => {
84 const html = (): string => {
85 const v = infraOf(app, admin);
86 if (!v.ok) throw new Error(v.error);
87 return runningRegion(v.value).toString();
88 };
89 app.db.query("UPDATE game_box SET diag_json = '{}' WHERE name = 'mc'").run();
90 expect(html()).not.toContain("data-agent-back");
91 app.db.query("UPDATE game_box SET diag_json = ?1 WHERE name = 'mc'").run(JSON.stringify({ rolledBack: WHY }));
92 expect(html()).toContain(`On its old agent: ${WHY.replace(/&/g, "&amp;")}`);
93 });
94
95 test("the terminal's Infra line says it, cut short for a narrow screen", () => {
96 app.db.query("UPDATE game_box SET diag_json = '{}' WHERE name = 'mc'").run();
97 expect(screenText(infraScreen(sessionFor(app, admin), quietCtx()), 200, 60)).not.toContain("on its old agent");
98 app.db.query("UPDATE game_box SET diag_json = ?1 WHERE name = 'mc'").run(JSON.stringify({ rolledBack: WHY }));
99 expect(screenText(infraScreen(sessionFor(app, admin), quietCtx()), 200, 60)).toContain("on its old agent: agent update rolled back");
100 const long = "x".repeat(300);
101 app.db.query("UPDATE game_box SET diag_json = ?1 WHERE name = 'mc'").run(JSON.stringify({ rolledBack: long }));
102 const text = screenText(infraScreen(sessionFor(app, admin), quietCtx()), 400, 60);
103 expect(text).toContain("on its old agent: " + "x".repeat(79) + "…");
104 expect(text).not.toContain("x".repeat(100));
105 });

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

Keyboard shortcuts

Docs