acezan on Discord (v0.1.2819, Linux x86_64, a systemd service): after
47 hours, 57 <defunct> magpie-bun children of magpie, growing toward the
unit's TasksMax until a restart.
One cause: the plugin host's only cmd.Wait ran in host.read after its
stdout reached EOF. A program a plugin started that kept a copy of the
host's stdout (Bun.spawn given Bun.stdout, which host.js's spawn guard
doesn't catch, #5063; a daemon left behind) held that pipe open past the
host's end, so EOF never came, Wait never ran, the host was never marked
dead, and every host stopped (Restart, a moved proxy, hostStale) stayed a
zombie until magpie quit. Reproduced on Linux (WSL magpie-desktop,
Bun 1.4.2): one more Z-state bun under the test process per Restart,
1, 2, 3, 4 over four rounds. The other cause, magpie web's restart to
update leaving the running host behind its exec (#3285), is the next
commit.
- proc.Output (new, internal/proc/output.go) gives a command's stdout and
stderr pipes of magpie's own and waits for the command the moment it
ends. Its readers then have OutputGrace (2s) to read the last lines;
the pipes are closed after that, which ends a read held up by a
grandchild. startOn uses it, and a reap goroutine fails the host when
its child ends. host.read no longer calls Wait. The tests' fake hosts
(no child) keep cmd.Wait.
- Every other start that wasn't waited for now goes through
proc.StartReaped (Start, then go cmd.Wait()). Process.Release doesn't
reap on Unix: codexrelay.Start (a relay that can end while magpie
runs), tui serveInBackground, uninstall's startAfter, update's
runAfterExit and OpenBeside (no Wait at all), and Windows' Reexec.
- TestEveryStartedCommandIsWaited (internal/proc) parses every non-test
.go file. In each function, an x.Start() on a command needs an
x.Wait(), or x handed on (a call's argument, a struct field), and
.Process.Release() is refused. It found exactly the sites above.
- docs/subsystems/provider-plugins.md says how the host is reaped.
Checked and left as they are (each waits): the StartTree callers
(provider/install, library mcp_run and mcp_check, gateway claude_warmup
and claude_subscription), pii/serve, provider grok and claude_signin,
claudetui child_unix and wslread, awake, every other bun start (bun.go,
bunupdate, store, dist use Output/CombinedOutput).
Run at 82460a2f9 (on origin/main 40a287b21):
- mote (macOS): gofmt -l clean; go vet on the touched packages,
GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: ok.
go test -count=1 -timeout 45m ./internal/plugin ./internal/proc
./internal/codexrelay ./internal/tui ./internal/uninstall
./internal/update: all ok. -race -count=3 of the new proc tests: ok.
- WSL magpie-desktop (Linux): the same six packages ok, including
TestHostReapedWhileItsChildHoldsStdout with a real Bun host; -race
-count=3 of it and the Output tests: ok.
- Windows (xiaomi-gpu), at the tree before the rebase (base 5ee5274bd):
proc and codexrelay ok. plugin and update had TestPiPackage,
TestLoadConcurrentWithSavesAndEdits and TestPackagedByDpkg red; each
fails the same at untouched origin/main 40a287b21 on that box, 3 of 3,
and is filed (#4115, #1827, #4603).
Broken by hand, each red:
- host.go back to StdoutPipe with Wait only after EOF:
TestHostReapedWhileItsChildHoldsStdout fails on Linux ("the host isn't
marked ended 15s after Restart").
- Output.Start waiting for the readers before Wait:
TestOutputWaitsPastWhatHoldsIt fails (not waited for in 10s).
- codexrelay back to Process.Release: TestEveryStartedCommandIsWaited
names relay.go:89 and :92.
Not tried: a full go test ./... (mote and WSL were each running other
sessions' package runs, load 39 and 110); a real magpie serve or web
running for hours on Linux; the host test on macOS (no /proc; the
Output test runs there). Not changed: killing what a host left behind
(its process group) when it is stopped; an orphan like the sleep above
stays in the service's cgroup until it ends on its own.
Reported by acezan on Discord.