Public: anyone can read this; the crew can change it.
Putting idle forges to sleep is one at a time: N idle forges take N times 12 to 15 s #13829
Check · Review · Land · Live done — Landed and live in production.
Idle forges running in cells are now stopped together, eight at a time, and each is logged the moment it sleeps. This covers two of the three things wanted. The clean exit that makes a stop cost milliseconds belongs to the issue before this one, so I left it alone.
shipped production is serving it deploy 59903fa
2 earlier comments
Idle forges running in cells are now stopped together, eight at a time, and each is logged the moment it sleeps. This covers two of the three things wanted. The clean exit that makes a stop cost milliseconds belongs to the issue before this one, so I left it alone. Until it lands, each stop still takes its 15 s grace. With the eight-at-once limit, 12 idle forges should take about two grace periods, where before they took about 12.
- What moved: in
src/spawn/cell.ts,sleepIdlewas a sequentialfor … await this.stop(). It now runs a small pool of workers over the held children, each doing the same checks and then the stop.SLEEP_AT_ONCE = 8is exported next to it. - Logging:
sleepIdletakes an optionalonAsleep(name, bodyId)callback.sleepIdleChildreninsrc/spawn/host.tspasses one that writes "child forge asleep" as each stop finishes. The end-of-pass log now covers only the in-process forges, so no name is logged twice. - Unchanged: the new-forge, busy and crew-at-work skips, and the names
sleepIdlereturns. - Not done: I did not change the sweep timer or how the
spawn-idlejob is held. The pass still holds the job until its slowest batch finishes, though that is now much shorter. I also did not make the limit configurable. - Test:
test/spawn-sleep-together.test.tsstarts 10 fake children that each take 300 ms to leave. It checks that all 10 sleep, that each is named as it sleeps, that no more than eight stop at once, and that the pass finishes well under the 3 s it would take one at a time. - Checks:
tscis clean and the cell, boot-idle and sleep tests pass.scripts/gate.ts --fixrewrapped comments in two files, and those are in the commit. Because cells can't run in this sandbox, the real-cell paths are exercised only by the forge's check.
To try it, put several forges idle together and watch the "child forge asleep" lines. They should appear in batches during the pass, not all at the end.
The gate was failing on an unmarked Bun.sleep(300) at test/spawn-sleep-together.test.ts:21. I added the // real-timer: marker it asks for, and the gate now exits 0.
The delay stays real because the test measures how many children are leaving at once and how long the whole sleep takes. A fake clock would defeat that. I did not change any other code. test/spawn-sleep-together.test.ts passes locally. I did not run tsc or the other tests here, and I did not re-check the preview. The forge's check will run on this push.
The original change is unchanged:
sleepIdleputs idle cells to sleep together, up toSLEEP_AT_ONCE(eight) at a time.- It logs each cell by name as it goes to sleep.
To try it, run bun test test/spawn-sleep-together.test.ts.
I merged main into the branch and pushed it, so the pull should merge cleanly again.
Conflict: src/spawn/cell.ts had one conflict, on the sleepIdle declaration in the CellChildren interface. main had only rewrapped comments in that file. I kept my signature, sleepIdle(idleMs, now?, onAsleep?), so each idle cell is still logged as it sleeps, eight at a time. src/spawn/host.ts merged without a conflict.
Checks run:
gate.ts --fixandtsc --noEmitwere clean.- Six sleep-related test files ran: 43 pass, 15 skip, 0 fail.
scripts/fast.tssaid the diff touches 2,368 test files, so I did not run those. The forge's check runs the full suite on this push.- I did not read the 15 skips closely. The sandbox runs the unix-socket and cell suites in skipped mode.
Approved. sleepIdle now stops idle cells through a bounded pool (8), keeps the new-forge/busy/crew-at-work skips, and logs each name as it sleeps. The test would fail on the old sequential loop (peak/elapsed and onAsleep). No UI, terminal or docs surface is touched, and there is no new dependency or input. Two things to do next: (1) in host.ts the end-of-pass log filters by name against cellsAsleep, so an in-process forge sharing a name with a cell would go unlogged. Log the in-process names before asleep.push(...cellsAsleep) instead. (2) The test asserts wall-clock time (under 2.4 s against a 0.6 s expected run). The margin is wide, but asserting only peak concurrency plus the batch count would be flake-proof, in line with the fast-tests-that-never-flake direction.
Idle forges running in cells are now stopped together, eight at a time, and each is logged the moment it sleeps. This covers two of the three things wanted. The clean exit that makes a stop cost milliseconds belongs to the issue before this one, so I left it alone. Until it lands, each stop still takes its 15 s grace. With the eight-at-once limit, 12 idle forges should take about two grace periods, where before they took about 12.
src/spawn/cell.ts,sleepIdlewas a sequentialfor … await this.stop(). It now runs a small pool of workers over the held children, each doing the same checks and then the stop.SLEEP_AT_ONCE = 8is exported next to it.sleepIdletakes an optionalonAsleep(name, bodyId)callback.sleepIdleChildreninsrc/spawn/host.tspasses one that writes "child forge asleep" as each stop finishes. The end-of-pass log now covers only the in-process forges, so no name is logged twice.sleepIdlereturns.spawn-idlejob is held. The pass still holds the job until its slowest batch finishes, though that is now much shorter. I also did not make the limit configurable.test/spawn-sleep-together.test.tsstarts 10 fake children that each take 300 ms to leave. It checks that all 10 sleep, that each is named as it sleeps, that no more than eight stop at once, and that the pass finishes well under the 3 s it would take one at a time.tscis clean and the cell, boot-idle and sleep tests pass.scripts/gate.ts --fixrewrapped comments in two files, and those are in the commit. Because cells can't run in this sandbox, the real-cell paths are exercised only by the forge's check.To try it, put several forges idle together and watch the "child forge asleep" lines. They should appear in batches during the pass, not all at the end.
Closes #13815