feat(orchestration): port thread title regeneration to the v2 runtime

Follow-ups from the main merge:

- Migration numbering: main's 035_ProjectionThreadTitleRegeneration is
  released and keeps its id; this branch's unreleased v2 migrations shift
  to 036-044 instead (a released migration can never be renumbered).
- thread.metadata.update accepts regenerateTitle: true arms an in-flight
  titleRegeneration marker on the thread payload (requestId + startedAt),
  a landing title or explicit false clears it. The marker projects onto
  thread shells and through the client-runtime shell model, so the
  sidebar's Regenerating state works unchanged.
- New ThreadTitleRegenerationService worker reacts to armed markers on
  the live domain-event stream (so ws, MCP, and mobile dispatches all
  behave the same): builds a newest-first conversation digest from the
  v2 projection (8k-char budget, retained attachments — ported from the
  v1 reactor), generates via TextGeneration, and lands the title with a
  follow-up metadata update. Failures clear the marker and log.
- The server advertises threadTitleRegeneration again, and the client
  updateThreadMetadata dispatches regenerateTitle-only updates.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and maria-rcks committed 2026-08-03 11:45:15 -04:00
1 parent 607ddc3618
commit 353f352c1e
22 files changed
+272 -49

No files matched your search

@@ -84,6 +84,8 @@ export interface UpdateThreadMetadataInput extends ThreadCommandInput {
readonly modelSelection?: ModelSelection;
readonly branch?: string | null;
readonly worktreePath?: string | null;
/** Kick off an async title regeneration for the thread. */
readonly regenerateTitle?: boolean;
}
export interface SetThreadRuntimeModeInput extends ThreadCommandInput {
@@ -418,7 +420,8 @@ export const updateThreadMetadata = Effect.fn("EnvironmentCommands.updateThreadM
if (
input.title !== undefined ||
input.branch !== undefined ||
input.worktreePath !== undefined
input.worktreePath !== undefined ||
input.regenerateTitle !== undefined
) {
result = yield* dispatch({
type: "thread.metadata.update",
@@ -427,6 +430,7 @@ export const updateThreadMetadata = Effect.fn("EnvironmentCommands.updateThreadM
...(input.title === undefined ? {} : { title: input.title }),
...(input.branch === undefined ? {} : { branch: input.branch }),
...(input.worktreePath === undefined ? {} : { worktreePath: input.worktreePath }),
...(input.regenerateTitle === undefined ? {} : { regenerateTitle: input.regenerateTitle }),
});
}
if (input.modelSelection !== undefined) {
@@ -101,6 +101,8 @@ export interface EnvironmentThreadShell {
* local visited state they keep.
*/
readonly lastVisitedAt?: string | null;
/** Pending title regeneration marker; null when no request is in flight. */
readonly titleRegeneration?: { readonly requestId: string; readonly startedAt: string } | null;
readonly deletedAt: string | null;
readonly source: OrchestrationV2ThreadShell;
}
@@ -198,6 +200,13 @@ export function presentThreadShell(
...(thread.lastVisitedAt === undefined
? {}
: { lastVisitedAt: nullableIso(thread.lastVisitedAt) }),
titleRegeneration:
thread.titleRegeneration == null
? null
: {
requestId: thread.titleRegeneration.requestId,
startedAt: iso(thread.titleRegeneration.startedAt),
},
deletedAt: nullableIso(thread.deletedAt),
source: thread,
};
+28
View File
@@ -326,6 +326,15 @@ export const OrchestrationV2AppThread = Schema.Struct({
lastVisitedAt: Schema.NullOr(Schema.DateTimeUtc).pipe(
Schema.withDecodingDefault(Effect.succeed(null)),
),
/** In-flight title regeneration marker; cleared when a new title lands. */
titleRegeneration: Schema.optional(
Schema.NullOr(
Schema.Struct({
requestId: CommandId,
startedAt: Schema.DateTimeUtc,
}),
),
),
deletedAt: Schema.NullOr(Schema.DateTimeUtc),
});
export type OrchestrationV2AppThread = typeof OrchestrationV2AppThread.Type;
@@ -1222,6 +1231,15 @@ export const OrchestrationV2ThreadShell = Schema.Struct({
* back to their local visited state when the field is absent.
*/
lastVisitedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)),
/** In-flight title regeneration marker; null/absent when no request is pending. */
titleRegeneration: Schema.optional(
Schema.NullOr(
Schema.Struct({
requestId: CommandId,
startedAt: Schema.DateTimeUtc,
}),
),
),
deletedAt: Schema.NullOr(Schema.DateTimeUtc),
});
export type OrchestrationV2ThreadShell = typeof OrchestrationV2ThreadShell.Type;
@@ -1296,6 +1314,14 @@ export const OrchestrationV2AppThreadJson = OrchestrationV2AppThread.mapFields((
lastVisitedAt: Schema.NullOr(Schema.DateTimeUtcFromString).pipe(
Schema.withDecodingDefault(Effect.succeed(null)),
),
titleRegeneration: Schema.optional(
Schema.NullOr(
Schema.Struct({
requestId: CommandId,
startedAt: Schema.DateTimeUtcFromString,
}),
),
),
deletedAt: Schema.NullOr(Schema.DateTimeUtcFromString),
}));
export type OrchestrationV2AppThreadJson = typeof OrchestrationV2AppThreadJson.Type;
@@ -1903,6 +1929,8 @@ export const OrchestrationV2Command = Schema.Union([
commandId: CommandId,
threadId: ThreadId,
title: Schema.optional(TrimmedNonEmptyString),
/** Kick off (true) or abandon (false) an async title regeneration. */
regenerateTitle: Schema.optional(Schema.Boolean),
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
expectedWorktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),