Skip to content

Commit 76cd8de

Browse files
committed
fix(server): let OpenCode generate session titles
OpenCode skips SessionPrompt.ensureTitle when session.create already has a title. T3 was sending the prompt seed, so those sessions never got a generated title. Only a user rename is forwarded now. Fixes #13247
1 parent e67abcf commit 76cd8de

3 files changed

Lines changed: 112 additions & 1 deletion

File tree

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,96 @@ describe("ProviderCommandReactor", () => {
887887
expect(thread?.session?.threadId).toBe("thread-1");
888888
expect(thread?.session?.status).toBe("starting");
889889
expect(thread?.session?.runtimeMode).toBe("approval-required");
890+
expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("title");
891+
});
892+
893+
it("forwards only a user-renamed title when starting a provider session", async () => {
894+
const harness = await createHarness({ initialTitle: "Add a progressive blur as you scroll" });
895+
const now = "2026-01-01T00:00:00.000Z";
896+
const modelSelection = {
897+
instanceId: ProviderInstanceId.make("codex"),
898+
model: "gpt-5-codex",
899+
};
900+
const startTurn = (threadId: string, text: string, titleSeed: string) =>
901+
Effect.runPromise(
902+
harness.engine.dispatch({
903+
type: "thread.turn.start",
904+
commandId: CommandId.make(`cmd-title-${threadId}`),
905+
threadId: ThreadId.make(threadId),
906+
message: {
907+
messageId: asMessageId(`message-${threadId}`),
908+
role: "user",
909+
text,
910+
attachments: [],
911+
},
912+
titleSeed,
913+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
914+
runtimeMode: "approval-required",
915+
createdAt: now,
916+
}),
917+
);
918+
919+
await startTurn(
920+
"thread-1",
921+
"Add a progressive blur as you scroll",
922+
"Add a progressive blur as you scroll",
923+
);
924+
await waitFor(() => harness.startSession.mock.calls.length === 1);
925+
expect(harness.startSession.mock.calls[0]?.[1]).not.toHaveProperty("title");
926+
927+
await Effect.runPromise(
928+
harness.engine.dispatch({
929+
type: "thread.create",
930+
commandId: CommandId.make("cmd-thread-create-renamed"),
931+
threadId: ThreadId.make("thread-renamed"),
932+
projectId: ProjectId.make("project-1"),
933+
title: "New thread",
934+
modelSelection,
935+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
936+
runtimeMode: "approval-required",
937+
branch: null,
938+
worktreePath: null,
939+
createdAt: now,
940+
}),
941+
);
942+
await Effect.runPromise(
943+
harness.engine.dispatch({
944+
type: "thread.meta.update",
945+
commandId: CommandId.make("cmd-thread-rename"),
946+
threadId: ThreadId.make("thread-renamed"),
947+
title: "Keep this name",
948+
}),
949+
);
950+
await startTurn("thread-renamed", "hello there", "hello there");
951+
await waitFor(() => harness.startSession.mock.calls.length === 2);
952+
expect(harness.startSession.mock.calls[1]?.[1]).toMatchObject({ title: "Keep this name" });
953+
954+
await Effect.runPromise(
955+
harness.engine.dispatch({
956+
type: "thread.create",
957+
commandId: CommandId.make("cmd-thread-create-seeded"),
958+
threadId: ThreadId.make("thread-seeded"),
959+
projectId: ProjectId.make("project-1"),
960+
title: "New thread",
961+
modelSelection,
962+
interactionMode: DEFAULT_PROVIDER_INTERACTION_MODE,
963+
runtimeMode: "approval-required",
964+
branch: null,
965+
worktreePath: null,
966+
createdAt: now,
967+
}),
968+
);
969+
await Effect.runPromise(
970+
harness.engine.dispatch({
971+
type: "thread.meta.update",
972+
commandId: CommandId.make("cmd-thread-autotitle"),
973+
threadId: ThreadId.make("thread-seeded"),
974+
title: "hello there",
975+
}),
976+
);
977+
await startTurn("thread-seeded", "hello there", "hello there");
978+
await waitFor(() => harness.startSession.mock.calls.length === 3);
979+
expect(harness.startSession.mock.calls[2]?.[1]).not.toHaveProperty("title");
890980
});
891981

