Skip to content

fix(vscode): start Agent Manager terminals instantly - #12866

Merged
marius-kilocode merged 2 commits into
mainfrom
research-terminal-startup-performance
Aug 5, 2026
Merged

fix(vscode): start Agent Manager terminals instantly#12866
marius-kilocode merged 2 commits into
mainfrom
research-terminal-startup-performance

Conversation

@marius-kilocode

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

Copy link
Copy Markdown
Collaborator

Agent Manager terminal startup currently waits for extension messaging, PTY creation, and the initial WebSocket replay before mounting xterm. That makes Command+/ feel unavailable even though VS Code can create and focus its terminal UI before the shell process is ready.

This changes terminal creation to mount and focus an optimistic xterm immediately, reuse its logical ID when the PTY is returned, and buffer early input until the PTY replay boundary has been parsed. Terminal protocol replies remain ahead of user input, reconnects retain their existing recovery behavior, and terminal font settings continue to follow VS Code configuration.

Performance

Measured with the isolated VS Code self-test against the same Agent Manager worktree. The baseline measured time until the xterm input target could receive focus. The optimized flow measures the same milestone, plus the replay boundary and command output.

Scenario Before After Improvement
First terminal, cold backend, focus ready 2,757 ms 20.8 ms 99.2% lower latency
Warm terminal creation, focus ready 183 ms 10.8 ms 94.1% lower latency
Command+/ warm flow, input target ready Blocked by PTY startup 10.8 ms Input available immediately
Command+/ warm flow, replay boundary Blocked by terminal creation 45.7 ms Shell initialization no longer blocks focus
Command+/ warm flow, command output Blocked by terminal creation 73.9 ms Early command executes successfully
Main-thread long tasks during final flow Not applicable 0 No terminal startup long task

The result is an immediately typeable Agent Manager terminal while preserving shell startup ordering and cleanup for stale or failed creates. PTY startup remains asynchronous, but it no longer prevents typing or causes early input to be lost.

const [activePendingId, setActivePendingId] = createSignal<string | undefined>()
const [terminalFont, setTerminalFont] = createSignal<TerminalFont>({
fontFamily: getComputedStyle(document.documentElement).getPropertyValue("--vscode-editor-font-family").trim(),
fontSize: readFontSize(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Initial optimistic font uses the chat UI font size, not the terminal font size

readFontSize() reads --kilo-font-size-13 — the Kilo chat UI font scale (default 13, clamped to 10–24). That's a different setting from terminal.integrated.fontSize (default 14 on Linux/Windows, 12 on macOS, unclamped), which is what the extension host sends via agentManager.state / terminal.created. An optimistic terminal created before the first state message lands will paint at the chat font size and then visibly jump when the real terminal font is applied in TerminalTab's created handler. Low impact since the state message usually arrives first and the mounted xterm self-corrects — but if the goal is a stable first paint, consider seeding the signal with the platform terminal defaults instead (or a short comment noting the deliberate approximation).


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

* tab back into the correct sidebar context.
*/
async create(params: {
terminalId: string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: The create docstring is now stale

With this new parameter, the terminal ID is generated by the webview and echoed back, but the docstring above still says "Returns the attach info the webview needs: our synthetic terminal ID, …". Suggest updating it to note the ID is caller-supplied (e.g. "the webview-supplied logical terminal ID, echoed back").


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 2

The core design holds up well: the backend guarantees the 0x00 meta frame after replay on every attach, so the replay gate always opens; the input buffer is bounded (256KB per class); all new listeners and xterm subscriptions are disposed in onCleanup; and the PTY cleanup races (close-during-create, dispose-during-create, create failure, webview reload) all settle the pending request and close the orphaned PTY. No memory leaks found. The two findings are minor polish items.

Issue Details (click to expand)

SUGGESTION

File Line Issue
packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx 377 Initial optimistic font uses the chat UI font size (readFontSize(), default 13, clamped 10–24) rather than the terminal font size setting, so an early optimistic terminal paints at the wrong size and jumps when terminal.created lands
packages/kilo-vscode/src/agent-manager/terminal-manager.ts 64 create docstring still says "our synthetic terminal ID" though the ID is now caller-supplied by the webview
Files Reviewed (14 files)
  • .changeset/instant-agent-manager-terminal.md
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/terminal-manager.ts - 1 issue
  • packages/kilo-vscode/src/agent-manager/terminal-routing.ts
  • packages/kilo-vscode/src/agent-manager/types.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-replay.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-routing.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-state.test.ts
  • packages/kilo-vscode/webview-ui/agent-manager/AgentManagerApp.tsx - 1 issue
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/TerminalTab.tsx
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/replay.ts
  • packages/kilo-vscode/webview-ui/agent-manager/terminal/state.ts
  • packages/kilo-vscode/webview-ui/src/types/messages/extension-messages.ts
  • packages/kilo-vscode/webview-ui/src/types/messages/webview-messages.ts

Fix these issues in Kilo Cloud


Reviewed by kimi-k3 · Input: 127.6K · Output: 39.5K · Cached: 3.3M

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 28d28fc into main Aug 5, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the research-terminal-startup-performance branch August 5, 2026 09:53
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…rtup-performance

fix(vscode): start Agent Manager terminals instantly
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