openclaw - ✅(Solved) Fix process.stdout.write followed by synchronous process.exit may truncate output on pipes [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#83922Fetched 2026-05-20 03:46:37
View on GitHub
Comments
1
Participants
2
Timeline
10
Reactions
1
Timeline (top)
labeled ×5commented ×1cross-referenced ×1mentioned ×1

Error Message

Shell test: node scripts/print-cli-backend-live-metadata.ts codex-cli | python3 -c "import sys, json; json.load(sys.stdin)" — must parse without error.

Root Cause

Reasoning

On the codex-cli early-exit path, process.stdout.write() is called immediately before process.exit(0). When stdout is a pipe (e.g. CI capturing output, jq, or other tooling), Node.js buffers writes and process.exit() bypasses the drain step, causing partial or empty output. This is a well-known Node.js hazard. The non-early-exit path at the bottom of the file avoids this because the process drains naturally after the top-level await settles, but the codex-cli branch does not.

Fix Action

Fix / Workaround

Severity: medium / Confidence: high / Category: bug Triage: confirmed-bug Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18) Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-23edfe2554-_eba7993d07.

PR fix notes

PR #84239: fix(scripts): use process.exitCode instead of process.exit in codex-cli branch

Description (problem / solution / changelog)

Fixes #83922

fix: optional chain log itself in channel error handler

log.error?.() doesn't do what you think it does when log is undefined. The ?. only guards the call — if log is undefined, you still blow up accessing .error on it. Classic.

Five spots in server.impl.ts have this pattern (lines 1959, 2011, 2040, 2047, 2065), all in the channel startup promise chain. The logger gets cleaned up before a pending .catch() fires during channel exit, so log can be undefined by then. It's a race. The fix is just changing log.error?.() to log?.error?.() everywhere it appears in that handler.

Crashes every ~5 minutes on any setup where a channel exits or errors during plugin registration. Not great.

No behavior change in the happy path.

Real behavior proof

Behavior addressed: process.exit(0) truncating stdout in the codex-cli early-exit branch of scripts/print-cli-backend-live-metadata.ts Real environment tested: macOS darwin arm64, Node v26.0.0 Exact steps or command run after this patch: node --import tsx scripts/print-cli-backend-live-metadata.ts codex-cli | python3 -c 'import sys, json; json.load(sys.stdin); print("OK")' Evidence after fix:

$ node --import tsx scripts/print-cli-backend-live-metadata.ts codex-cli
{
  "provider": "codex-cli",
  "unsupported": true,
  "reason": "codex-cli is no longer a bundled CLI backend. Use openai/* with the Codex app-server runtime instead."
}

$ node --import tsx scripts/print-cli-backend-live-metadata.ts codex-cli | python3 -c 'import sys, json; json.load(sys.stdin); print("OK")'
OK

Observed result after fix: Full JSON object written to stdout, parsed without error, process exits 0 What was not tested: Live provider paths (claude-cli, google-gemini-cli) — only the codex-cli early-exit branch was exercised

Changed files

  • scripts/print-cli-backend-live-metadata.ts (modified, +53/-53)

Code Example

process.stdout.write(
    JSON.stringify(
      {
        provider,
        unsupported: true,
        ...
      },
      null,
      2,
    ),
  );
  process.exit(0);
RAW_BUFFERClick to expand / collapse

Severity: medium / Confidence: high / Category: bug Triage: confirmed-bug Detected against: openclaw v2026.5.18 (latest stable at time of scan, 2026-05-18) Tooling: clawpatch 0.3.0 + acpx/claude-sonnet-4-5 via Brad Mills protocol

Evidence

  • scripts/print-cli-backend-live-metadata.ts:17-29 (None)
process.stdout.write(
    JSON.stringify(
      {
        provider,
        unsupported: true,
        ...
      },
      null,
      2,
    ),
  );
  process.exit(0);

Reasoning

On the codex-cli early-exit path, process.stdout.write() is called immediately before process.exit(0). When stdout is a pipe (e.g. CI capturing output, jq, or other tooling), Node.js buffers writes and process.exit() bypasses the drain step, causing partial or empty output. This is a well-known Node.js hazard. The non-early-exit path at the bottom of the file avoids this because the process drains naturally after the top-level await settles, but the codex-cli branch does not.

Reproduction

node scripts/print-cli-backend-live-metadata.ts codex-cli | cat — may produce empty output on a slow pipe; consistently observed when the stdout buffer is larger than the write.

Recommendation

Either use process.stdout.write(data, () => process.exit(0)) to exit only after the drain callback fires, or set process.exitCode = 0 and remove the explicit process.exit(0) so the process drains normally. The latter matches the non-early-exit path at the bottom of the file.

Why existing tests miss this

No tests exist for this script and the truncation only manifests when stdout is a pipe with buffering, which a simple unit test would not exercise.

Suggested regression test

Shell test: node scripts/print-cli-backend-live-metadata.ts codex-cli | python3 -c "import sys, json; json.load(sys.stdin)" — must parse without error.

Minimum fix scope

Replace process.exit(0) with process.exitCode = 0 in the codex-cli branch of scripts/print-cli-backend-live-metadata.ts.


Standardized clawpatch finding. Persistent in v2026.5.18 (not resolved by upgrading from v2026.5.12). Finding ID: fnd_sig-feat-cli-command-23edfe2554-_eba7993d07.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix process.stdout.write followed by synchronous process.exit may truncate output on pipes [1 pull requests, 1 comments, 2 participants]