agent-orchestrator icon indicating copy to clipboard operation
agent-orchestrator copied to clipboard

bug(web): terminal shows connected but renders blank — no output despite agent running in tmux

Open OrcInc opened this issue 7 months ago • 2 comments

Description

The web dashboard terminal connects successfully (shows "CONNECTED" status) but renders a completely blank viewport — only a blinking cursor is visible, no text output at all. The underlying agent process is confirmed running in tmux and producing output.

Reproduction

  1. ao spawn an agent (confirmed with both opencode and codex)
  2. Open the session detail page in the web dashboard
  3. Terminal header shows session name + "CONNECTED" (blue dot)
  4. Terminal viewport is completely empty — solid black, just a cursor

Expected

Terminal should render the agent output visible in the tmux session.

Actual

Blank terminal despite successful WebSocket connection.

Environment

  • Affects: OpenCode and Codex agents (possibly all)
  • Dashboard shows: session name, "CONNECTED" status, correct font size controls
  • tmux: agent is running and producing output normally

Suspected Area

Likely in the xterm.js ↔ tmux WebSocket bridge — the connection establishes but the data stream is not being written into the xterm terminal instance. Could be:

  1. WebSocket message handler not piping data to term.write()
  2. Terminal fit/render not triggering after initial mount
  3. Race condition where terminal initializes before the WS data stream starts

Related Issues

  • #1197 — garbled rendering (xterm.js v5 issue)
  • #1023 — clipped terminal
  • #1151 — garbled on device switch

These are different symptoms but may share root cause in the xterm.js integration layer.

OrcInc avatar Apr 23 '26 15:04 OrcInc

I investigated this locally and the primary failure mode does not look like term.write() or xterm initialization. The data path is failing earlier: the web client opens the mux with the wrong terminal identity.

What I reproduced

On the session detail page the terminal header showed CONNECTED, but the browser console logged:

[MuxProvider] Terminal error for gmp-orchestrator-2: Session not found: gmp-orchestrator-2

That means the WebSocket transport is up, but the terminal open request is being rejected by the mux backend. So the viewport stays blank even though the connection badge says connected.

Concrete evidence

1. The real tmux session exists and is alive

From the live session API:

GET /api/sessions/gmp-orchestrator-2

returned metadata including:

"tmuxName":"b40fd959d776-gut_microbiome_project-gmp-orchestrator-2"

And from tmux itself:

tmux list-sessions -F '#{session_name}'

returned:

b40fd959d776-gut_microbiome_project-gmp-orchestrator-2

So tmux is alive and the correct target is known.

2. The web client still opens the mux with the user-facing sessionId

Current web path:

  • packages/web/src/components/DirectTerminal.tsx
  • calls openTerminal(sessionId) / subscribeTerminal(sessionId, ...)

This has apparently been true since ddd96852 (fix(web): sync fullscreen terminal viewport fix (#1140)). That assumption was fine only as long as the backend could map sessionId -> real tmux name.

3. The mux resolver still assumes the old tmux naming scheme

Current resolver path:

  • packages/web/server/mux-websocket.ts calls resolveTmuxSession(id, this.TMUX)
  • packages/web/server/tmux-utils.ts resolves only:
    • exact match of sessionId, or
    • 12hex-sessionId via HASH_PREFIX_PATTERN.test(s) && s.substring(13) === sessionId

That logic came from dcfee04e1 (fix: terminal servers compatible with hash-based architecture (#87)) and only understands the old hash-only prefix shape.

4. Recent tmux naming changed to a storage-key-prefixed form

f3ce113c (Add multi-project storage, resolution, and project settings support (#1343)) changed packages/core/src/paths.ts so generateTmuxName() now emits:

{storageKey}-{prefix}-{num}

instead of the older:

{12-char-hash}-{prefix}-{num}

In practice this now produces names like:

b40fd959d776-gut_microbiome_project-gmp-orchestrator-2

That no longer matches the resolver's assumption that everything after the first 13 chars is the session id. There is now an extra -gut_microbiome_project- segment in the middle.

Why this only started happening recently

The web client's sessionId assumption is old. The mux resolver's 12hex-sessionId assumption is old.

The thing that changed recently is the tmux name shape in f3ce113c.

That is the regression boundary that made the existing web assumption stop working.

Secondary symptom after ao stop / ao start

I also reproduced a second issue after restart:

  • the orchestrator session could be restored,
  • tmux remained alive,
  • but the session API reported status: terminated with lifecycle.runtimeState: alive
  • and SessionDetail hid the terminal behind the Terminal session has ended placeholder because it keys off terminal status.

That seems related but separate. It made the rendering problem much more visible after restore/restart cycles.

Local proof-of-fix

I locally validated that rendering becomes possible again if the web terminal opens the mux using the exact tmux target from session metadata instead of the user-facing session id.

Concretely:

  • pass session.metadata.tmuxName from SessionDetail into DirectTerminal
  • use that exact value for openTerminal, subscribeTerminal, writeTerminal, resizeTerminal, and closeTerminal
  • keep the visible session label as the human-facing session.id

With that patch in place, the terminal rendered correctly again.

I also validated a small UI mitigation for the restart case:

  • if session.lifecycle.runtimeState === "alive", do not replace the terminal with the "Terminal session has ended" placeholder even if session.status is terminal.

That avoids suppressing a still-live tmux terminal when lifecycle classification is stale or overly aggressive.

Suggested fixes

Preferred fix

Update the web terminal path to use the exact runtime/tmux identifier already available in session metadata:

  • prefer session.metadata.tmuxName
  • or session.runtimeHandle.id / serialized lifecycle runtime handle when available

This avoids heuristic tmux resolution entirely and is resilient to future naming changes.

Backend hardening

Also update resolveTmuxSession() in packages/web/server/tmux-utils.ts to understand the current storage-key-prefixed format, or at least add coverage for it. A regression test should include names like:

b40fd959d776-gut_microbiome_project-gmp-orchestrator-2

UX improvement

CONNECTED currently only means the mux WebSocket is alive. It does not mean the terminal open succeeded. It would help to surface terminal-open failures inline when the server returns type: "error" for a terminal id.

Commits most relevant to the regression

  • f3ce113c — changed tmux naming to storage-key-prefixed format and exposed the mismatch
  • dcfee04e1 — resolver logic still assumes old 12hex-sessionId shape
  • ddd96852 — web terminal still opens mux by plain sessionId
  • dcd003fb — restore-from-session-detail made the post-restart terminal suppression easier to hit

So my current read is:

Root cause: tmux identity mismatch between current runtime naming and the web terminal's resolver/open path.

Not primarily: xterm render/fit/write race.

miniMaddy avatar Apr 23 '26 15:04 miniMaddy

Closing this as this is fixed in this PR: https://github.com/ComposioHQ/agent-orchestrator/pull/1488

miniMaddy avatar Apr 25 '26 16:04 miniMaddy