Fix the memory leak that filled RAM and swap; launch monitor, memory log

wasmhost leaked the arguments of every host call. wt_stub.c handed them to
the MoonBit dispatcher expecting it to own them, but the compiler borrowed
the parameter, so nothing released them (about 600 kB/s in a test with one
busy terminal; a long session reached over 16 GB resident plus swap).
MoonBit now allocates the buffer and C copies into it.

Also:
- Unannotated pointer FFI parameters default to #owned, and none of these C
  functions released theirs, including the native KMS present (a whole frame
  each). Annotated #borrow; the wasmhost build now fails on that warning,
  which --warn-list -a had hidden.
- Watched launches forked the whole compositor, and each monitor kept a
  snapshot of its heap for the app's lifetime. It now posix_spawns a fresh
  copy of the binary that takes over before main.
- The host logs memory, window buffers and images once a minute.
- chandra-session keeps the previous log as session.log.1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hj5m35Lj6Rt9vwwLGZ
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-26 17:10:47 -08:00
1 parent 44688453d7
commit ada9850b8d
11 files changed
+211 -75

No files matched your search

+3 -1
View File
@@ -96,7 +96,9 @@ Settings > Session > Lighter animations overrides it, and `CHANDRA_FRAME_TRACE=1
`CHANDRA_DEBUG_CONFIGURE=1` (any host) logs each window's configures, acks and committed buffer
sizes, for an app that draws at the wrong size.
The installed session logs to `~/.local/state/chandra/session.log`. Start it as yourself, never
The installed session logs to `~/.local/state/chandra/session.log`. The session before is kept as
`session.log.1`, and the host writes a timestamped line once a minute with its memory use and the
window buffers and images it holds. Start it as yourself, never
as root: `chandra-session` refuses to run as root (`CHANDRA_ALLOW_ROOT=1` overrides). Installing
goes through `scripts/as-root`, which prefers run0 and falls back to sudo, doas or pkexec
(`CHANDRA_AS_ROOT` picks one). What it installs and its flags: [docs/install.md](docs/install.md). To run a graphical app as root inside Chandra, use