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

+7
View File
@@ -238,9 +238,11 @@ pub fn wall_time_field(which : Int) -> Int {
}
///|
#borrow(name)
extern "C" fn c_has_exe(name : Bytes) -> Int = "mp_has_exe"
///|
#borrow(cmd, display)
extern "C" fn c_spawn(cmd : Bytes, display : Bytes) -> Int = "mp_spawn"
///| Whether `name` is an executable on PATH.
@@ -254,6 +256,7 @@ pub fn spawn(cmd : String, display : String) -> Bool {
}
///|
#borrow(argv)
extern "C" fn c_spawn_socket(argv : Bytes) -> Int = "mp_spawn_socket"
///| Run `argv` (an absolute program path, then its arguments) with its stdin and stdout on a
@@ -272,9 +275,11 @@ pub fn take_sigusr1() -> Bool {
}
///|
#borrow(dir)
extern "C" fn c_list_desktop(dir : Bytes) -> Bytes = "mp_list_desktop"
///|
#borrow(name)
extern "C" fn c_getenv(name : Bytes) -> Bytes = "mp_getenv"
///| Newline-separated names of the `*.desktop` files directly in `dir`.
@@ -306,6 +311,7 @@ pub fn getenv(name : String) -> String {
}
///|
#borrow(path)
extern "C" fn c_mkdir_p(path : Bytes) -> Int = "mp_mkdir_p"
///| Create `path` and any missing parents; true when it exists afterwards.
@@ -361,6 +367,7 @@ pub fn frame_memfd() -> Int {
}
///|
#borrow(cmd, display)
extern "C" fn c_spawn_watch(cmd : Bytes, display : Bytes) -> Int = "mp_spawn_watch"
///| Launch `cmd` like `spawn`, watched: returns a non-blocking socket (-1 when nothing could