Skip to content

fix(vscode): speed up embedded terminal startup and fix cold-connection race - #12630

Merged
marius-kilocode merged 1 commit into
mainfrom
optimize-terminal-startup-performance
Jul 29, 2026
Merged

fix(vscode): speed up embedded terminal startup and fix cold-connection race#12630
marius-kilocode merged 1 commit into
mainfrom
optimize-terminal-startup-performance

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Problem

Embedded Agent Manager terminals displayed a visible delay on startup. Fish shells waited roughly two seconds before showing the prompt, and terminal creation could fail with Not connected when the user opened a terminal while kilo serve was still starting. Local terminals also waited for unrelated Agent Manager worktree/session state recovery before opening.

What changed

  • Replay startup bytes from cursor 0. Initial xterm WebSocket attachment now uses cursor=0 instead of cursor=-1. The backend PTY can emit shell capability queries (and early output) between PTY creation and xterm connection; tailing from -1 discarded those bytes. xterm now receives the replayed startup data, answers Fish's capability handshake immediately, and the prompt appears without the timeout. Each newly created terminal has one initial attachment, so there is no duplicate-output risk.
  • Join the shared backend connection. Terminal creation awaits getClientAsync() rather than calling the synchronous getClient() accessor. When kilo serve is already starting, the request joins that connection instead of failing with Not connected.
  • Skip unrelated state recovery for local terminals. Local terminal creation no longer waits for Agent Manager worktree/session recovery. Worktree terminals still gate on that recovery because they need the recovered worktree path.

Why

The missed capability handshake was a concrete user-visible regression for Fish users. The cold-connection race made terminal creation unreliable on first use in a window. Both are fixed in Kilo-owned extension code with no shared OpenCode changes.

Validation

  • Full extension unit suite passes (3,324 tests).
  • Typechecks, lint, knip, and check-kilocode-change pass.
  • Self-test verified that opening Agent Manager creates zero terminals and no speculative processes.
  • Measured warm terminal prompt at ~200-215ms; Fish capability timeout removed.

…on race

Replay retained PTY startup bytes from cursor 0 on initial xterm
attachment so shells receive capability queries emitted before the
WebSocket connected. Fish previously waited ~2s for a terminal
capability response that xterm never saw, then displayed the prompt.

Local terminal creation no longer waits for unrelated Agent Manager
worktree recovery, and now joins the shared backend connection via
getClientAsync instead of racing the synchronous getClient accessor,
which could fail with 'Not connected' during cold kilo serve startup.

Worktree terminals still gate on state recovery since they need the
recovered worktree path.
@marius-kilocode
marius-kilocode enabled auto-merge (squash) July 29, 2026 08:20
@kilo-code-bot

kilo-code-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (5 files)
  • .changeset/fast-agent-manager-terminals.md
  • packages/kilo-vscode/src/agent-manager/AgentManagerProvider.ts
  • packages/kilo-vscode/src/agent-manager/terminal-routing.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-font.test.ts
  • packages/kilo-vscode/tests/unit/agent-manager-terminal-routing.test.ts

Reviewed by claude-sonnet-5 · Input: 34 · Output: 7.7K · Cached: 918.3K

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit a7f972f into main Jul 29, 2026
24 checks passed
@marius-kilocode
marius-kilocode deleted the optimize-terminal-startup-performance branch July 29, 2026 08:31
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…on race (Kilo-Org#12630)

Replay retained PTY startup bytes from cursor 0 on initial xterm
attachment so shells receive capability queries emitted before the
WebSocket connected. Fish previously waited ~2s for a terminal
capability response that xterm never saw, then displayed the prompt.

Local terminal creation no longer waits for unrelated Agent Manager
worktree recovery, and now joins the shared backend connection via
getClientAsync instead of racing the synchronous getClient accessor,
which could fail with 'Not connected' during cold kilo serve startup.

Worktree terminals still gate on state recovery since they need the
recovered worktree path.
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