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

A request during a forge's stop waits for the old process to be gone and starts it once: one data directory never has two forge processes #13897

Closed opened this
Closed without merging

Issue #13814 (second half: "stop forgets the cell before it is gone").

Notes

stopped closed without shipping deploy ec0ec01

opened this

Issue #13814 (second half: "stop forgets the cell before it is gone"). Measured on production on 2026-11-16: a stop takes about 15 s, and six times a request that arrived in those seconds started a second forge process on the same forge.db (scale-12, -13, -14, -16, -17, -18), because the registry forgot the child before its process had left and the request read it as asleep.

What is now true

  • src/spawn/cell.ts has one lock for each child data directory (inTurn, kept per parent app). launch, the one place a child's process is made, takes the directory's turn before anything is started; stop holds the turn until stopGently has seen the old process gone.
  • A request during a stop therefore waits for the stop and then wakes the forge once. Every request in that time joins the same start (starting already made them one flight; the flight now includes the wait). The request is held as any wake is (wakeLimits.waitMs, 20 s) and answered with the forge's own page; past that it gets the existing "Waking up" page, which asks again by itself.
  • A stop asked while the forge is still starting waits for the start and stops what came up. Before, it returned at once ("already asleep" inside the registry) and the start carried on; for a removal that meant a process starting on a directory being deleted.
  • The stopped child is still forgotten at once, so nothing more is forwarded to a process on its way out.

Test test/one-process-per-forge.test.ts, with real processes that leave only when the test lets them (no timers): eight starts fired during a stop make no process while the old one is alive, then one; the count of live processes at the moment each is made is [0, 0]. With the lock taken out, the first two tests fail (Expected: 1, Received: 2).

Not in this pull: the 15 s itself (a child forge that does not leave on SIGTERM, first half of #13814), the serial idle sweep (#13815), and the four stops that answered "was already asleep" at the owner's button (sleepChild in host.ts still reads a forge that is mid-start as asleep; the registry no longer loses it, but the sentence is unchanged). No limit, ceiling or confirmation is added or changed.

Checked: bun x tsc --noEmit exit 0; bun scripts/gate.ts exit 0; on Linux in the 0.7.614 image, the always-run set plus one-process-per-forge, first-ten-minutes, spawn-cell, forges-memory, forge-sleep: 1545 pass, 0 fail.

🤖 Generated with Claude Code

commented

Superseded by #13824 (d7c1cd6e5 on main), which landed while this pull was in check: the same guard in the same place (a stopping map in the cell registry that start waits on), a test with one live process, and the child leaving at once on SIGTERM as well. This branch now conflicts with it in src/spawn/cell.ts, and merging both would leave two mechanisms for one rule, so I am closing this one instead of resolving.

One case here that main does not have, left for whoever wants it: a stop asked while the forge is still starting returns at once on main (nothing is held yet) and the start carries on; for a removal that is a process coming up on a directory being deleted. test/one-process-per-forge.test.ts on this branch has a test for it ("a stop asked while the forge is starting waits for the start and stops what came up").

🤖 Generated with Claude Code

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs