Skip to content

[Bug]: Hermes Agent does not cleanly hand control back to CLI after session ends #38252

@CycSpring

Description

@CycSpring

Bug Description

When a Hermes Agent session finishes or exits, the CLI does not properly resume control. The terminal appears to become desynchronized: the previous session summary is printed, but the prompt and Hermes Agent UI remain mixed together.

In the screenshot, the CLI shows:

  • A resumed Hermes session summary:
    • Session: 20260603_213004_47ce1f
    • Title: AI Assistant and User Introduction
    • Duration: 2m 38s
    • Messages: 40
    • The shell prompt appears as:
    • PS C:\Users\SpringChen>
  • At the same time, the Hermes Agent interface is still visible and accepts commands such as /exit.

This makes it unclear whether the user is currently interacting with the system shell, the Hermes Agent, or a partially resumed session.
Image

Steps to Reproduce

  1. Start or resume a Hermes Agent session from the CLI.
  2. Let the Hermes Agent complete the conversation or exit the session.
  3. Observe the terminal after the session ends.
  4. Try entering a command such as /exit.

Expected Behavior

After the Hermes Agent session ends, the CLI should cleanly return to the normal shell prompt, or clearly remain inside the Hermes Agent UI. The terminal state should not mix the shell prompt and Hermes Agent interface.

Actual Behavior

The CLI does not cleanly take back control after the Hermes Agent session ends. The terminal output becomes mixed:

  • A PowerShell prompt is shown.
  • Hermes Agent UI elements are still displayed.
  • Agent commands still appear to be accepted.
  • The session state looks inconsistent or desynchronized.

Affected Component

CLI (interactive chat)

Messaging Platform (if gateway-related)

N/A (CLI only)

Debug Report

Debug report uploaded:
  Report       https://paste.rs/irgha
  agent.log    https://paste.rs/Cy0UC
  gateway.log  https://paste.rs/lJwsC

⏱  Pastes will auto-delete in 6 hours.
To delete now:  hermes debug delete <url>

Share these links with the Hermes team for support.

Operating System

Windows11

Python Version

Python 3.11.9

CLI

PowerShell 7.6.2

Hermes Version

Hermes Agent v0.15.1 (2026.5.29)

Additional Logs / Traceback (optional)

## Additional Logs / Traceback (optional)

No Python/Node traceback was observed in the screenshot.

Relevant visible terminal output:


Resume this session with:
  hermes --resume 20260603_213004_47ce1f
  hermes -c "AI Assistant and User Introduction"

Session:   20260603_213004_47ce1f
Title:     AI Assistant and User Introduction
Duration:  2m 38s
Messages:  40 (8 user, 24 tool calls)
PS C:\Users\SpringChen>

Welcome to Hermes Agent! Type your message or /help for commands.
Initializing agent...
...
/exit

Root Cause Analysis (optional)

Root Cause Analysis (optional)

This looks like a terminal/session handoff issue rather than a normal application crash.

Possible causes:

  • The Hermes Agent process exits or finalizes a session, but the parent CLI does not correctly restore terminal ownership/state.
  • The CLI prints or returns to the PowerShell prompt before the Hermes Agent TUI/input loop has fully shut down.
  • The resumed session summary and the active Hermes Agent UI may be writing to the same terminal concurrently.
  • Cleanup logic may be missing or running out of order, especially around TTY restoration, prompt rendering, and agent process lifecycle completion.

In short, the shell prompt appears before the Hermes Agent interface has fully detached, leaving the user in an ambiguous mixed state.

Proposed Fix (optional)

Proposed Fix (optional)

Suggested fixes:

  • Ensure the Hermes Agent fully stops its TUI/input loop before returning control to the parent CLI or shell.
  • Add an explicit lifecycle boundary between:
    1. session finalization,
    2. TTY cleanup/restoration,
    3. CLI prompt rendering,
    4. shell handoff.
  • Prevent the shell prompt or resumed-session summary from being printed while the Hermes Agent UI is still active.
  • If the agent is intentionally still running, suppress the shell prompt and keep the UI state clearly inside Hermes Agent.
  • Add a regression test or integration test for session exit/resume behavior on Windows PowerShell.
  • Log lifecycle events around session end, TTY restore, process exit, and prompt render to make future debugging easier.

Expected result: after /exit or session completion, the terminal should either cleanly return to PS C:\Users\SpringChen> or clearly remain inside Hermes Agent, but never display both states at once.

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/cliCLI entry point, hermes_cli/, setup wizardtype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions