Skip to content

fix(cli): keep backup sqlite snapshot source remedies on JSON failures - #199760

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/backup-sqlite-source-guards-remedy
Nov 15, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/backup-sqlite-source-guards-remedy

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw backup sqlite create validates its snapshot source before touching any state, but all three guards in resolveSnapshotDatabase threw a plain Error. The shared CLI runner only preserves the message for ExpectedCliError/ExitError, so in --json mode the actionable remedy was replaced on stderr by:

[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw doctor`.

Why This Change Was Made

The guards already carry the actionable remedy (--global or --agent <id>, non-blank --agent). Routing them through the existing throwExpectedCliError helper keeps that text on both output lanes, matching the remedy-preservation fixes already shipped for other CLI guards (#199562, #199573, #199608).

Only the throw sites change: the three guards in src/commands/backup-sqlite.ts now raise ExpectedCliError with byte-identical messages. No message text, exit code, JSON envelope shape, or validation ordering changes.

User Impact

Scripts calling backup sqlite create --json now see the actual fix in stderr instead of a generic failure. Text-mode output, exit codes, and the JSON payload are unchanged.

Evidence

Both arms built with node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup and exercised through the shipped entry point node openclaw.mjs, each with its own scratch HOME/OPENCLAW_STATE_DIR.

Arm identity (self-reported):

$ node openclaw.mjs --version   # frozen main
OpenClaw 2026.11.3 (292a425)
$ node openclaw.mjs --version   # candidate 450994164c7
OpenClaw 2026.11.3 (4509941)

Before/after, --json lane, stderr (Node security warning and log-append noise elided; identical on both arms):

command before: 292a425 (frozen main) after: 4509941
backup sqlite create --repository /tmp/snap --json The CLI command failed. / For help, run \openclaw doctor`.` Choose a SQLite snapshot source: --global or --agent <id>.
backup sqlite create --global --agent main --repository /tmp/snap --json The CLI command failed. / For help, run \openclaw doctor`.` Choose exactly one SQLite snapshot source: --global or --agent <id>.
backup sqlite create --agent " " --repository /tmp/snap --json The CLI command failed. / For help, run \openclaw doctor`.` --agent must not be blank

Invariants across the three cells: cmp reports stdout JSON payloads byte-identical between arms, text-lane stderr byte-identical, and every cell exits 1.

Regression tests folded into the existing backup-sqlite.test.ts cases (net 0 test lines):

# baseline RED: candidate test file against base production code
FAIL src/commands/backup-sqlite.test.ts > SQLite backup commands > requires exactly one named OpenClaw database source
AssertionError: expected Error: Choose a SQLite snapshot source: -… to match object { name: 'ExpectedCliError' }
FAIL src/commands/backup-sqlite.test.ts > SQLite backup commands > rejects an whitespace-only SQLite snapshot agent
AssertionError: expected Error: --agent must not be blank to match object { …(2) }
Test Files  1 failed (1)
     Tests  2 failed | 9 passed (11)

# candidate GREEN
Test Files  1 passed (1)
     Tests  11 passed (11)

Maintainer validation

Validated 8d225731b3c4249bca7d94fdf21fcbee213483f0: real CLI source-selection diagnostics, identical stdout/text/exit controls, successful global snapshots, regression, typecheck and packed-install receipts. The contributor production fix is unchanged. A compact four-case test table retains all messages and classifications while reducing test lines.

Merge danger: reversible error-classification/test change. Blast radius: stderr presentation of the three local SQLite snapshot-source refusals.

@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.

@SunnyShu0925
SunnyShu0925 marked this pull request as ready for review November 15, 2026 20:56
@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: 🐚 platinum hermit Good normal PR readiness with ordinary 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. 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

Classifies three invalid SQLite snapshot source selections as expected CLI errors so JSON-mode stderr preserves their existing remedies.

Example: Run openclaw backup sqlite create --repository /tmp/snap --json without selecting a source.

  • Before: Stderr reports a generic command failure and suggests Doctor.
  • After: Stderr says Choose a SQLite snapshot source: --global or --agent &lt;id>.; JSON stdout and exit status 1 remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Minimal producer-level repair with real CLI proof, red/green regressions, preserved controls, and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The body supplies built-launcher before/after output, and obviyus's final-head validation exercises all three JSON refusals through the real CLI in isolated state, confirms unchanged stdout/text/exit controls, and verifies successful global snapshots.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Invalid SQLite snapshot source choices produce generic stderr guidance in JSON mode instead of the existing actionable diagnostic.
Reason: The narrowly scoped fix restores established diagnostics through the existing error owner and follows complementary merged backup repairs.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main diagnostic defect with a minimal change and verified CLI evidence; no actionable findings remain, while exact-head CI is unfinished.

Priority: P3
Reviewed head: 8d225731b3c4249bca7d94fdf21fcbee213483f0

Before merge

None.

Findings

None.

Agent review details

How this fits together

The backup CLI passes source options to the snapshot command, whose validation errors reach the shared CLI renderer for JSON stdout, stderr diagnostics, and exit handling.

flowchart TD
  A[Backup CLI arguments] --> B[SQLite snapshot command]
  B --> C[Source validation]
  C --> D[Expected CLI error]
  D --> E[Shared failure renderer]
  E --> F[JSON stdout and actionable stderr]
Loading

Technical review

Best possible solution:

Use the existing expected-error helper at the three source guards while retaining source-selection behavior and the consolidated regression cases.

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

Current-main guards and the shared failure renderer establish the failure path; supplied CLI before/after output independently demonstrates it, with no target code executed during this review.

Is this the best way to solve the issue?

This is the smallest complete repair: classify the existing expected input failures at their producer and reuse the shared renderer without adding policy, state, or wrappers.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • SQLite snapshot source selection keeps the original intent (2f25e9c: Verified SQLite snapshots require exactly one named OpenClaw database source; the original feature and its merged PR establish this boundary.)
  • Blank and unknown agent rejection keeps the original intent (46dcc57: Operator selectors must reject blank or unconfigured agent identifiers instead of operating on nonexistent agents.)
  • Invalid-source regression coverage keeps the original intent (05c3308: Earlier test consolidation reduced repeated fixtures while retaining ownership and recovery contracts; the revised table retains all four source cases and strengthens message and classification assertions.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Vincent Koc: Raw commit 2f25e9c adds src/commands/backup-sqlite.ts:142 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2f25e9cba384; files: src/commands/backup-sqlite.ts)
  • Peter Steinberger: Raw commit 46dcc57 adds src/commands/backup-sqlite.ts:173 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 46dcc57c5498; files: src/commands/backup-sqlite.ts)

PR surface

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

View PR surface stats
Area Files Added Removed Net
Source 1 4 3 +1
Tests 1 12 24 -12
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 27 -11

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 rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This improves invalid-input diagnostics in an advanced backup CLI workflow; the failure exit status and actionable JSON stdout already exist.
  • 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-15T21:11:35.894Z sha 4509941 :: needs maintainer review before merge. :: none

Reviewed November 15, 2026, 4:52 PM ET / 21:52 UTC (Revision 2).

@obviyus

obviyus commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

Validated final head 8d225731b3c4249bca7d94fdf21fcbee213483f0 against main baseline 292a425338ac. SunnyShu's production fix is retained. The added test cleanup preserves all four existing invalid-source scenarios and strengthens the first two cases to check both their existing messages and expected-error classification.

Real CLI observations

Tier: source, host through ocx src, pinned Bun fork. Each side used a separate isolated HOME/state/config/repository and the same profile name (p199760proof) for comparable diagnostics. No Gateway was started, and no live state directory was used.

These three commands were run once per side with --json and again in text mode, always with a task-owned --repository path:

backup sqlite create --repository <private-path>
backup sqlite create --repository <private-path> --global --agent main
backup sqlite create --repository <private-path> --agent ' '

For all three JSON failures, main stderr was:

[openclaw] The CLI command failed.
[openclaw] For help, run `openclaw --profile p199760proof doctor`.

Candidate stderr instead contained the existing specific message:

Input Candidate diagnostic
Neither source selected Choose a SQLite snapshot source: --global or --agent <id>.
Both sources selected Choose exactly one SQLite snapshot source: --global or --agent <id>.
Blank agent --agent must not be blank

All six invalid executions on each side exited 1, and none created a snapshot repository. Text-mode stdout/stderr and JSON stdout were byte-identical before and after. Only JSON stderr changed to the existing diagnostic.

Identical JSON stdout SHA-256 on both sides:

  • No source: b55f052e206a8a6727b1b4d4bb4d51221813501f14ee8b15bfd2f818cc65dd15.
  • Both sources: c01f0b86a49e9d2ef606f446e07f75675165e2538e1831a51a33b6e558e0dc70.
  • Blank agent: 29419dab17ae5ba417c67878dd53d180dceabf2128085003d1d871a1931a429c.

Successful control

backup sqlite create --global --repository <private-path> --json succeeded on both sides, exited 0, and committed one real snapshot each. Both reported:

{"ok":true,"schemaVersion":1,"database":{"role":"global","basename":"openclaw.sqlite","userVersion":40},"artifactPath":"database.sqlite","artifactBytes":1400832,"artifactHashMatches":true,"snapshotCount":1}

The artifact bytes were independently hashed and matched their respective manifests. The two private databases were initialized independently, so snapshot IDs/times and whole-database hashes were not treated as identical inputs.

Regression and scope

  • vitest-source, host: candidate 12 passed; the identical regression file on main produced 3 failed / 9 passed, exactly the three missing expected-error classifications. Candidate check sequence took 77.65 s including install/typecheck/format; baseline test command took 49.65 s.
  • Matching test typecheck passed: test/tsconfig/tsconfig.core.test.commands.json, under the ocx heavy gate.
  • Targeted Oxfmt passed for both touched files.
  • The compact table retains no-source, both-source, unknown-agent and blank-agent cases. The unknown agent remains an ordinary error; all exact messages remain asserted. No source-selection rule, SQLite access, snapshot behavior, public API or runtime message text was added.

Merge danger: reversible error-classification/test change. Blast radius: stderr presentation of the three local SQLite snapshot-source refusals.

Full package and final scope

  • full, host: ocx build --dts passed (137 seconds), including all 163 public Plugin SDK declaration subpaths. The supported core source-package builder checked the tarball; a fresh isolated npm install passed the installed CLI --version and backup sqlite create --help smoke at 8d22573.
  • Final host-ocx eligibility passed: only src/commands/backup-sqlite.ts and its test changed. No package, lockfile, workspace, install, script or hook inputs changed.
  • Whole-PR delta: production +4/-3; tests +12/-24 (net -12); no allocation file. No production code beyond the contributor fix was changed.
  • Worktrunk creation and commit/push hooks were disabled. The normal ocx dependency-install lifecycle did run scripts/prepare-git-hooks.mjs; no hook approval or dependency update was performed.

Hosted gates on the final head

  • CI run 43765555437, attempt 2: success, 0 cancelled CI jobs.
  • openclaw/ci-gate: success — “CI and applicable security review requirements passed.” Security-sensitive review also passed: “No sensitive product changes.”
  • ClawSweeper review: exact head 8d225731b3c4249bca7d94fdf21fcbee213483f0, ready, 5/5/5, no actionable findings.

@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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 15, 2026
@obviyus
obviyus merged commit 90af47b into openclaw:main Nov 15, 2026
124 of 126 checks passed
@obviyus

obviyus commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Landed in 90af47b. Thanks @SunnyShu0925.

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

fix(cli): report backup sqlite create source errors through the expected-error path

`openclaw backup sqlite create --json` threw plain errors when no snapshot source was given, when both `--global` and `--agent` were given, and when `--agent` was blank, so `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The three checks run before any state is read and now use the expected-error path with the same messages. No new text.

Evidence: host, isolated state, no Gateway. Source CLI with --json and in text mode: `backup sqlite create --repository <tmp>` with no source, with `--global --agent main`, and with `--agent ' '`. Base prints the generic failure and Doctor hint, this change prints the existing message; text output, JSON stdout and exit codes are identical, and a valid `--global` snapshot succeeds the same way on both. Vitest-source: three cases fail on base, 12 pass here; typecheck, full build and packed smoke pass. Receipts: openclaw#199760 (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