Skip to content

fix(cli): show backup namespace remedy in JSON errors - #199781

Merged
obviyus merged 2 commits into
mainfrom
fix/backup-namespace-requires-from
Nov 15, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/backup-namespace-requires-from

Conversation

@obviyus

@obviyus obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

openclaw backup verify <archive> --namespace n --json and backup restore without --from hide the existing remedy on stderr behind a generic failure and Doctor hint.

User Impact

Both commands now print --namespace requires --from <location>. on stderr in JSON mode, just as they already do in text mode. JSON stdout, exit codes and remote backup routing are unchanged.

Why This Change Was Made

Route the existing guard through throwExpectedCliError; the predicate, message and command dispatch stay unchanged.

Evidence

  • Source CLI, isolated home/profile, no Gateway: reproduced on main 091312a21c1a and verified the fix for both commands, each in JSON and text mode. Restore used its required --target option.
  • JSON stdout is byte-identical before/after, including the existing message; all failure exits remain 1. Text output is identical. With --from and --namespace, both versions reach the same remote-key validation instead of this guard.
  • Registration regression fails against unchanged main production code and passes with the fix. The original git log --limit 1oops rejection-before-dispatch case is retained beside it in the same table; no test case was deleted. Shorter synthetic SQLite path fixtures preserve every dispatch assertion while keeping tests net -1. Production +2/-1.
  • Focused tests, command-test typecheck leaf, targeted lint/format, full build and packed CLI smoke are recorded in the proof comment.

This is a two-way door: reverting restores the prior error classification. No state, config, policy or output wording changes. Blast radius is the shared verify/restore missing---from guard.

@obviyus

obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Before/after proof

Baseline: main 091312a21c1a. The guard and its message are unchanged; only the error classification changes. Restore was exercised with its required --target option.

All runtime commands ran on the host through ocx, with a temporary HOME/OPENCLAW_HOME and explicit --profile backupnamespace. config file resolved inside that temporary profile on both sides. No Gateway, real tokens or operator state were used. The host-ocx policy check touches only the registration source and its test: no package/lock/workspace/install files, scripts, patches or hooks. Worktrunk and commit hooks were disabled.

source tier, main once and candidate once, for each command:

backup verify ./x.tar.gz --namespace n --json
backup restore ./x.tar.gz --target <isolated>/restore --namespace n --json

