Repository navigation
fix(cli): keep backup remote guard remedies in --json error output - #199900
SunnyShu0925 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: blocked before merge. What this changesThis PR preserves remote-backup guard messages on stderr when commands run with --json. Example: Run openclaw backup verify bogus-key --from archive --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep open: this PR fixes a current CLI diagnostic bug through the existing error owner, with no introduced correctness or security defects found. Priority: P3 Before merge
FindingsNone. Agent review detailsHow this fits togetherBackup CLI commands pass storage and archive options to the remote-backup owner, whose errors reach the shared CLI renderer for stderr diagnostics and JSON failure output. flowchart TD
A[Backup CLI command] --> B[Remote backup owner]
B --> C[Storage location]
B --> D[Expected CLI error]
D --> E[Root failure renderer]
E --> F[Stderr remedy]
E --> G[JSON stdout envelope]
Technical reviewBest possible solution: Use the existing ExpectedCliError owner at these five guards while preserving their messages, validation, and cleanup. Do we have a high-confidence way to reproduce the issue? Current-main source shows plain errors reaching the generic JSON-mode stderr renderer, and the contributor records the matching failure through a pinned base CLI build; this read-only review ran no target code. Is this the best way to solve the issue? The patch restores the existing expected-error rendering contract at the guard producer without adding formatting, state, options, or a parallel owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 7e48c6be722a. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests 0. Total +1 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 15, 2026, 9:58 PM ET / November 16, 2026, 02:58 UTC. |
|
Thanks for the work here. We're closing this one along with the other open per-command |
fix(cli): show the existing failure message for plain errors in --json mode `runCommandWithRuntime` rethrew every plain error in JSON mode, so the root renderer printed only the generic "The CLI command failed." plus the Doctor hint on stderr, while text mode printed the error's own (redacted) message. Contributors had been patching this one command at a time by converting individual throws to expected errors. JSON mode now shows the same redacted message text mode already shows, once in the shared wrapper; the JSON stdout envelope, exit codes and text-mode output are unchanged. Commands that fail outside the wrapper (for example `models auth login` conflicts and `attach` target resolution) are not covered. No new text. Evidence: host, isolated state. 76 CLI runs across eight command flows (including `backup verify`, `backup remote`, `skills list/check/info` and `migrate plan/apply`), twice per side: base prints the generic failure in --json mode, this change prints the existing message; text failure output, JSON stdout and exit codes are identical across 150 comparisons. 156 unit and 124 consumer tests pass; full build and installed packed smoke pass. CI reds are inherited from main (receipt: #199970 (comment)). Supersedes the closed per-command PRs #199891, #199900, #199910 and #199448. Co-authored-by: Ayaan Zaidi <[email protected]>
fix(cli): show the existing failure message for plain errors in --json mode `runCommandWithRuntime` rethrew every plain error in JSON mode, so the root renderer printed only the generic "The CLI command failed." plus the Doctor hint on stderr, while text mode printed the error's own (redacted) message. Contributors had been patching this one command at a time by converting individual throws to expected errors. JSON mode now shows the same redacted message text mode already shows, once in the shared wrapper; the JSON stdout envelope, exit codes and text-mode output are unchanged. Commands that fail outside the wrapper (for example `models auth login` conflicts and `attach` target resolution) are not covered. No new text. Evidence: host, isolated state. 76 CLI runs across eight command flows (including `backup verify`, `backup remote`, `skills list/check/info` and `migrate plan/apply`), twice per side: base prints the generic failure in --json mode, this change prints the existing message; text failure output, JSON stdout and exit codes are identical across 150 comparisons. 156 unit and 124 consumer tests pass; full build and installed packed smoke pass. CI reds are inherited from main (receipt: openclaw#199970 (comment)). Supersedes the closed per-command PRs openclaw#199891, openclaw#199900, openclaw#199910 and openclaw#199448. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw backup verify bogus-key --from archive --jsonexits 1 with a stderr that only says the command failed, even though the guard that rejected the key already carries the exact next step: "Expected a backup key fromopenclaw backup list --from <location>or latest." The same happens for the storage-location probe failure, the empty-location listing, and the missing-key guard in the remote backup flow, and for the upload size-confirmation guard onbackup create --to. This converts those five operator-facing guards to the canonical expected-CLI-error owner so the remedy survives the--jsonlane, with identical message text.src/commands/backup-remote.tsthrows plainErrorfor five operator-facing guards. In the--jsonlanerunCommandWithRuntimerethrows plain errors to the root renderer, which generalizes them to a two-line banner; the remedy text that the guard already wrote is lost to scripts and automation reading stderr.throw new Error(...)sites withthrowExpectedCliError(...)fromsrc/cli/expected-cli-error.ts, keeping every message byte-identical.ExpectedCliErrorcarrieshumanOutput/machineOutput, so the JSON failure envelope keeps the same message and stderr keeps the remedy.src/commands/backup-remote.ts(one import plus five guard conversions: location probe, stored-size confirmation, backup-key shape, empty listing, missing key) andsrc/cli/program/register.backup.offsite.test.ts(a class assertion folded into the existing offsite integration case, net 0 test lines).openBackupLocation, and adjacent owners (resolveBackupNamespaceinsrc/infra/backup-retention.ts,src/commands/backup-namespace.ts, the registration-layer--namespace requires --fromguard).Why This Change Was Made
Best fix: reuse the repository's canonical
ExpectedCliErrorowner instead of formatting JSON stderr per site; this is the same conversion already merged for the sibling backup guards (#199763backup create --to, #199850backup gitscope, #199760 sqlite snapshot sources, #199573 record guards, #199562 shared path guards), so the remote flow joins the family behavior instead of inventing a new policy. Alternative considered: converting the neighboringresolveBackupNamespaceguard too — rejected because it lives in a different owner file and belongs to its own change; the matrix keeps it as an untouched plain-error control. Risk: the stored-size confirmation guard cannot be triggered naturally without a storage backend that misreports object sizes, so its runtime cell is not claimed (see What was not tested); its conversion is message-identical and symmetric with the four exercised guards.User Impact
Operators and scripts driving
openclaw backup verify/restore --from <location>(andbackup create --to) with--jsonnow get the actionable remedy on stderr when a guard rejects the request — which key format to use, whichopenclaw storage test/storage initstep to run, or that the location/namespace holds no such backup — instead of a generic failure banner. Text-lane users, JSON envelopes, and exit codes see no change.Evidence
6d6b7b7)b3f948f)backup verify bogus-key --from probe-loc --jsonstderrThe CLI command failed.Expected a backup key from \openclaw backup list --from ` or latest.`backup verify latest --from archive --namespace probe-ns --json(empty location) stderrNo backups in archive/probe-ns.backup verify <missing-key> --from archive --namespace probe-ns --jsonstderrBackup <missing-key> was not found in archive/probe-ns.{ok:false,error:{type:"cli_error",message:<remedy>}}cmp)cmp)backup list --from archive --namespace probe-ns(control)cmp)--namespace "bad ns"(control)cmp)End-to-end shipped proof (dual-arm built launcher)
Both arms were built from source with
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup(per-packagenode_modulessymlinked first; build exit 0 on both). The base arm is frozen atorigin/maincommit6d6b7b7; the head arm is commitb3f948f. Each cell runs the real built launchernode openclaw.mjs <command>underenv -iwith a freshchmod 700scratchHOME/XDG_RUNTIME_DIR/OPENCLAW_STATE_DIR, no credentials and no mocks. The storage location is a real filesystem provider initialized withopenclaw storage init archiveand a synthetic passphrase; the success-path object is provisioned by a realopenclaw backup create --to archive --namespace probe-ns --only-configrun (618 plaintext bytes, 762 stored), and its bytes are preserved across arms so the listing is deterministic.--versionself-reports each arm's commit:Guard cells, base vs head
--jsonstderr (the discriminating stream). A deterministic log-append notice (log file append failed; records dropped; ... file=openclaw-2026-11-16.log) appears identically on both arms in every stderr and is part of thecmpinvariants; it is an isolated-HOMEenvironment artifact, not a behavior change.The JSON failure envelope on stdout already carried the remedy on the base arm and is unchanged by the fix (byte-identical across arms for every guard):
{ "ok": false, "error": { "type": "cli_error", "message": "Expected a backup key from `openclaw backup list --from <location>` or latest." } }The text lane already showed the remedy on both arms (byte-identical):
Success-path control — the provisioned encrypted object lists identically on both arms (exit 0,
cmpstdout identical):Cross-arm invariants (
cmp)A 26-assertion compare script ran over both arms' captured stdout/stderr/exit for every cell:
FAILED=0. It asserts, per converted guard, exit 1 both arms/lanes, empty text stdout, remedy present in text stderr both arms, remedy present in head json stderr, remedy absent + generalized banner in base json stderr, and byte-identical json stdout envelope and text stdout. Controls (c1already-Expected registration guard,g2storage-layer absent-directory error,c3adjacent-owner namespace guard,c2success listing) assert all four streams + exit byte-identical across arms, and thatg2/c3keep the real text message + generalized json banner on BOTH arms (over-conversion check).Built-bundle self-attestation
The shipped bundles prove the executed form. Base
dist/backup-remote-DvIBe8s3.mjshas 0throwExpectedCliError; headdist/backup-remote-Dp8-Qwbd.mjshas 6 (5 guards + 1 import). All five converted sites, message text unchanged:Base-arm
OPENCLAW_DEBUG=1stack confirms a plainErrorreaching the root renderer (absolute paths sanitized to neutral placeholders):Regression test (red on base, green with the fix)
A class assertion was folded into the existing offsite integration case (net 0 test lines):
await expect(backupRemoteVerifyCommand(defaultRuntime, { from: "archive", archive: "x" })).rejects.toSatisfy(isExpectedCliError). Message assertions cannot discriminate the class because the harness renders both classes with the same text, so the assertion targets the error class directly.Open PR collision check
Searched the submission-day open-PR snapshot by changed file (
src/commands/backup-remote.ts) and by anchor/anti-pattern keywords across three lanes (per-PR changed-file intersection, stem search, recent-created search); zero open PRs touch this file or convert these guards. The sibling backup-guard conversions already merged (#199763, #199850, #199760, #199573, #199562) cover other owner files, notbackup-remote.ts.What was not tested
openStorageLocationsucceeds but the subsequentprobe()returns non-ok — a TOCTOU race for the filesystem provider, not deterministically reachable in an isolated single-process run. The absent-directory cell (g2) is thrown earlier by the storage-layer owner (StorageLocationError, a plainError) and is kept as an untouched adjacent-owner control; :58's conversion is proven by the bundle snippet.HOMEartifact present identically on both arms; it is not addressed by this change.