Skip to content

[CELEBORN-2557] Fix CLI process exit status - #3974

Open
huangxiaopingRD wants to merge 2 commits into
apache:mainfrom
huangxiaopingRD:fix-cli-exit-code
Open

huangxiaopingRD wants to merge 2 commits into
apache:mainfrom
huangxiaopingRD:fix-cli-exit-code

Conversation

@huangxiaopingRD

@huangxiaopingRD huangxiaopingRD commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Pass the exit code returned by picocli to System.exit in CelebornCli.main. Extract command execution into a package-private method for the existing in-process tests, and add process-level exit code tests.

Why are the changes needed?

The CLI currently discards picocli's return value. For example, celeborn-cli --unknown-option reports an error but exits with status 0, so shell scripts cannot detect the failure. This change returns picocli's status to the shell.

JIRA: https://issues.apache.org/jira/browse/CELEBORN-2557

Does this PR resolve a correctness bug?

  • Yes

Does this PR introduce any user-facing change?

  • Yes

How was this patch tested?

  • CelebornCliExitCodeSuite: 2 tests passed, covering --help (0) and an unknown option (2) in separate JVM processes.
  • TestCelebornCliCommands: 49 tests passed and 1 existing test was canceled; the suite ran with an isolated HOME.
  • mvn -o -pl cli spotless:check passed.

Both test suites were run with Maven using -pl cli -am test -Dtest=none -Dcheckstyle.skip -Drat.skip=true and the corresponding -DwildcardSuites value.

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.87%. Comparing base (dfdada3) to head (c72a163).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3974      +/-   ##
============================================
+ Coverage     62.64%   62.87%   +0.24%     
  Complexity      451      451              
============================================
  Files           407      407              
  Lines         29032    29037       +5     
  Branches       2858     2861       +3     
============================================
+ Hits          18185    18255      +70     
+ Misses         9467     9398      -69     
- Partials       1380     1384       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot removed the correctness Correctness bugfix label Nov 20, 2026

@pan3793 pan3793 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing picocli's status through looks correct. However, a few failure paths still exit 0, so shell scripts still can't detect them. Since that's the goal of this PR, please cover them here too:

  1. No subcommand: celeborn-cli with no args only calls logError in CelebornCli.run() and returns, so it exits 0. Please make it a usage error, e.g. inject @Spec and throw ParameterException (exit 2).
  2. Server-side rejections: for --exclude-worker, --remove-excluded-worker, --remove-workers-unavailable-info, --send-worker-event, --update-interruption-notices and --unregister-shuffles, the master returns HandleResponse with success = false and HTTP 200 (WorkerResource, ShuffleResource). MasterSubcommandImpl.run() only prints the response, so these exit 0. Please fail the command when getSuccess is false.
  3. Config write failures: CliConfigManager.saveConfig catches and logs every exception, so --add-cluster-alias / --remove-cluster-alias report success and exit 0 even when the config file wasn't written. Please let the exception propagate.

Tests:

  1. The TestCelebornCliCommands helpers discard the value returned by execute. Please assert CommandLine.ExitCode.OK in captureOutputAndValidateResponse and CommandLine.ExitCode.USAGE in captureErrorAndValidateResponse (all current error cases are usage errors).
  2. CelebornCliExitCodeSuite covers only picocli's defaults. Please add the no-args case and an execution failure (e.g. master --show-workers --hostport 127.0.0.1:1 -> ExitCode.SOFTWARE), and use CommandLine.ExitCode.* instead of the literal 2.
  3. captureErrorAndValidateResponse calls System.setErr(...) and never restores it, so stderr output from the rest of the suite is lost. Since this PR touches the helper, please save System.err and restore it in a finally block, and reuse stderrPrintStream instead of creating a second PrintStream.

@huangxiaopingRD

huangxiaopingRD commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Passing picocli's status through looks correct. However, a few failure paths still exit 0, so shell scripts still can't detect them. Since that's the goal of this PR, please cover them here too:

  1. No subcommand: celeborn-cli with no args only calls logError in CelebornCli.run() and returns, so it exits 0. Please make it a usage error, e.g. inject @Spec and throw ParameterException (exit 2).
  2. Server-side rejections: for --exclude-worker, --remove-excluded-worker, --remove-workers-unavailable-info, --send-worker-event, --update-interruption-notices and --unregister-shuffles, the master returns HandleResponse with success = false and HTTP 200 (WorkerResource, ShuffleResource). MasterSubcommandImpl.run() only prints the response, so these exit 0. Please fail the command when getSuccess is false.
  3. Config write failures: CliConfigManager.saveConfig catches and logs every exception, so --add-cluster-alias / --remove-cluster-alias report success and exit 0 even when the config file wasn't written. Please let the exception propagate.

Tests:

  1. The TestCelebornCliCommands helpers discard the value returned by execute. Please assert CommandLine.ExitCode.OK in captureOutputAndValidateResponse and CommandLine.ExitCode.USAGE in captureErrorAndValidateResponse (all current error cases are usage errors).
  2. CelebornCliExitCodeSuite covers only picocli's defaults. Please add the no-args case and an execution failure (e.g. master --show-workers --hostport 127.0.0.1:1 -> ExitCode.SOFTWARE), and use CommandLine.ExitCode.* instead of the literal 2.
  3. captureErrorAndValidateResponse calls System.setErr(...) and never restores it, so stderr output from the rest of the suite is lost. Since this PR touches the helper, please save System.err and restore it in a finally block, and reuse stderrPrintStream instead of creating a second PrintStream.

@pan3793 Thanks for the review! I’ve updated the code to address your comments. Could you please take another look?

@pan3793 pan3793 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all addressed. Two more on the tests:

  1. CliConfigManager.cliConfigFilePath is a val fixed at class load to $HOME/.celeborn-cli.conf, and a JVM cannot change its own env vars, so in-process tests have no way to redirect it. As a result, TestCelebornCliCommands writes the unit-test alias into the developer's real config file, and its afterAll then deletes the whole file, wiping any aliases they had configured. The subprocess HOME override in this PR works around this for the new suite only.

    Please make the path overridable in tests only, following the same idea as Spark's SparkConfWithEnv, e.g.

    def cliConfigFilePath: String =
      sys.props.get("celeborn.testing.cli.config.file")
        .filter(_ => sys.props.contains("celeborn.testing"))
        .getOrElse(s"${sys.env("HOME")}/.celeborn-cli.conf")

    celeborn.testing is set by CelebornFunSuite, so production behavior is unchanged. It must be a def rather than a val, so the property is picked up whenever it is set. Then let the CLI suites extend CelebornFunSuite, set the property to a file under a temp directory in beforeAll, and clear the property and delete the temp directory in afterAll, so no test touches $HOME.

  2. CelebornCliExitCodeSuite now starts 18 JVMs (12 in the rejection test alone), which is overkill. Only the System.exit wiring in main needs a separate process. With 1 in place, please keep a single subprocess case (e.g. --unknown-option -> ExitCode.USAGE) and check the rest in-process via CelebornCli.execute, including the config-save failure case.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants