Repository navigation
fix(cli): surface migrate blank agent remedy in JSON - #199448
SunnyShu0925 wants to merge 1 commit into
Conversation
Ref: BUG-421-migrate-context-agent-blank-json-remedy-hidden (local finding)
|
🦞👀 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 changesThe PR preserves the blank-agent validation message on stderr when migration commands use JSON output. Example: Run openclaw migrate plan hermes --agent " " --json.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR: it fixes a current diagnostic bug with a minimal change, supplied CLI proof, and no identified correctness defects. Priority: P3 Before merge
FindingsNone. Agent review detailsHow this fits togetherMigration plan and apply commands build a shared migration context, whose argument errors reach the root CLI renderer for JSON stdout and human-readable stderr. flowchart TD
A[Migration CLI arguments] --> B[Plan or apply command]
B --> C[Shared migration context]
C --> D[Expected CLI error]
D --> E[Root failure renderer]
E --> F[JSON stdout and actionable stderr]
Technical reviewBest possible solution: Retain this focused conversion in the shared migration context and land it after the required CI workflows pass. Do we have a high-confidence way to reproduce the issue? Current-main source shows the plain Error reaching generic failure rendering, and the contributor supplies before/after built CLI traces for both affected commands; no target code was executed during this review. Is this the best way to solve the issue? This is the smallest complete fix: preserve blank-agent rejection while using the existing error-classification owner shared by CLI diagnostics. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b9036d4f002d. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +1, Tests -1. Total 0 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 14, 2026, 11:54 PM ET / November 15, 2026, 04:54 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 migrate plan hermes --agent " " --jsonprints the correct--agent must not be blankmessage inside its JSON envelope, but its stderr collapses to the generic[openclaw] The CLI command failed.plus a doctor hint, so anyone reading stderr (or any wrapper that surfaces stderr only) loses the actionable remedy.openclaw migrate apply ... --jsonbehaves the same way. The guard now throws through the existing expected-CLI-error path, so JSON failures keep the concrete message.resolveMigrationTargetAgentId()threw a plainErrorfor an explicitly blank--agent. In JSON mode the runtime treats an unrecognized error as an unexpected failure and replaces the stderr hint with the generic failure line, even though the user-facing message already existed.throwExpectedCliError, the canonical expected-CLI-error owner already used by thesandbox explainandsessions compactblank-agent guards.src/commands/migrate/context.tsimportsthrowExpectedCliErrorand converts the single blank-value guard;src/commands/migrate/context.test.tsfolds the error-name assertion into the existing migration-target test and drops the now-redundant standalone case.Why This Change Was Made
resolveMigrationTargetAgentId()is the single owner shared bymigrate planandmigrate apply, so one conversion covers both entry points without duplicating a guard per subcommand.register.migrate.tswould duplicate ownership in two call sites; changing the global JSON failure formatter would alter behavior for unrelated commands. Both were rejected.--agentpath. Invalid ids such asresearch/../mainand unknown ids such asmissingkeep their existing plainErrorpath, which the control case below verifies. Full-repository type checking was left to CI.User Impact
A JSON consumer that reads stderr now receives
--agent must not be blankinstead of a generic failure line, matching the message that was already available on stdout. Text mode, stdout bytes and exit codes are unchanged, so existing scripts that parse either stream keep working.Evidence
Both arms are real built CLIs: the frozen
origin/mainbase and the candidate were each built withbuild-all.mts cliStartup, and every cell below is a fullnode openclaw.mjs ...invocation under a minimal environment (only PATH, HOME, XDG_RUNTIME_DIR, state dir and config), with 0700 scratch directories, an empty config, no credentials and no mocks.--versionself-reports each arm.migrate plan hermes --agent " " --jsonstderrThe CLI command failed.plus doctor hint--agent must not be blankmigrate apply hermes --yes --agent " " --jsonstderrThe CLI command failed.plus doctor hint--agent must not be blankmigrate plan hermes --agent " " --jsonstdoutcli_errorenvelope carrying the blank-agent messagemigrate plan hermes --agent " "--agent missing --jsonArm identity:
Bug case on the launched CLI:
Control case, unknown agent:
Full matrix as emitted by the comparison harness (
cmpper stream, 1 = byte-identical):Built bundle, proving which form actually shipped:
Regression test, same assertion on both arms:
What was not tested
oxlint(0 warnings, 0 errors),oxfmtand the focused suite passed, so type checking is left to CI.Open PR collision check
Searched the changed-file lists of the latest 300 open PRs plus title and body searches for
migrate,blank agentandexpected-cli-error: no open PR touchessrc/commands/migrate/context.tsorsrc/commands/migrate/context.test.ts. The same-day merged #199386 converts the equivalent guard insessions compactonly, leaving the migrate owner untouched, so this is not a duplicate.