@devries-cameron20 / t3code Mirror · read-only / commits / 6071022cb7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 11:00 UTC

fix(server): Claude session name follows thread renames without waiting for the next turn (#37185)

Julius Marminge committed Nov 15, 2026 at 04:52 UTC 6071022cb71b92c761bc06aabff6865243fa956c
9 files changed +248 -18
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+37 -18
@@ -6390,6 +6390,28 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
6390 );
6391 });
6392
6393 + // `claude --resume` shows the native title. A failed or timed-out rename forgets the
6394 + // applied title so the next turn, even after a restart, sends it again.
6395 + const applySessionTitle = Effect.fn("ClaudeAdapterV2.applySessionTitle")(function* (
6396 + query: ClaudeAgentSdkQuerySession,
6397 + nativeThreadId: string,
6398 + title: string,
6399 + ) {
6400 + if (appliedSessionTitles.get(nativeThreadId) === title) return;
6401 + const renamed = yield* query
6402 + .renameSession(title)
6403 + .pipe(Effect.timeout("10 seconds"), Effect.isSuccess);
6404 + if (renamed) {
6405 + appliedSessionTitles.set(nativeThreadId, title);
6406 + } else {
6407 + appliedSessionTitles.delete(nativeThreadId);
6408 + }
6409 + const remembered = (yield* Ref.get(lastProviderThreadByNativeThread)).get(nativeThreadId);
6410 + if (remembered !== undefined) {
6411 + yield* rememberProviderThread(remembered);
6412 + }
6413 + });
6414 +
6415 const rosterForNativeThread = (
6416 all: ReadonlyMap<string, Map<string, OrchestrationV2PendingBackgroundTask>>,
6417 nativeThreadId: string,
@@ -13029,24 +13051,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
13051 Effect.provideService(Path.Path, path),
13052 );
13053 const querySession = yield* openQuery(turnInput, nativeThreadId, queryPolicy);
13032 - // `claude --resume` shows the native title. A failed or timed-out rename forgets the
13033 - // applied title so the next turn, even after a restart, sends it again.
13034 - if (appliedSessionTitles.get(nativeThreadId) !== turnInput.appThread.title) {
13035 - const renamed = yield* querySession.query
13036 - .renameSession(turnInput.appThread.title)
13037 - .pipe(Effect.timeout("10 seconds"), Effect.isSuccess);
13038 - if (renamed) {
13039 - appliedSessionTitles.set(nativeThreadId, turnInput.appThread.title);
13040 - } else {
13041 - appliedSessionTitles.delete(nativeThreadId);
13042 - }
13043 - const remembered = (yield* Ref.get(lastProviderThreadByNativeThread)).get(
13044 - nativeThreadId,
13045 - );
13046 - if (remembered !== undefined) {
13047 - yield* rememberProviderThread(remembered);
13048 - }
13049 - }
13054 + yield* applySessionTitle(querySession.query, nativeThreadId, turnInput.appThread.title);
13055 const autoCompactWindow = yield* resolveAutoCompactWindow(
13056 querySession.settingsCwd,
13057 turnInput.modelSelection,
@@ -14029,6 +14034,20 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
14034 ),
14035 );
14036 }),
14037 + applyThreadTitle: Effect.fn("ClaudeAdapterV2.applyThreadTitle")(function* ({
14038 + providerThread,
14039 + title,
14040 + }) {
14041 + const live = yield* Ref.get(queryContext);
14042 + if (
14043 + live === null ||
14044 + live.stopping ||
14045 + live.nativeThreadId !== providerThread.nativeThreadRef?.nativeId
14046 + ) {
14047 + return;
14048 + }
14049 + yield* applySessionTitle(live.query, live.nativeThreadId, title);
14050 + }),
14051 stopTask: Effect.fn("ClaudeAdapterV2.stopTask")(function* ({ providerThread, taskId }) {
14052 const liveQuery = yield* Ref.get(queryContext);
14053 const task = (yield* Ref.get(sessionSubagentsByTaskId)).get(taskId);
apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts
+147
@@ -607,6 +607,153 @@ it.effect("applies an effort change to the running Claude query without waiting
607 ),
608 );
609
610 +const renamedClaudeSessionTitles = (options: { readonly renameDuringStartup: boolean }) =>
611 + Effect.gen(function* () {
612 + const cwd = yield* checkpointWorkspace("claude-live-rename");
613 + const sdkMessages = yield* Queue.unbounded<SDKMessage>();
614 + const renames: string[] = [];
615 + const startupEntered = yield* Deferred.make<void>();
616 + const startupReleased = yield* Deferred.make<void>();
617 + const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
618 + instanceId: modelSelection.instanceId,
619 + settings,
620 + environment: {},
621 + attachmentsDir: cwd,
622 + fileSystem: yield* FileSystem.FileSystem,
623 + path: yield* Path.Path,
624 + random: yield* SecureRandom.SecureRandom,
625 + idAllocator: yield* IdAllocator.IdAllocatorV2,
626 + queryRunner: {
627 + allocateSessionId: Effect.succeed(sessionId),
628 + open: () =>
629 + Effect.succeed({
630 + messages: Stream.fromQueue(sdkMessages),
631 + offer: () => Effect.void,
632 + setModel: () => Effect.void,
633 + applyFlagSettings: () => Effect.void,
634 + setPermissionMode: () => Effect.void,
635 + renameSession: (title) =>
636 + Effect.sync(() => {
637 + renames.push(title);
638 + }),
639 + backgroundTasks: () => Effect.succeed(false),
640 + mcpServerStatus: Effect.succeed([]),
641 + readMcpResource: () => Effect.die("unexpected MCP resource read"),
642 + callMcpTool: () => Effect.die("unexpected MCP tool call"),
643 + listPermissionRules: Effect.die("unexpected permission rules read"),
644 + stopTask: () => Effect.void,
645 + interrupt: Effect.die("a rename must not interrupt the turn"),
646 + close: Effect.void,
647 + }),
648 + forkSession: () => Effect.die("unused"),
649 + subagentLaunchToolUseId: () => Effect.succeed(null),
650 + subagentModel: () => Effect.succeed(null),
651 + assertComplete: Effect.void,
652 + },
653 + });
654 + return yield* Effect.gen(function* () {
655 + const orchestrator = yield* Orchestrator.OrchestratorV2;
656 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
657 + const threadId = ThreadId.make("thread:live-rename");
658 + const running = yield* orchestrator.streamDomainEvents.pipe(
659 + Stream.filter(
660 + (event) => event.type === "provider-turn.updated" && event.payload.status === "running",
661 + ),
662 + Stream.take(1),
663 + Stream.runDrain,
664 + Effect.forkScoped,
665 + );
666 + yield* orchestrator.dispatch({
667 + type: "thread.create",
668 + commandId: CommandId.make("create"),
669 + threadId,
670 + projectId: ProjectId.make("project:live-rename"),
671 + title: "Seed title",
672 + modelSelection,
673 + runtimeMode: "full-access",
674 + interactionMode: "default",
675 + branch: null,
676 + worktreePath: cwd,
677 + createdBy: "user",
678 + creationSource: "web",
679 + });
680 + yield* orchestrator.dispatch({
681 + type: "message.dispatch",
682 + commandId: CommandId.make("first"),
683 + threadId,
684 + messageId: MessageId.make("first"),
685 + text: "Keep working.",
686 + attachments: [],
687 + dispatchMode: { type: "start_immediately" },
688 + createdBy: "user",
689 + creationSource: "web",
690 + });
691 + const rename = orchestrator.dispatch({
692 + type: "thread.metadata.update",
693 + commandId: CommandId.make("rename"),
694 + threadId,
695 + title: "Renamed title",
696 + });
697 + if (options.renameDuringStartup) {
698 + const starting = yield* worker.drain().pipe(Effect.forkScoped);
699 + yield* Deferred.await(startupEntered);
700 + yield* rename;
701 + yield* Deferred.succeed(startupReleased, undefined);
702 + yield* Fiber.join(starting);
703 + yield* Fiber.join(running);
704 + } else {
705 + yield* worker.drain();
706 + yield* Fiber.join(running);
707 + assert.deepEqual(renames, []);
708 + yield* rename;
709 + }
710 + yield* worker.drain();
711 + return renames;
712 + }).pipe(
713 + Effect.provide(
714 + ProviderReplayHarness.layerWithRegistry(
715 + { name: "claude-live-rename" },
716 + ProviderAdapterRegistry.layerSingle({
717 + ...adapter,
718 + openSession: (input) =>
719 + options.renameDuringStartup
720 + ? Deferred.succeed(startupEntered, undefined).pipe(
721 + Effect.andThen(Deferred.await(startupReleased)),
722 + Effect.andThen(adapter.openSession(input)),
723 + )
724 + : adapter.openSession(input),
725 + }),
726 + { runEffectWorker: false },
727 + ),
728 + ),
729 + );
730 + }).pipe(
731 + Effect.provide(
732 + Layer.mergeAll(
733 + IdAllocator.layer,
734 + McpProviderSessions.layer,
735 + NodeServices.layer,
736 + NodeCrypto.layer,
737 + ),
738 + ),
739 + );
740 +
741 +it.effect("renames the running Claude session when the thread is renamed mid-turn", () =>
742 + Effect.gen(function* () {
743 + assert.deepEqual(yield* renamedClaudeSessionTitles({ renameDuringStartup: false }), [
744 + "Renamed title",
745 + ]);
746 + }),
747 +);
748 +
749 +it.effect("renames the Claude session when the thread is renamed while it starts", () =>
750 + Effect.gen(function* () {
751 + assert.deepEqual(yield* renamedClaudeSessionTitles({ renameDuringStartup: true }), [
752 + "Renamed title",
753 + ]);
754 + }),
755 +);
756 +
757 const backgroundTaskStarted = (taskId: string) =>
758 frame({
759 type: "system",
apps/server/src/orchestration-v2/EffectOutbox.ts
+5
@@ -50,6 +50,10 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
50 providerThreadId: ProviderThreadId,
51 modelSelection: ModelSelection,
52 }),
53 + Schema.Struct({
54 + type: Schema.Literal("provider-session.apply-thread-title"),
55 + title: Schema.String,
56 + }),
57 Schema.Struct({
58 type: Schema.Literal("provider-turn.start"),
59 runId: RunId,
@@ -150,6 +154,7 @@ export const REPLAY_SAFE_EFFECT_TYPES_AFTER_PROCESS_LOSS = [
154
155 export const PROCESS_BOUND_EFFECT_TYPES = [
156 "provider-session.apply-model-selection",
157 + "provider-session.apply-thread-title",
158 "provider-turn.start",
159 "provider-turn.interrupt",
160 "provider-turn.steer",
apps/server/src/orchestration-v2/EffectWorker.test.ts
+1
@@ -102,6 +102,7 @@ function layerExecutorFor(input: {
102 interrupt: input.interrupt ?? (() => Effect.void),
103 steer: () => Effect.void,
104 applyModelSelection: () => Effect.void,
105 + applyThreadTitle: () => Effect.void,
106 interruptAndAwaitTerminal: (request) =>
107 record(
108 request.replacementProviderSessionId === undefined
apps/server/src/orchestration-v2/EffectWorker.ts
+13
@@ -222,6 +222,19 @@ export const layerExecutor: Layer.Layer<
222 }),
223 ),
224 );
225 + case "provider-session.apply-thread-title":
226 + return providerTurnControl
227 + .applyThreadTitle({ threadId: effect.threadId, title: effect.request.title })
228 + .pipe(
229 + Effect.mapError(
230 + (cause) =>
231 + new OrchestrationEffectExecutionError({
232 + effectId: effect.id,
233 + effectType: effect.request.type,
234 + cause,
235 + }),
236 + ),
237 + );
238 case "provider-turn.start":
239 return startRun(effect, effect.request.runId, willRetry).pipe(
240 Effect.mapError(
apps/server/src/orchestration-v2/Orchestrator.ts
+17
@@ -5312,6 +5312,23 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5312 }
5313 }
5314
5315 + // Queued even while no session is live: it runs after any in-flight turn start publishes one.
5316 + if (
5317 + (command.type === "thread.metadata.update" ||
5318 + command.type === "thread.title.regeneration.complete") &&
5319 + updatedThread.title !== thread.title
5320 + ) {
5321 + yield* Ref.update(effects, (existing) => [
5322 + ...existing,
5323 + {
5324 + id: `effect:${command.commandId}:provider-session.apply-thread-title`,
5325 + commandId: command.commandId,
5326 + threadId: command.threadId,
5327 + request: { type: "provider-session.apply-thread-title", title: updatedThread.title },
5328 + } satisfies PendingOrchestrationEffectV2,
5329 + ]);
5330 + }
5331 +
5332 if (command.type === "thread.metadata.update" && command.regenerateTitle === true) {
5333 yield* Ref.update(effects, (existing) => [
5334 ...existing,
apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.test.ts
+1
@@ -901,6 +901,7 @@ it.effect(
901 assert.equal(summary.retiredEffects, 2);
902 assert.deepEqual(committedInput?.cancelUnsettledEffects?.effectTypes, [
903 "provider-session.apply-model-selection",
904 + "provider-session.apply-thread-title",
905 "provider-turn.start",
906 "provider-turn.interrupt",
907 "provider-turn.steer",
apps/server/src/orchestration-v2/ProviderTurnControlService.ts
+22
@@ -84,6 +84,16 @@ export interface ProviderTurnControlServiceV2Shape {
84 | ProviderSessionManager.ProviderSessionManagerV2Error
85 | ProviderAdapter.ProviderAdapterV2Error
86 >;
87 + /** Best effort: a provider thread that is no longer live picks the title up when its next turn starts. */
88 + readonly applyThreadTitle: (input: {
89 + readonly threadId: ThreadId;
90 + readonly title: string;
91 + }) => Effect.Effect<
92 + void,
93 + | ProjectionStore.ProjectionStoreV2Error
94 + | ProviderSessionManager.ProviderSessionManagerV2Error
95 + | ProviderAdapter.ProviderAdapterV2Error
96 + >;
97 readonly interruptAndAwaitTerminal: (input: {
98 readonly threadId: ThreadId;
99 readonly providerSessionId: ProviderSessionId;
@@ -249,6 +259,18 @@ export const layer: Layer.Layer<
259 });
260 },
261 ),
262 + applyThreadTitle: Effect.fn("ProviderTurnControlService.applyThreadTitle")(function* (input) {
263 + const { thread, providerThreads } = yield* projections.getThreadRecords(input.threadId, [
264 + "providerThreads",
265 + ]);
266 + const providerThread = providerThreads.find(
267 + (candidate) => candidate.id === thread.activeProviderThreadId,
268 + );
269 + if (!providerThread?.providerSessionId) return;
270 + const session = yield* sessions.get(providerThread.providerSessionId);
271 + if (Option.isNone(session) || session.value.applyThreadTitle === undefined) return;
272 + yield* session.value.applyThreadTitle({ providerThread, title: input.title });
273 + }),
274 interrupt: Effect.fn("ProviderTurnControlService.interrupt")(
275 function* (input) {
276 const loaded = yield* load({ ...input, operation: "interrupt" });
packages/provider-core/src/server/ProviderAdapter.ts
+5
@@ -750,6 +750,11 @@ export interface ProviderAdapterV2SessionRuntime {
750 readonly providerThread: OrchestrationV2ProviderThread;
751 readonly modelSelection: ModelSelection;
752 }) => Effect.Effect<void, ProviderAdapterV2Error>;
753 + /** Renames the provider's native session while its process is running; otherwise the next turn does. */
754 + readonly applyThreadTitle?: (input: {
755 + readonly providerThread: OrchestrationV2ProviderThread;
756 + readonly title: string;
757 + }) => Effect.Effect<void, ProviderAdapterV2Error>;
758 readonly stopTask?: (input: {
759 readonly providerThread: OrchestrationV2ProviderThread;
760 readonly taskId: string;