Skip to content

fix(jetbrains): harden CLI startup and install diagnostics - #12060

Merged
kirillk merged 6 commits into
mainfrom
investigate-jetbrains-plugin-startup-issue
Jul 9, 2026
Merged

fix(jetbrains): harden CLI startup and install diagnostics#12060
kirillk merged 6 commits into
mainfrom
investigate-jetbrains-plugin-startup-issue

Conversation

@kirillk

@kirillk kirillk commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What

  • Surface a clear error when the JetBrains backend CLI fails to announce a port instead of hanging on loading.
  • Make CLI startup readiness cancellable: on timeout, kill the process tree, close streams, and return a visible State.Error.
  • Write rotated kilo-dev.log diagnostics in release builds, not just sandbox/RC builds.
  • Add startup diagnostics for the CLI binary, user/data paths, XDG env, filesystem hints, stdout/stderr tails, and process state.
  • Add CLI install diagnostics for relocated JetBrains system folders: effective PathManager paths, idea.*.path properties, cache root, expected executable, .complete marker, and cache checks.
  • Add a bounded timeout around the CLI cache lock so Core Reinstall/Restart cannot appear to do nothing behind a stuck downloader lock.
  • Add restart/reinstall lifecycle mutex logs so support can tell whether the action fired, queued behind startup, acquired the mutex, or failed.

Why

A user reported Rider staying on endless loading while the VS Code CLI binary starts normally. Their Rider installation uses custom idea.system.path, idea.log.path, and related directories, which made it unclear where the JetBrains plugin was trying to cache/download kilo.exe. The previous startup path could also block forever on a child-process stdout read or cache lock, causing Core Restart/Reinstall to look like no-ops.

This change makes those failure modes bounded and observable: startup now fails loud with diagnostics, release builds produce a stable diagnostic log, and the downloader logs the effective JetBrains system/cache paths so users with custom Rider folder configuration can verify the exact expected kilo.exe location.

Validation

  • ./gradlew :backend:test --tests ai.kilocode.backend.cli.KiloCliDownloaderTest --tests ai.kilocode.backend.app.KiloBackendAppServiceTest --tests ai.kilocode.backend.cli.KiloBackendCliManagerReadyTest
  • ./gradlew :shared:test --tests ai.kilocode.log.KiloLogTest
  • ./gradlew typecheck
  • pre-push hook: bun turbo typecheck --filter=!@kilocode/kilo-jetbrains
  • pre-push hook: bun turbo typecheck --filter=@kilocode/kilo-jetbrains

@kirillk kirillk changed the title fix(jetbrains): harden CLI startup fix(jetbrains): harden CLI startup and install diagnostics Jul 9, 2026
@kilo-code-bot

kilo-code-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental update

