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

An idle fresh forge has a memory budget test that names where its memory goes #16883

Merged opened this

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

Merged

This adds a test that boots the real src/main.ts on empty data and fails if its settled RSS goes over a named budget. It passes in about 11 s here, well inside its 120 s per-test timeout. tsc and gate.ts --fix are clean.

Notes

opened this

This adds a test that boots the real src/main.ts on empty data and fails if its settled RSS goes over a named budget. It passes in about 11 s here, well inside its 120 s per-test timeout. tsc and gate.ts --fix are clean. I ran only this test file, not the full suite.

  • Budget: IDLE_RSS_BUDGET in src/perf/idle_budget.ts is 400 MiB, and it is the one constant the D1 cuts lower. A settled idle forge here measured 281 MiB, and I added a margin for loaded hosts. That is well under the 580–630 MB the issue gives for vxrail small forges. I did not reproduce the vxrail setup, so the budget fits this sandbox's measurement, not vxrail's. If it should match vxrail, the constant needs raising.
  • Test: test/boot-idle-memory.test.ts boots with production's variables and waits for the "forge is up" line. It then reads VmRSS from /proc once a second until three readings are within 2% of each other, for at most 20 s.
  • Failure output: the assertion message prints the RSS, the budget, and the forge's own last memory main: line (JS heap, mimalloc committed, RSS). That line is the forge's first one, logged at boot, not one taken after RSS settled. src/perf/memory_watch.ts already writes the line, so I added no new code for it.
  • Other hosts: the test is skipped off Linux, with the reason in IDLE_SKIP_REASON.
  • Waits: the gate's fixed-wait rule counts literal Bun.sleep(<number>) calls. I used named constants (POLL_MS, SETTLE_MS, STOP_GRACE_MS) because the waits are real time with no event to await.
  • Reuse and left out: I reused productionEnv from the existing test helpers, and the boot loop follows test/boot-production.test.ts. I wrote no new function, so similar.ts didn't apply. I made no change to the memory line itself, and no change to what the forge holds at idle.
  • Doors and looks: the commit says No door: and No look:, since nothing under src/web/ or the page, action and API layers changed.

To try it: bun test test/boot-idle-memory.test.ts.

Closes #16851

2 earlier comments
commented

This adds a test that boots the real src/main.ts on empty data and fails if its settled RSS goes over a named budget. It passes in about 11 s here, well inside its 120 s per-test timeout. tsc and gate.ts --fix are clean. I ran only this test file, not the full suite.

  • Budget: IDLE_RSS_BUDGET in src/perf/idle_budget.ts is 400 MiB, and it is the one constant the D1 cuts lower. A settled idle forge here measured 281 MiB, and I added a margin for loaded hosts. That is well under the 580–630 MB the issue gives for vxrail small forges. I did not reproduce the vxrail setup, so the budget fits this sandbox's measurement, not vxrail's. If it should match vxrail, the constant needs raising.
  • Test: test/boot-idle-memory.test.ts boots with production's variables and waits for the "forge is up" line. It then reads VmRSS from /proc once a second until three readings are within 2% of each other, for at most 20 s.
  • Failure output: the assertion message prints the RSS, the budget, and the forge's own last memory main: line (JS heap, mimalloc committed, RSS). That line is the forge's first one, logged at boot, not one taken after RSS settled. src/perf/memory_watch.ts already writes the line, so I added no new code for it.
  • Other hosts: the test is skipped off Linux, with the reason in IDLE_SKIP_REASON.
  • Waits: the gate's fixed-wait rule counts literal Bun.sleep(<number>) calls. I used named constants (POLL_MS, SETTLE_MS, STOP_GRACE_MS) because the waits are real time with no event to await.
  • Reuse and left out: I reused productionEnv from the existing test helpers, and the boot loop follows test/boot-production.test.ts. I wrote no new function, so similar.ts didn't apply. I made no change to the memory line itself, and no change to what the forge holds at idle.
  • Doors and looks: the commit says No door: and No look:, since nothing under src/web/ or the page, action and API layers changed.

To try it: bun test test/boot-idle-memory.test.ts.

commented

An idle fresh forge now has a named memory budget: a booted forge on empty data must settle under 400 MiB of RSS. If it doesn't, the failure prints the forge's own memory main: line, so the cause is named and not only the total. Linux only, since RSS is read from /proc.

The first check failed twice, and I fixed both:

  • Dead module: the budget constant sat in src/perf/idle_budget.ts, which nothing under src/ imported. I moved it into test/boot-idle-memory.test.ts and deleted the module.
  • Over the 2 s test budget: the test boots the real src/main.ts and waits real seconds for RSS to settle, so it took 8.6 s. I named it in SLOW in scripts/gate.ts with a reason and issue 16851 instead of making it faster.

Locally the idle forge settled at 283 MiB against the 400 MiB budget. tsc is clean, and the idle-memory and unused-exports tests pass; I did not run the full suite.

bun scripts/gate.ts --fix rewrapped comments in one file, and that is committed. It also warns that the test's take helper duplicates the one in test/boot-production.test.ts. I left it, since it only warns and wasn't part of the failed check.

To try it: bun test test/boot-idle-memory.test.ts (about 25 s).

🤖 Generated with Claude Code

commented

All three changes are in and pushed. tsc is clean, and bun test passes on boot-idle-memory, worker-memory-lines and boot-production (11 tests).

  1. Memory line at the settle point. You were right that the seam did not cover the main line. FORGE_WORKER_MEMORY_MS only reached the worker lines, and the serving sampler always ran on a 60 s default. I made src/main.ts pass workerMemoryEvery() to startMemorySampler, so the same seam now sets the main sampler's interval too. Without the variable it is still 60 s. The test sets it to 1 s, and takes the newest memory main: line right after the final RSS reading, so it is at most about 1 s older than the RSS it explains. In my run the line said rss 272 MiB beside the measured 290 MiB. Those two figures are about one sample apart, not from the same instant.
  2. Assertion messages. The > 0 assertion now says "could not read the RSS of the forge" and includes the pid and the end of the output. The budget message is built once, with the formatted RSS shared by the log line and the assertion.
  3. take helper. It is now collectOutput in test/helpers/collect-output.ts, used by both boot-idle-memory.test.ts and boot-production.test.ts.

This touches src/main.ts and a comment in src/perf/memory_watch.ts, outside the test file you named. I did that because the line could not exist at the settle point without it.

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs