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

Sentinel: memory-growth was degraded 16 minutes today: The forge's own memory is 4689 MiB, over twice its first-hour 1629 MiB and past the 2176 MiB more its database caches m… #16906

Merged opened this

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

Merged

A memory-growth finding filed after a restart now quotes the evidence that the process which grew had saved, instead of figures from the new process. What was wrong with #16872's evidence.

Notes

opened this

A memory-growth finding filed after a restart now quotes the evidence that the process which grew had saved, instead of figures from the new process.

What was wrong with #16872's evidence. The sentence ("4689 MiB … main VM's JS heap grew 450 MiB to 3130 MiB since 19:30:43") comes from the record saved by the process that grew. The 19:40 deploy (c90d0844d) then restarted the forge, and the evidence lines underneath were read from the new process: trip none, main heap 644 MiB, still in its first hour. So the issue sets one process's sentence beside another process's numbers. The data that would name the leak, including the per-job allocation line added in #16828, is lost on every restart, and releases restart the forge several times a day.

What changed

  • src/perf/memory_kept.ts (new): keepIfGrown writes the watch's evidence lines to memory-kept.json in the data directory. It writes only in minutes when memory-growth is open, using writePrivate. keptEvidence reads the file back with readPrivate and checks its shape and size; a file that fails the check counts as none.
  • src/boards/memory.ts: the minute sampler calls keepIfGrown.
  • src/perf/memory_watch.ts: the watch now exposes startedAt and tripAt(), so the sentinel can tell its own process from an earlier one.
  • src/crew/sentinel.ts: a new memoryEvidence function. If this process tripped, it quotes its own watch as before. If not, and an earlier process saved evidence that day, it quotes those lines under memory kept by the process started …; the forge restarted since, then adds one memory now (process started …) line for the current process.
  • docs/features/memory-growth.md: one paragraph describing this.

Tests. I added two tests to test/sentinel-memory-evidence.test.ts:

  • After a restart, the finding quotes the saved trip figures and the "now" line. The process that grew still reads its own watch, and evidence saved before that day is ignored.
  • The file is written only while memory is grown, and malformed files are rejected.

tsc, the gate, and 18 related test files (the sentinel, memory and unused-exports tests) pass. The full suite was not run here; the forge's check runs it on the push.

Not done. This does not find or fix the main-heap leak, so memory-growth can still trip. The next finding should carry the grown process's own heap, held-count and job-allocation lines even across a restart, and that is what will name the leak. Closing the issue needs a day without the trip ("stays out of the degraded list for a day").

To try it: bun test test/sentinel-memory-evidence.test.ts. On the preview, memory-kept.json appears in the data directory only while memory-growth is open on /system.

🤖 Generated with Claude Code

Closes #16872

commented

A memory-growth finding filed after a restart now quotes the evidence that the process which grew had saved, instead of figures from the new process.

What was wrong with #16872's evidence. The sentence ("4689 MiB … main VM's JS heap grew 450 MiB to 3130 MiB since 19:30:43") comes from the record saved by the process that grew. The 19:40 deploy (c90d0844d) then restarted the forge, and the evidence lines underneath were read from the new process: trip none, main heap 644 MiB, still in its first hour. So the issue sets one process's sentence beside another process's numbers. The data that would name the leak, including the per-job allocation line added in #16828, is lost on every restart, and releases restart the forge several times a day.

What changed

  • src/perf/memory_kept.ts (new): keepIfGrown writes the watch's evidence lines to memory-kept.json in the data directory. It writes only in minutes when memory-growth is open, using writePrivate. keptEvidence reads the file back with readPrivate and checks its shape and size; a file that fails the check counts as none.
  • src/boards/memory.ts: the minute sampler calls keepIfGrown.
  • src/perf/memory_watch.ts: the watch now exposes startedAt and tripAt(), so the sentinel can tell its own process from an earlier one.
  • src/crew/sentinel.ts: a new memoryEvidence function. If this process tripped, it quotes its own watch as before. If not, and an earlier process saved evidence that day, it quotes those lines under memory kept by the process started …; the forge restarted since, then adds one memory now (process started …) line for the current process.
  • docs/features/memory-growth.md: one paragraph describing this.

Tests. I added two tests to test/sentinel-memory-evidence.test.ts:

  • After a restart, the finding quotes the saved trip figures and the "now" line. The process that grew still reads its own watch, and evidence saved before that day is ignored.
  • The file is written only while memory is grown, and malformed files are rejected.

tsc, the gate, and 18 related test files (the sentinel, memory and unused-exports tests) pass. The full suite was not run here; the forge's check runs it on the push.

Not done. This does not find or fix the main-heap leak, so memory-growth can still trip. The next finding should carry the grown process's own heap, held-count and job-allocation lines even across a restart, and that is what will name the leak. Closing the issue needs a day without the trip ("stays out of the degraded list for a day").

To try it: bun test test/sentinel-memory-evidence.test.ts. On the preview, memory-kept.json appears in the data directory only while memory-growth is open on /system.

🤖 Generated with Claude Code

commented

When a release restarts the forge, a memory-growth finding now quotes the evidence of the process that actually grew. Before this, it paired that process's stored sentence with a fresh process's "trip none". Each minute the process is grown, the memory sampler writes the watch's evidence to memory-kept.json under the data directory (src/perf/memory_kept.ts). When the sentinel runs in a later process that never tripped, it quotes those kept lines, as long as they were written the same day. It adds one line on where the new process stands, and the how-to is docs/features/memory-growth.md.

Review follow-up: a test now covers the sampler's call to keepIfGrown. startMemorySampler takes the watch it notes into as an optional third argument, which defaults to the process's own memoryWatch, so src/main.ts and production behave as before. The new test in test/sentinel-memory-evidence.test.ts runs the sampler twice:

  • On a fresh watch, it finds no kept file.
  • On an already-grown watch, it reads memory-kept.json back and finds that watch's start time and evidence lines.

In the grown case the test watch ignores the tick's own reading. The real RSS of a test process could otherwise make the watch look like it had fallen back, and the test would depend on the machine. I checked the test the way the review asked: with the keepIfGrown line deleted, it fails.

What to look at:

  • src/boards/memory.ts: the sampler signature and the two lines that now use watch.
  • The last test in test/sentinel-memory-evidence.test.ts.

Checks:

  • bun x tsc --noEmit and bun scripts/gate.ts pass. The gate also prints two notes:
    • It flags startMemorySampler as similar to its own inner tick. That's a function and its nested helper, not duplicate code.
    • It flags long comment lines that the nightly job rewraps on main.
  • scripts/fast.ts named too many files to run, so I picked the suites that drive the sampler myself: sentinel-memory-evidence, held, job-alloc, perf-jobs-per-forge, job-slices and memory*. All 75 tests pass.

No door: the sampler is internal, and no page, action, route or tool changed.

Try it: bun test test/sentinel-memory-evidence.test.ts

🤖 Generated with Claude Code

Sign in to join this conversation.

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

Keyboard shortcuts

Docs