Skip to content

/exit does not cleanly exit TUI — session hangs, MCP connections not drained #520

Description

@SOSANA

Summary

Typing /exit in the Command Code TUI interactive session does not cleanly exit. The terminal often hangs or returns to shell in a broken state, requiring a manual process kill (SIGTERM). This happens consistently when MCP servers are connected.

Expected Behavior

/exit should gracefully terminate the TUI session:

  1. Drain all active MCP server connections
  2. Cancel any in-flight tool calls (GitHub, Neon, Chrome DevTools, Playwright, etc.)
  3. Save session state
  4. Restore terminal to clean shell state
  5. Exit with code 0

Actual Behavior

  • Terminal hangs indefinitely after /exit with no output
  • Requires Ctrl+C or kill <pid> from another terminal
  • Sometimes leaves terminal in raw mode (broken echo, line endings)
  • Session state may be lost
  • MCP server processes may remain running as orphans

Steps to reproduce the issue

  1. Start Command Code: cmd
  2. Connect to a project with MCP servers configured (e.g. GitHub, Neon, Chrome DevTools, Playwright)
  3. Run a few tool calls (any file reads, searches, or commands)
  4. Type /exit
  5. Observe: terminal hangs, cursor blinks but no response
  6. Press Ctrl+C to force kill
  7. If /exit does eventually return, terminal may be in raw mode (broken echo, garbled input)

Command Code Version

0.40.4

Operating System

Linux (Ubuntu/NixOS — x64)

Terminal/IDE

kitty / Konsole / GNOME Terminal

Shell

zsh / bash

Additional context

  • Node v24.16.0
  • Configured MCP servers that may affect exit behavior: GitHub, Neon, Chrome DevTools, Playwright, shadcn/ui, Tailwind CSS, docs-mcp-server, Brave Search, Z.AI Vision, sequential-thinking
  • Theory: The TUI event loop doesn't check the exit flag between tool call iterations. When MCP connections are in-flight or streaming, the exit handler never gets a clean window to run. Suggested fix: add an exit-flag check in the main loop after each tool call completes, and add a forced-drain timeout for MCP connections (e.g. 3s) before SIGKILL fallback.
  • ~/.commandcode/config.json contents (no PII): provider command-code, model zai-org/GLM-5.2
  • Auth status: authenticated as SOSANA via Command Code provider

Metadata

Metadata

Assignees

Labels

No labels
No labels

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