TypeScript
fix(server): let OpenCode generate session titles (#13368)
maco2679d279ce4b
diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.tsindex 254aec4bde7..87f9bd03d46 100644--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts@@ -891,8 +891,92 @@ describe("ProviderCommandReactor", () => {expect(thread?.session?.threadId).toBe("thread-1");expect(thread?.session?.status).toBe("starting");expect(thread?.session?.runtimeMode).toBe("approval-required");+ expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("title");});+ effectIt.effect("forwards only a user-renamed title when starting a provider session", () =>+ Effect.gen(function* () {+ const harness = yield* Effect.promise(() =>+ createHarness({ initialTitle: "Add a progressive blur as you scroll" }),+ );+ const now = "2026-01-01T00:00:00.000Z";+ const modelSelection = {+ instanceId: ProviderInstanceId.make("codex"),+ model: "gpt-5-codex",+ };+ const startTurn = (threadId: string, text: string, titleSeed: string) =>+ harness.engine.dispatch({+ type: "thread.turn.start",+ commandId: CommandId.make(`cmd-title-${threadId}`),+ threadId: ThreadId.make(threadId),+ message: {+ messageId: asMessageId(`message-${threadId}`),+ role: "user",+ text,+ attachments: [],+ },+ titleSeed,+ interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,+ runtimeMode: "approval-required",+ createdAt: now,+ });++ yield* startTurn(+ "thread-1",+ "Add a progressive blur as you scroll",+ "Add a progressive blur as you scroll",+ );+ yield* Effect.promise(() => waitFor(() => harness.startSession.mock.calls.length === 1));+ expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("title");++ yield* harness.engine.dispatch({+ type: "thread.create",+ commandId: CommandId.make("cmd-thread-create-renamed"),+ threadId: ThreadId.make("thread-renamed"),+ projectId: asProjectId("project-1"),+ title: "New thread",+ modelSelection,+ interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,+ runtimeMode: "approval-required",+ branch: null,+ worktreePath: null,+ createdAt: now,+ });+ yield* harness.engine.dispatch({+ type: "thread.meta.update",+ commandId: CommandId.make("cmd-thread-rename"),+ threadId: ThreadId.make("thread-renamed"),+ title: "Keep this name",+ });+ yield* startTurn("thread-renamed", "hello there", "hello there");+ yield* Effect.promise(() => waitFor(() => harness.startSession.mock.calls.length === 2));+ expect(harness.startSession.mock.calls[1]?.[1]).toMatchObject({ title: "Keep this name" });++ yield* harness.engine.dispatch({+ type: "thread.create",+ commandId: CommandId.make("cmd-thread-create-seeded"),+ threadId: ThreadId.make("thread-seeded"),+ projectId: asProjectId("project-1"),+ title: "New thread",+ modelSelection,+ interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,+ runtimeMode: "approval-required",+ branch: null,+ worktreePath: null,+ createdAt: now,+ });+ yield* harness.engine.dispatch({+ type: "thread.meta.update",+ commandId: CommandId.make("cmd-thread-autotitle"),+ threadId: ThreadId.make("thread-seeded"),+ title: "hello there",+ });+ yield* startTurn("thread-seeded", "hello there", "hello there");+ yield* Effect.promise(() => waitFor(() => harness.startSession.mock.calls.length === 3));+ expect(harness.startSession.mock.calls[2]?.[1]).not.toHaveProperty("title");+ }),+ );+effectIt.effect("projects inline context before sending the provider turn", () =>Effect.gen(function* () {const harness = yield* Effect.promise(() => createHarness());diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.tsindex f6794135a92..77022a8518d 100644--- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts+++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts@@ -575,6 +575,9 @@ const make = Effect.gen(function* () {options?: {readonly modelSelection?: ModelSelection;readonly pendingTurnStart?: boolean;+ // First-turn prompt seed. A manual title that still equals this seed was+ // written by the client's auto-title, not a user rename.+ readonly titleSeed?: string;},) {const thread = yield* resolveThreadShell(threadId);@@ -712,6 +715,15 @@ const make = Effect.gen(function* () {.refreshWorkspaceSnapshot({ instanceId: desiredInstanceId, cwd: effectiveCwd }).pipe(Effect.forkDetach): Effect.void;+ // OpenCode skips SessionPrompt.ensureTitle when session.create already has+ // a title. Prompt seeds and "New thread" are not user titles, so omit them+ // and let the provider generate one. A real rename is source "manual" and+ // differs from the first-turn prompt seed (the web client writes that seed+ // through thread.meta.update, which also marks the title manual).+ const manualTitle = thread.titleState?.source === "manual" ? thread.title.trim() : "";+ const promptSeed = options?.titleSeed?.trim();+ const sessionTitle =+ manualTitle.length > 0 && manualTitle !== promptSeed ? thread.title : undefined;const startProviderSession = (input?: {readonly resumeCursor?: unknown;@@ -723,7 +735,7 @@ const make = Effect.gen(function* () {...(preferredProvider ? { provider: preferredProvider } : {}),providerInstanceId: desiredInstanceId,...(effectiveCwd ? { cwd: effectiveCwd } : {}),- ...(thread.title ? { title: thread.title } : {}),+ ...(sessionTitle ? { title: sessionTitle } : {}),modelSelection: desiredModelSelection,...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),runtimeMode: desiredRuntimeMode,@@ -839,6 +851,7 @@ const make = Effect.gen(function* () {readonly modelSelection?: ModelSelection;readonly interactionMode?: "default" | "plan";readonly createdAt: string;+ readonly titleSeed?: string;}) {const thread = yield* resolveThreadShell(input.threadId);if (!thread) {@@ -848,6 +861,7 @@ const make = Effect.gen(function* () {}yield* ensureSessionForThread(input.threadId, input.createdAt, {...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),+ ...(input.titleSeed !== undefined ? { titleSeed: input.titleSeed } : {}),pendingTurnStart: true,});if (input.modelSelection !== undefined) {@@ -1488,6 +1502,11 @@ const make = Effect.gen(function* () {: {}),interactionMode: event.payload.interactionMode,createdAt: event.payload.createdAt,+ // Later turns must not reuse the current title as titleSeed. Only the+ // first prompt seed should suppress a not-yet-renamed session title.+ ...(!hasOtherUserMessages && event.payload.titleSeed !== undefined+ ? { titleSeed: event.payload.titleSeed }+ : {}),}).pipe(Effect.asSome,Effect.catchCause((cause) => handleTurnStartFailure(cause).pipe(Effect.as(Option.none()))),