Skip to content

fix(cli): surface backup path guard remedies in --json failures - #199562

Merged
obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/backup-shared-path-remedies-427
Nov 15, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
SunnyShu0925:fix/backup-shared-path-remedies-427

Conversation

@SunnyShu0925

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw backup verify "" --json exits 1, but stderr only prints the generic [openclaw] The CLI command failed. and a doctor hint — the actionable remedy Missing required <archive> value. reaches the text channel and the JSON stdout envelope, but never the --json stderr. This routes the two shared backup path guards through the existing expected-CLI-error owner so the remedy surfaces on every channel.

  • Problem: resolveRequiredBackupPath and resolveBackupArchivePath in src/commands/backup-shared.ts throw a plain Error for blank path values. The CLI failure renderer treats plain errors as unexpected, so --json stderr degrades to the generic two lines while the text channel prints the message. Five command families (backup verify/restore, backup create, backup git, backup sqlite, backup schedule) share these guards.
  • Solution: call throwExpectedCliError(...) from src/cli/expected-cli-error.ts instead of throw new Error(...) at both guards — the same owner conversion already merged for sibling CLI guards.
  • What changed: src/commands/backup-shared.ts (one import + two throw sites); the existing blank-value unit case now asserts ExpectedCliError (net 0 test lines).
  • What did NOT change: guard messages, exit codes, the JSON stdout envelope, text-channel stderr, path-resolution semantics, and every non-guard failure path (all byte-identical across arms below). No other backup guard is touched.

Why This Change Was Made

Best fix: yes — a two-line conversion at the shared owner covers every caller at once, using the canonical ExpectedCliError contract (message + humanOutput + machineOutput) that the failure renderer already understands. This is the same shape as the merged sibling conversions #199369, #199386, #198965, #198975, and #198861.

Alternative: catching and reformatting the error in each of the five command actions — rejected because it duplicates the owner's policy at 10+ call sites and drifts; special-casing the message string in the JSON failure renderer — rejected because string matching is fragile and the owner already exists.

Risk: the failure is now classified as expected rather than unexpected, which is the intent (no doctor hint for a user input mistake). The envelope message, text output, and exit code are proven byte-identical, so scripts parsing stdout see no change. Blank --output on backup create still resolves to the default destination before reaching the guard (caller behavior unchanged); the conversion keeps the owner consistent for all labels.

Related: #195644 (open, literal-path preservation) rewrites the resolution return of resolveRequiredBackupPath and explicitly keeps the blank-value error unchanged; this PR converts that error's class without touching resolution semantics. The two are complementary: git merge-tree shows a single content conflict in that function body (the test file auto-merges), resolved by keeping his literal-path return and this throwExpectedCliError call — whichever lands first, the other needs only that mechanical rebase.

User Impact

Operators scripting backups with --json now see the actual remedy on stderr — Missing required <archive> value., Missing required <snapshot> value., Missing required --repository value. — instead of a generic failure that points at openclaw doctor. Text-channel users see no difference.

Evidence

Case (node openclaw.mjs …, isolated scratch profile) Before (base 6695768) After (this head 420bfec)
backup verify "" --json stderr generic [openclaw] The CLI command failed. + doctor hint (208 B) Missing required <archive> value. (163 B)
backup sqlite verify " " --json stderr same generic two lines Missing required <snapshot> value.
backup sqlite create --repository "" --json stderr same generic two lines Missing required --repository value.
backup git create --repository "" --json stderr same generic two lines Missing required --repository value.
backup verify "" text stderr Missing required <archive> value. byte-identical (cmp)
backup verify "" --json stdout envelope {"ok":false,"error":{"type":"cli_error","message":"Missing required <archive> value."}} (112 B) byte-identical (cmp)
backup verify /nonexistent-427.tar.gz (control, both channels) Archive does not exist… remedy, exit 1 byte-identical stdout/stderr/exit (cmp)

Two-arm built shipped matrix

