From 160b06661acc5f04b21221ab6578c468325f64c5 Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Tue, 28 Jul 2026 12:48:30 +0200 Subject: [PATCH 1/2] fix(vscode): avoid eager worktree watchers --- .changeset/quiet-vscode-watchers.md | 6 ++++++ packages/opencode/src/kilocode/watcher.ts | 8 ++++++-- .../test/kilocode/instance-vcs-watcher.test.ts | 14 +++++++++++++- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .changeset/quiet-vscode-watchers.md diff --git a/.changeset/quiet-vscode-watchers.md b/.changeset/quiet-vscode-watchers.md new file mode 100644 index 0000000000..0f44b7cfda --- /dev/null +++ b/.changeset/quiet-vscode-watchers.md @@ -0,0 +1,6 @@ +--- +"@kilocode/cli": patch +"kilo-code": patch +--- + +Prevent the VS Code backend from eagerly starting native file watchers for every Agent Manager worktree. diff --git a/packages/opencode/src/kilocode/watcher.ts b/packages/opencode/src/kilocode/watcher.ts index b953762e59..533e854b12 100644 --- a/packages/opencode/src/kilocode/watcher.ts +++ b/packages/opencode/src/kilocode/watcher.ts @@ -15,6 +15,10 @@ export namespace KilocodeWatcher { export class Service extends Context.Service()("@kilocode/Watcher") {} + export function eager(client = process.env["KILO_CLIENT"]) { + return client !== "vscode" + } + export const layer = Layer.effect( Service, Effect.gen(function* () { @@ -51,10 +55,10 @@ export namespace KilocodeWatcher { }), ) - // Gate the whole layer so LocationServiceMap's dependency graph is never built when the watcher is disabled. + // Gate the whole layer so LocationServiceMap is only warmed for clients that consume branch-update events. export const defaultLayer = Layer.unwrap( Effect.gen(function* () { - if (yield* Flag.KILO_EXPERIMENTAL_DISABLE_FILEWATCHER.pipe(Effect.orElseSucceed(() => false))) + if (!eager() || (yield* Flag.KILO_EXPERIMENTAL_DISABLE_FILEWATCHER.pipe(Effect.orElseSucceed(() => false)))) return Layer.succeed(Service, Service.of({ init: () => Effect.void })) return layer.pipe(Layer.provide(LocationServiceMap.layer)) }), diff --git a/packages/opencode/test/kilocode/instance-vcs-watcher.test.ts b/packages/opencode/test/kilocode/instance-vcs-watcher.test.ts index 3bd83f86fe..995555f368 100644 --- a/packages/opencode/test/kilocode/instance-vcs-watcher.test.ts +++ b/packages/opencode/test/kilocode/instance-vcs-watcher.test.ts @@ -1,10 +1,11 @@ -import { afterAll, beforeAll, expect } from "bun:test" +import { afterAll, beforeAll, describe, expect, test } from "bun:test" import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner" import { Deferred, Effect, Fiber, Layer } from "effect" import { GlobalBus, type GlobalEvent } from "../../src/bus/global" import { Git } from "../../src/git" import { InstanceLayer } from "../../src/project/instance-layer" import { InstanceStore } from "../../src/project/instance-store" +import { KilocodeWatcher } from "../../src/kilocode/watcher" import { tmpdirScoped } from "../fixture/fixture" import { awaitWithTimeout, testEffect } from "../lib/effect" @@ -23,6 +24,17 @@ afterAll(() => { // The watcher is unreliable on Windows CI, so this test only runs on unix. const live = process.platform === "win32" ? it.live.skip : it.live +describe("KilocodeWatcher.eager", () => { + test("skips eager location watchers for VS Code", () => { + expect(KilocodeWatcher.eager("vscode")).toBe(false) + }) + + test("keeps eager location watchers for the standalone CLI", () => { + expect(KilocodeWatcher.eager("cli")).toBe(true) + expect(KilocodeWatcher.eager(undefined)).toBe(true) + }) +}) + live("instances publish branch updates after git switch", () => Effect.gen(function* () { const dir = yield* tmpdirScoped({ git: true }) From 8f4b14610398c5f89d671d4c602115df529e095b Mon Sep 17 00:00:00 2001 From: marius-kilocode Date: Tue, 28 Jul 2026 12:55:41 +0200 Subject: [PATCH 2/2] fix(vscode): use normalized client flag --- packages/opencode/src/kilocode/watcher.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opencode/src/kilocode/watcher.ts b/packages/opencode/src/kilocode/watcher.ts index 533e854b12..1e7f70f39f 100644 --- a/packages/opencode/src/kilocode/watcher.ts +++ b/packages/opencode/src/kilocode/watcher.ts @@ -15,7 +15,7 @@ export namespace KilocodeWatcher { export class Service extends Context.Service()("@kilocode/Watcher") {} - export function eager(client = process.env["KILO_CLIENT"]) { + export function eager(client = Flag.KILO_CLIENT) { return client !== "vscode" }