Skip to content

[Bug]: TUI leaves terminal in corrupted state after clean /quit — breaks legacy ncurses apps (e.g. nano); survives stty sane and manual escape-sequence resets, requires full reset #56759

Description

@calamityclay

Bug Description

After exiting the Hermes TUI via a normal /quit command, the terminal session is left in a corrupted state. Any subsequent legacy ncurses program run in the same terminal pane — confirmed with nano — receives raw, unparsed escape sequence fragments (e.g. 0;133u, ;129u) as literal text input instead of having them interpreted as control keys (Ctrl+X, Ctrl+O, etc.).

What doesn't fix it (tried and confirmed insufficient):
stty sane
printf '\033[<u\033[>4;0m' (pop kitty keyboard protocol stack)
printf '\033[=0u\033[?1000l\033[?1002l\033[?1003l\033[?1006l\033[?2004l' (explicit zero of keyboard protocol flags + disable mouse tracking modes + disable bracketed paste)

What does fix it:
Running the full reset command. This suggests the corruption isn't limited to the keyboard protocol or mouse tracking flags specifically — something more fundamental about terminal mode state isn't being restored on exit.

Steps to Reproduce

  1. SSH into a Hermes host using a terminal with kitty keyboard protocol support (Kitty terminal, via SSH kitten).
  2. Confirm nano works normally beforehand — Ctrl+X exits cleanly.
  3. Launch hermes --tui.
  4. Exit the TUI using the /quit slash command (not Ctrl+C, not a crash — a clean exit).
  5. Immediately run nano again in the same terminal session.
  6. Attempt Ctrl+X / Ctrl+O / Esc — instead of triggering nano's commands, raw fragments like 0;133u are inserted into the document as text.

Expected Behavior

On exit (including via /quit), the TUI should pop any keyboard protocol mode it pushed on entry, returning the terminal to its prior state — the same way it presumably already tries to do for alt-screen/cursor state.

Actual Behavior

After exiting the Hermes TUI via a normal /quit command, the terminal session is left in a corrupted state. Any subsequent legacy ncurses program run in the same terminal pane — confirmed with nano — receives raw, unparsed escape sequence fragments (e.g. 0;133u, ;129u) as literal text input instead of having them interpreted as control keys (Ctrl+X, Ctrl+O, etc.).

Affected Component

Other

Messaging Platform (if gateway-related)

No response

Debug Report

Report       https://paste.rs/7wgsn
  agent.log    https://paste.rs/0UsKt
  gateway.log  https://paste.rs/KrWfZ
  gui.log      https://paste.rs/HmHAf

Operating System

Ubuntu 24.04.4 LTS (Proxmox-hosted VM)

Python Version

3.11.15

Hermes Version

0.18.0

Additional Logs / Traceback (optional)

Terminal: Kitty (via SSH kitten)
Client OS: Windows 11, WSL2 Ubuntu
nano version: 7.2

Root Cause Analysis (optional)

Given reset's bluntness works while targeted escape sequences don't, this may point to multiple stacked pushes of the same mode (unwound by reset but not a single pop), or a terminal mode outside the ones tested above. Worth checking whatever exit/cleanup path /quit runs versus what a bare terminal disable_raw_mode()-style teardown would do.

Proposed Fix (optional)

No response

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 existsbugcomp/tuiTerminal UI (ui-tui/ + tui_gateway/)type/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions