Skip to content

Gateway-backed --json commands emit no JSON on connection failure #79108

@MAdArab872

Description

@MAdArab872

Summary

Several gateway-backed commands advertise --json, but when the gateway connection fails they emit no JSON on stdout and only write a human-readable error to stderr. This makes automation brittle because callers cannot parse the failure shape.

gateway probe --json already behaves better in the same situation: it exits non-zero but still returns a structured JSON failure object.

Environment

  • OpenClaw: 2026.5.7 (eeef486)
  • Node: v24.15.0
  • OS: Windows
  • Install: isolated npm install of openclaw@latest
  • Profile: imladri-sidequest-2026-5-7
  • Gateway: not running for this profile

Reproduction

openclaw --profile imladri-sidequest-2026-5-7 health --json --timeout 1000
openclaw --profile imladri-sidequest-2026-5-7 gateway health --json --timeout 1000
openclaw --profile imladri-sidequest-2026-5-7 devices list --json --timeout 1000
openclaw --profile imladri-sidequest-2026-5-7 gateway probe --json --timeout 1000

Actual

These commands exit 1, stdout is empty, and stderr contains human text such as:

[openclaw] Failed to start CLI: GatewayTransportError: gateway closed (1006 abnormal closure (no close frame)): no close reason

Affected in this repro:

  • health --json
  • gateway health --json
  • devices list --json

Control case:

  • gateway probe --json exits 1 but returns valid JSON on stdout:
{
  "ok": false,
  "degraded": false,
  "capability": "unknown",
  "timeoutMs": 1000
}

Expected

When --json is requested, gateway-backed commands should return a structured JSON error object on stdout even on connection failure, similar to gateway probe --json.

At minimum, the CLI should document which --json commands are best-effort success-only and which provide machine-readable errors.

Why this matters

These commands are natural health-check and automation surfaces. A non-JSON failure path forces scripts to special-case stderr text parsing even though the command advertises JSON output.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions