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

A change nobody has touched in days keeps a full preview running forever #409

Merged opened this

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

Merged

A preview whose pull has had no push and no comment for three days is now stopped, and the change's page says it is asleep. The new `test/apps-idle.test.ts` passes. In the full `bun test` run, 28 tests failed and 4 errored. I re-ran the app, studio, TUI, vitals and web test files one at a time and each passed. I did not re-run the rest of the suite one file at a time, such as the origins tests tha…

shipped production is serving it deploy d63cf43

opened this

A preview whose pull has had no push and no comment for three days is now stopped, and the change's page says it is asleep. The new test/apps-idle.test.ts passes. In the full bun test run, 28 tests failed and 4 errored. I re-ran the app, studio, TUI, vitals and web test files one at a time and each passed. I did not re-run the rest of the suite one file at a time, such as the origins tests that showed up in the failing output. tsc couldn't run here (the bun type definitions are missing), so there was no typecheck.

What changed

  • Sleep: the existing sweep on the runtime tick stops the process but keeps the environment row, its data and its pictures. A sleeping preview reads as stopped with a new dormant field, never as failed, and its error is cleared.
  • Measuring idle: idle is the later of the pull's updatedAt and its newest deploy run caused by a person: a push, an opening, a redeploy or a wake. A push doesn't update updatedAt, so without the run check a freshly pushed preview would have gone straight back to sleep.
  • Never reaped:

- Production. - A pull with a run queued or running on it. - A preview mid-deploy.

  • Restart: boot leaves an idle preview stopped, with no run and no process. This is derived from the pull on each boot, so no new state is stored.
  • Waking: a request to a sleeping preview's host, or the new "Wake it" button on the pull page (writers only; readers see the explanation but no button), goes through requestDeploy as any other deploy does. The wake counts as a touch, so the preview stays up afterwards.
  • Words: the pull page, the studio's previews list and the TUI say "asleep <when> — nobody pushed or commented since <when>; its data and pictures are kept".
  • Setting: FORGE_PREVIEW_IDLE_DAYS defaults to 3, and 0 keeps every preview warm. It is documented in README.md and docs/APPS.md.

Tests

  • A pull touched an hour ago is untouched.
  • A pull idle for four days is stopped, with no error, and its page says so; a signed-in writer sees "Wake it" and an anonymous reader doesn't.
  • A request to the sleeping preview redeploys it with reason wake.
  • A restart leaves a sleeping preview stopped and creates no new deploy run.

Left out

  • Reaping nothing but previews: production's own idle sleep (SLEEP_AFTER_MS) is untouched.
  • A "decided right now" check beyond queued or running runs on the pull; open review threads don't count.
  • Waking from the terminal path (tty.ts).
  • A dormant count in vitals.

To try Set FORGE_PREVIEW_IDLE_DAYS=0.0001 and leave a pull alone for a few seconds, then open its page or its preview host. To run the new tests: bun test test/apps-idle.test.ts.

🤖 Generated with Claude Code

Closes #299

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs