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

An idle forge drains and sleeps after a quiet period its owner can set #16903

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The quiet period before a forge sleeps is now an admin setting, and the forges page and terminal both say when a forge sleeps and what that means.

Notes

opened this

The quiet period before a forge sleeps is now an admin setting, and the forges page and terminal both say when a forge sleeps and what that means. The 3 tests I added pass, as do the existing forge-sleep, front-wake, spawn-limits and week-line tests I ran, bun x tsc --noEmit is clean, and bun scripts/gate.ts --explain reads 0 fail. I did not run the full suite or bun scripts/design-lint.ts after the last two commits.

What changed

  • New setting forges.idle_minutes at /admin/limits. The default is 10, with its reason beside it. FORGE_CHILD_IDLE_S is read only while the setting is unset. The sweep and the awake-set bookkeeping in src/spawn/host.ts read it live through idleAfterMs(env, db).
  • The page and the terminal say it. A new sleepWords() in src/spawn/sleep.ts states when a forge sleeps, that its process exits and its data stays, and that the next visit, push or scheduled run wakes it. It appears as a data-sleep line on /forges and at the top of the terminal's "Forges you sent" screen.
  • The sleep and drain path already existed. Cell children drain with FORGE_DRAIN_LINGER_S=0 and the front router already wakes them, so I did not rebuild it.
  • Docs: docs/features/forge-sleep.md is updated.
  • Reused: the existing limits.ts settings registry and settled/limitIsSet pattern, the front-wake stub of the cell (copied into the new test), and answerFromCell/sleepIdleChildren.

Tests (test/forge-idle-setting.test.ts)

  • The setting wins over the env, which wins over the default.
  • The sleep words are correct.
  • One forge is woken, put to sleep by the sweep using the 3-minute setting, then hit with 12 concurrent requests. All 12 are answered with the right body from a single wake.

What I left out

  • Scheduled app work. Crew runs that fall due already wake a sleeping cell through wakeWhenDue. I did not add a wake for an app's own timers inside a sleeping child forge, so the third part of "scheduled work still runs" is only partly met. The doc says so.
  • Sweep interval. It is fixed at 60 s, so a 1-minute setting sleeps a forge within about 2 minutes.
  • Page test. There is no test of the /forges line itself. The shared sleepWords text is tested directly.
  • Similarity gate. It noted the new test's stub as similar to the one in front-wake.test.ts. I left it as a copy.

Try it: as an admin, open /forges and read the sleep line. Change "Quiet minutes before a forge sleeps" at /admin/limits and reload.

Closes #16855

4 earlier comments
commented

The quiet period before a forge sleeps is now an admin setting, and the forges page and terminal both say when a forge sleeps and what that means. The 3 tests I added pass, as do the existing forge-sleep, front-wake, spawn-limits and week-line tests I ran, bun x tsc --noEmit is clean, and bun scripts/gate.ts --explain reads 0 fail. I did not run the full suite or bun scripts/design-lint.ts after the last two commits.

What changed

  • New setting forges.idle_minutes at /admin/limits. The default is 10, with its reason beside it. FORGE_CHILD_IDLE_S is read only while the setting is unset. The sweep and the awake-set bookkeeping in src/spawn/host.ts read it live through idleAfterMs(env, db).
  • The page and the terminal say it. A new sleepWords() in src/spawn/sleep.ts states when a forge sleeps, that its process exits and its data stays, and that the next visit, push or scheduled run wakes it. It appears as a data-sleep line on /forges and at the top of the terminal's "Forges you sent" screen.
  • The sleep and drain path already existed. Cell children drain with FORGE_DRAIN_LINGER_S=0 and the front router already wakes them, so I did not rebuild it.
  • Docs: docs/features/forge-sleep.md is updated.
  • Reused: the existing limits.ts settings registry and settled/limitIsSet pattern, the front-wake stub of the cell (copied into the new test), and answerFromCell/sleepIdleChildren.

Tests (test/forge-idle-setting.test.ts)

  • The setting wins over the env, which wins over the default.
  • The sleep words are correct.
  • One forge is woken, put to sleep by the sweep using the 3-minute setting, then hit with 12 concurrent requests. All 12 are answered with the right body from a single wake.

