diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 5ae9f321286..9b657a32b95 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -308,7 +308,7 @@ const layer = Layer.effect( subpath: RelativePath.make(path.relative(project.directory, location.directory).replaceAll("\\", "/")), title: input.title, agent: input.agent, - // Placement overrides do not change the inherited host policies. + // Children inherit metadata and permissions even when placed at another location. metadata: input.metadata ?? parent?.metadata, permissions: input.permissions ?? parent?.permissions, model: input.model, diff --git a/packages/protocol/openapi.json b/packages/protocol/openapi.json index 850e46cd3c5..f867cfd7be3 100644 --- a/packages/protocol/openapi.json +++ b/packages/protocol/openapi.json @@ -1059,7 +1059,7 @@ } } }, - "description": "Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's location. An explicit location takes precedence. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.", + "description": "Create a session at the requested location. A parentID creates a linked child session; when location is omitted, the child inherits its parent's full location. An explicit location takes precedence. The public location is directory-only: supplying it selects local placement, even when the directory matches a parent with an internal workspace ID. Metadata and permissions still inherit when omitted. List by parentID without a directory filter to include children in other locations.", "summary": "Create session", "requestBody": { "content": { diff --git a/packages/protocol/src/groups/session.ts b/packages/protocol/src/groups/session.ts index 8117bedf536..acfa9f2f8ef 100644 --- a/packages/protocol/src/groups/session.ts +++ b/packages/protocol/src/groups/session.ts @@ -180,7 +180,7 @@ export const makeSessionGroup = + Effect.gen(function* () { + const tmp = yield* tmpdirScoped() + const context = yield* Layer.build( + createEmbeddedRoutes({ + app: { version: "test" }, + database: { path: ":memory:" }, + fs: { filewatcher: false }, + }).pipe(Layer.provide(HttpServer.layerServices)), + ) + const sessions = Context.get(context, Session.Service) + const handler = Context.get(context, HttpRouter.HttpRouter) + .asHttpEffect() + .pipe(HttpEffect.toWebHandlerWith(context)) + const parent = yield* sessions.create({ + location: { directory: AbsolutePath.make(tmp.path), workspaceID: Workspace.ID.make("wrk_parent") }, + }) + const create = (location?: { directory: string }) => + Effect.promise(async () => { + const response = await handler( + new Request("http://opencode.local/api/session", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ parentID: parent.id, location }), + }), + ) + expect(response.status).toBe(200) + return Session.ID.make(Schema.decodeUnknownSync(SessionResponse)(await response.json()).data.id) + }) + const inherited = yield* sessions.get(yield* create()) + const explicit = yield* sessions.get(yield* create({ directory: `${tmp.path}${path.sep}` })) + expect(inherited.location).toEqual(parent.location) + expect(explicit.location.directory).toBe(parent.location.directory) + expect(explicit.location.workspaceID).toBeUndefined() + }).pipe(Effect.scoped), +) + it.live("creates a child at its parent's location and lists it under the parent", () => Effect.gen(function* () { + const tmp = yield* tmpdirScoped() const handler = yield* ServerFetch.make({ app: { version: "test" }, database: { path: ":memory:" }, @@ -29,7 +71,7 @@ it.live("creates a child at its parent's location and lists it under the parent" expect(response.status).toBe(200) return Schema.decodeUnknownSync(SessionResponse)(await response.json()).data }) - const parent = yield* create({ title: "Parent" }) + const parent = yield* create({ title: "Parent", location: { directory: tmp.path } }) const child = yield* create({ parentID: parent.id, title: "Child" }) const response = yield* Effect.promise(() => handler(new Request(`http://opencode.local/api/session?parentID=${parent.id}`)),