Both arms built with node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup (exit 0 each, per-package node_modules links). --version self-reports the arm identity:

$ node openclaw.mjs --version        # base arm, frozen origin/main 669576890a1
OpenClaw 2026.11.3 (6695768)
$ node openclaw.mjs --version        # head arm, this branch 420bfec996d
OpenClaw 2026.11.3 (420bfec)

Every cell is a full product command run with node openclaw.mjs under an isolated chmod-700 scratch HOME/state/XDG_RUNTIME_DIR with the user bus cut, no credentials, no mocks: 5 commands × {text, --json} × {base, head} = 20 cells, all exit 1.

Primary cell, verbatim stderr:

$ node openclaw.mjs backup verify "" --json     # base arm stderr
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.
$ node openclaw.mjs backup verify "" --json     # head arm stderr
Missing required <archive> value.

A trailing log file append failed warning from the scratch profile appears byte-identically in both arms' stderr and is omitted above; it is unrelated to the guard. The remedy message itself attests the guard was reached: the pre-action state-store guard would print a different refusal, and ExpectedCliError intentionally carries no debug stack.

cmp invariants across arms (all pass):

  • Guard cells: text stderr, JSON stdout envelope, and exit codes byte-identical (16/16 comparisons).
  • Guard cells: JSON stderr differs in exactly the four guard cells (generic → remedy).
  • Control cell: stdout, stderr, and exit byte-identical on both channels (6/6).

Built bundle attestation (the executed form, not just source):

// base dist/backup-shared-CFEo89gi.mjs
...if(!n)throw new Error(`Missing required ${t} value.`)...
...if(!e?.trim())throw new Error(`Missing required ${t} value.`)...
// head dist/backup-shared-CSyJTK1C.mjs
import{n as throwExpectedCliError}from"./expected-cli-error-oDVmXYil.mjs"
...if(!n)throwExpectedCliError(`Missing required ${t} value.`)...
...if(!e?.trim())throwExpectedCliError(`Missing required ${t} value.`)...

Focused tests and mutation RED

  • Consumer suites (commands + infra lanes): backup-shared, backup-sqlite, backup-git, backup-verify, backup-restore, backup-schedule, backup-create — 184 passed, 1 pre-existing skip.
  • The existing blank-value case now asserts ExpectedCliError (net 0 test lines; the remedy text stays pinned by the backup-sqlite consumer suite and the byte-identical envelope).
  • Mutation RED: with only backup-shared.ts reverted to base, all 6 blank-value cases fail with expected error to be instance of ExpectedCliError while the 6 path-resolution cases stay green; restored and re-verified clean.
  • oxfmt --check clean on both files; oxlint 0 findings (232 rules); targeted tsc program over the two touched files: 0 errors in them (3 pre-existing environment errors elsewhere: JSON.rawJSON lib target, missing qrcode types).

What was not tested

  • Full backup create/restore happy paths end to end (the guards fire before any archive/git/database I/O; the consumer suites cover the resolution semantics).
  • macOS/Windows; the full-repo typecheck lane (targeted program above; CI typecheck lanes run on the PR).

Open PR collision check

Searched today's open PRs by anchor keywords (backup remedy / Missing required backup / ExpectedCliError backup / resolveRequiredBackupPath / resolveBackupArchivePath) and by changed-file intersection across my 39 open PRs and the latest 60 community open PRs. The submission-time recheck surfaced #195644 (opened Nov 9, outside the latest-60 slice): it touches the same two files but fixes literal-path whitespace, not error classification — complementary, not a duplicate (see Related above). The recently merged #199367 (backup multi-core compression) touches backup-restore.test.ts / backup-create-stream.ts only — zero file overlap.

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS labels Nov 15, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes blank backup-path errors show their existing remedy on stderr when using --json.

