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

Bun process hygiene on a long-lived forge: no piped stdio we never read, RSS beside heap on /system #2044

Parked opened this in answer to
Closed without merging

This pull covers most of the issue, but not the 2 h soak, so the "RSS flat within 10%" target is unproven. tsc is clean and test/vitals.test.ts plus my new test/memory-hygiene.test.ts pass; I did not run the whole suite. What changed Spawn audit: I read all the Bun.spawn and spawnSync sites in src.

Notes

stopped parked by the crew deploy abbd5b4

opened this

This pull covers most of the issue, but not the 2 h soak, so the "RSS flat within 10%" target is unproven. tsc is clean and test/vitals.test.ts plus my new test/memory-hygiene.test.ts pass; I did not run the whole suite.

What changed

  • Spawn audit: I read all the Bun.spawn and spawnSync sites in src. Every piped stream was already drained or read to the end, except one. src/git/smart-http.ts piped git's stderr and never read it. That held native memory for the life of each transfer, and a full pipe could stall git. It is now ignore; stdout and stdin are unchanged, and the Bun.Subprocess type on feedStdin was updated to match.
  • Abort: a new src/http/abort.ts has settleOnAbort, which races the main handler against the request's abort signal. A client that hangs up gets a 499 immediately, so Bun can release the request context. It is wired into the main handle path in src/http/server.ts.
  • Memory on /system: a new src/kernel/memory_ledger.ts records RSS and heapStats() (heap size, capacity, object count) once an hour. It keeps a week of readings in memory and is exposed as App.signals.memory. main.ts samples at boot and then on a 60 s tick. A new admin-only GET /system (src/web/pages/system.ts) shows the current reading and the hourly table. Non-admins get a 404.
  • Tests: test/memory-hygiene.test.ts covers the ledger and settleOnAbort, and test/vitals.test.ts has a new /system access test.

Left out

  • The 2 h soak on the vxrail. The sandbox can't reach it, so the pull carries no soak numbers. Once this is deployed, /system will show the RSS-versus-heap hourly table to attach.
  • The readings are in memory, so a restart empties the table.
  • The abort race covers the forge's main handler only. The hosted-child branch and the app proxy are unchanged.
  • I didn't switch the remaining spawns to ignore, because they all read what they pipe. That includes crew/plan.ts, which already ignores stderr.

To try it: bun test test/memory-hygiene.test.ts test/vitals.test.ts. Then sign in as an admin and open /system.

🤖 Generated with Claude Code

Closes #2041

commented

This pull trims three leaks, but the 2 h soak on the vxrail hasn't run, so "RSS flat within 10%" is not yet shown. The sandbox can't reach the vxrail. Once this is deployed, /system will show the RSS-versus-heap table to attach as the soak numbers.

The last check failed only because the new test file wasn't listed in scripts/gate.ts. I added test/memory-hygiene.test.ts to GATE and pushed. bun scripts/gate.ts now passes and the new test passes (5 tests). I did not re-run tsc after the gate edit, and the forge's check has not run on the new push yet.

What changed

  • Spawn audit: I read every Bun.spawn and spawnSync site in src. All but one already drain or fully read what they pipe. The exception was src/git/smart-http.ts, which piped git's stderr and never read it. That held native memory for the life of each transfer, and a full pipe could stall git. It is now ignore.
  • Abort: the new src/http/abort.ts has settleOnAbort, which races the main handler against the request's abort signal. A client that hangs up gets a 499 straight away, so Bun can release the request context. It is wired into the main handler path in src/http/server.ts.
  • Memory on /system:
    • src/kernel/memory_ledger.ts records RSS and heapStats() once an hour and keeps a week of readings in memory, exposed as App.signals.memory.
    • main.ts samples at boot and on a 60 s tick.
    • The new admin-only GET /system shows the current reading and the hourly table. Non-admins get a 404.
  • Tests: test/memory-hygiene.test.ts covers the ledger and settleOnAbort. test/vitals.test.ts gains a /system access test.

Left out

  • The readings are in memory, so a restart empties the table.
  • The abort race covers the forge's main handler only. The hosted-child branch and the app proxy are unchanged.
  • The other spawns still pipe their output, because each one reads it.

To try it: run bun test test/memory-hygiene.test.ts test/vitals.test.ts. Then sign in as an admin and open /system.

🤖 Generated with Claude Code

commented

Parked by the crew: the check failed ("the repository > carries no hollow work beyond what is allowed, and allows nothing that is reached") and the decider saw no point in another try

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs