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, 19:45 UTC
fix(clients): report title regeneration outcomes (#31418)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Yash Singh <saiansh2525@gmail.com>
oliver committed
Nov 12, 2026 at 11:44 UTC
1c9ea568a14d2e9fb17e5faedf0403a660465a9e
19 files changed
+549
-78
apps/mobile/src/features/home/useThreadListActions.test.ts
+16
-2
@@ -7,6 +7,7 @@ import {
7
ProviderInstanceId,
8
RunId,
9
ThreadId,
10
+ type ThreadTitleRegenerationOutcome,
11
} from "@t3tools/contracts";
12
import * as Cause from "effect/Cause";
13
import { AsyncResult } from "effect/reactivity";
@@ -18,6 +19,7 @@ const state = vi.hoisted(() => ({
19
dropBusy: false,
20
holdingRows: false,
21
failedAction: null as string | null,
22
+ titleOutcome: null as ThreadTitleRegenerationOutcome | null,
23
archivedRefreshes: [] as string[],
24
scopes: new Map<string, Set<string>>(),
25
shells: [] as EnvironmentThreadShell[],
@@ -141,6 +143,7 @@ vi.mock("../../state/threads", () => ({
143
"reorderPin",
144
"reorderActive",
145
"updateMetadata",
146
+ "regenerateTitle",
147
].map((action) => [
148
action,
149
async (request: {
@@ -155,7 +158,7 @@ vi.mock("../../state/threads", () => ({
158
if (action === state.failedAction)
159
return AsyncResult.failure(Cause.fail(new Error("Server rejected action")));
160
state.afterRequest?.();
158
- return AsyncResult.success(undefined);
161
+ return AsyncResult.success(action === "regenerateTitle" ? state.titleOutcome : undefined);
162
},
163
]),
164
),
@@ -186,12 +189,13 @@ const mutationCases = [
189
["unsnoozeThread", "unsnooze"],
190
["pinThread", "pin"],
191
["unpinThread", "unpin"],
189
- ["regenerateThreadTitle", "updateMetadata"],
192
+ ["regenerateThreadTitle", "regenerateTitle"],
193
] as const;
194
195
beforeEach(() => {
196
state.connectedEnvironmentIds = [primaryEnvironmentId, otherEnvironmentId];
197
state.failedAction = null;
198
+ state.titleOutcome = null;
199
state.archivedRefreshes = [];
200
state.pendingOrder = null;
201
state.dropBusy = false;
@@ -214,6 +218,16 @@ afterEach(() => {
218
vi.unstubAllEnvs();
219
});
220
221
+it("reports a failed title generation as unsuccessful and allows another request", async () => {
222
+ const actions = useThreadListActions();
223
+ const thread = makeThread();
224
+ state.titleOutcome = { status: "failed", message: "Model unavailable" };
225
+ expect(await actions.regenerateThreadTitle(thread)).toBe(false);
226
+
227
+ state.titleOutcome = { status: "renamed" };
228
+ expect(await actions.regenerateThreadTitle(thread)).toBe(true);
229
+});
230
+
231
describe("thread list operation permissions", () => {
232
it.each(mutationCases)(
233
"%s rejects a retained callback after its environment loses permission",
apps/mobile/src/features/home/useThreadListActions.ts
+12
-2
@@ -240,6 +240,9 @@ export function useThreadListActions(): {
240
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
241
reportFailure: false,
242
});
243
+ const regenerateTitle = useAtomCommand(threadEnvironment.regenerateTitle, {
244
+ reportFailure: false,
245
+ });
246
const snoozeInFlightThreadKeys = useRef(new Set<string>());
247
const titleRegenerationInFlightThreadKeys = useRef(new Set<string>());
248
@@ -529,9 +532,9 @@ export function useThreadListActions(): {
532
titleRegenerationInFlightThreadKeys.current.add(key);
533
selectionHaptic();
534
const succeeded = await (async () => {
532
- const result = await updateThreadMetadata({
535
+ const result = await regenerateTitle({
536
environmentId: thread.environmentId,
534
- input: { threadId: thread.id, regenerateTitle: true },
537
+ input: { threadId: thread.id },
538
});
539
if (result._tag === "Failure") {
540
const error = Cause.squash(result.cause);
@@ -543,6 +546,13 @@ export function useThreadListActions(): {
546
);
547
return false;
548
}
549
+ if (result.value?.status === "failed") {
550
+ Dialog.alert(
551
+ "Could not regenerate title",
552
+ result.value.message ?? "The thread title could not be regenerated.",
553
+ );
554
+ return false;
555
+ }
556
return true;
557
})();
558
titleRegenerationInFlightThreadKeys.current.delete(key);
apps/server/src/mcp/OrchestratorMcpService.ts
+7
@@ -898,6 +898,13 @@ function threadDetail(
898
requestId: projection.thread.titleRegeneration.requestId,
899
startedAt: DateTime.formatIso(projection.thread.titleRegeneration.startedAt),
900
},
901
+ lastTitleRegeneration:
902
+ projection.thread.lastTitleRegeneration == null
903
+ ? null
904
+ : {
905
+ ...projection.thread.lastTitleRegeneration,
906
+ completedAt: DateTime.formatIso(projection.thread.lastTitleRegeneration.completedAt),
907
+ },
908
branch: projection.thread.branch,
909
worktreePath: projection.thread.worktreePath,
910
parentThreadId: projection.thread.lineage.parentThreadId,
apps/server/src/orchestration-v2/Orchestrator.ts
+9
@@ -4768,6 +4768,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4768
? {
4769
...thread,
4770
...(command.title === undefined ? {} : { title: command.title }),
4771
+ ...(command.outcome === undefined
4772
+ ? {}
4773
+ : {
4774
+ lastTitleRegeneration: {
4775
+ ...command.outcome,
4776
+ requestId: command.requestId,
4777
+ completedAt: now,
4778
+ },
4779
+ }),
4780
titleRegeneration: null,
4781
updatedAt: now,
4782
}
apps/server/src/orchestration-v2/ProjectionStore.ts
+2
@@ -1795,6 +1795,7 @@ export function threadShellFromProjection(
1795
lastVisitedAt: projection.thread.lastVisitedAt,
1796
opens: projection.thread.opens ?? null,
1797
titleRegeneration: projection.thread.titleRegeneration ?? null,
1798
+ lastTitleRegeneration: projection.thread.lastTitleRegeneration ?? null,
1799
limitRecovery: projection.thread.limitRecovery ?? null,
1800
deletedAt: projection.thread.deletedAt,
1801
};
@@ -2091,6 +2092,7 @@ function shellFromState(input: {
2092
lastVisitedAt: input.state.thread.lastVisitedAt,
2093
opens: input.state.thread.opens ?? null,
2094
titleRegeneration: input.state.thread.titleRegeneration ?? null,
2095
+ lastTitleRegeneration: input.state.thread.lastTitleRegeneration ?? null,
2096
limitRecovery: input.state.thread.limitRecovery ?? null,
2097
deletedAt: input.state.thread.deletedAt,
2098
};
apps/server/src/orchestration-v2/ThreadTitleRegenerationService.test.ts
+51
-1
@@ -11,6 +11,7 @@ import {
11
ProviderInstanceId,
12
ProviderThreadId,
13
RunId,
14
+ TextGenerationError,
15
ThreadId,
16
} from "@t3tools/contracts";
17
import * as DateTime from "effect/DateTime";
@@ -432,6 +433,10 @@ describe("ThreadTitleRegenerationService", () => {
433
const projection = yield* threads.getThreadProjection(threadId);
434
assert.equal(projection.thread.title, "Fresh title");
435
assert.isNotOk(projection.thread.titleRegeneration);
436
+ assert.deepInclude(projection.thread.lastTitleRegeneration, {
437
+ requestId,
438
+ status: "renamed",
439
+ });
440
}
441
}).pipe(Effect.provide(harness.layer));
442
}).pipe(Effect.provide(NodeServices.layer)),
@@ -518,7 +523,14 @@ describe("ThreadTitleRegenerationService", () => {
523
it.effect("clears the marker and keeps the title when generation fails", () =>
524
Effect.gen(function* () {
525
const harness = makeHarness({
521
- generateTitle: () => Effect.die(new Error("model unavailable")),
526
+ generateTitle: () =>
527
+ Effect.fail(
528
+ new TextGenerationError({
529
+ operation: "generateThreadTitle",
530
+ detail:
531
+ "Codex CLI command failed: OpenAI Codex\nuser\nConversation text\nmodel unavailable\n",
532
+ }),
533
+ ),
534
});
535
yield* Effect.gen(function* () {
536
const threads = yield* ThreadManagement.ThreadManagementService;
@@ -540,6 +552,44 @@ describe("ThreadTitleRegenerationService", () => {
552
const projection = yield* threads.getThreadProjection(threadId);
553
assert.equal(projection.thread.title, "Seed title");
554
assert.isNotOk(projection.thread.titleRegeneration);
555
+ assert.deepInclude(projection.thread.lastTitleRegeneration, {
556
+ requestId,
557
+ status: "failed",
558
+ message: "model unavailable",
559
+ });
560
+ }).pipe(Effect.provide(harness.layer));
561
+ }),
562
+ );
563
+
564
+ it.effect("records an unchanged outcome when the model keeps the current title", () =>
565
+ Effect.gen(function* () {
566
+ const harness = makeHarness({
567
+ generateTitle: () => Effect.succeed({ title: "Seed title" }),
568
+ });
569
+ yield* Effect.gen(function* () {
570
+ const threads = yield* ThreadManagement.ThreadManagementService;
571
+ const titleRegeneration = yield* ThreadTitleRegeneration.ThreadTitleRegenerationService;
572
+ const threadId = yield* createThread({
573
+ command: "command:title:unchanged:create",
574
+ thread: "thread:title:unchanged",
575
+ });
576
+ yield* dispatchUserMessage({
577
+ command: "command:title:unchanged:message",
578
+ threadId,
579
+ text: "Some conversation",
580
+ });
581
+ const requestId = yield* armRegeneration({
582
+ command: "command:title:unchanged:1",
583
+ threadId,
584
+ });
585
+
586
+ yield* titleRegeneration.execute({ threadId, requestId, kind: { type: "regenerate" } });
587
+
588
+ const projection = yield* threads.getThreadProjection(threadId);
589
+ assert.deepInclude(projection.thread.lastTitleRegeneration, {
590
+ requestId,
591
+ status: "unchanged",
592
+ });
593
}).pipe(Effect.provide(harness.layer));
594
}),
595
);
apps/server/src/orchestration-v2/ThreadTitleRegenerationService.ts
+48
-16
@@ -8,6 +8,7 @@ import {
8
type OrchestrationV2ConversationMessage,
9
type RunId,
10
type ServerSettingsError,
11
+ TextGenerationError,
12
type ThreadId,
13
} from "@t3tools/contracts";
14
import * as Cause from "effect/Cause";
@@ -17,6 +18,7 @@ import * as FileSystem from "effect/FileSystem";
18
import * as Layer from "effect/Layer";
19
import * as Option from "effect/Option";
20
import * as Schedule from "effect/Schedule";
21
+import * as Schema from "effect/Schema";
22
23
import * as ServerSettings from "../serverSettings.ts";
24
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
@@ -46,6 +48,29 @@ export class ThreadTitleRegenerationService extends Context.Service<
48
}
49
>()("t3/orchestration-v2/ThreadTitleRegenerationService") {}
50
51
+type Outcome =
52
+ | { readonly status: "renamed"; readonly title: string }
53
+ | { readonly status: "unchanged" }
54
+ | { readonly status: "failed"; readonly message: string };
55
+
56
+const MAX_FAILURE_MESSAGE_LENGTH = 300;
57
+const isTextGenerationError = Schema.is(TextGenerationError);
58
+
59
+function failureMessage(cause: Cause.Cause<unknown>): string {
60
+ const error = Cause.squash(cause);
61
+ const lines = isTextGenerationError(error)
62
+ ? error.detail
63
+ .split("\n")
64
+ .map((line) => line.trim())
65
+ .filter((line) => line.length > 0)
66
+ : [];
67
+ const detail = lines.at(-1);
68
+ if (detail === undefined) return "Title generation failed.";
69
+ return detail.length > MAX_FAILURE_MESSAGE_LENGTH
70
+ ? `${detail.slice(0, MAX_FAILURE_MESSAGE_LENGTH - 1)}…`
71
+ : detail;
72
+}
73
+
74
const make = Effect.gen(function* () {
75
const threads = yield* ThreadManagementService.ThreadManagementService;
76
const projects = yield* ProjectStore.ProjectStoreV2;
@@ -56,7 +81,8 @@ const make = Effect.gen(function* () {
81
const complete = (input: {
82
readonly threadId: ThreadId;
83
readonly requestId: CommandId;
59
- readonly title?: string;
84
+ readonly kind: { readonly type: "initial" | "regenerate" };
85
+ readonly outcome: Outcome;
86
}) =>
87
threads
88
.dispatch({
@@ -64,7 +90,15 @@ const make = Effect.gen(function* () {
90
commandId: CommandId.make(`${input.requestId}:title-complete`),
91
threadId: input.threadId,
92
requestId: input.requestId,
67
- ...(input.title === undefined ? {} : { title: input.title }),
93
+ ...(input.outcome.status === "renamed" ? { title: input.outcome.title } : {}),
94
+ ...(input.kind.type === "regenerate"
95
+ ? {
96
+ outcome: {
97
+ status: input.outcome.status,
98
+ ...(input.outcome.status === "failed" ? { message: input.outcome.message } : {}),
99
+ },
100
+ }
101
+ : {}),
102
})
103
.pipe(Effect.asVoid);
104
@@ -110,9 +144,7 @@ const make = Effect.gen(function* () {
144
const execute: ThreadTitleRegenerationService["Service"]["execute"] = Effect.fn(
145
"ThreadTitleRegenerationService.execute",
146
)(function* (input) {
113
- const outcome:
114
- | { readonly type: "stale" }
115
- | { readonly type: "complete"; readonly title?: string } = yield* Effect.gen(function* () {
147
+ const outcome: Outcome | { readonly status: "stale" } = yield* Effect.gen(function* () {
148
const projection = yield* threads.getThreadRecords(
149
input.threadId,
150
["messages"],
@@ -121,12 +153,12 @@ const make = Effect.gen(function* () {
153
: { messageRoles: ["user", "assistant"] },
154
);
155
if (projection.thread.titleRegeneration?.requestId !== input.requestId) {
124
- return { type: "stale" as const };
156
+ return { status: "stale" as const };
157
}
158
159
const project = yield* projects.get(projection.thread.projectId);
160
if (Option.isNone(project)) {
129
- return { type: "complete" as const };
161
+ return { status: "failed" as const, message: "This thread's project no longer exists." };
162
}
163
164
let context: {
@@ -151,7 +183,10 @@ const make = Effect.gen(function* () {
183
);
184
}
185
if (context.message.length === 0 && context.attachments.length === 0) {
154
- return { type: "complete" as const };
186
+ return {
187
+ status: "failed" as const,
188
+ message: "This thread has no messages to title yet.",
189
+ };
190
}
191
192
// A deleted source should not cost the fork its title.
@@ -181,8 +216,8 @@ const make = Effect.gen(function* () {
216
const generatedTitle = result.title.trim();
217
return generatedTitle === "New thread" ||
218
(input.kind.type === "regenerate" && generatedTitle === projection.thread.title.trim())
184
- ? { type: "complete" as const }
185
- : { type: "complete" as const, title: result.title };
219
+ ? { status: "unchanged" as const }
220
+ : { status: "renamed" as const, title: result.title };
221
}).pipe(
222
Effect.retry({
223
times: input.kind.type === "initial" ? 2 : 0,
@@ -195,17 +230,14 @@ const make = Effect.gen(function* () {
230
threadId: input.threadId,
231
requestId: input.requestId,
232
cause,
198
- }).pipe(Effect.as({ type: "complete" as const })),
233
+ }).pipe(Effect.as({ status: "failed" as const, message: failureMessage(cause) })),
234
),
235
);
236
202
- if (outcome.type === "stale") {
237
+ if (outcome.status === "stale") {
238
return;
239
}
205
- yield* complete({
206
- ...input,
207
- ...(outcome.title === undefined ? {} : { title: outcome.title }),
208
- });
240
+ yield* complete({ ...input, outcome });
241
});
242
243
return ThreadTitleRegenerationService.of({ execute });
apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+11
-10
@@ -1365,13 +1365,10 @@ describe("VcsStatusBroadcaster", () => {
1365
1366
it.effect("a checkout read that fails while index.lock is held retries until it succeeds", () =>
1367
Effect.gen(function* () {
1368
- const fs = yield* FileSystem.FileSystem;
1369
- const path = yield* Path.Path;
1370
- const gitDir = yield* fs.makeTempDirectoryScoped({ prefix: "vcs-head-watch-" });
1371
- const headPath = path.join(gitDir, "HEAD");
1372
- yield* fs.writeFileString(headPath, "ref: refs/heads/main\n");
1368
+ const events = yield* Queue.unbounded<FileSystem.WatchEvent>();
1369
+ const headPath = "/repo/.git/HEAD";
1370
const failed = yield* Deferred.make<void>();
1374
- const state = {
1371
+ const state: Parameters<typeof layerTestFor>[0] = {
1372
currentLocalStatus: { ...baseLocalStatus, isDefaultRef: true, refName: "main" },
1373
currentRemoteStatus: null,
1374
localStatusCalls: 0,
@@ -1379,6 +1376,12 @@ describe("VcsStatusBroadcaster", () => {
1376
localInvalidationCalls: 0,
1377
remoteInvalidationCalls: 0,
1378
headPath,
1379
+ fileSystem: FileSystem.makeNoop({
1380
+ realPath: (target) => Effect.succeed(target),
1381
+ exists: () => Effect.succeed(true),
1382
+ watch: (_target, options) =>
1383
+ Stream.fromQueue(events).pipe(Stream.onStart(Effect.sync(() => options?.onReady?.()))),
1384
+ }),
1385
failLocalStatus: false,
1386
onLocalStatusFailure: Deferred.succeed(failed, undefined).pipe(Effect.asVoid),
1387
};
@@ -1402,9 +1405,7 @@ describe("VcsStatusBroadcaster", () => {
1405
// A terminal commit holds index.lock across the checkout, so the HEAD event's read fails.
1406
state.failLocalStatus = true;
1407
state.currentLocalStatus = { ...baseLocalStatus, isDefaultRef: false, refName: "repro" };
1405
- const lockPath = path.join(gitDir, "HEAD.lock");
1406
- yield* fs.writeFileString(lockPath, "ref: refs/heads/repro\n");
1407
- yield* fs.rename(lockPath, headPath);
1408
+ yield* Queue.offer(events, { _tag: "Update", path: "HEAD" });
1409
yield* Deferred.await(failed);
1410
const failedCalls = state.localStatusCalls;
1411
@@ -1414,7 +1415,7 @@ describe("VcsStatusBroadcaster", () => {
1415
yield* Deferred.await(checkedOut);
1416
assert.strictEqual(state.localStatusCalls, failedCalls + 1);
1417
}).pipe(Effect.provide(layerTestFor(state)), Effect.scoped);
1417
- }).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
1418
+ }).pipe(Effect.scoped),
1419
);
1420
1421
it.effect("subscribers share one HEAD watch that ends with the last of them", () =>
apps/web/src/components/Sidebar.tsx
+22
-32
@@ -232,6 +232,7 @@ import {
232
useActiveRowReveal,
233
} from "./sidebar/routeReveal";
234
import { stackedThreadToast, toastManager } from "./ui/toast";
235
+import { titleRegenerationToast } from "./threadTitleRegenerationToast";
236
import { copyThreadReference } from "../lib/copyThreadReference";
237
import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
238
import { Button } from "./ui/button";
@@ -936,6 +937,9 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
937
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
938
reportFailure: false,
939
});
940
+ const regenerateThreadTitle = useOrchestrationCommand(threadEnvironment.regenerateTitle, {
941
+ reportFailure: false,
942
+ });
943
const { copyToClipboard: copyPathToClipboard } = useCopyToClipboard<{ path: string }>({
944
onCopy: ({ path }) => {
945
toastManager.add({
@@ -2453,25 +2457,18 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2457
return;
2458
}
2459
if (clicked.value === "regenerate-title") {
2456
- for (const thread of regeneratableTitleThreads) {
2457
- const result = await updateThreadMetadata({
2458
- environmentId: thread.environmentId,
2459
- input: { threadId: thread.id, regenerateTitle: true },
2460
- });
2461
- if (result._tag === "Success") continue;
2462
- if (!isAtomCommandInterrupted(result)) {
2463
- const error = squashAtomCommandFailure(result);
2464
- toastManager.add(
2465
- stackedThreadToast({
2466
- type: "error",
2467
- title: "Failed to regenerate thread titles",
2468
- description: error instanceof Error ? error.message : "An error occurred.",
2469
- }),
2470
- );
2471
- }
2472
- return;
2473
- }
2460
clearSelection();
2461
+ const toast = titleRegenerationToast(
2462
+ await Promise.all(
2463
+ regeneratableTitleThreads.map((thread) =>
2464
+ regenerateThreadTitle({
2465
+ environmentId: thread.environmentId,
2466
+ input: { threadId: thread.id },
2467
+ }),
2468
+ ),
2469
+ ),
2470
+ );
2471
+ if (toast) toastManager.add(toast);
2472
return;
2473
}
2474
if (clicked.value === "settle") {
@@ -2784,20 +2781,13 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve
2781
return;
2782
case "regenerate-title": {
2783
if (isRegeneratingTitle) return;
2787
- const result = await updateThreadMetadata({
2788
- environmentId: threadRef.environmentId,
2789
- input: { threadId: threadRef.threadId, regenerateTitle: true },
2790
- });
2791
- if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
2792
- const error = squashAtomCommandFailure(result);
2793
- toastManager.add(
2794
- stackedThreadToast({
2795
- type: "error",
2796
- title: "Failed to regenerate thread title",
2797
- description: error instanceof Error ? error.message : "An error occurred.",
2798
- }),
2799
- );
2800
- }
2784
+ const toast = titleRegenerationToast([
2785
+ await regenerateThreadTitle({
2786
+ environmentId: threadRef.environmentId,
2787
+ input: { threadId: threadRef.threadId },
2788
+ }),
2789
+ ]);
2790
+ if (toast) toastManager.add(toast);
2791
return;
2792
}
2793
case "mark-unread":
apps/web/src/components/chat/useThreadLifecycle.tsx
+10
-3
@@ -49,6 +49,7 @@ import { useUiStateStore } from "../../uiStateStore";
49
import { type ChatMessage, DEFAULT_INTERACTION_MODE } from "../../types";
50
import { AlarmClockIcon, CheckCircle2Icon } from "lucide-react";
51
import { stackedThreadToast, toastManager } from "../ui/toast";
52
+import { titleRegenerationToast } from "../threadTitleRegenerationToast";
53
import { newMessageId } from "~/lib/utils";
54
import { buildThreadRouteParams } from "../../threadRoutes";
55
import { composerDraftHasUserContent, useComposerDraftStore } from "../../composerDraftStore";
@@ -186,6 +187,9 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
187
const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
188
reportFailure: false,
189
});
190
+ const regenerateThreadTitle = useOrchestrationCommand(threadEnvironment.regenerateTitle, {
191
+ reportFailure: false,
192
+ });
193
const startThreadTurn = useOrchestrationCommand(threadEnvironment.startTurn, {
194
reportFailure: false,
195
});
@@ -688,10 +692,13 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
692
if (!readEnvironmentScope(environmentId, AuthOrchestrationOperateScope)) return false;
693
if (!activeThreadShell || !activeThreadRef || !serverConfigLoaded) return;
694
if (activeThreadShell.titleRegeneration != null) return;
691
- void updateThreadMetadata({
695
+ void regenerateThreadTitle({
696
environmentId: activeThreadRef.environmentId,
693
- input: { threadId: activeThreadRef.threadId, regenerateTitle: true },
694
- }).then(toastThreadActionFailure("Failed to regenerate thread title"));
697
+ input: { threadId: activeThreadRef.threadId },
698
+ }).then((result) => {
699
+ const toast = titleRegenerationToast([result]);
700
+ if (toast) toastManager.add(toast);
701
+ });
702
},
703
} satisfies ChatShortcutCommands;
704
return {
apps/web/src/components/threadTitleRegenerationToast.ts
new
+59
@@ -0,0 +1,59 @@
1
+import type { ThreadTitleRegenerationOutcome } from "@t3tools/contracts";
2
+import {
3
+ type AtomCommandResult,
4
+ isAtomCommandInterrupted,
5
+ squashAtomCommandFailure,
6
+} from "@t3tools/client-runtime/state/runtime";
7
+
8
+import { stackedThreadToast } from "./ui/toast";
9
+
10
+type TitleRegenerationResult = AtomCommandResult<ThreadTitleRegenerationOutcome | null, unknown>;
11
+
12
+function failureMessage(result: TitleRegenerationResult): string | null {
13
+ if (result._tag === "Failure") {
14
+ if (isAtomCommandInterrupted(result)) return null;
15
+ const error = squashAtomCommandFailure(result);
16
+ return error instanceof Error ? error.message : "An error occurred.";
17
+ }
18
+ return result.value?.status === "failed"
19
+ ? (result.value.message ?? "Title generation failed.")
20
+ : null;
21
+}
22
+
23
+function isKept(result: TitleRegenerationResult): boolean {
24
+ return result._tag === "Success" && result.value?.status === "unchanged";
25
+}
26
+
27
+export function titleRegenerationToast(results: ReadonlyArray<TitleRegenerationResult>) {
28
+ const failures = results.flatMap((result) => {
29
+ const message = failureMessage(result);
30
+ return message === null ? [] : [message];
31
+ });
32
+ if (failures.length > 0) {
33
+ return stackedThreadToast({
34
+ type: "error",
35
+ title:
36
+ results.length === 1
37
+ ? "Failed to regenerate thread title"
38
+ : `Failed to regenerate ${failures.length} of ${results.length} thread titles`,
39
+ description: failures[0],
40
+ });
41
+ }
42
+ const kept = results.filter(isKept).length;
43
+ if (kept === 0) return null;
44
+ if (results.length === 1) {
45
+ return stackedThreadToast({
46
+ type: "info",
47
+ title: "Title kept",
48
+ description: "The current title already fits this thread.",
49
+ });
50
+ }
51
+ return stackedThreadToast({
52
+ type: "info",
53
+ title: kept === results.length ? "Titles kept" : `Kept ${kept} of ${results.length} titles`,
54
+ description:
55
+ kept === results.length
56
+ ? "The current titles already fit these threads."
57
+ : "Those titles already fit their threads.",
58
+ });
59
+}
apps/web/src/hooks/useThreadActionMenu.ts
+9
-6
@@ -21,6 +21,7 @@ import {
21
threadActionRequiresOperate,
22
type ThreadActionMenuId,
23
} from "../components/threadActionMenu.logic";
24
+import { titleRegenerationToast } from "../components/threadTitleRegenerationToast";
25
import { stackedThreadToast, toastManager } from "../components/ui/toast";
26
import { copyThreadReference } from "../lib/copyThreadReference";
27
import { threadChipCopyTarget } from "@t3tools/client-runtime/thread-reference";
@@ -88,7 +89,7 @@ export function useThreadActionMenu(input: {
89
markThreadUnread,
90
turnThreadIntoProject,
91
} = useThreadActions();
91
- const updateThreadMetadata = useOrchestrationCommand(threadEnvironment.updateMetadata, {
92
+ const regenerateThreadTitle = useOrchestrationCommand(threadEnvironment.regenerateTitle, {
93
reportFailure: false,
94
});
95
const handleNewThread = useNewThreadHandler();
@@ -250,15 +251,17 @@ export function useThreadActionMenu(input: {
251
case "rename":
252
onStartRename();
253
return;
253
- case "regenerate-title":
254
+ case "regenerate-title": {
255
if (isRegeneratingTitle) return;
255
- await reportFailure("Failed to regenerate thread title", () =>
256
- updateThreadMetadata({
256
+ const toast = titleRegenerationToast([
257
+ await regenerateThreadTitle({
258
environmentId: threadRef.environmentId,
258
- input: { threadId: threadRef.threadId, regenerateTitle: true },
259
+ input: { threadId: threadRef.threadId },
260
}),
260
- );
261
+ ]);
262
+ if (toast) toastManager.add(toast);
263
return;
264
+ }
265
case "mark-unread":
266
markThreadUnread(threadRef);
267
return;
packages/client-runtime/src/state/runtime.ts
+7
@@ -619,6 +619,13 @@ function environmentConnectionAtoms<R, ER>(
619
return family;
620
}
621
622
+export function environmentConnectionAtom<R, ER>(
623
+ runtime: Atom.AtomRuntime<EnvironmentRegistry.EnvironmentRegistry | R, ER>,
624
+ environmentId: EnvironmentIdType,
625
+) {
626
+ return environmentConnectionAtoms(runtime)(environmentId);
627
+}
628
+
629
const sessionGenerationAtomsByRuntime = new WeakMap<
630
object,
631
(environmentId: EnvironmentIdType) => Atom.Atom<number>
packages/client-runtime/src/state/threadCommands.test.ts
+119
-3
@@ -22,11 +22,16 @@ import * as Layer from "effect/Layer";
22
import * as Option from "effect/Option";
23
import * as Queue from "effect/Queue";
24
import * as Scope from "effect/Scope";
25
+import * as Stream from "effect/Stream";
26
import * as SubscriptionRef from "effect/SubscriptionRef";
27
import { Atom, AtomRegistry } from "effect/reactivity";
28
29
import * as EnvironmentRegistry from "../connection/registry.ts";
29
-import { BearerConnectionTarget } from "../connection/model.ts";
30
+import {
31
+ AVAILABLE_CONNECTION_STATE,
32
+ BearerConnectionTarget,
33
+ type SupervisorConnectionState,
34
+} from "../connection/model.ts";
35
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
36
import type { RpcSession } from "../rpc/session.ts";
37
import { createThreadEnvironmentAtoms } from "./threadCommands.ts";
@@ -96,12 +101,19 @@ const makeHarness = Effect.fn("TestThreadCommands.makeHarness")(function* (optio
101
reply: Deferred.Deferred<{ sequence: number }, Error>;
102
}>();
103
const reconciled = yield* Queue.unbounded<ThreadId>();
104
+ const connectionFollowed = yield* Deferred.make<void>();
105
+ const connection = yield* SubscriptionRef.make<SupervisorConnectionState>({
106
+ ...AVAILABLE_CONNECTION_STATE,
107
+ desired: true,
108
+ phase: "connected",
109
+ });
110
const supervisor = EnvironmentSupervisor.EnvironmentSupervisor.of({
111
target: new BearerConnectionTarget({
112
environmentId: ENVIRONMENT_ID,
113
label: "Test",
114
connectionId: "test",
115
}),
116
+ state: connection,
117
session: yield* SubscriptionRef.make(
118
Option.some({
119
client: {
@@ -120,6 +132,12 @@ const makeHarness = Effect.fn("TestThreadCommands.makeHarness")(function* (optio
132
Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, {
133
run: (_environmentId, effect) =>
134
Effect.provideService(effect, EnvironmentSupervisor.EnvironmentSupervisor, supervisor),
135
+ followStream: (_environmentId, stream) =>
136
+ Stream.provideService(
137
+ stream,
138
+ EnvironmentSupervisor.EnvironmentSupervisor,
139
+ supervisor,
140
+ ).pipe(Stream.onStart(Deferred.succeed(connectionFollowed, undefined))),
141
} as EnvironmentRegistry.EnvironmentRegistry["Service"]),
142
Layer.succeed(
143
SecureRandom.SecureRandom,
@@ -137,13 +155,24 @@ const makeHarness = Effect.fn("TestThreadCommands.makeHarness")(function* (optio
155
),
156
),
157
);
140
- const snapshotAtom = Atom.family((_environmentId: EnvironmentId) => Atom.make(SNAPSHOT));
158
+ const snapshotAtom = Atom.family((_environmentId: EnvironmentId) =>
159
+ Atom.make<OrchestrationV2ShellSnapshot | null>(SNAPSHOT),
160
+ );
161
const commands = createThreadEnvironmentAtoms(runtime, snapshotAtom);
162
const registry = AtomRegistry.make();
163
yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
164
const visibleAtom = commands.snapshotAtom(ENVIRONMENT_ID);
165
registry.mount(visibleAtom);
146
- return { registry, commands, snapshotAtom, visibleAtom, requests, reconciled };
166
+ return {
167
+ registry,
168
+ commands,
169
+ snapshotAtom,
170
+ visibleAtom,
171
+ requests,
172
+ reconciled,
173
+ connection,
174
+ connectionFollowed,
175
+ };
176
});
177
178
describe("history loading", () => {
@@ -255,6 +284,93 @@ describe("interrupt turn", () => {
284
);
285
});
286
287
+describe("title regeneration", () => {
288
+ it.effect("resolves with the outcome recorded for its own request", () =>
289
+ Effect.gen(function* () {
290
+ const h = yield* makeHarness();
291
+ const source = h.snapshotAtom(ENVIRONMENT_ID);
292
+ const thread = SNAPSHOT.threads[0]!;
293
+ const target = { environmentId: ENVIRONMENT_ID, input: { threadId: THREAD_ID } };
294
+ const earlier = {
295
+ requestId: CommandId.make("earlier"),
296
+ status: "renamed" as const,
297
+ completedAt: NOW,
298
+ };
299
+
300
+ h.registry.set(source, null);
301
+ const result = h.commands.regenerateTitle.run(h.registry, target);
302
+ const request = yield* Queue.take(h.requests);
303
+ const requestId = request.command.commandId;
304
+ yield* Deferred.succeed(request.reply, { sequence: 2 });
305
+ yield* Deferred.await(h.connectionFollowed);
306
+ h.registry.set(source, {
307
+ ...SNAPSHOT,
308
+ snapshotSequence: 2,
309
+ threads: [
310
+ {
311
+ ...thread,
312
+ titleRegeneration: { requestId, startedAt: NOW },
313
+ lastTitleRegeneration: earlier,
314
+ },
315
+ ],
316
+ });
317
+ h.registry.set(source, {
318
+ ...SNAPSHOT,
319
+ snapshotSequence: 3,
320
+ threads: [],
321
+ archivedThreads: [
322
+ {
323
+ ...thread,
324
+ archivedAt: NOW,
325
+ titleRegeneration: null,
326
+ lastTitleRegeneration: {
327
+ requestId,
328
+ status: "failed",
329
+ message: "model unavailable",
330
+ completedAt: NOW,
331
+ },
332
+ },
333
+ ],
334
+ });
335
+ const outcome = yield* Effect.promise(() => result);
336
+ expect(outcome).toMatchObject({
337
+ _tag: "Success",
338
+ value: { status: "failed", message: "model unavailable" },
339
+ });
340
+
341
+ const superseded = h.commands.regenerateTitle.run(h.registry, target);
342
+ const second = yield* Queue.take(h.requests);
343
+ h.registry.set(source, {
344
+ ...SNAPSHOT,
345
+ snapshotSequence: 4,
346
+ threads: [{ ...thread, titleRegeneration: null, lastTitleRegeneration: earlier }],
347
+ });
348
+ yield* Deferred.succeed(second.reply, { sequence: 4 });
349
+ expect(yield* Effect.promise(() => superseded)).toMatchObject({
350
+ _tag: "Success",
351
+ value: null,
352
+ });
353
+ }),
354
+ );
355
+
356
+ it.effect("settles without an outcome when the environment disconnects while waiting", () =>
357
+ Effect.gen(function* () {
358
+ const h = yield* makeHarness();
359
+ const result = h.commands.regenerateTitle.run(h.registry, {
360
+ environmentId: ENVIRONMENT_ID,
361
+ input: { threadId: THREAD_ID },
362
+ });
363
+ const request = yield* Queue.take(h.requests);
364
+ yield* Deferred.succeed(request.reply, { sequence: 2 });
365
+ yield* SubscriptionRef.update(h.connection, (state) => ({
366
+ ...state,
367
+ phase: "backoff" as const,
368
+ }));
369
+ expect(yield* Effect.promise(() => result)).toMatchObject({ _tag: "Success", value: null });
370
+ }),
371
+ );
372
+});
373
+
374
describe("remote thread lifecycle commands", () => {
375
const actions = [
376
["settle", {}, { settledOverride: "settled", pinnedAt: null, snoozedUntil: null }],
packages/client-runtime/src/state/threadCommands.ts
+57
-2
@@ -1,8 +1,8 @@
1
-import type { ModelSelection, ThreadId } from "@t3tools/contracts";
1
+import { CommandId, type ModelSelection, type ThreadId } from "@t3tools/contracts";
2
import * as SecureRandom from "effect/crypto/SecureRandom";
3
import * as Effect from "effect/Effect";
4
import * as Option from "effect/Option";
5
-import { Atom } from "effect/reactivity";
5
+import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity";
6
import {
7
WS_METHODS,
8
type EnvironmentId,
@@ -17,7 +17,10 @@ import {
17
createAtomCommandScheduler,
18
createEnvironmentCommand,
19
createEnvironmentRpcCommand,
20
+ environmentConnectionAtom,
21
+ mapAtomCommandResult,
22
} from "./runtime.ts";
23
+import { waitForTitleRegenerationOutcome } from "./threadTitleRegeneration.ts";
24
import {
25
type InterruptThreadTurnInput,
26
type UpdateThreadMetadataInput,
@@ -60,6 +63,7 @@ import {
63
visitThread,
64
watchThreadPullRequest,
65
} from "../operations/commands.ts";
66
+import { connectionProjectionPhase } from "../connection/model.ts";
67
import type { EnvironmentRegistry } from "../connection/registry.ts";
68
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
69
import * as ThreadHistoryController from "./threadHistoryController.ts";
@@ -120,6 +124,19 @@ export function createThreadEnvironmentAtoms<R, E>(
124
);
125
});
126
127
+ const armTitleRegeneration = Effect.fn("ThreadCommands.armTitleRegeneration")(function* (input: {
128
+ readonly threadId: ThreadId;
129
+ }) {
130
+ const random = yield* SecureRandom.SecureRandom;
131
+ const requestId = CommandId.make(yield* random.uuidV4());
132
+ const result = yield* updateThreadMetadata({
133
+ threadId: input.threadId,
134
+ regenerateTitle: true,
135
+ commandId: requestId,
136
+ });
137
+ return { requestId, sequence: result.sequence };
138
+ });
139
+
140
// Counts the commands that move or remove a thread's row. A list that holds its rows while
141
// environments synchronize (`stepSteadyShells`) shows the user's own change at once.
142
const rowActionsAtom = Atom.family((_environmentId: EnvironmentId) =>
@@ -136,6 +153,13 @@ export function createThreadEnvironmentAtoms<R, E>(
153
});
154
155
const sent = {
156
+ armTitleRegeneration: createEnvironmentCommand(runtime, {
157
+ label: "environment-data:commands:thread:regenerate-title",
158
+ execute: armTitleRegeneration,
159
+ scheduler,
160
+ concurrency,
161
+ }),
162
+
163
create: createEnvironmentCommand(runtime, {
164
label: "environment-data:commands:thread:create",
165
execute: createThread,
@@ -411,8 +435,39 @@ export function createThreadEnvironmentAtoms<R, E>(
435
unpin: rowAction(sent.unpin),
436
};
437
const optimistic = createOptimisticThreadLifecycle(snapshotAtom);
438
+ const disconnectedAtom = Atom.family((environmentId: EnvironmentId) =>
439
+ Atom.make((get) => {
440
+ const connection = AsyncResult.getOrElse(
441
+ get(environmentConnectionAtom(runtime, environmentId)),
442
+ () => null,
443
+ );
444
+ return connection !== null && connectionProjectionPhase(connection[0]) === "disconnected";
445
+ }),
446
+ );
447
+ const regenerateTitle = {
448
+ label: commands.armTitleRegeneration.label,
449
+ run: async (
450
+ registry: AtomRegistry.AtomRegistry,
451
+ target: { readonly environmentId: EnvironmentId; readonly input: { threadId: ThreadId } },
452
+ ) => {
453
+ const armed = await commands.armTitleRegeneration.run(registry, target);
454
+ const outcome =
455
+ armed._tag === "Success"
456
+ ? await waitForTitleRegenerationOutcome(
457
+ registry,
458
+ {
459
+ snapshot: snapshotAtom(target.environmentId),
460
+ disconnected: disconnectedAtom(target.environmentId),
461
+ },
462
+ { threadId: target.input.threadId, ...armed.value },
463
+ )
464
+ : null;
465
+ return mapAtomCommandResult(armed, () => outcome);
466
+ },
467
+ };
468
return {
469
...commands,
470
+ regenerateTitle,
471
rowActionsAtom,
472
snapshotAtom: optimistic.snapshotAtom,
473
pendingThreadIdsAtom: optimistic.pendingThreadIdsAtom,
packages/client-runtime/src/state/threadTitleRegeneration.ts
new
+66
@@ -0,0 +1,66 @@
1
+import type {
2
+ CommandId,
3
+ OrchestrationV2ShellSnapshot,
4
+ ThreadId,
5
+ ThreadTitleRegenerationOutcome,
6
+} from "@t3tools/contracts";
7
+import type { Atom, AtomRegistry } from "effect/reactivity";
8
+
9
+export interface TitleRegenerationRequest {
10
+ readonly threadId: ThreadId;
11
+ readonly requestId: CommandId;
12
+ readonly sequence: number;
13
+}
14
+
15
+export interface TitleRegenerationSources {
16
+ readonly snapshot: Atom.Atom<OrchestrationV2ShellSnapshot | null>;
17
+ readonly disconnected: Atom.Atom<boolean>;
18
+}
19
+
20
+function settledOutcome(
21
+ snapshot: OrchestrationV2ShellSnapshot | null,
22
+ request: TitleRegenerationRequest,
23
+): ThreadTitleRegenerationOutcome | null | undefined {
24
+ if (snapshot === null) return undefined;
25
+ if (snapshot.snapshotSequence < request.sequence) return undefined;
26
+ const thread =
27
+ snapshot.threads.find((candidate) => candidate.id === request.threadId) ??
28
+ snapshot.archivedThreads.find((candidate) => candidate.id === request.threadId);
29
+ if (thread === undefined) return null;
30
+ const last = thread.lastTitleRegeneration;
31
+ if (last?.requestId === request.requestId) {
32
+ return last.message === undefined
33
+ ? { status: last.status }
34
+ : { status: last.status, message: last.message };
35
+ }
36
+ return thread.titleRegeneration?.requestId === request.requestId ? undefined : null;
37
+}
38
+
39
+export function waitForTitleRegenerationOutcome(
40
+ registry: AtomRegistry.AtomRegistry,
41
+ sources: TitleRegenerationSources,
42
+ request: TitleRegenerationRequest,
43
+): Promise<ThreadTitleRegenerationOutcome | null> {
44
+ return new Promise((resolve) => {
45
+ let settled = false;
46
+ let unsubscribes: ReadonlyArray<() => void> = [];
47
+ const release = () => {
48
+ for (const unsubscribe of unsubscribes) unsubscribe();
49
+ };
50
+ const check = () => {
51
+ if (settled) return;
52
+ let outcome = settledOutcome(registry.get(sources.snapshot), request);
53
+ if (outcome === undefined && registry.get(sources.disconnected)) outcome = null;
54
+ if (outcome === undefined) return;
55
+ settled = true;
56
+ release();
57
+ resolve(outcome);
58
+ };
59
+ unsubscribes = [
60
+ registry.subscribe(sources.snapshot, check),
61
+ registry.subscribe(sources.disconnected, check),
62
+ ];
63
+ if (settled) release();
64
+ else check();
65
+ });
66
+}
packages/contracts/src/orchestrationV2.ts
+26
@@ -45,6 +45,7 @@ import { AuthMcpClientAccess } from "./auth.ts";
45
import { ChatAttachment } from "./chatAttachment.ts";
46
import { ThreadGuestShare } from "./guestShare.ts";
47
import { StoredThreadTags, ThreadTag } from "./threadTags.ts";
48
+import { ThreadTitleRegenerationOutcome } from "./threadTitle.ts";
49
import {
50
OrchestrationSearchThreadsInput,
51
OrchestrationSearchThreadsResult,
@@ -456,6 +457,12 @@ const LenientThreadOpens = Schema.NullOr(OrchestrationV2ThreadOpens).pipe(
457
Schema.catchDecoding(() => Effect.succeedSome(null)),
458
);
459
460
+const OrchestrationV2LastTitleRegeneration = Schema.Struct({
461
+ ...ThreadTitleRegenerationOutcome.fields,
462
+ requestId: CommandId,
463
+ completedAt: Schema.DateTimeUtc,
464
+});
465
+
466
export const OrchestrationV2AppThread = Schema.Struct({
467
...OrchestrationV2CreationFields,
468
id: ThreadId,
@@ -519,6 +526,7 @@ export const OrchestrationV2AppThread = Schema.Struct({
526
}),
527
),
528
),
529
+ lastTitleRegeneration: Schema.optional(Schema.NullOr(OrchestrationV2LastTitleRegeneration)),
530
rollbackRequestId: Schema.optional(CommandId),
531
rollbackFailure: Schema.optional(
532
Schema.NullOr(
@@ -2212,6 +2220,7 @@ export const OrchestrationV2ThreadShell = Schema.Struct({
2220
}),
2221
),
2222
),
2223
+ lastTitleRegeneration: Schema.optional(Schema.NullOr(OrchestrationV2LastTitleRegeneration)),
2224
deletedAt: Schema.NullOr(Schema.DateTimeUtc),
2225
});
2226
export type OrchestrationV2ThreadShell = typeof OrchestrationV2ThreadShell.Type;
@@ -2381,6 +2390,14 @@ export const OrchestrationV2AppThreadJson = OrchestrationV2AppThread.mapFields((
2390
}),
2391
),
2392
),
2393
+ lastTitleRegeneration: Schema.optional(
2394
+ Schema.NullOr(
2395
+ OrchestrationV2LastTitleRegeneration.mapFields((fields) => ({
2396
+ ...fields,
2397
+ completedAt: Schema.DateTimeUtcFromString,
2398
+ })),
2399
+ ),
2400
+ ),
2401
deletedAt: Schema.NullOr(Schema.DateTimeUtcFromString),
2402
}));
2403
export type OrchestrationV2AppThreadJson = typeof OrchestrationV2AppThreadJson.Type;
@@ -2820,6 +2837,14 @@ export const OrchestrationV2ThreadShellJson = OrchestrationV2ThreadShell.mapFiel
2837
}),
2838
),
2839
),
2840
+ lastTitleRegeneration: Schema.optional(
2841
+ Schema.NullOr(
2842
+ OrchestrationV2LastTitleRegeneration.mapFields((fields) => ({
2843
+ ...fields,
2844
+ completedAt: Schema.DateTimeUtcFromString,
2845
+ })),
2846
+ ),
2847
+ ),
2848
deletedAt: Schema.NullOr(Schema.DateTimeUtcFromString),
2849
}));
2850
export type OrchestrationV2ThreadShellJson = typeof OrchestrationV2ThreadShellJson.Type;
@@ -3211,6 +3236,7 @@ export const OrchestrationV2Command = Schema.Union([
3236
threadId: ThreadId,
3237
requestId: CommandId,
3238
title: Schema.optional(TrimmedNonEmptyString),
3239
+ outcome: Schema.optional(ThreadTitleRegenerationOutcome),
3240
}),
3241
Schema.Struct({
3242
type: Schema.Literal("thread.runtime-mode.set"),
packages/contracts/src/orchestratorMcp.ts
+2
-1
@@ -34,7 +34,7 @@ import {
34
} from "./threadPullRequest.ts";
35
import { secretRequestPageUrl } from "./secretRequest.ts";
36
import { hasOnlyPairedSurrogates } from "./threadMetadataMcp.ts";
37
-import { ThreadTitleRegeneration } from "./threadTitle.ts";
37
+import { LastThreadTitleRegeneration, ThreadTitleRegeneration } from "./threadTitle.ts";
38
import {
39
OrchestrationV2Actor,
40
OrchestrationV2CreationSource,
@@ -453,6 +453,7 @@ export const OrchestratorMcpThreadDetail = Schema.Struct({
453
pullRequests: Schema.optional(Schema.Array(OrchestratorMcpThreadPullRequest)),
454
pullRequestCount: Schema.optional(NonNegativeInt),
455
titleRegeneration: Schema.NullOr(ThreadTitleRegeneration),
456
+ lastTitleRegeneration: Schema.optional(Schema.NullOr(LastThreadTitleRegeneration)),
457
branch: Schema.NullOr(Schema.String),
458
worktreePath: Schema.NullOr(Schema.String),
459
parentThreadId: Schema.NullOr(ThreadId),
packages/contracts/src/threadTitle.ts
+16
@@ -7,3 +7,19 @@ export const ThreadTitleRegeneration = Schema.Struct({
7
startedAt: IsoDateTime,
8
});
9
export type ThreadTitleRegeneration = typeof ThreadTitleRegeneration.Type;
10
+
11
+export const ThreadTitleRegenerationStatus = Schema.Literals(["renamed", "unchanged", "failed"]);
12
+export type ThreadTitleRegenerationStatus = typeof ThreadTitleRegenerationStatus.Type;
13
+
14
+export const ThreadTitleRegenerationOutcome = Schema.Struct({
15
+ status: ThreadTitleRegenerationStatus,
16
+ message: Schema.optional(Schema.String),
17
+});
18
+export type ThreadTitleRegenerationOutcome = typeof ThreadTitleRegenerationOutcome.Type;
19
+
20
+export const LastThreadTitleRegeneration = Schema.Struct({
21
+ ...ThreadTitleRegenerationOutcome.fields,
22
+ requestId: CommandId,
23
+ completedAt: IsoDateTime,
24
+});
25
+export type LastThreadTitleRegeneration = typeof LastThreadTitleRegeneration.Type;