diff --git a/packages/sdk/test/instances.test.ts b/packages/sdk/test/instances.test.ts index b5439263f25..24e5780f9cc 100644 --- a/packages/sdk/test/instances.test.ts +++ b/packages/sdk/test/instances.test.ts @@ -88,10 +88,10 @@ test("Promise instances are lazy, share by key and Location, and stay isolated b expect(await second.sessions.get({ sessionID })).toEqual(separateHost) expect(configured).toEqual([]) expect(setups).toEqual([]) - // Permission and form lists read instance services, so they acquire the Session's instance. + // Pending permissions and forms live only in a loaded instance, so listing them never acquires one. expect(await first.permission.list({ sessionID })).toEqual([]) expect(await first.session.form.list({ sessionID })).toEqual([]) - expect(configured).toEqual(["first:alpha"]) + expect(configured).toEqual([]) await Promise.all( [ diff --git a/packages/server/src/handlers/permission.ts b/packages/server/src/handlers/permission.ts index 68d0543a4c1..da1f1607280 100644 --- a/packages/server/src/handlers/permission.ts +++ b/packages/server/src/handlers/permission.ts @@ -60,6 +60,9 @@ export const PermissionHandler = HttpApiBuilder.group(Api, "server.permission", "session.permission.list", Effect.fn(function* (ctx) { const session = yield* sessionInfo(sessions, ctx.params.sessionID) + // Pending requests live in a loaded Location's memory, so an unloaded one has none to report. + // Answering must not boot it: clients poll whole subagent trees, including deleted worktrees. + if (instances.live && !(yield* instances.live(session))) return { data: [] } const requests = yield* Permission.Service.use((permission) => permission.forSession(ctx.params.sessionID), ).pipe(instances.provide(session), locationErrors) diff --git a/packages/server/test/fetch.test.ts b/packages/server/test/fetch.test.ts index 310e3effa09..4eb0f526ef8 100644 --- a/packages/server/test/fetch.test.ts +++ b/packages/server/test/fetch.test.ts @@ -38,12 +38,7 @@ it.live("returns LocationNotFoundError for a missing folder and recovers once it const session = Schema.decodeUnknownSync(Schema.Struct({ data: Session.Info }))( yield* Effect.promise(() => created.json()), ).data - const endpoints = [ - "/api/model", - "/api/integration", - `/api/session/${session.id}/permission`, - "/api/session/global/form", - ] + const endpoints = ["/api/model", "/api/integration", "/api/session/global/form"] for (const endpoint of endpoints) { const response = yield* Effect.promise(() => handler( @@ -59,6 +54,17 @@ it.live("returns LocationNotFoundError for a missing folder and recovers once it message: `Location not found: ${directory}`, }) } + // Pending requests live in memory, so listing them never boots the Location and cannot fail on its folder. + const pending = yield* Effect.promise(() => + handler( + new Request(`http://opencode.local/api/session/${session.id}/permission`, { + headers: { "x-opencode-directory": encodeURIComponent(directory) }, + }), + ), + ) + expect(pending.status).toBe(200) + expect(yield* Effect.promise(() => pending.json())).toEqual({ data: [] }) + yield* Effect.promise(() => fs.mkdir(directory)) const recovered = yield* Effect.promise(() => handler( diff --git a/packages/server/test/session-instances.test.ts b/packages/server/test/session-instances.test.ts index f2b32ee6ec4..18486cc14be 100644 --- a/packages/server/test/session-instances.test.ts +++ b/packages/server/test/session-instances.test.ts @@ -145,6 +145,7 @@ it.live( ) const selector = Instance.Service.of({ provide: (session) => Effect.provide(instances.get(session.id)), + live: (session) => RcMap.has(instances.rcMap, session.id), }) const bindings: LayerNode.Replacements = [ ...replacements, @@ -197,8 +198,13 @@ it.live( expect(yield* Effect.promise(() => response.json())).toEqual({ data: [] }) } } - // Reading permissions or forms builds the Session's Instance and starts its plugin activation at once; the - // ordering assertion after the prompts is what proves each Session boots exactly once. + // Pending permissions and forms live only in a loaded Instance, so listing them for these cold Sessions + // must answer without acquiring one. `live` is the immediate signal; plugin activation and `boots` land later. + for (const config of configs) { + const session = yield* sessions.get(config.id) + expect(yield* instances.live!(session)).toBe(false) + } + expect(boots).toEqual([]) for (const config of configs) { const session = yield* sessions.get(config.id)