What I left out

  • Scheduled app work. Crew runs that fall due already wake a sleeping cell through wakeWhenDue. I did not add a wake for an app's own timers inside a sleeping child forge, so the third part of "scheduled work still runs" is only partly met. The doc says so.
  • Sweep interval. It is fixed at 60 s, so a 1-minute setting sleeps a forge within about 2 minutes.
  • Page test. There is no test of the /forges line itself. The shared sleepWords text is tested directly.
  • Similarity gate. It noted the new test's stub as similar to the one in front-wake.test.ts. I left it as a copy.

Try it: as an admin, open /forges and read the sleep line. Change "Quiet minutes before a forge sleeps" at /admin/limits and reload.

commented

<!-- look-pages 5558199102e2 --> Look pages for 5558199, from the gate:

  • look pages (none): this pull changes src/web/pages/forges.ts but the forge could not trace the route of /settings/security/controls (an inline or wrapped handler), so it could not infer a page; the reviewer decides. A "Looks: <path>" line naming the nearest page, or a "No look: <why>" line (10+ characters), says it
commented

The look-pages note is answered, and the branch is pushed. The change itself is unchanged: an idle forge sleeps after a quiet period its owner sets at /admin/limits, and /forges and the terminal show it.

  • Look pages: the new commit carries Looks: /admin/limits and a No look: line saying /forges only gains one muted line and isn't in app.looks. The gate couldn't trace the /settings/security/controls route, so this tells the reviewer which page to open.
  • Test inputs: test/forge-idle-setting.test.ts has no as never or as any.
  • Issue number: the earlier commit that has a Direction: line already carries (#16855), and the gate's "name the issue" rule passes.
  • Dead-code and untimed-job tests: I didn't run these. The gate's rules were the only part I ran here, and none of them failed.
  • Comment rewrap: bun scripts/gate.ts --fix rewrapped nothing. It still notes one comment line over 100 columns in src/spawn/host.ts, which it says the nightly rewrap handles on main.
  • Not addressed: the gate's duplicate-function note says parentWithAsleepForge in my test resembles asleep in test/front-wake.test.ts. I left them separate because mine also records sleep requests and their start timing differs. The duplicate scan also stopped after 8000 ms, so it compared only part of the tree.

To try it: open /forges as an admin, read the line about when a forge sleeps, and change the setting at /admin/limits.

🤖 Generated with Claude Code

commented

Box 2 stays open: an app's own timer still doesn't wake a sleeping forge. I split it into #16918 rather than build it here. The other review points are done, and the branch is pushed. The new tests, tsc and the gate's rules pass. I didn't run the dead-code or untimed-job tests.

  • Box 2 (app timers): crew work due already wakes a sleeping forge through wakeWhenDue. #16918 covers arming that same path from an app's timer, and docs/features/forge-sleep.md now says the app-timer wake is not built yet and points to it. That tidies the "It sleeps:" line too.
  • Shorter words: sleepWords is now one sentence: "A forge nobody has asked for in N minutes goes to sleep; its data stays." The /admin/limits pointer is gone, so non-admins no longer see a link they can't use.
  • Page and terminal tests: in test/clients-week-line.test.ts, /forges must show the data-sleep line with the set 7 minutes, and nothing when the list is empty. The terminal's forges screen, driven through a headless terminal, must contain the same words. I removed the terminal line to check, and the test failed.
  • Sleep racing a request: in test/forge-idle-setting.test.ts, the stubbed cell's drain now holds until released. Requests arrive while the sweep is mid-sleep and more arrive after, and every one is answered. The original burst-after-sleep stub test stays.

Box 3 is still shown only against a stubbed cell, not a real process drain. The cell suites are skipped in my sandbox, so the forge's check covers them.

The gate still flags parentWithAsleepForge as similar to asleep in test/front-wake.test.ts. I kept them separate because mine also records sleep requests and holds the drain. Its duplicate scan stopped at 8000 ms, so it only compared part of the tree.

To try it: open /forges as an admin and read the sleep line. Change the minutes at /admin/limits and reload.

🤖 Generated with Claude Code

commented

Left #16855 open: 1 unticked item remain (Scheduled work an app owns still runs (it wakes the forge), and the forge's page says plainly when it sleeps and what that means.).

Sign in to join this conversation.

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

Keyboard shortcuts

Docs