Repository navigation
fix(cli): devices --json refusals print an empty stdout - #159489
masatohoshino wants to merge 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 27, 2026, 11:54 AM ET / 15:54 UTC (Revision 3). ClawSweeper reviewWhat this changesDevice commands now route local refusals through OpenClaw’s JSON failure output when Merge readiness✅ Ready for maintainer review The linked device-command bug remains on current main. This PR has a focused repair, direct before-and-after CLI proof, and no identified blocking patch defect. Priority: P2 Review scores
Verification
How this fits togetherThe flowchart LR
A[Device command and options] --> B[Device CLI]
B --> C{Local refusal?}
C -->|Yes, JSON mode| D[Root failure handler]
D --> E[JSON error on stdout]
C -->|Yes, text mode| F[Error on stderr]
C -->|No| G[Gateway operation]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -2, Tests +100. Total +98 across 3 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Use the shared JSON failure envelope for device-command refusals while retaining text-mode behavior and sanitized approval guidance. Do we have a high-confidence way to reproduce the issue? Yes. Current main still sends these refusals directly to stderr, and the PR provides before-and-after runs of the affected CLI commands; this read-only review did not execute contributor code. Is this the best way to solve the issue? Yes. The patch uses the existing root JSON failure owner and preserves the device CLI’s text-mode refusal behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b8894086496e. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Closes #159488
What Problem This Solves
Fixes:
openclaw devicescommands run with--jsonexit 1 with an empty stdout when they refuse (for exampledevices clearwithout--yes,devices approvewith no pending or no matching request, a blank device or request id), instead of the JSON failure envelope documented in docs/cli/index.md ("JSON failures").User Impact
User impact: a script that runs
openclaw devices ... --jsonnow gets{"ok": false, "error": {"type": "cli_error", "message": "..."}}on stdout when a devices command refuses, like other JSON-mode commands. Exit codes, successful JSON output, and output without--jsonare unchanged.Why This Change Was Made
Each refusal in
src/cli/devices-cli.runtime.tscalleddefaultRuntime.error(...)anddefaultRuntime.exit(1)without looking at--json, so the error never reached the root CLI failure handler that writes the envelope. #159212 fixed the same shape inopenclaw agent --json.The refusals now go through one module-private helper,
failDevicesCommand: with--jsonit throws the same message (multi-line guidance such as the node reapproval notice joined into it) so the root handler writes the envelope; without--jsonit keeps the current stderr lines andexit(1). Refusals covered:clearwithout--yes,approvewith no pending request, a scope upgrade the device cannot approve itself, and no matching request (with node reapproval notices), plus blank ids forremove,reject,rename,rotate/revoke. The approve preview, which already writes JSON, and Gateway transport errors, which already have their own JSON output, are unchanged.With
--json, stderr now carries the root handler's standard failure lines instead of the bare message, as for other JSON-mode failures. Two existing tests asserted the old stderr-only output for JSON-mode approval errors; they move, with the new cases, intosrc/cli/devices-cli.json-failures.test.ts, which keepsdevices-cli.test.tsunder its line cap and asserts the same guidance and secret redaction on the envelope message.Evidence
Tested at
5372c248432dceebc1583d03adc504645a735328(base upstream/main804376566a8189f80e8a0d0f3a3172c7f97de876).Both sides were built from source on Linux (Node 24.18.0) by a before/after harness that runs each side in its own isolated home (
OPENCLAW_STATE_DIR/OPENCLAW_CONFIG_PATHinside it, stdin/dev/null); every command runs throughpnpm --silent openclaw. No Gateway is needed for these refusals. Nothing is mocked.Before (base):
After (this PR):
Control, identical on both sides:
openclaw devices clear(no--json) exits 1 with the refusal on stderr.Focused tests and measured cost
src/cli/devices-cli.json-failures.test.ts(4 cases: clear without--yes, approve with no pending request, no matching request with node reapproval guidance and redacted connection secrets, operator-label-only query) fails 4 of 4 on the base runtime and passes on this branch.src/cli/devices-cli.test.tspasses 63 of 63.pnpm test src/cli/devices-cli.json-failures.test.ts --maxWorkers=1: 2.0 s wall; the cases take 193 ms (first, includes module load), then 4 ms each. In CI (run https://github.com/openclaw/openclaw/actions/runs/36301082504, jobchecks-node-changed-1) its 4 tests take 0.41 s andsrc/cli/devices-cli.test.ts(63 tests) 0.23 s in total.pnpm check:changedpasses (including the line-cap ratchet:devices-cli.runtime.tsdoes not grow anddevices-cli.test.tsshrinks). The repository'sautoreviewskill (branch mode, up to P2) reported no actionable findings.CI seconds (per-test durations reported by Vitest, summed per file from the CI job log on head
5372c248432; module import and worker startup are not included):src/cli/devices-cli.json-failures.test.ts: 4 tests, 0.41 s inchecks-node-changed-1(https://github.com/openclaw/openclaw/actions/runs/36301082504/job/108569118065)src/cli/devices-cli.test.ts: 63 tests, 0.23 s inchecks-node-changed-1(same job)