Repository navigation
fix(cli): surface fatal conversation errors and exit non-zero in headless/json mode - #846
Open
zsicheng0214 wants to merge 1 commit into
Open
zsicheng0214 wants to merge 1 commit into
zsicheng0214 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In
--headless(and--headless --json) mode,ConversationRunner._execute_conversation()catchesConversationRunErrorand unexpectedExceptions and forwards them only to_notification_callback(a Textual UI toast). In headless mode:stderrand no error event is emitted to the--jsonJSONL stdout stream;finally: self._update_run_status(False)triggersConversationFinished;OpenHandsApp.on_conversation_finished()unconditionally callsself.exit()(return_code=0), causingopenhands --headlessto printGoodbye! 👋and exit with code0even on fatal errors such as upstreamHTTP 402orAgent._initialize()ValueError.This breaks CI/CD pipelines, batch automation, and benchmark runners that rely on exit codes and JSONL error events.
Changes
openhands_cli/tui/core/state.py: Addlast_errorproperty andset_error(error)onConversationContainerto track the fatal error from the most recent run.openhands_cli/tui/core/conversation_runner.py: Clearstate.set_error(None)before each run in_execute_conversation()and recordstate.set_error(e)when catchingConversationRunErroror unexpectedException.openhands_cli/tui/textual_app.py:self.json_mode = json_modeonOpenHandsApp.on_conversation_finished(), whenheadless_mode=Trueandconversation_state.last_erroris set, emit a structured JSONLConversationErrorEvent(in--jsonmode) and write the error tosys.stderr, then callself.exit(return_code=1).textual_main(), propagate non-zero integerapp.return_codeviasys.exit(app.return_code)in headless mode.tests/tui/test_headless_mode.py: Add 6 unit tests coveringConversationRunError, unexpectedException,stderr+ JSONL emission, clean-run zero exit, andtextual_main()exit code propagation.Verification
uv run pytest tests/tui/test_headless_mode.py tests/test_main.py -q→ 65 passeduv run ruff check&uv run ruff format --check→ All checks passeduv run pyrighton all modified source files → 0 errors, 0 warnings