The only change since the last review (585d6ba8eb..556145c447) updates the three JetBrains .run/*.run.xml configs so their log_file paths point at kilo-dev.log.0 instead of kilo-dev.log. This correctly follows up on the earlier KiloLog.kt finding: with the kilo-dev.log.%g rotation pattern and count = 3, the active log file on disk really is kilo-dev.log.0, so the run configs now match actual behavior. No bugs, security, or performance issues in this change.

Files Reviewed (3 files)
  • packages/kilo-jetbrains/.run/Run IDE (Backend).run.xml (changed this round)
  • packages/kilo-jetbrains/.run/Run IDE (Frontend).run.xml (changed this round)
  • packages/kilo-jetbrains/.run/runIdeSplitMode.run.xml (changed this round)
Previous Review Summaries (3 snapshots, latest commit 585d6ba)

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

Previous review (commit 585d6ba)

Status: No Issues Found | Recommendation: Merge

Incremental update

The only change since the last review (5a86ca08c5..585d6ba8eb) is a CI-only addition to .github/workflows/codeql-kotlin.yml (a disk-cleanup step before the CodeQL Kotlin build). No bugs, security, or performance issues found in this change.

All previously flagged findings were re-verified against current HEAD (585d6ba8eb) and are now fixed:

  • KiloBackendCliManager.ktspawn() is now bounded by a coarse startup timeout wrapping resolve/spawn/awaitReady, and the CLI process is now killed on all State.Error paths (not just the timeout path).
  • KiloCliDownloader.kt — cache lock wait now uses monotonic System.nanoTime(); logPaths() diagnostics are now consistently wrapped in safe { }.
  • KiloLog.ktFileHandler pattern now includes %g (kilo-dev.log.%g), matching the documented rotated kilo-dev.log.* naming.
  • KiloBackendAppService.ktrestart()/reinstall() now catch and rethrow CancellationException before the generic Exception branch.
  • KiloBackendCliManagerReadyTest.kt — the 50 literal timeout is now a named WATCHDOG_TIMEOUT_MS constant.
  • KiloCliDownloaderTest.kt — the test name now accurately describes same-process lock contention.
Files Reviewed (7 files)
  • .github/workflows/codeql-kotlin.yml (changed this round)
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloBackendCliManager.kt — re-verified, fixed
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDownloader.kt — re-verified, fixed
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/app/KiloBackendAppService.kt — re-verified, fixed
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/log/KiloLog.kt — re-verified, fixed
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloBackendCliManagerReadyTest.kt — re-verified, fixed
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDownloaderTest.kt — re-verified, fixed

Previous review (commit 5a86ca0)

Status: 8 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
KiloBackendCliManager.kt 67 spawn(path) (resolve + process launch) is no longer bounded by any timeout — only awaitReady()'s internal wait is
KiloBackendCliManager.kt 160 CLI process/shutdown-hook not cleaned up on Error paths unrelated to the timeout branch (potential orphaned process)
KiloCliDownloader.kt 134 Cache lock timeout measured with non-monotonic System.currentTimeMillis() instead of System.nanoTime()
KiloLog.kt 124 FileHandler(..., LIMIT, COUNT, true) with no %g pattern writes kilo-dev.log.0, not literally kilo-dev.log as documented
KiloBackendAppService.kt 165 catch (e: Exception) in restart()/reinstall() also catches CancellationException, logging benign cancellation as "failed"

SUGGESTION

File Line Issue
KiloCliDownloader.kt 380 logPaths() inconsistently wraps some diagnostic calls in safe { } but not others
KiloBackendCliManagerReadyTest.kt 47 Hardcoded literal 50 timeout instead of a named constant, per package AGENTS.md guidance
KiloCliDownloaderTest.kt 277 Test name implies cross-process contention but actually exercises same-process OverlappingFileLockException
Files Reviewed (9 files)
  • packages/kilo-jetbrains/CHANGELOG.md
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/app/KiloBackendAppService.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloBackendCliManager.kt - 2 issues
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDownloader.kt - 2 issues
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/app/KiloBackendAppServiceTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloBackendCliManagerReadyTest.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDownloaderTest.kt - 1 issue
  • packages/kilo-jetbrains/shared/build.gradle.kts
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/log/KiloLog.kt - 1 issue
  • packages/kilo-jetbrains/shared/src/test/kotlin/ai/kilocode/log/KiloLogTest.kt

Fix these issues in Kilo Cloud

Previous review (commit 6609a76)

Status: 8 Issues Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
KiloBackendCliManager.kt 67 spawn(path) (resolve + process launch) is no longer bounded by any timeout — only awaitReady()'s internal wait is
KiloBackendCliManager.kt 160 CLI process/shutdown-hook not cleaned up on Error paths unrelated to the timeout branch (potential orphaned process)
KiloCliDownloader.kt 134 Cache lock timeout measured with non-monotonic System.currentTimeMillis() instead of System.nanoTime()
KiloLog.kt 124 FileHandler(..., LIMIT, COUNT, true) with no %g pattern writes kilo-dev.log.0, not literally kilo-dev.log as documented
KiloBackendAppService.kt 165 catch (e: Exception) in restart()/reinstall() also catches CancellationException, logging benign cancellation as "failed"

SUGGESTION

File Line Issue
KiloCliDownloader.kt 380 logPaths() inconsistently wraps some diagnostic calls in safe { } but not others
KiloBackendCliManagerReadyTest.kt 47 Hardcoded literal 50 timeout instead of a named constant, per package AGENTS.md guidance
KiloCliDownloaderTest.kt 277 Test name implies cross-process contention but actually exercises same-process OverlappingFileLockException
Files Reviewed (9 files)
  • packages/kilo-jetbrains/CHANGELOG.md
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/app/KiloBackendAppService.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloBackendCliManager.kt - 2 issues
  • packages/kilo-jetbrains/backend/src/main/kotlin/ai/kilocode/backend/cli/KiloCliDownloader.kt - 2 issues
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/app/KiloBackendAppServiceTest.kt
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloBackendCliManagerReadyTest.kt - 1 issue
  • packages/kilo-jetbrains/backend/src/test/kotlin/ai/kilocode/backend/cli/KiloCliDownloaderTest.kt - 1 issue
  • packages/kilo-jetbrains/shared/build.gradle.kts
  • packages/kilo-jetbrains/shared/src/main/kotlin/ai/kilocode/log/KiloLog.kt - 1 issue
  • packages/kilo-jetbrains/shared/src/test/kotlin/ai/kilocode/log/KiloLogTest.kt

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-5-20260630 · Input: 22 · Output: 5.5K · Cached: 542.8K

Review guidance: REVIEW.md from base branch main

@kirillk

kirillk commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Addressed all 8 findings from the review summary in 23f89aa and 5a86ca0:

  • KiloBackendCliManager.kt: restored a coarse timeout around the full CLI startup path (resolveCli(), onResolved(), and spawn()), passed the remaining startup budget into awaitReady(), and cleaned up process trees on non-timeout State.Error paths.
  • KiloCliDownloader.kt: switched cache-lock elapsed time to monotonic System.nanoTime() and wrapped the remaining path diagnostics in safe { }.
  • KiloLog.kt: added an explicit kilo-dev.log.%g rotation pattern and updated docs/release notes to describe kilo-dev.log.* files.
  • KiloBackendAppService.kt: rethrow CancellationException before generic restart/reinstall failure logging.
  • Tests: replaced the literal short timeout with WATCHDOG_TIMEOUT_MS and renamed the same-process lock test to match the branch it exercises.

All review conversations were replied to individually and resolved.

@kirillk
kirillk merged commit 1426dca into main Jul 9, 2026
27 checks passed
@kirillk
kirillk deleted the investigate-jetbrains-plugin-startup-issue branch July 9, 2026 17:07
t7tran pushed a commit to t7tran/kilocode that referenced this pull request Aug 14, 2026
…-plugin-startup-issue

fix(jetbrains): harden CLI startup and install diagnostics
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