Skip to content

Fix #4612: Return non-zero exit code when CLI session ends with error#4621

Merged
DOsinga merged 1 commit intoblock:mainfrom
jalateras:fix/cli-exit-code-on-error
Sep 29, 2025
Merged

Fix #4612: Return non-zero exit code when CLI session ends with error#4621
DOsinga merged 1 commit intoblock:mainfrom
jalateras:fix/cli-exit-code-on-error

Conversation

@jalateras
Copy link
Copy Markdown
Contributor

Summary

This PR fixes the CLI to properly return a non-zero exit code (1) when a session ends with an error, allowing scripts and CI/CD pipelines to detect failures.

Problem

When the goose CLI encounters an error during a session (such as an invalid temperature parameter), it prints the error message to stderr but still exits with code 0. This makes it impossible for automated scripts to detect when goose has failed.

Solution

Added std::process::exit(1) after printing the error message when a session fails. This ensures the process exits with a non-zero status code that scripts can detect.

Changes

  • Modified crates/goose-cli/src/cli.rs to call std::process::exit(1) when session.interactive() returns an error

Testing

  • Built the project with cargo build --package goose-cli
  • Ran existing tests with cargo test --package goose-cli
  • Verified clippy passes with no warnings
  • Manual testing confirms:
    • Normal sessions still exit with code 0
    • Error conditions now exit with code 1

Example

Before this fix:

$ GOOSE_TEMPERATURE="0.3" goose <<< "hey"
Session ended with error: ...
$ echo $?
0  # Wrong - should be non-zero

After this fix:

$ GOOSE_TEMPERATURE="0.3" goose <<< "hey"
Session ended with error: ...
$ echo $?
1  # Correct - non-zero exit code indicates failure

Fixes #4612

When a session fails due to an error (e.g., invalid temperature parameter),
the CLI now exits with code 1 instead of 0. This allows scripts and automation
tools to properly detect when goose encounters an error.

Previously, the error was only printed to stderr but the process would exit
successfully with code 0, making it impossible to detect failures in automated
environments.

Fixes block#4612

Signed-off-by: jalateras <[email protected]>
@jalateras jalateras force-pushed the fix/cli-exit-code-on-error branch from 2eb04a2 to c4c4dfa Compare September 12, 2025 04:14
@DOsinga DOsinga merged commit 3844209 into block:main Sep 29, 2025
10 checks passed
zanesq added a commit that referenced this pull request Sep 30, 2025
…-unification

* 'main' of github.com:block/goose: (24 commits)
  feat(cli): add `path` & `limit` to `session list` command (#4878)
  Allow better concurrent access (#4896)
  fix: Windows prompt cursor positioning issue with ANSI escape sequences (#4464)
  Fix: LiteLLM API key field not showing in UI configuration (#4105)
  fix: path is duplicated on tool calls causing them to fail (#4658) (#4859)
  add new prompt to get all available tutorials (#4802)
  Add filtering for agentVisible: false messages on streaming providers (#4847)
  alexhancock/mcp-crate-cleanup (#4885)
  docs: rename sub-recipe to subrecipe (#4886)
  docs: new multi-model section with autopilot topic (#4864)
  make agent manager singleton (#4880)
  Cli web auth token (#4456)
  fix(token_counter): fix panic with GitHub Copilot (#4632)
  Revert "Internal MCP Crate Cleanup (#4800)" (#4883)
  remove 2 redundant comments and one that lies (#4866)
  Internal MCP Crate Cleanup (#4800)
  Fix #4612: Return non-zero exit code when CLI session ends with error (#4621)
  Dead code cleanup (#4873)
  fix: restoring test data and correcting name (#4875)
  Add .goosehints file to enforce lowercase branding in documentation (#4870)
  ...
HikaruEgashira pushed a commit to HikaruEgashira/goose that referenced this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI wrong exit code and silent failure

2 participants