Merge pull request #13418 from Kilo-Org/fix/13378-location-ref-key

fix(cli): align file location cache keys
This commit is contained in:
Marius
2026-08-25 17:09:54 +02:00
committed by GitHub
3 changed files with 52 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@kilocode/cli": patch
---
Keep file route location services on the same cache key as workspace-aware server routes.
@@ -1,4 +1,5 @@
import * as InstanceState from "@/effect/instance-state"
import { WorkspaceRef } from "@/effect/instance-ref" // kilocode_change - preserve the shared location key shape
import { FileSystem } from "@opencode-ai/core/filesystem"
import { LocationServiceMap } from "@opencode-ai/core/location-services" // kilocode_change - reuse the server location map
import { Ripgrep } from "@opencode-ai/core/ripgrep"
@@ -17,11 +18,19 @@ export const fileHandlers = HttpApiBuilder.group(InstanceHttpApi, "file", (handl
const locations = yield* LocationServiceMap.Service
const filesystem = Effect.fnUntraced(function* <A, E, R>(effect: Effect.Effect<A, E, R>) {
// kilocode_change start - preserve the shared location key shape
const workspaceID = yield* WorkspaceRef
return yield* effect.pipe(
Effect.provide(
locations.get(Location.Ref.make({ directory: AbsolutePath.make((yield* InstanceState.context).directory) })),
locations.get(
Location.Ref.make({
directory: AbsolutePath.make((yield* InstanceState.context).directory),
workspaceID,
}),
),
),
)
// kilocode_change end
})
const findText = Effect.fn("FileHttpApi.findText")(function* (ctx: { query: { pattern: string } }) {
@@ -0,0 +1,37 @@
import { describe, expect, test } from "bun:test"
import { Equal, Hash } from "effect"
import { readFileSync } from "node:fs"
import { Location } from "@opencode-ai/core/location"
import { AbsolutePath } from "@opencode-ai/core/schema"
const opencode = new URL("../../src/", import.meta.url)
const server = new URL("../../../server/src/", import.meta.url)
function source(root: URL, path: string) {
return readFileSync(new URL(path, root), "utf8")
}
describe("shared location service map keys", () => {
test("all location route consumers include workspaceID in their cache key", () => {
const consumers = [
[opencode, "server/routes/instance/httpapi/handlers/file.ts"],
[opencode, "server/routes/instance/httpapi/handlers/pty.ts"],
[server, "middleware/session-location.ts"],
] as const
for (const [root, path] of consumers) {
expect(source(root, path), path).toMatch(/Location\.Ref\.make\(\{[^}]*workspaceID/)
}
})
test("omitted and explicit undefined workspace IDs are distinct keys", () => {
const directory = AbsolutePath.make("/workspace")
const omitted = Location.Ref.make({ directory })
const explicit = Location.Ref.make({ directory, workspaceID: undefined })
expect(Object.hasOwn(omitted, "workspaceID")).toBe(false)
expect(Object.hasOwn(explicit, "workspaceID")).toBe(true)
expect(Equal.equals(omitted, explicit)).toBe(false)
expect(Hash.hash(omitted)).not.toBe(Hash.hash(explicit))
})
})