main stderr:
[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw --profile backupnamespace doctor`.

candidate stderr:
--namespace requires --from <location>.

For both commands, stdout is byte-identical on both sides:

{
  "ok": false,
  "error": {
    "type": "cli_error",
    "message": "--namespace requires --from <location>."
  }
}

Controls on both sides:

  • Remove --json: empty stdout, the same existing remedy on stderr, exit 1.
  • Add --from missing-proof-location together with --namespace n: both operations reach the existing remote-key validation (Expected a backup key from ... or latest.), not the namespace guard. JSON/text output and exit 1 are identical before/after. This proves routing, not remote upload/download success.
  • Every JSON envelope, exit code and text-mode output was compared directly. Only the requested JSON stderr differs.

vitest-source tier: the registration regression failed against unchanged main production code (promise resolved ... instead of rejecting) and passed with the fix. The original partial Git-log limit rejection-before-dispatch case is retained in the same table; no test case is deleted. Shorter synthetic SQLite path fixtures retain all dispatch assertions. Tests net -1; production +2/-1. The simplification pass kept the existing expected-error owner and added no new logic or message text.

Candidate head: 148f80b8bbbd7a85c78a0d1c6f7e5ce7aaf346c2. Source before/after and baseline-red evidence are reused from 81768c06cd98: the production blob is byte-identical (4b2317527674bef18955f0ff2d1ad7747f4265d8), and the later commit only restores/parameterizes test coverage. Targeted tests, typecheck, lint/format, full build and packed smokes were rerun for this head.

Local checks on the host through ocx:

  • ocx test src/cli/program/register.agent.test.ts src/cli/program/helpers.test.ts --maxWorkers=1: both shards pass (27 registration tests plus the helper suite), 30.14 s total. The existing compiled-subprocess preparation dominates the registration file's 27.04 s wall time; the guard cases themselves take milliseconds.
  • node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.commands.json --incremental: pass.
  • Targeted Oxfmt/Bun parity and Oxlint on the two changed files: pass, zero lint warnings/errors.
  • full tier: ocx build --dts passes on this head (75 s wall). The package-tarball integrity check passes; the extracted packed CLI reports 148f80b and both verify/restore JSON failure smokes pass with the existing remedy and exit 1. Dependency links were supplied from the prepared install; no registry install or Gateway was used.

Inspectable local receipts: base-source.json, candidate-source.json, source-comparison.txt, base-tests.log, candidate-tests.log, typecheck.log, lint.log, format.log, full-build.log, packed-smoke.log. The terminal captures above contain the complete relevant output, with only temporary paths redacted.

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: XS labels Nov 15, 2026
@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

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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@clawsweeper clawsweeper Bot added 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: 👀 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. clawsweeper:intake:needs-environment 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 backup verify and restore print the existing missing --from remedy on stderr in JSON mode.

Example: Run openclaw backup verify ./x.tar.gz --namespace n --json.

  • Before: Stderr reports a generic command failure and recommends Doctor.
  • After: Stderr prints --namespace requires --from <location>.; JSON stdout and exit code 1 remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal repair with direct CLI proof, a reported red-to-green regression, retained existing coverage, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied source CLI and packed CLI output exercises the changed guard for verify and restore in isolated state, showing the remedy on stderr with unchanged JSON stdout, text behavior, routing controls, and exit 1; reused source proof matches the current production blob.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: JSON-mode backup verification and restore send users to Doctor instead of showing the existing actionable option remedy on stderr.
Reason: This maintainer-authored repair restores useful diagnostics through the existing owner while preserving successful behavior and machine-readable output.

Merge readiness

✅ Ready for maintainer review

This PR is a correct, focused diagnostic fix that current main still needs; no actionable findings remain, and exact-head CI is still running.

Priority: P3
Reviewed head: 148f80b8bbbd7a85c78a0d1c6f7e5ce7aaf346c2

Before merge

None.

Findings

None.

Agent review details

How this fits together

Backup command registration validates local versus remote options before dispatch; the shared CLI failure renderer turns expected errors into human stderr and structured JSON stdout.

flowchart TD
  A[Backup CLI arguments] --> B[Verify and restore registration]
  B --> C[Namespace without location guard]
  B --> D[Local or remote backup command]
  C --> E[Expected CLI error]
  E --> F[Root failure renderer]
  F --> G[Remedy stderr and JSON stdout]
Loading

Technical review

Best possible solution:

Use the existing expected-error helper at the shared namespace guard, as this PR does.

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

Current-main source confirms the generic-error path, and the author's isolated CLI captures demonstrate the failure for both affected commands; this review ran no target code.

Is this the best way to solve the issue?

The patch fixes error classification at its producer and reuses the canonical renderer without adding formatting logic, state, or another reporting path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5b080d29ff84.

Provenance checked

  • Backup namespace option validation keeps the original intent (37ffe3c: Storage locations added remote backup routing and namespace validation; subsequent consolidation preserved those semantics.)
  • Registration regression coverage keeps the original intent (test(core,plugins): remove low-value tests (batch d436) #180365: Earlier test consolidation retained owner-boundary assertions while removing redundant setup; this PR extends the existing rejection table and preserves prior cases.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 37ffe3c adds src/cli/program/register.backup.ts:131 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 37ffe3ce94e2; files: src/cli/program/register.backup.ts)
  • shichangs: Raw commit 0ecfd37 adds src/cli/program/register.backup.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0ecfd37b4465; files: src/cli/program/register.backup.ts)

PR surface

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

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 1 16 17 -1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 18 18 0

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:

No label changes.

Label justifications:

  • P3: This improves an advanced backup CLI diagnostic; the command already rejects invalid input and preserves the remedy in JSON stdout.
  • 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-15T22:22:58.481Z sha 81768c0 :: needs maintainer review before merge. :: none

Reviewed November 15, 2026, 5:31 PM ET / 22:31 UTC (Revision 2).

@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

@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. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus
obviyus merged commit f17c941 into main Nov 15, 2026
122 of 123 checks passed
@obviyus
obviyus deleted the fix/backup-namespace-requires-from branch November 15, 2026 22:38
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in f17c941.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
fix(cli): show backup namespace remedy in JSON errors

`openclaw backup verify` and `restore` with `--namespace` and no `--from` threw "--namespace requires --from <location>." as a plain error, so with `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The check runs before dispatch and now uses the expected-error path with the same message. No new text.

Evidence: host, isolated state, no Gateway. Source CLI with --json and in text mode: `backup verify ./x.tar.gz --namespace n` and the same for `restore`. Base prints the generic failure and Doctor hint, this change prints the existing message; text output, JSON stdout and exit codes are identical, and with both --from and --namespace both sides take the remote path the same way. Vitest-source: the pre-dispatch case fails on base and passes here; the git log partial-limit rejection and every dispatch case stay covered. Full build and packed smoke pass. Receipts: openclaw#199781 (comment).

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

cli CLI command changes 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.

1 participant