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
torque/forge:torque/10502-after-every-release-a-cell-child-cannot → main 4 commits fork
4 files
changed +41
−5
scripts/unreached-allow.json −1
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | "src/flow/review_rounds.ts", |
| 16 | 16 | "src/flow/shared_red.ts", |
| 17 | 17 | "src/flow/stale_fold.ts", |
| 18 | "src/kernel/why_now.ts", | |
| 19 | 18 | "src/spawn/pod.ts", |
| 20 | 19 | "src/tui/gallery.ts", |
| 21 | 20 | "src/tui/ui/qr.ts", |
src/spawn/host.ts +18 −2
| @@ -111,7 +111,11 @@ const personWakes = new WeakMap<App, WakeRate>(); | ||
| 111 | 111 | export const gateClock = { now: () => Date.now() }; |
| 112 | 112 | const sweepers = new WeakMap<App, ReturnType<typeof setInterval>>(); |
| 113 | 113 | |
| 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 | ||
| 114 | 117 | function touch(parent: App, ledger: { bodyId: string; name: string }, now = Date.now()): void { |
| 118 | bootOpened.get(parent)?.delete(ledger.bodyId); | |
| 115 | 119 | let m = touched.get(parent); |
| 116 | 120 | if (!m) touched.set(parent, (m = new Map())); |
| 117 | 121 | m.set(ledger.bodyId, { name: ledger.name, at: now }); |
| @@ -119,7 +123,11 @@ function touch(parent: App, ledger: { bodyId: string; name: string }, now = Date | ||
| 119 | 123 | |
| 120 | 124 | /** Forges awake now: hosted children open in this process plus children running in a cell. */ |
| 121 | 125 | 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; | |
| 123 | 131 | // A wake granted but not finished holds its slot, so two at once cannot both pass the ceiling. |
| 124 | 132 | return awake + reservedCount(parent); |
| 125 | 133 | } |
| @@ -295,6 +303,7 @@ export function closeHostedChildren(parent: App): void { | ||
| 295 | 303 | if (sweeper !== undefined) clearInterval(sweeper); |
| 296 | 304 | sweepers.delete(parent); |
| 297 | 305 | touched.delete(parent); |
| 306 | bootOpened.delete(parent); | |
| 298 | 307 | waking.delete(parent); |
| 299 | 308 | inFlight.delete(parent); |
| 300 | 309 | const m = caches.get(parent); |
| @@ -441,7 +450,14 @@ export async function bootHostedChild(parent: App, name: string): Promise<void> | ||
| 441 | 450 | ledger = { ...ledger, placement: "hosted" }; |
| 442 | 451 | } |
| 443 | 452 | 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); | |
| 445 | 461 | } catch (error) { |
| 446 | 462 | parent.log.error("hosted child did not open", { name, error: String(error) }); |
| 447 | 463 | } |
test/child-quota.test.ts +1 −1
| @@ -101,7 +101,7 @@ describe("child quota", () => { | ||
| 101 | 101 | |
| 102 | 102 | test("room for small but not large is refused only for large", async () => { |
| 103 | 103 | clear(); |
| 104 | process.env["FORGE_CHILD_MEMORY_MIB"] = "2000"; | |
| 104 | process.env["FORGE_CHILD_MEMORY_MIB"] = "5000"; | |
| 105 | 105 | expect(quotaRefusal(dir, "small")).toBeUndefined(); |
| 106 | 106 | expect(quotaRefusal(dir, "large")).toContain("memory limit"); |
| 107 | 107 | }); |
test/forge-sleep.test.ts +22 −1
| @@ -15,7 +15,7 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 15 | 15 | import { createSession } from "../src/core/sessions.ts"; |
| 16 | 16 | import { createUser } from "../src/core/users.ts"; |
| 17 | 17 | 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"; | |
| 19 | 19 | import { removeForge, stopForge } from "../src/spawn/manage.ts"; |
| 20 | 20 | import { setLimit } from "../src/settings/limits.ts"; |
| 21 | 21 | import { awakeRefusal, personRefusal, WakeRate } from "../src/spawn/sleep.ts"; |
| @@ -381,6 +381,27 @@ describe("a hosted forge scales to zero", () => { | ||
| 381 | 381 | } |
| 382 | 382 | }); |
| 383 | 383 | |
| 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 | ||
| 384 | 405 | test("the owner stops a forge, then removes it with its data", async () => { |
| 385 | 406 | expect((await stopForge(parent, "homie")).says).toContain("asleep"); |
| 386 | 407 | expect(childAwake(parent, "homie")).toBe(false); |
new above
offline