The best way to control Claude Code, Codex and more from any computer or phone
fix(server): keep a launched thread's title when its first message arrives (#35117)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Noah committed
Nov 15, 2026 at 03:03 UTC
4d47d0b76eca2af12a202e7da9349514538f13fe
5 files changed
+93
-7
apps/server/src/mcp/OrchestratorMcpService.ts
+2
-1
@@ -108,6 +108,7 @@ import {
108
runOutcome,
109
} from "../orchestration-v2/RestartBackgroundNote.ts";
110
import * as ThreadManagementService from "../orchestration-v2/ThreadManagementService.ts";
111
+import { placeholderThreadTitle } from "../orchestration-v2/placeholderThreadTitle.ts";
112
import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
113
import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
114
import { isSnoozed } from "../orchestration-v2/ThreadSettlementService.ts";
@@ -778,7 +779,7 @@ function threadTitle(input: {
779
readonly index: number;
780
}): string {
781
const detail = input.title?.trim() || input.prompt?.trim();
781
- if (!detail) return `${input.parentTitle} thread ${input.index + 1}`;
782
+ if (!detail) return placeholderThreadTitle(input.parentTitle, input.index);
783
if (detail.length <= 80) return detail;
784
let end = 77;
785
const previous = detail.charCodeAt(end - 1);
apps/server/src/orchestration-v2/Orchestrator.ts
+27
-5
@@ -82,6 +82,7 @@ import {
82
import * as KeyedLock from "@t3tools/shared/KeyedLock";
83
import { modelSelectionsEqual } from "@t3tools/shared/model";
84
import { modelSwitchSince } from "./modelSwitch.ts";
85
+import { isPlaceholderThreadTitle } from "./placeholderThreadTitle.ts";
86
import { combinePullRequestWatchWakes, type PullRequestWatchWake } from "./pullRequestWatch.ts";
87
import { recordThreadOpen } from "@t3tools/shared/paletteSearch";
88
import {
@@ -722,6 +723,24 @@ function pendingThreadTitleGenerationEffect(
723
};
724
}
725
726
+// Clients seed a new thread with its first message, and empty threads start as "New thread" or
727
+// an agent's placeholder. Any other title on a thread without messages was chosen on purpose.
728
+// Forks and side chats are titled from their source history instead.
729
+function hasTitleSetBeforeFirstMessage(
730
+ thread: OrchestrationV2AppThread,
731
+ titleSeed: string | undefined,
732
+): boolean {
733
+ const title = thread.title.trim();
734
+ return (
735
+ thread.forkedFrom === null &&
736
+ thread.lineage.sideChat !== true &&
737
+ title.length > 0 &&
738
+ title !== "New thread" &&
739
+ !isPlaceholderThreadTitle(title) &&
740
+ title !== titleSeed?.trim()
741
+ );
742
+}
743
+
744
function delegatedTasksStopEffect(command: {
745
readonly commandId: CommandId;
746
readonly threadId: ThreadId;
@@ -6956,13 +6975,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6975
mapDispatchError(command),
6976
)
6977
: Effect.succeed(false);
6978
+ // A thread named before its first message (for example by an MCP launch that tracks an issue)
6979
+ // keeps that name instead of a title generated from a terse prompt such as "work on this".
6980
+ const seedsUntitledThread =
6981
+ command.titleSeed !== undefined &&
6982
+ (yield* projectionStore.getMessageCount(command.threadId).pipe(mapDispatchError(command))) ===
6983
+ 0 &&
6984
+ !hasTitleSetBeforeFirstMessage(projection.thread, command.titleSeed);
6985
if (
6986
!isNativeMaintenanceCommand(command) &&
6961
- ((command.titleSeed !== undefined &&
6962
- (yield* projectionStore
6963
- .getMessageCount(command.threadId)
6964
- .pipe(mapDispatchError(command))) === 0) ||
6965
- (command.createdBy === "user" && (yield* onlyMaintenanceHistory)))
6987
+ (seedsUntitledThread || (command.createdBy === "user" && (yield* onlyMaintenanceHistory)))
6988
) {
6989
const now = yield* DateTime.now;
6990
const thread: OrchestrationV2AppThread = {
apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts
+57
@@ -34,6 +34,7 @@ import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
34
import * as ThreadManagement from "./ThreadManagementService.ts";
35
import * as ThreadTitleRegeneration from "./ThreadTitleRegenerationService.ts";
36
import * as ProviderReplayHarness from "./testkit/ProviderReplayHarness.ts";
37
+import { placeholderThreadTitle } from "./placeholderThreadTitle.ts";
38
import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
39
40
const projectId = ProjectId.make("project:title-regeneration");
@@ -333,6 +334,62 @@ describe("formatThreadTitleContext", () => {
334
});
335
336
describe("ThreadTitleRegenerationService", () => {
337
+ it.effect("keeps a title set before the first message unless it is a placeholder", () =>
338
+ Effect.gen(function* () {
339
+ const seed = "work on this and pr to dev";
340
+ const harness = makeHarness();
341
+ yield* Effect.gen(function* () {
342
+ const threads = yield* ThreadManagement.ThreadManagementService;
343
+ const outbox = yield* EffectOutbox.EffectOutboxV2;
344
+ // An MCP launch names the thread, or leaves a placeholder, and sends no message.
345
+ for (const [key, title, expectedTitle, generates] of [
346
+ ["preset", "[API] #4821 — retry webhook deliveries after a timeout", undefined, false],
347
+ ["placeholder", placeholderThreadTitle("Parent", 0), seed, true],
348
+ ] as const) {
349
+ const threadId = ThreadId.make(`thread:title:${key}`);
350
+ yield* threads.dispatch({
351
+ type: "thread.create",
352
+ commandId: CommandId.make(`command:title:${key}:create`),
353
+ threadId,
354
+ projectId,
355
+ title,
356
+ modelSelection,
357
+ runtimeMode: "full-access",
358
+ interactionMode: "default",
359
+ branch: null,
360
+ worktreePath: null,
361
+ createdBy: "agent",
362
+ creationSource: "mcp",
363
+ });
364
+ const requestId = CommandId.make(`command:title:${key}:message`);
365
+ yield* threads.dispatch({
366
+ type: "message.dispatch",
367
+ commandId: requestId,
368
+ threadId,
369
+ messageId: MessageId.make(`command:title:${key}:message:message`),
370
+ text: seed,
371
+ titleSeed: seed,
372
+ attachments: [],
373
+ modelSelection,
374
+ dispatchMode: { type: "defer_start" },
375
+ createdBy: "user",
376
+ creationSource: "web",
377
+ });
378
+
379
+ const settled = yield* threads.getThreadProjection(threadId);
380
+ assert.equal(settled.thread.title, expectedTitle ?? title, key);
381
+ assert.equal(
382
+ (yield* outbox.listByCommandId(requestId)).some(
383
+ (effect) => effect.request.type === "thread-title.generate",
384
+ ),
385
+ generates,
386
+ key,
387
+ );
388
+ }
389
+ }).pipe(Effect.provide(harness.layer));
390
+ }),
391
+ );
392
+
393
it.effect(
394
"titles an image-only first message without sending bootstrap text to the title model",
395
() =>
apps/server/src/orchestration-v2/placeholderThreadTitle.ts
new
+6
@@ -0,0 +1,6 @@
1
+// An agent may create a thread with neither a title nor a prompt; its name is then a placeholder
2
+// that the first message should replace, unlike a title the caller chose.
3
+export const placeholderThreadTitle = (parentTitle: string, index: number): string =>
4
+ `${parentTitle} thread ${index + 1}`;
5
+
6
+export const isPlaceholderThreadTitle = (title: string): boolean => / thread \d+$/u.test(title);
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+1
-1
@@ -10213,7 +10213,7 @@ it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
10213
commandId: CommandId.make("runtime-layer-snoozed-thread-create"),
10214
threadId,
10215
projectId,
10216
- title: "Snoozed thread",
10216
+ title: "New thread",
10217
modelSelection,
10218
runtimeMode: "full-access",
10219
interactionMode: "default",