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

After every release a cell child cannot wake for ten minutes: the boot opens every hosted child and fills FORGE_CHILD_AWAKE_MAX ("the forge is full") #10504

Parked opened this in answer to
Closed without merging

torque/forge:torque/10502-after-every-release-a-cell-child-cannot → main 4 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +41 −5
scripts/unreached-allow.json −1
@@ -15,7 +15,6 @@
1515 "src/flow/review_rounds.ts",
1616 "src/flow/shared_red.ts",
1717 "src/flow/stale_fold.ts",
18 "src/kernel/why_now.ts",
1918 "src/spawn/pod.ts",
2019 "src/tui/gallery.ts",
2120 "src/tui/ui/qr.ts",
src/spawn/host.ts +18 −2
@@ -111,7 +111,11 @@ const personWakes = new WeakMap<App, WakeRate>();
111111 export const gateClock = { now: () => Date.now() };
112112 const sweepers = new WeakMap<App, ReturnType<typeof setInterval>>();
113113
114 /** Children the boot opened that no request has reached since: open, but nobody is using them. */
115 const bootOpened = new WeakMap<App, Set<string>>();
116
114117 function touch(parent: App, ledger: { bodyId: string; name: string }, now = Date.now()): void {
118 bootOpened.get(parent)?.delete(ledger.bodyId);
115119 let m = touched.get(parent);
116120 if (!m) touched.set(parent, (m = new Map()));
117121 m.set(ledger.bodyId, { name: ledger.name, at: now });
@@ -119,7 +123,11 @@ function touch(parent: App, ledger: { bodyId: string; name: string }, now = Date
119123
120124 /** Forges awake now: hosted children open in this process plus children running in a cell. */
121125 export function awakeCount(parent: App): number {
122 const awake = (caches.get(parent)?.size ?? 0) + cellChildren(parent).list().length;
126 // A child the boot opened for its apps and nobody has asked for holds no slot: a person's wake
127 // is never refused because of forges nobody is using. A request to it (touch) gives it one.
128 let idle = 0;
129 for (const id of bootOpened.get(parent) ?? []) if (caches.get(parent)?.has(id) === true) idle++;
130 const awake = (caches.get(parent)?.size ?? 0) - idle + cellChildren(parent).list().length;
123131 // A wake granted but not finished holds its slot, so two at once cannot both pass the ceiling.
124132 return awake + reservedCount(parent);
125133 }
@@ -295,6 +303,7 @@ export function closeHostedChildren(parent: App): void {
295303 if (sweeper !== undefined) clearInterval(sweeper);
296304 sweepers.delete(parent);
297305 touched.delete(parent);
306 bootOpened.delete(parent);
298307 waking.delete(parent);
299308 inFlight.delete(parent);
300309 const m = caches.get(parent);
@@ -441,7 +450,14 @@ export async function bootHostedChild(parent: App, name: string): Promise<void>
441450 ledger = { ...ledger, placement: "hosted" };
442451 }
443452 try {
444 await startChildApps(parent, await openOnce(parent, ledger), name);
453 const wasOpen = caches.get(parent)?.has(ledger.bodyId) === true;
454 const child = await openOnce(parent, ledger);
455 if (!wasOpen) {
456 let set = bootOpened.get(parent);
457 if (!set) bootOpened.set(parent, (set = new Set()));
458 set.add(ledger.bodyId);
459 }
460 await startChildApps(parent, child, name);
445461 } catch (error) {
446462 parent.log.error("hosted child did not open", { name, error: String(error) });
447463 }
test/child-quota.test.ts +1 −1
@@ -101,7 +101,7 @@ describe("child quota", () => {
101101
102102 test("room for small but not large is refused only for large", async () => {
103103 clear();
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "2000";
104 process.env["FORGE_CHILD_MEMORY_MIB"] = "5000";
105105 expect(quotaRefusal(dir, "small")).toBeUndefined();
106106 expect(quotaRefusal(dir, "large")).toContain("memory limit");
107107 });
test/forge-sleep.test.ts +22 −1
@@ -15,7 +15,7 @@ import { createApp, type App } from "../src/app.ts";
1515 import { createSession } from "../src/core/sessions.ts";
1616 import { createUser } from "../src/core/users.ts";
1717 import { serve, type Servers } from "../src/http/server.ts";
18 import { awakeCount, childAwake, gateClock, holdChild, resolveHostedChild, sleepIdleChildren, wakeGate } from "../src/spawn/host.ts";
18 import { awakeCount, bootHostedChildren, childAwake, gateClock, holdChild, resolveHostedChild, sleepIdleChildren, wakeGate } from "../src/spawn/host.ts";
1919 import { removeForge, stopForge } from "../src/spawn/manage.ts";
2020 import { setLimit } from "../src/settings/limits.ts";
2121 import { awakeRefusal, personRefusal, WakeRate } from "../src/spawn/sleep.ts";
@@ -381,6 +381,27 @@ describe("a hosted forge scales to zero", () => {
381381 }
382382 });
383383
384 test("children the boot opened hold no slot: a person's wake is not refused as full", async () => {
385 await sleepIdleChildren(parent, 600_000, later());
386 expect(childAwake(parent, "homie")).toBe(false);
387 const was = process.env["FORGE_CHILD_AWAKE_MAX"];
388 process.env["FORGE_CHILD_AWAKE_MAX"] = "1";
389 try {
390 await bootHostedChildren(parent);
391 expect(childAwake(parent, "homie")).toBe(true);
392 // Open, but nobody asked for it: no slot held, so the ceiling of 1 is not reached.
393 expect(awakeCount(parent)).toBe(0);
394 expect(awakeRefusal(awakeCount(parent))).toBeUndefined();
395 // A request to it is use: now it counts.
396 await asChild("/api/v1/repos/bob/app");
397 expect(awakeCount(parent)).toBe(1);
398 expect(awakeRefusal(awakeCount(parent))).toContain("the forge is full");
399 } finally {
400 if (was === undefined) delete process.env["FORGE_CHILD_AWAKE_MAX"];
401 else process.env["FORGE_CHILD_AWAKE_MAX"] = was;
402 }
403 });
404
384405 test("the owner stops a forge, then removes it with its data", async () => {
385406 expect((await stopForge(parent, "homie")).says).toContain("asleep");
386407 expect(childAwake(parent, "homie")).toBe(false);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs