Skip to content

fix(agent-manager): remove unsafe WebGL terminal renderer - #13413

Merged
marius-kilocode merged 2 commits into
mainfrom
audit-webgl-terminal-rendering
Aug 25, 2026
Merged

fix(agent-manager): remove unsafe WebGL terminal renderer#13413
marius-kilocode merged 2 commits into
mainfrom
audit-webgl-terminal-rendering

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Agent Manager mounted one WebGL renderer for every terminal, including terminals hidden in inactive tabs. Chromium limits the number of live WebGL contexts in a document. The pinned xterm WebGL addon also has known context-disposal and shared glyph-atlas reliability problems. With enough concurrent terminals, or after repeated terminal creation and disposal, a visible terminal could lose its renderer or display stale and corrupted glyphs.

This is especially risky in Agent Manager because terminal instances remain mounted so they can continue receiving PTY output while users switch tabs.

Why This Change Was Made

Agent Manager terminals now use xterm’s DOM renderer instead of allocating one scarce WebGL context per mounted terminal. This removes the browser-level context exhaustion and xterm WebGL atlas risks while preserving the other performance improvements from the original change:

  • PTY output is batched by animation frame instead of causing one xterm write and render schedule per WebSocket message.
  • Hidden terminal slots remain mounted but are moved outside the viewport so xterm can suspend their render work.
  • Terminal hosts remain mounted while History is open, preventing unnecessary xterm and WebSocket teardown and recreation.
  • Local connection and exit status messages use the same output batch as PTY data, preserving output order.

The scope was intentionally reduced after review. No shared PTY, server, CLI, transport-protocol, or bun-pty changes are included. No new kilocode_change markers are required.

User Impact

Users can run many Agent Manager terminals concurrently without consuming one WebGL context per terminal. Switching between terminals continues to preserve each terminal’s output and buffer. Opening and closing History does not recreate the existing terminal instances. The tradeoff is that terminal rendering uses the DOM path rather than WebGL; this favors predictable behavior and correctness over the unsafe GPU optimization.

Review Follow-up

Automated review identified three issues. The hidden History stack originally covered the tab bar and could change the terminal height; its bounds now start below the 36px tab bar. Replay overflow could leave buffered keystrokes available to a later reconnect; failed replay now clears the input buffer and closes the connection. The changeset now describes the user-facing WebGL stability fix rather than only the batching change.

There are no unresolved review threads. The bot summary is a non-thread issue comment, so GitHub does not expose a resolve action for it. No reply was posted.

Evidence

Local validation passed for the extension typecheck, lint, Knip, compile, focused terminal tests, conflict-marker check, and formatting checks. GitHub CI passed, including TypeScript analysis, unit tests, source-link validation, visual regression tests, and Kilo Code Review.

The isolated VS Code stress test created 20 simultaneously mounted terminals, streamed 10,000 verified output lines through each terminal, and cycled through the terminal tabs. All 200,000 lines were received without xterm discard errors or terminal-specific console errors. The same test opened and closed History while the terminals were alive and confirmed that the terminal DOM instances were preserved. The final renderer inventory showed 20 DOM renderers and zero WebGL canvases.

The implementation is limited to Agent Manager and dependency metadata. It does not change PTY transport behavior for other clients.

@kilo-code-bot

kilo-code-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx 337 WebSocket.close(1009) throws in Chromium, so overflow never disconnects
Files Reviewed (6 files)
  • .changeset/agent-manager-terminal-render-performance.md
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-layout.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-replay.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts

Fix these issues in Kilo Cloud

Previous Review Summary (commit db40b6d)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit db40b6d)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css 4914 Hidden History stack uses inset: 0 on .am-detail, so opening History makes the still-active terminal ~2 rows taller and ResizeObserver resizes the PTY

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts 186 8 MiB fail-open drops queued replay and skips flush(), so buffered keystrokes can land on a later reconnect
.changeset/agent-manager-terminal-render-performance.md 5 Changeset describes rAF batching instead of the user-visible WebGL stability fix
Files Reviewed (13 files)
  • .changeset/agent-manager-terminal-render-performance.md - 1 issue
  • bun.lock
  • packages/kilo-vscode/package.json
  • packages/kilo-vscode/tests/unit/agent-manager-ambient-setup.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-layout.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-replay.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/agent-manager.css - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/ambient.ts
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/index.ts
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/render.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts - 1 issue

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 170K · Output: 17.4K · Cached: 710.1K

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit b010019 into main Aug 25, 2026
33 checks passed
@marius-kilocode
marius-kilocode deleted the audit-webgl-terminal-rendering branch August 25, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants