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

Relationships

#4886 serve --json never counts webhook (and likely scheduled) run outcomes in /api/v1/health metrics

Opened by zack · 11/18/2026· Shipped 11/18/2026

Description

With --json, swamp serve never counts webhook run outcomes in the /api/v1/health run metrics (swamp-club#2303). Completions, failures and cancellations stay at 0, even though serve prints the webhook_completed and webhook_failed events. In log mode the same deliveries are counted.

Steps to reproduce

  1. Run swamp init and add two workflows: wf-ok (echo hi) and wf-bad (exit 3).
  2. Start swamp serve --json --no-schedule --webhook /hooks/ok:wf-ok:sec --webhook /hooks/bad:wf-bad:sec.
  3. Send one signed POST to each route and wait for both events on stdout.
  4. Request GET /api/v1/health and read metrics. Wait more than 1 s first, since the snapshot is cached for 1 s.

Expected

{completions: 1, failures: 1, cancellations: 0}, the same as without --json.

Actual

  • With --json: {completions: 0, failures: 0, cancellations: 0}.
  • Without --json: {completions: 1, failures: 1, cancellations: 0}.

Root cause (from source)

In the webhookService.setEventHandler callback in src/cli/commands/serve.ts (around lines 6219-6264), auditWebhookEvent runs first. Then comes if (isJson) { console.log(JSON.stringify(event)) } else { switch … }. The calls runMetricsTracker.record("completed", …) (line 6253) and record("failed", 0) (line 6261) sit only in the else branch.

The handler's own comment ("Audit before the output branch so --json mode audits too") shows that side effects are meant to happen whatever the output format.

The scheduler event handler is built the same way (record calls around lines 5682 and 5696), so scheduled runs are probably not counted under --json either. I haven't reproduced that end to end.

Fix: record the metrics before or outside the isJson branch, as auditing already is, in both handlers.

Environment

  • swamp built from main 8b8e14c6, Linux.
  • Found by the swamp-uat test tests/cli/serve/none/webhook_outcomes_test.ts: "swamp serve --webhook --json counts webhook run outcomes in /api/v1/health metrics" (swamp-uat#399).
02Bog Flow
✓OPEN✓TRIAGED✓IN PROGRESS✓SHIPPED+ 1 MOREASSIGNED+ 5 MOREREVIEW+ 6 MOREPR_LINKED+ 2 MORESESSION_SUMMARIZED

Shipped

11/18/2026, 9:44:08 PM

Click a lifecycle step above to view its details.

03Sludge Pulse
zack assigned zack11/18/2026, 9:23:43 PM

Sign in to post a ripple.