fix(status): keep stdout clean for status --json during gateway recovery#4644
Merged
cv merged 3 commits intoJun 3, 2026
Merged
Conversation
Contributor
📝 WalkthroughWalkthroughAdds a helper to redirect stdout writes to stderr during async work, applies it to sandbox status/report and JSON CLI paths (list, sandbox doctor), and adds unit and integration tests ensuring human progress output does not appear on stdout when ChangesStdout Redirection for JSON Status Reports
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…ery (NVIDIA#4643) status --json builds its report by reconciling the gateway, and on a recoverable gateway error that reconcile streams human startup progress ("[2/8] Starting OpenShell gateway", "Starting gateway cluster...") to stdout via console.log. On the --json path those lines land ahead of the JSON document and make stdout unparseable. Build the report under a stdout guard that redirects writes to stderr, so the machine-readable document on stdout stays valid while recovery progress stays visible on stderr. The plain (non --json) status view is unchanged. Fixes NVIDIA#4643 Signed-off-by: latenighthackathon <latenighthackathon@users.noreply.github.com>
cd7f5b1 to
98b872e
Compare
cv
approved these changes
Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
status --jsonis meant to print only a machine-readable document on stdout, but when the status check finds the gateway in a recoverable error state it reconciles (recovers) the gateway while building the report, and that recovery streams human progress ([2/8] Starting OpenShell gateway,Starting gateway cluster...,Waiting for gateway health...) to stdout. Those lines land ahead of the JSON, so the stdout stream is not valid JSON and anything pipingstatus --jsoninto a parser fails. This builds the--jsonreport under a small stdout guard that redirects such writes to stderr, so the machine-readable document on stdout stays parseable while the progress stays visible on stderr. The plain (non---json) status view is unchanged. During review, this was extended to the other gateway-recovery-adjacent JSON paths (list --jsonandsandbox doctor --json) so their structured stdout stays clean if report construction has to recover the gateway as well.Related Issue
Fixes #4643
Changes
withStdoutRedirectedToStderr(src/lib/cli/stdout-guard.ts), which runs a callback withprocess.stdoutwrites sent toprocess.stderrand restores the original writer afterwards (including when the callback throws).getSandboxStatusReportnow builds the report under that guard, so the gateway reconcile/recovery progress it can trigger no longer reaches stdout on the--jsonpath. The humanshowSandboxStatuspath is untouched and keeps printing that progress as before.list --jsonnow builds the sandbox inventory under the same guard, covering inventory recovery that can reattach/restart the named gateway while preparing the JSON payload.sandbox doctor --jsonnow builds diagnostics under the same guard, covering doctor’s gateway recovery probe before oclif serializes the report.Type of Change
Verification
--jsonreport builder keeps stdout clean while the reconcile path writes progress (fails before the guard, passes after), plus unit tests for the guard itself (redirect, restore, restore-on-throw)list --jsonandsandbox doctor --jsonto verify progress writes are redirected away from stdout before oclif emits JSONRan: the
status --jsonsuite (7 passing), the newstdout-guardandsandbox-status-json-stdouttests, the global/sandbox oclif adapter regression tests,typecheck:cli, andmarkdownlint/biome linton the touched files (all clean). The push hook also re-ran CLI typecheck and CLI tests successfully.Signed-off-by: latenighthackathon latenighthackathon@users.noreply.github.com
Summary by CodeRabbit
New Features
Bug Fixes
Tests