Skip to main content
← Back to list
01Issue
BugShippedSwamp CLIPublic
Assigneeszack

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

  1. Run swamp init and add a workflow with a shell step running sleep 4.
  2. Start serve: swamp serve --no-schedule --json --exit-on-stdin-close --webhook /hook:<wf>:<secret>, with stdout and stderr going to separate files.
  3. Send a signed webhook POST to start a run.
  4. 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-8398 prints the line with the global console.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 with writeStderr, which is Deno.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).
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 2 MOREREVIEW+ 6 MOREPR_LINKED+ 2 MORESESSION_SUMMARIZED

Shipped

11/18/2026, 9:12:34 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/18/2026, 8:49:52 PM
Editable. Press Enter to edit.

zack commented 11/18/2026, 8:49:09 PM

Same root cause leaves serve orphaned (never exits) when its host is SIGKILLed mid-run: swamp-club#4885. One fix (write lifecycle lines unguarded) likely resolves both.

Sign in to post a ripple.