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

Terminal rendering glitches and blank terminal after switching sessions

Open ApexYash11 opened this issue 5 months ago • 6 comments

Description

Was trying out AO locally to explore the codebase and ran into a couple of UI issues.

The terminal rendering occasionally gets a bit garbled/misaligned after using it for a while.

[terminal rendering issue] Image

I also had the terminal go almost completely blank once after switching between sessions from two different repos. The input box was still there, but the rest of the terminal pane was just black.

[blank terminal] Image

ApexYash11 avatar Jul 01 '26 15:07 ApexYash11

please find the underlying cause for this and extend that within this same issue, after that a PR can be raised

Vaibhaav-Tiwari avatar Jul 01 '26 15:07 Vaibhaav-Tiwari

Did some more digging into this and I think I found the likely root causes behind both issues.

  1. Garbled / misaligned terminal rendering

The main issue appears to be the renderer fallback path in XtermTerminal.tsx.

When the WebglAddon loses its context at runtime, onContextLoss() only disposes the addon. It never falls back to the CanvasAddon, so xterm ends up using the DOM renderer, which doesn't correctly render box-drawing characters. That matches the garbled/misaligned TUI rendering I was seeing.

There's also a secondary issue in the resize stabilizer. If proposeDimensions() returns undefined while the terminal container is still settling (for example during a flex/CSS transition), the convergence loop exits without triggering another fit, leaving the terminal with an incorrect grid size until another resize event occurs.

  1. Blank terminal after switching sessions

This looks like a timing/race issue during session switching.

While changing to a session from another workspace, terminalHandleId is briefly unavailable, causing TerminalPane to mount an AttachedTerminal with an "empty" handle. The terminal instance is created, but no mux connection is established, resulting in the blank terminal state.

There's also what looks like a double-attach race where attach() can be invoked twice during initialization. The first connection is torn down, terminal.clear() is called, and a second connection starts. That would explain the temporary black/empty terminal with only the input area visible.

From what I can tell, the affected areas are:

frontend/src/renderer/components/XtermTerminal.tsx frontend/src/renderer/components/TerminalPane.tsx frontend/src/renderer/hooks/useTerminalSession.ts frontend/src/renderer/lib/terminal-mux.ts

ApexYash11 avatar Jul 04 '26 07:07 ApexYash11

@Vaibhaav-Tiwari take a look

ApexYash11 avatar Jul 06 '26 04:07 ApexYash11

Image @somewherelostt

ApexYash11 avatar Jul 17 '26 10:07 ApexYash11

A bounded runtime WebGL context-loss slice landed in fork PR https://github.com/xuelongmu/agent-orchestrator/pull/209. It adds a guarded, idempotent Canvas renderer fallback when an active WebGL context is lost, with regression coverage for duplicate/reentrant loss events. The broad blank-terminal/session-switch report remains open because this only addresses the deterministic WebGL-loss path.

Follow-up on current fork main: a reproduce-first Sol/high AO audit exercised deterministic cross-project handle-gap switch and terminal reopen-race cases; those tests passed. Current keyed remount and connection-generation guards made the older handle-unavailable/double-attach hypotheses non-reproducible, so no speculative second patch or PR was created. A fresh current reproduction is still needed before changing the remaining session-switch path.

xuelongmu avatar Jul 20 '26 16:07 xuelongmu

Fresh reproduction on current main, with a root cause and a PR: #3901.

Reproduction. Keep a board with more than six sessions and visit them in turn. Panes that were visited earliest go black first while their backend sessions stay healthy — tmux still holds the content. Switching away and back does not repaint; only restarting the app clears it, which is what makes this look intermittent rather than deterministic.

Cause. MAX_RETAINED_TERMINALS = 6 was removed in 4986af7d0 ("fix: retain terminals without eviction"). Since then every visited session keeps a mounted xterm — with its WebGL context and its mux lease — for the whole lifetime of the renderer process. Past Chromium's per-page WebGL context cap the browser forcibly loses the oldest contexts, which matches the observed order exactly.

On top of that, the activation state machine holds the pane at visibility: hidden while preparing, and several paths could throw or reject without ever lifting that cover — a black pane over a healthy session. #3901 closes five of them.

Relationship to the context-loss fallback in xuelongmu/agent-orchestrator#209 (@xuelongmu): that handles the reaction to a lost WebGL context; this handles the accumulation that causes the loss. Both are needed — neither subsumes the other, which may explain why the broad report stayed open after that slice landed.

axisrow avatar Aug 12 '26 17:08 axisrow