892982
effectIt.effect("projects inline context before sending the provider turn", () =>

‎apps/server/src/orchestration/Layers/ProviderCommandReactor.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ const make = Effect.gen(function* () {
573573
options?: {
574574
readonly modelSelection?: ModelSelection;
575575
readonly pendingTurnStart?: boolean;
576+
// First-turn prompt seed. A manual title that still equals this seed was
577+
// written by the client's auto-title, not a user rename.
578+
readonly titleSeed?: string;
576579
},
577580
) {
578581
const thread = yield* resolveThreadShell(threadId);
@@ -710,6 +713,15 @@ const make = Effect.gen(function* () {
710713
.refreshWorkspaceSnapshot({ instanceId: desiredInstanceId, cwd: effectiveCwd })
711714
.pipe(Effect.forkDetach)
712715
: Effect.void;
716+
// OpenCode skips SessionPrompt.ensureTitle when session.create already has
717+
// a title. Prompt seeds and "New thread" are not user titles, so omit them
718+
// and let the provider generate one. A real rename is source "manual" and
719+
// differs from the first-turn prompt seed (the web client writes that seed
720+
// through thread.meta.update, which also marks the title manual).
721+
const manualTitle = thread.titleState?.source === "manual" ? thread.title.trim() : "";
722+
const promptSeed = options?.titleSeed?.trim();
723+
const sessionTitle =
724+
manualTitle.length > 0 && manualTitle !== promptSeed ? thread.title : undefined;
713725

714726
const startProviderSession = (input?: {
715727
readonly resumeCursor?: unknown;
@@ -721,7 +733,7 @@ const make = Effect.gen(function* () {
721733
...(preferredProvider ? { provider: preferredProvider } : {}),
722734
providerInstanceId: desiredInstanceId,
723735
...(effectiveCwd ? { cwd: effectiveCwd } : {}),
724-
...(thread.title ? { title: thread.title } : {}),
736+
...(sessionTitle ? { title: sessionTitle } : {}),
725737
modelSelection: desiredModelSelection,
726738
...(input?.resumeCursor !== undefined ? { resumeCursor: input.resumeCursor } : {}),
727739
runtimeMode: desiredRuntimeMode,
@@ -837,6 +849,7 @@ const make = Effect.gen(function* () {
837849
readonly modelSelection?: ModelSelection;
838850
readonly interactionMode?: "default" | "plan";
839851
readonly createdAt: string;
852+
readonly titleSeed?: string;
840853
}) {
841854
const thread = yield* resolveThreadShell(input.threadId);
842855
if (!thread) {
@@ -846,6 +859,7 @@ const make = Effect.gen(function* () {
846859
}
847860
yield* ensureSessionForThread(input.threadId, input.createdAt, {
848861
...(input.modelSelection !== undefined ? { modelSelection: input.modelSelection } : {}),
862+
...(input.titleSeed !== undefined ? { titleSeed: input.titleSeed } : {}),
849863
pendingTurnStart: true,
850864
});
851865
if (input.modelSelection !== undefined) {
@@ -1495,6 +1509,11 @@ const make = Effect.gen(function* () {
14951509
: {}),
14961510
interactionMode: event.payload.interactionMode,
14971511
createdAt: event.payload.createdAt,
1512+
// Later turns reuse the current title as titleSeed. Only the first
1513+
// prompt seed should suppress a not-yet-renamed session title.
1514+
...(!hasOtherUserMessages && event.payload.titleSeed !== undefined
1515+
? { titleSeed: event.payload.titleSeed }
1516+
: {}),
14981517
}).pipe(
14991518
Effect.map(Option.some),
15001519
Effect.catchCause((cause) => handleTurnStartFailure(cause).pipe(Effect.as(Option.none()))),

‎apps/server/src/provider/Layers/OpenCodeAdapter.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2953,6 +2953,8 @@ export function makeOpenCodeAdapter(
29532953
}
29542954
const createdSession = yield* runOpenCodeSdk("session.create", () =>
29552955
client.session.create({
2956+
// A title here makes OpenCode skip SessionPrompt.ensureTitle.
2957+
// Callers pass one only for a user rename; prompt seeds stay omitted.
29562958
...(input.title ? { title: input.title } : {}),
29572959
permission: buildOpenCodePermissionRules(input.runtimeMode),
29582960
}),

0 commit comments

Comments
 (0)