Example: Run openclaw backup verify "" --json.

  • Before: Stderr reports a generic command failure and recommends openclaw doctor.
  • After: Stderr reports Missing required <archive> value.; JSON stdout and exit code remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused shared-owner repair with concrete built-CLI proof, reported regression coverage and no actionable findings; incomplete CI remains a landing gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied base/head terminal traces exercise both changed validators through the built openclaw.mjs launcher in isolated Linux profiles, showing remedy stderr and unchanged JSON stdout, text output, exit codes and non-guard behavior.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Backup operators using --json receive an unrelated Doctor hint instead of the missing-path remedy on stderr.
Reason: The patch restores useful input diagnostics through the established error contract without adding policy, configuration or persisted state.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes a current backup diagnostic defect with a minimal shared-owner change and no actionable findings; required CI has not completed.

Priority: P3
Reviewed head: 420bfec996d753ce7fe112d315fab7eb55aa5609

Before merge

None.

Findings

None.

Agent review details

How this fits together

Backup command actions send path arguments through shared validators, whose errors reach the CLI failure renderer for stderr diagnostics and JSON output.

flowchart LR
  A[Backup arguments] --> B[Backup command action]
  B --> C[Shared path validators]
  C --> D[Expected CLI error]
  D --> E[CLI failure renderer]
  E --> F[Stderr remedy]
  E --> G[JSON failure envelope]
Loading

Technical review

Best possible solution:

Use the existing expected-error helper at both shared validators while preserving their messages and path-resolution semantics.

Do we have a high-confidence way to reproduce the issue?

Current-main validators, JSON-mode propagation and root rendering establish the failure path, matching the contributor's before/after built-CLI traces; this read-only review ran no target code.

Is this the best way to solve the issue?

This is the smallest complete repair: classify invalid arguments at their existing shared owner rather than adding catches or message matching in callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8f9bd10825ff.

Provenance checked

  • Required backup-path rejection changes intended behavior with a stated reason (68b4aab: Consolidate required-path validation across backup commands while preserving messages, trimming and resolution.)
  • Archive backup-path rejection changes intended behavior with a stated reason (e32d529: Preserve literal nonblank archive paths while retaining blank rejection; this PR explains the intentional diagnostic-classification change.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction changes only both blank-path throws to the existing expected-error helper and updates the existing rejection assertion. (src/commands/backup-shared.ts:117, 420bfec996d7)
  • Current main retains the defect: Both shared guards still throw plain Error on current main. (src/commands/backup-shared.ts:116, 8f9bd10825ff)
  • Existing rendering contract: The helper preserves the message as human and machine output; the root renderer emits expected errors directly, while unexpected backup errors receive a generic failure and Doctor hint. (src/cli/expected-cli-error.ts:27, 420bfec996d7)
  • Supplied shipped-entry-point proof: The full PR body records isolated Linux base/head built-launcher executions for archive, snapshot and repository blank inputs, including actual stderr, unchanged stdout and exit codes, and a non-guard control; it also reports consumer-suite coverage and mutation-red classification assertions. (420bfec996d7)
  • Distinct overlapping work: fix(backup): preserve literal repository and restore paths #195644 remains open and repairs literal repository-path preservation; its stated contract retains blank rejection, so it does not replace this error-classification fix.
  • History and local history limit: Scoped history and blame identify the shared required-path consolidation and later literal archive-path repair; following older test history encountered one unavailable blob, without obscuring either guard's provenance. (src/commands/backup-shared.ts:111, 8f9bd10825ff)

Likely related people:

  • Vincent Koc: Raw commit 68b4aab adds src/commands/backup-shared.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 68b4aab8b389; files: src/commands/backup-shared.ts)
  • Alix-007: Raw commit e32d529 adds src/commands/backup-shared.ts:117 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e32d529a3b5d; files: src/commands/backup-shared.ts)

PR surface

Source +1, Tests 0. Total +1 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 3 2 +1
Tests 1 2 2 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 5 4 +1

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This improves diagnostics for explicitly blank backup arguments; commands already reject them with the correct JSON error and exit status.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-15T10:26:48.146Z sha 420bfec :: blocked before merge. :: none

