-
Notifications
You must be signed in to change notification settings - Fork 81
[bug] tmux PTY attach inherits TERM=dumb in container environments #150
Description
Bug Description
When CAO runs inside a Docker container or devcontainer, the TERM environment variable is often unset or set to dumb. The tmux attach-session subprocess inherits this, causing broken terminal rendering — no colors, garbled cursor positioning, and corrupted TUI output from agent CLIs.
Steps to Reproduce
- Run CAO inside a Docker container where
TERMis unset orTERM=dumb - Launch an agent (e.g. Claude Code, Codex)
- Connect to the terminal via the web UI WebSocket
Expected Behavior
Terminal renders correctly with colors and proper cursor positioning.
Actual Behavior
Terminal output is garbled. Agent TUIs (which rely on xterm-256color capabilities) render incorrectly. Status bars, spinners, and interactive elements are broken.
Root Cause
In cli_agent_orchestrator/api/main.py, the tmux attach subprocess inherits the process environment without ensuring TERM is set:
proc = subprocess.Popen(
["tmux", "attach-session", "-t", f"{session_name}:{window_name}"],
stdin=slave_fd,
stdout=slave_fd,
stderr=slave_fd,
close_fds=True,
preexec_fn=os.setsid,
)Proposed Fix
Default TERM to xterm-256color when spawning tmux:
pty_env = os.environ.copy()
pty_env.setdefault("TERM", "xterm-256color")
proc = subprocess.Popen(
["tmux", "attach-session", "-t", f"{session_name}:{window_name}"],
stdin=slave_fd,
stdout=slave_fd,
stderr=slave_fd,
close_fds=True,
preexec_fn=os.setsid,
env=pty_env,
)This is a minimal change — it only sets TERM if not already defined, preserving any user-configured value.
Environment
- CAO: main branch
- Docker: 27.x (base image:
mcr.microsoft.com/devcontainers/python:3.13) - tmux: 3.4+