Skip to content

fix(cli): skip background port scans in VS Code#10786

Merged
marius-kilocode merged 1 commit into
mainfrom
foul-oval
Jun 1, 2026
Merged

fix(cli): skip background port scans in VS Code#10786
marius-kilocode merged 1 commit into
mainfrom
foul-oval

Conversation

@marius-kilocode

@marius-kilocode marius-kilocode commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

VS Code and Agent Manager can start tracked background processes through the shared kilo serve backend, but they do not surface inferred listening ports. Each tracked process still scheduled recurring inferred-port scans, which launched ps and lsof from the long-lived Bun runtime without providing any extension functionality.

Restrict inferred-port discovery and its recurring polling timer to CLI clients. The background-process tool remains available in VS Code, explicit ready.port TCP probes still work for agent-driven readiness checks, and CLI TUI sessions retain automatic inferred-port discovery for the /process UI.

Comment thread packages/opencode/src/kilocode/background-process/ports.ts Outdated
Comment thread packages/opencode/test/kilocode/background-process.test.ts
Comment thread packages/opencode/src/kilocode/background-process/ports.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/opencode/src/kilocode/background-process/ports.ts N/A clean() called twice — once from stop() and again from the "exit" event handler after SIGTERM
packages/opencode/test/kilocode/background-process.test.ts 28 TOCTOU port reservation: port released before subprocess binds it, risking flaky tests under parallel CI

SUGGESTION

File Line Issue
packages/opencode/src/kilocode/background-process/ports.ts 121 code() helper duplicated verbatim in index.ts; consider consolidating
Other Observations (not in diff)

Incremental review (new commits): The two guards added in this update — Flag.KILO_CLIENT === "cli" in refresh() (line 176) and Flag.KILO_CLIENT !== "cli" early-return in poll() (line 214) — are symmetric and correct. VS Code clients now skip both the port scan and the recurring poll timer as intended.

New tests: Three new it.instance tests cover the VS Code/CLI port-discovery split. process.env["KILO_CLIENT"] is mutated and restored via finally — safe because Bun isolates test files in separate workers. The port() helper TOCTOU concern (existing warning on line 28) applies to all three new tests using it, but is already covered by the existing inline comment. The 2.5s fixed sleep in "does not infer ports for VS Code clients" is sound: poll() early-returns for non-CLI clients so no scan ever runs regardless of timing.

Overall design: The approach — spawning a detached shell script with a lease file, writing port lists to a temp file, and reading them from the Bun backend — is sound. The shell script's trap cleanup EXIT correctly removes temp files, and kill -0 "$owner" / kill -0 "$root" correctly terminates the loop when either the backend or the tracked process exits. The stale-cache check (STALE_MS = 10_000) on the list() path correctly handles the case where the helper exited unexpectedly.

No memory leaks: proc.unref() ensures the scanner subprocess does not hold the Bun event loop open. Temp files are cleaned on both the JS side (clean()) and the shell side (trap cleanup). The scanner reference is cleared to undefined before stop() is called, preventing double-stop.

Fork hygiene: All changed files are under packages/opencode/src/kilocode/ and packages/opencode/test/kilocode/ — no shared upstream files are modified. No kilocode_change markers are needed.

Files Reviewed (4 files)
  • packages/opencode/src/kilocode/background-process/ports.ts — 2 issues (unchanged from previous review)
  • packages/opencode/src/kilocode/background-process/index.ts — clean
  • packages/opencode/test/kilocode/background-process.test.ts — 1 issue (existing warning; 3 new tests look correct)
  • .changeset/calm-background-process-scans.md — clean

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 395,086 tokens

Review guidance: REVIEW.md from base branch main

@marius-kilocode marius-kilocode changed the title fix(cli): isolate background process port scanning fix(cli): skip background port scans in VS Code Jun 1, 2026
@marius-kilocode marius-kilocode merged commit 1eeab10 into main Jun 1, 2026
18 checks passed
@marius-kilocode marius-kilocode deleted the foul-oval branch June 1, 2026 11: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