Reviewed November 15, 2026, 6:09 AM ET / 11:09 UTC (Revision 2).

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Nov 15, 2026
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Verified on head 420bfec against merge-base 6695768.

Host isolation check: diff contains only src/commands/backup-shared.ts and its existing test file; no dependency, lifecycle, hook, or scripts changes. All product execution ran through ocx on the host, with task-owned HOME/state/config and profiles p199562base/p199562cand; no Gateway was started. Worktrunk hooks were disabled; ocx's normal install lifecycle ran.

Source tier (Node + tsx): the real CLI passes the empty positional argument through register.backup.ts to backupVerifyCommand and resolveBackupArchivePath. Commands:

openclaw backup verify "" --json
openclaw backup verify ""
openclaw backup git log --repository "" --json
openclaw backup verify <nonexistent-path> --json
openclaw backup verify <valid-synthetic-archive> --json

The first and third commands printed generic failure plus a Doctor hint on base stderr. Candidate stderr prints respectively:

Missing required <archive> value.
Missing required --repository value.

The JSON stdout bytes and exit codes were identical in every before/after pair (cmp). Empty-path commands exit 1; the valid archive exits 0 with ok:true, assetCount:1 and entryCount:7. Text mode retains the existing missing-archive message. The nonexistent-archive control retains its original error. Successful verification has timing-dependent progress lines; its stdout is identical. No message text changes in the patch.

Vitest-source: copied the candidate's existing backup-shared.test.ts to the base checkout: 6 blank-input cases fail because the thrown Error is not ExpectedCliError, while 6 path-resolution controls pass. Candidate: all 12 pass. No new tests or allocation file; production +3/-2, tests +2/-2 (net 0).

Simplification: the existing expected-error helper at both shared owners is the smallest complete change; no extra catch layer or machinery. Contributor commit retained unchanged: SunnyShu [email protected] (human author and committer); no agent trailers. Related #195644 changes another behavior in the same function and is only a textual overlap.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Full tier completed on 420bfec: ocx build --dts passed on the host (163 public SDK subpaths verified), followed by the supported self-contained package builder and its tarball-integrity check through ocx. Extracted packed CLI reports OpenClaw 2026.11.3 (420bfec); backup verify "" --json exits 1, preserves the source JSON envelope byte-for-byte, and prints Missing required <archive> value. on stderr. External dependencies were linked from the ocx-installed checkout; bundled workspace dependencies came from the tarball. No code changes or push were needed. after-push.sh requested the fresh exact-head review, now 5/6 and ready. CI gate is green: https://github.com/openclaw/openclaw/actions/runs/43709428954 . Source and regression receipts: #199562 (comment) .

@obviyus
obviyus merged commit e734174 into openclaw:main Nov 15, 2026
141 of 142 checks passed
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Landed in e734174. Thanks @SunnyShu0925.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
…claw#199562)

fix(cli): show the missing backup path error with --json

A blank backup path, for example `openclaw backup verify "" --json`, threw a plain error from the shared backup path resolver, so the JSON failure printed only "The CLI command failed." and the doctor hint instead of the existing "Missing required <archive> value.". The resolver now throws the same messages through the existing expected-CLI-error path, as the other blank-argument checks do. Text mode, JSON stdout and exit codes are unchanged. No new text.

Evidence: source tier with isolated state and no Gateway; a blank argument reaches the check unchanged. `backup verify ""` and a second backup caller with --json: base's stderr had only the generic failure and the doctor hint; this change prints the existing message. Text mode, the JSON stdout envelope and exit codes match on both, and a real archive path verifies the same. Vitest-source: the regression fails on base and 12 tests pass here; full build and packed smoke pass. Net 0 test lines. Receipts: openclaw#199562 (comment).

Thanks @SunnyShu0925.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants