CLI: route JSON preaction logs to stderr#52060
CLI: route JSON preaction logs to stderr#5206008820048 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR fixes a bug where plugin/bootstrap initialization logs could leak to stdout before the JSON payload when running CLI commands with
Confidence Score: 5/5
Last reviewed commit: "CLI: route JSON prea..." |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f902d49892
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (jsonOutputMode) { | ||
| routeLogsToStderr(); |
There was a problem hiding this comment.
Do not redirect
--json command payloads to stderr
Setting routeLogsToStderr() here flips global console routing before command execution, and in normal CLI execution (src/cli/run-main.ts) enableConsoleCapture() has already patched console.*. Since defaultRuntime.log uses console.log and many JSON-mode handlers emit their payload via runtime.log(JSON.stringify(...)) (for example in status/update/backup commands), the actual JSON result is moved to stderr rather than stdout, breaking pipelines like openclaw ... --json | jq that expect machine-readable stdout.
Useful? React with 👍 / 👎.
Summary
--jsoncould still print plugin/bootstrap logs to stdout before the JSON payload.openclaw agents list --json | jq ....preActionhook now routes logs to stderr for real JSON-output commands before config guard or plugin loading runs, and the regression test covers both enabled and excluded--jsonpaths.--jsonaliases such asconfig set --jsonremain untouched.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
--jsonCLI flags output plugin logs to stdout, breaking JSON parsing #52032User-visible / Behavior Changes
CLI commands that support real
--jsonoutput now keep stdout reserved for JSON by routing preAction/plugin/bootstrap logs to stderr.Security Impact (required)
Yes/No) NoYes/No) NoYes/No) NoYes/No) NoYes/No) NoYes, explain risk + mitigation:Repro + Verification
Environment
preAction--jsoncommands that can load plugins during startupSteps
openclaw agents list --json.Expected
--jsonoutput commands.Actual
Evidence
Attach at least one:
Human Verification (required)
What you personally verified (not just CI), and how:
pnpm test -- src/cli/program/preaction.test.tspasses and now assertsstatus --json,update status --json, andbackup create --jsonflip stderr routing, whileconfig set --jsondoes not.pnpm buildalso fails on currentupstream/maindue to unrelated untouched memory export errors insrc/memory/embeddings-openai.tsandsrc/memory/manager-sync-ops.ts.Review Conversations
Compatibility / Migration
Yes/No) YesYes/No) NoYes/No) NoFailure Recovery (if this breaks)
f902d4989src/cli/program/preaction.ts,src/cli/program/preaction.test.ts--jsonas an input-parsing modeRisks and Mitigations
--jsoncommand could accidentally be treated as JSON output and change stderr behavior.isJsonOutputMode(...)gate and regression coverage forconfig set --json.