Skip to content

fix(cli): normalize undefined cleanup exit codes - #8246

Closed
ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-cli-exit-status
Closed

ShuaixinHuang wants to merge 2 commits into
morluto:mainfrom
ShuaixinHuang:codex/fix-cli-exit-status

Conversation

@ShuaixinHuang

@ShuaixinHuang ShuaixinHuang commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #8313 at the author's request to resubmit the current eight PRs. The replacement preserves the identical head and complete patch; this closed PR retains the earlier discussion and validation history.

Supersedes #8079 at the author's request. This replacement reuses the same verified head commit and preserves the original discussion and validation record at #8079. Hosted CI for this new PR must complete independently.

Summary

Fixes #8049. The CLI dispatcher can receive an omitted exit code from serve. If JavaScript worker cleanup then fails, let status = code leaves status undefined; the cleanup branch only changes status when it equals numeric 0, and process.exit(undefined) exits successfully. This hides a cleanup failure from shells and CI.

Problem and expected behavior

When exit(undefined) is followed by a cleanup or SDK-output finalization failure, the process must return a non-zero status. A defined numeric exit code keeps its existing value, while an omitted code is normalized to the normal success baseline before failure handling.

Change and scope

Normalize the callback code with typeof code === "number" ? code : 0 before the existing cleanup/error handling. This is one line in scripts/rea.mjs; no worker ownership, output protocol, or cleanup ordering changes.

Evidence and regression coverage

  • The source reproduction in [Bug] CLI dispatcher exits with status 0 on cleanup failure when exit callback receives undefined code #8049 identifies the failing path: exit(undefined) bypasses both status === 0 checks and reaches process.exit(undefined), which reports success.
  • The fix makes both existing cleanup failure branches assign status 1 for an omitted code while preserving explicit numeric codes.
  • node --check scripts/rea.mjs passed.
  • npm run check:fast: dependency check, typecheck and lint passed 2/2.
  • Normal precommit and prepush hooks passed.

The reported failure was reproduced from the dispatcher control flow; no external provider or platform-specific runtime is required for this change.

Exit-code review regression

Follow-up 68918691951bbc820a20ee5624d265f89f594de4 expands the existing executable dispatcher shutdown cases without changing production code. They cover omitted and explicit undefined exit codes during cleanup and final output failure, successful omitted-code finalization, and preservation of explicit status 7; the existing explicit-zero and closed-pipe cases remain.

Windows, Node 24.22.1 / npm 11.16.0: the complete dispatcher file passes 21/21 with three build tasks successful. Temporarily reverting only the original one-line normalization makes 4 fail / 17 pass: omitted/undefined cleanup and output failures incorrectly exit 0. The production script was restored byte-for-byte afterward. Normal precommit passed and retained identical tested file bytes; check:fast passed 2/2. These are real child-process invocations of the production executable dispatcher with synthetic cleanup/output producers, not a real external analysis provider or MCP session. The new head needs its own hosted CI.

Author readiness

Human owner: @ShuaixinHuang

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-31T00:53:07.937740Z
We couldn’t complete this review. Comment @codex review to try again.
6891869 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issue was found.

Summary

The PR makes omitted exit codes start at zero, so cleanup or final-output failures can change the process status to one.

  • The CLI reports shutdown failures when serve omits its exit code.

Reviews (1) · Last reviewed commit: "test(cli): cover omitted exit codes duri..." · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] CLI dispatcher exits with status 0 on cleanup failure when exit callback receives undefined code

2 participants