Repository navigation
fix(cli): preserve machine output through fatal terminal restores - #117487
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 12:03 PM ET / 16:03 UTC. ClawSweeper reviewWhat this changesRoutes CLI terminal restoration through the shared runtime so JSON and other machine-readable stdout stays free of ANSI reset bytes during normal, deferred, and fatal exits; it also classifies Merge readinessKeep this PR open for its protected maintainer review path. The patch appears to correctly move terminal-reset stream selection to the shared runtime owner, covering normal exits and fatal handlers while preserving an explicitly supplied reset stream. Likely related people: steipete (high confidence). Priority: P1 Review scores
Verification
How this fits togetherOpenClaw CLI commands establish whether stdout is human-facing or machine-consumed before command execution. Normal exits, deferred finalizers, and process-level fatal handlers restore terminal state afterward, so this boundary determines whether reset bytes go to stdout or stderr. flowchart LR
A[CLI invocation] --> B[Machine-output detection]
B --> C[Console routing state]
C --> D[Command output]
D --> E[Normal or fatal exit]
E --> F[Runtime terminal restoration]
F --> G[Clean stdout and terminal reset stream]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +15, Tests +228. Total +243 across 10 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the single runtime-owned restoration wrapper, land it once the final exact-head checks are green, and keep structured-output detection responsible for setting the existing console-routing state rather than adding per-exit stream decisions. Do we have a high-confidence way to reproduce the issue? Yes — current source shows terminal restoration defaults to stdout, and the PR supplies focused dual-TTY subprocess cases that exercise JSON output followed by normal, deferred, and fatal exits. Is this the best way to solve the issue? Yes — centralizing stream selection in the existing runtime owner is narrower and safer than teaching every fatal handler or command to choose a reset stream independently. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 30972edaea78. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…enclaw#117487) Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Machine-readable CLI commands could append terminal-reset escape sequences to stdout during normal, deferred, uncaught-exception, unhandled-rejection, configuration-failure, or legacy exits. Configuration path and schema commands also failed to reserve their machine-output stream. Downstream operators therefore received invalid JSON precisely when commands succeeded, failed, or terminated fatally.
Why This Change Was Made
Move terminal-reset stream selection into the existing application runtime owner and route every normal and fatal CLI exit through that single boundary. Preserve explicitly selected reset streams, human terminal behavior, interactive onboarding, public plugin SDK contracts, dynamic startup imports, existing exit codes, and config-set JSON parsing behavior.
User Impact
Automation receives clean JSON or raw machine output even on fatal exit 1 and invalid-configuration exit 78. Terminal cleanup still occurs on stderr for machine output and on stdout for human sessions; config get, file, and schema consistently reserve their output stream.
Evidence