Relationships
#4884 serve --json writes {"status":"stopping"} to stderr instead of stdout while a run is in flight
Opened by zack · 11/18/2026· Shipped 11/18/2026
Description
With --json, swamp serve writes its {"status":"stopping"} lifecycle line to stderr whenever a run is in flight at shutdown. A supervising host such as swamp's serve host, which reads lifecycle lines from stdout, never sees stopping during a drain. When serve is idle, the line goes to stdout as it should.
Steps to reproduce
- Run
swamp initand add a workflow with a shell step runningsleep 4. - Start serve:
swamp serve --no-schedule --json --exit-on-stdin-close --webhook /hook:<wf>:<secret>, with stdout and stderr going to separate files. - Send a signed webhook POST to start a run.
- About 1.5 s later, close serve's stdin or send SIGTERM. Both behave the same.
Expected
stdout has listening, the webhook_* events, {"status":"stopping"} and {"status":"stopped"}, in that order.
Actual
stdout has listening, the webhook_* events and stopped, but no stopping. {"status":"stopping"} is the only JSON line on stderr. Serve still exits 0.
Control, with no run in flight: stopping is on stdout and stderr has no JSON.
Root cause (from source)
src/cli/commands/serve.ts:8396-8398prints the line with the globalconsole.log.- While any model method runs,
withConsoleGuard(src/domain/models/console_guard.ts:151-190) has replaced the global console. In JSON mode it records each line in the run's logs and writes it withwriteStderr, which isDeno.stderr.writeSync. stopped(serve.ts:8696) reaches stdout only because it is printed after the drain, when no guard is active.
Fix: write serve's lifecycle JSON lines with unguardedConsole.log (console_guard.ts:131) or straight to Deno.stdout. The same applies to any other lifecycle line that can be printed mid-run, such as shutdown_stage_timed_out (serve.ts:8416).
The same root cause also leaves serve orphaned and never exiting when its host is killed mid-run; that is filed separately.
Environment
- swamp built from main
8b8e14c6, Linux. - Found by the swamp-uat test
tests/cli/serve/none/exit_on_stdin_close_test.ts: "swamp serve --exit-on-stdin-close --json drains an in-flight run and exits 0 when stdin closes" (swamp-uat#975).
Shipped
Click a lifecycle step above to view its details.