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
- Run
swamp initand add two workflows:wf-ok(echo hi) andwf-bad(exit 3). - Start
swamp serve --json --no-schedule --webhook /hooks/ok:wf-ok:sec --webhook /hooks/bad:wf-bad:sec. - Send one signed POST to each route and wait for both events on stdout.
- Request
GET /api/v1/healthand readmetrics. 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).
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.