Repository navigation
fix(backup): surface record guard remedies in --json failures - #199573
Conversation
`backup record` validated --status/--target/--bytes with plain Error, so --json runs printed only the generic CLI failure plus the doctor hint and lost the remediation text on stderr. Route the three argument guards through throwExpectedCliError so the JSON lane keeps the same message the text lane already prints.
|
🦞👀 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. What this changesThis PR makes invalid backup record arguments print their existing remedies on stderr in JSON mode. Example: Run openclaw backup record --status bogus --target label --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current CLI diagnostic bug with a focused change; no actionable defects were found, and current-head CI remains pending. Priority: P3 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe backup command validates external-job outcome arguments before recording them; the shared CLI failure renderer converts rejected arguments into stderr diagnostics and a JSON failure envelope. flowchart TD
A[Backup record CLI] --> B[Argument guards]
B --> C[Expected CLI error]
C --> D[Shared failure renderer]
D --> E[Stderr remedy]
D --> F[JSON failure envelope]
B --> G[Valid outcome recording]
Technical reviewBest possible solution: Use the existing expected-error helper at these three argument guards, as this PR does. Do we have a high-confidence way to reproduce the issue? Current-main guards and the shared renderer establish the failure path, supported by supplied before/after shipped-CLI output; no target code was executed during this review. Is this the best way to solve the issue? The patch is the smallest complete fix: classify argument failures at their producer while retaining the existing renderer, validation rules, and recording owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 636454ee16af. 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 HistoryReviewed November 15, 2026, 9:47 AM ET / 14:47 UTC (Revision 3). |
|
Independent before/after proof against base 69c3aca, using the unchanged production fix from contributor commit 43eb3ee. Host isolation check: only src/commands/backup-record.ts and its existing test file differ; no package, lockfile, workspace, lifecycle, hook or scripts changes. Product commands ran through ocx with task-owned HOME and profile p199573; no Gateway was started. CLI state resolved under the task-owned HOME/.openclaw-p199573/state/openclaw.sqlite. Worktrunk and commit hooks were skipped; normal ocx install lifecycle ran. Source tier (Node + tsx): ran each command once on base and candidate, with --json and without it: Base JSON stderr prints generic failure plus the Doctor hint. Candidate JSON stderr prints the existing messages: All six corresponding stdout captures and exit codes compare identically; invalid cases exit 1. Text-mode product stderr is identical as well (excluding ocx's own diagnostics). The patch changes error classification only, not message text. The guards at backup-record.ts:20-29 execute before constructing the outcome and before recordBackupOutcomeBestEffort at line 39. Valid control: initialized each isolated profile database with the existing state owner, then ran Vitest-source: the strengthened backup-outcome regression has nine malformed-input cases, including all original nondecimal byte forms and the status/target guards. On base these nine fail on the Error-vs-ExpectedCliError contract while six existing controls pass; candidate's full file passes all fifteen. Every malformed-input case verifies that no outcome was recorded in its initialized database. The consolidation removes repeated assertions and the incidental runtime.error spy assertion rather than adding a separate suite. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Final head: 45b8928. Production +4/-3, tests +7/-7 (net zero), no allocation file. The contributor commit remains intact; only the existing regression was consolidated. No production message changed. Simplification keeps the existing expected-error owner, with no new catches or state machinery. Final local checks: backup-outcome.test.ts 15/15 passes (108.63s total wrapper wall time on this loaded host); targeted formatting passes. Full tier on the host: Credit retained: SunnyShu [email protected], human author/committer of the production fix. The test-only maintenance commit uses Ayaan Zaidi [email protected]; no agent trailers. Worktrunk and Git hooks were skipped; the normal ocx install lifecycle ran. after-push.sh requested a fresh exact-head review. Source and persistence receipts: #199573 (comment) . |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Repaired our regression-table typing on final head 0c7e070: the outer table and mapped rows now retain their tuple types. Production is unchanged; tests remain +7/-7, net zero. The prior check-test-types-core-4 failure was caused by our test consolidation, not inherited. Verified through ocx on the host: Both pushes were normal fast-forwards after checking the current contributor ref was an ancestor. after-push.sh requested a new exact-head review. The same two-file host-isolation check passes; no production, dependency, lifecycle or message-text changes were added by the repairs. Prior source and persistence proof remains applicable because all later changes are test-only: #199573 (comment) . |
|
Final head 0c7e070 is ready: exact-head ClawSweeper review is 5/6 and ready (#199573 (comment)); CI and ci-gate are green (https://github.com/openclaw/openclaw/actions/runs/43725968078 and https://github.com/openclaw/openclaw/actions/runs/43728484007). No failed or cancelled checks remain. Proof and the resolved test-type regression are recorded above. No merge performed. |
|
Landed in 3e1c0cd. Thanks @SunnyShu0925. |
…aw#199573) fix(cli): report backup record input errors through the expected-error path `openclaw backup record --json` threw plain errors for a bad `--status`, a blank `--target` and a bad `--bytes`, so `--json` stderr showed the generic failure plus the Doctor hint instead of the existing message. The three checks now use throwExpectedCliError with the same messages. All three run before anything is recorded; no new text. Evidence: host, isolated state. Source CLI: each bad value with `--json` and in text mode, on base and on this change: base prints the generic failure and Doctor hint, this change prints the existing message; text mode, JSON stdout and exit codes are identical, and a valid `--status ok --target label --bytes 10 --json` records exactly one matching outcome on both. Vitest-source: base 9 failures, 15 pass here. Targeted typecheck, full build and packed smoke pass. Receipts: openclaw#199573 (comment). Thanks @SunnyShu0925. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
openclaw backup record --status bogus --target label --jsonexits 1 with only[openclaw] The CLI command failed.and the doctor hint on stderr, so machine callers that read stderr never see the--status must be ok or failed.remediation that the text lane already prints.backup recordargument guards (--statusenum, blank--targetlabel, non-numeric/negative--bytes) throw a plainError. The text lane renders its message, but the JSON lane classifies it as an unexpected failure and replaces it with the generic failure banner, leaving the remediation only inside the stdout envelope.ExpectedCliErrorfrom the same guards, so the JSON lane renders the same remediation the text lane prints while keeping the envelope untouched.src/commands/backup-record.tsroutes the three guards throughthrowExpectedCliError(one new import, threethrowcall sites, identical message text).src/commands/backup-outcome.test.tsfolds regression assertions into the existing malformed-argument test (name: "ExpectedCliError"plus the unchanged messages).backupsubcommand.Why This Change Was Made
ExpectedCliErroris the shipped owner for argument-level CLI failures (src/cli/expected-cli-error.ts), so the fix reuses the existing failure classifier instead of adding a new rendering path.error.messagefor plainErrortoo. Rejected: that would leak stack-y unexpected failures into the "expected" lane and change every other command at once.User Impact
Operators and CI jobs that run
backup recordwith--jsonnow get the actionable remediation (--status must be ok or failed.,Missing required --target label.,--bytes must be a nonnegative integer.) on stderr, matching the text lane, instead of a generic failure banner. Scripts that parse the stdout envelope see no change.Evidence
Both arms were built with the shipped CLI pipeline (
node --import ./scripts/tsx.mjs scripts/build-all.mts cliStartup) and exercised through the real launcher (node openclaw.mjs <cmd>) with a fresh scratchHOME/OPENCLAW_STATE_DIR/ config per cell.--versionself-reports both arm identities: baseOpenClaw 2026.11.3 (69c3aca), this headOpenClaw 2026.11.3 (43eb3ee).backup record ...)--status bogus --target label --json[openclaw] The CLI command failed.+For help, run \openclaw doctor`.`; remedy confined to stdout envelope--status must be ok or failed.; stdout envelope byte-identical (109 B)--status ok --target " " --jsonMissing required --target label.; stdout envelope byte-identical (111 B)--status ok --target label --bytes nope --json--bytes must be a nonnegative integer.; stdout envelope byte-identical (117 B)--json)cmpreports no difference)--status ok --target label --bytes 42 --jsoncmpreports no difference)Pre-fix JSON lane (base build):
Post-fix JSON lane (this head build, identical command):
Invariants across the two builds (
cmpon captured files):Serialized shipped bundle of the changed owner (this head,
dist/backup-record-*.mjs) proves the guard now throws the expected-error type:Regression test is red on the pre-fix owner and green after (test kept, production file reverted with
git stash push -- src/commands/backup-record.ts):What was not tested: no Windows run; the
--targetmissing-value path that commander rejects before the owner is not exercised (only the blank-string path). Both arms emit the same Node security-patch warning on stderr; it was filtered out of the quoted output and is unrelated to this change.Open PR collision check: searched open PRs by changed-file list for
src/commands/backup-record.ts,src/commands/backup-outcome.test.ts, andsrc/cli/program/register.backup.tson the day of writing; no open PR touched them. Same-family merges this week are per-site siblings (#199369 sandbox explain, #198975/#198965/#198861 selector guards), none coveringbackup record.