Fix CLI /new command not properly resetting conversation display #11125
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.
End-user friendly description of the problem this fixes or functionality this introduces.
Fixed an issue where the CLI
/new
command would show old session statistics before starting a new conversation. Now when users type/new
, the screen is cleared immediately for a cleaner transition to the new session.Summarize what the PR does, explaining any non-trivial design decisions.
This PR fixes issue #11123 where the CLI
/new
command wasn't properly resetting the conversation display. The problem was that when users requested a new session, the old session's statistics (usage metrics, conversation history) were displayed before the new session started, creating a confusing user experience.Changes made:
Modified
handle_new_command()
inopenhands/cli/commands.py
: Replaced the call todisplay_shutdown_message(usage_metrics, sid)
withclear()
fromprompt_toolkit.shortcuts
. This provides a cleaner transition by immediately clearing the screen instead of showing old session stats.Added comprehensive tests in
tests/unit/cli/test_new_command_reset.py
to verify:/new
command behavior correctly clears the screen instead of displaying shutdown messagesDesign decision rationale:
The core session mechanics (unique session ID generation, fresh UsageMetrics objects, proper state reset) were already working correctly. The issue was purely a user experience problem where old session information was displayed during the transition. By clearing the screen immediately, users get a clean slate when they explicitly request a new session with
/new
.Link of any specific issues this addresses:
Fixes #11123
@xingyaoww can click here to continue refining the PR
To run this PR locally, use the following command:
GUI with Docker:
CLI with uvx: