feat(server): surface legacy thread migration progress
- Publish migration lifecycle events during startup - Show a web toast while legacy threads are restored
This commit is contained in:
1 parent
dbf97e42bf
commit
ba05523ed2
14 files changed
+186
-14
No files matched your search
@@ -157,10 +157,12 @@ it.layer(TestLayer)("LegacyV1ThreadImporter", (it) => {
|
||||
1,
|
||||
'2026-01-04T01:00:00.000Z',
|
||||
'2026-01-04T01:00:00.000Z'
|
||||
)
|
||||
)
|
||||
`;
|
||||
|
||||
assert.equal(yield* importer.pendingThreadCount, 1);
|
||||
const shellImport = yield* importer.reconcileShells;
|
||||
assert.equal(yield* importer.pendingThreadCount, 1);
|
||||
assert.deepStrictEqual(shellImport, {
|
||||
importedThreadCount: 1,
|
||||
importedMessageCount: 2,
|
||||
@@ -214,6 +216,7 @@ it.layer(TestLayer)("LegacyV1ThreadImporter", (it) => {
|
||||
});
|
||||
|
||||
const transcriptImport = yield* importer.ensureTranscript(threadId);
|
||||
assert.equal(yield* importer.pendingThreadCount, 0);
|
||||
assert.deepStrictEqual(transcriptImport, {
|
||||
importedThreadCount: 1,
|
||||
importedMessageCount: 2,
|
||||
|
||||
@@ -83,6 +83,7 @@ export class LegacyV1ThreadImportError extends Schema.TaggedErrorClass<LegacyV1T
|
||||
}
|
||||
|
||||
export interface LegacyV1ThreadImporterShape {
|
||||
readonly pendingThreadCount: Effect.Effect<number, LegacyV1ThreadImportError>;
|
||||
readonly reconcileShells: Effect.Effect<LegacyV1ImportSummary, LegacyV1ThreadImportError>;
|
||||
readonly ensureTranscript: (
|
||||
threadId: ThreadId,
|
||||
@@ -461,6 +462,31 @@ const make = Effect.gen(function* () {
|
||||
Effect.mapError((cause) => new LegacyV1ThreadImportError({ operation: "import", cause })),
|
||||
);
|
||||
|
||||
const pendingThreadCount = sql<{ readonly count: number }>`
|
||||
SELECT COUNT(*) AS count
|
||||
FROM (
|
||||
SELECT thread.thread_id
|
||||
FROM projection_threads AS thread
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM orchestration_events AS event
|
||||
WHERE event.application_event_version = 2
|
||||
AND event.aggregate_kind = 'thread'
|
||||
AND event.stream_id = thread.thread_id
|
||||
AND event.event_type = 'thread.created'
|
||||
)
|
||||
UNION
|
||||
SELECT legacy_import.thread_id
|
||||
FROM orchestration_v2_legacy_imports AS legacy_import
|
||||
WHERE legacy_import.transcript_imported_at IS NULL
|
||||
)
|
||||
`.pipe(
|
||||
Effect.map((rows) => rows[0]?.count ?? 0),
|
||||
Effect.mapError(
|
||||
(cause) => new LegacyV1ThreadImportError({ operation: "inspect pending", cause }),
|
||||
),
|
||||
);
|
||||
|
||||
const ensureTranscriptBase = (threadId: ThreadId) =>
|
||||
transcriptImports.withLock(
|
||||
threadId,
|
||||
@@ -583,6 +609,7 @@ const make = Effect.gen(function* () {
|
||||
);
|
||||
|
||||
return LegacyV1ThreadImporter.of({
|
||||
pendingThreadCount,
|
||||
reconcileShells,
|
||||
ensureTranscript,
|
||||
importPendingTranscripts,
|
||||
|
||||
@@ -645,6 +645,7 @@ const make = Effect.gen(function* () {
|
||||
const legacyV1ThreadImporterNoopLayer = Layer.succeed(
|
||||
LegacyV1ThreadImporter,
|
||||
LegacyV1ThreadImporter.of({
|
||||
pendingThreadCount: Effect.succeed(0),
|
||||
reconcileShells: Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
|
||||
ensureTranscript: () => Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
|
||||
importPendingTranscripts: Effect.succeed({ importedThreadCount: 0, importedMessageCount: 0 }),
|
||||
|
||||
@@ -46,8 +46,31 @@ it.effect(
|
||||
assertTrue(Option.isSome(ready));
|
||||
assert.equal(ready.value.sequence, 2);
|
||||
|
||||
yield* lifecycleEvents.publish({
|
||||
version: 1,
|
||||
type: "legacyThreadMigration",
|
||||
payload: {
|
||||
status: "running",
|
||||
totalThreadCount: 12,
|
||||
},
|
||||
});
|
||||
yield* lifecycleEvents.publish({
|
||||
version: 1,
|
||||
type: "legacyThreadMigration",
|
||||
payload: {
|
||||
status: "complete",
|
||||
totalThreadCount: 12,
|
||||
},
|
||||
});
|
||||
|
||||
const snapshot = yield* lifecycleEvents.snapshot;
|
||||
assert.equal(snapshot.sequence, 2);
|
||||
assert.deepEqual(snapshot.events.map((event) => event.type).toSorted(), ["ready", "welcome"]);
|
||||
assert.equal(snapshot.sequence, 4);
|
||||
assert.deepEqual(snapshot.events.map((event) => event.type).toSorted(), [
|
||||
"legacyThreadMigration",
|
||||
"ready",
|
||||
"welcome",
|
||||
]);
|
||||
const migration = snapshot.events.find((event) => event.type === "legacyThreadMigration");
|
||||
assert.equal(migration?.payload.status, "complete");
|
||||
}).pipe(Effect.provide(ServerLifecycleEvents.layer)),
|
||||
);
|
||||
@@ -8,7 +8,8 @@ import * as Stream from "effect/Stream";
|
||||
|
||||
type LifecycleEventInput =
|
||||
| Omit<Extract<ServerLifecycleStreamEvent, { type: "welcome" }>, "sequence">
|
||||
| Omit<Extract<ServerLifecycleStreamEvent, { type: "ready" }>, "sequence">;
|
||||
| Omit<Extract<ServerLifecycleStreamEvent, { type: "ready" }>, "sequence">
|
||||
| Omit<Extract<ServerLifecycleStreamEvent, { type: "legacyThreadMigration" }>, "sequence">;
|
||||
|
||||
interface SnapshotState {
|
||||
readonly sequence: number;
|
||||
@@ -39,10 +40,10 @@ const make = Effect.gen(function* () {
|
||||
...event,
|
||||
sequence: nextSequence,
|
||||
} satisfies ServerLifecycleStreamEvent;
|
||||
const nextEvents =
|
||||
nextEvent.type === "welcome"
|
||||
? [nextEvent, ...current.events.filter((entry) => entry.type !== "welcome")]
|
||||
: [nextEvent, ...current.events.filter((entry) => entry.type !== "ready")];
|
||||
const nextEvents = [
|
||||
nextEvent,
|
||||
...current.events.filter((entry) => entry.type !== nextEvent.type),
|
||||
];
|
||||
return [nextEvent, { sequence: nextSequence, events: nextEvents }] as const;
|
||||
}).pipe(Effect.tap((event) => PubSub.publish(pubsub, event))),
|
||||
snapshot: Ref.get(state),
|
||||
|
||||
@@ -419,6 +419,17 @@ export const make = Effect.gen(function* () {
|
||||
|
||||
const welcomeBase = yield* resolveWelcomeBase;
|
||||
const environment = yield* serverEnvironment.getDescriptor;
|
||||
const legacyMigrationThreadCount = yield* legacyV1ThreadImporter.pendingThreadCount;
|
||||
if (legacyMigrationThreadCount > 0) {
|
||||
yield* lifecycleEvents.publish({
|
||||
version: 1,
|
||||
type: "legacyThreadMigration",
|
||||
payload: {
|
||||
status: "running",
|
||||
totalThreadCount: legacyMigrationThreadCount,
|
||||
},
|
||||
});
|
||||
}
|
||||
const { recovery, bootstrap: bootstrapTargets } = yield* runOrderedV2StartupPhases({
|
||||
importLegacyShells: runStartupPhase(
|
||||
"orchestration-v2.legacy-v1.import-shells",
|
||||
@@ -475,14 +486,29 @@ export const make = Effect.gen(function* () {
|
||||
|
||||
yield* Effect.logDebug("Accepting commands");
|
||||
yield* commandGate.signalCommandReady;
|
||||
yield* legacyV1ThreadImporter.importPendingTranscripts.pipe(
|
||||
const importPendingTranscripts = legacyV1ThreadImporter.importPendingTranscripts.pipe(
|
||||
Effect.tap((summary) =>
|
||||
summary.importedThreadCount === 0
|
||||
? Effect.void
|
||||
: Effect.logInfo("Hydrated legacy v1 thread transcripts", summary),
|
||||
),
|
||||
Effect.forkScoped,
|
||||
);
|
||||
yield* (
|
||||
legacyMigrationThreadCount > 0
|
||||
? importPendingTranscripts.pipe(
|
||||
Effect.tap(() =>
|
||||
lifecycleEvents.publish({
|
||||
version: 1,
|
||||
type: "legacyThreadMigration",
|
||||
payload: {
|
||||
status: "complete",
|
||||
totalThreadCount: legacyMigrationThreadCount,
|
||||
},
|
||||
}),
|
||||
),
|
||||
)
|
||||
: importPendingTranscripts
|
||||
).pipe(Effect.forkScoped);
|
||||
|
||||
yield* Effect.logDebug("startup phase: publishing welcome event", {
|
||||
environmentId: environment.environmentId,
|
||||
|
||||
@@ -6378,9 +6378,6 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{!isDraftHeroState ? (
|
||||
<div className="chat-composer-horizontal-inset relative z-10 pb-[calc(env(safe-area-inset-bottom)+0.75rem)] sm:pb-[calc(env(safe-area-inset-bottom)+1rem)]" />
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
{activeThreadRef && activePreviewMiniPlayer ? (
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
import { primaryServerLegacyThreadMigrationAtom } from "../state/server";
|
||||
import { toastManager } from "./ui/toast";
|
||||
|
||||
type MigrationToastId = ReturnType<typeof toastManager.add>;
|
||||
|
||||
export function LegacyThreadMigrationToast() {
|
||||
const migration = useAtomValue(primaryServerLegacyThreadMigrationAtom);
|
||||
const toastIdRef = useRef<MigrationToastId | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (migration?.status === "running") {
|
||||
if (toastIdRef.current !== null) {
|
||||
return;
|
||||
}
|
||||
toastIdRef.current = toastManager.add({
|
||||
type: "loading",
|
||||
title: "Restoring your threads…",
|
||||
description: `Migrating ${migration.totalThreadCount.toLocaleString()} ${
|
||||
migration.totalThreadCount === 1 ? "thread" : "threads"
|
||||
} from the previous version. You can keep working while this finishes.`,
|
||||
timeout: 0,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (toastIdRef.current !== null) {
|
||||
toastManager.close(toastIdRef.current);
|
||||
toastIdRef.current = null;
|
||||
}
|
||||
}, [migration]);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (toastIdRef.current !== null) {
|
||||
toastManager.close(toastIdRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -109,6 +109,7 @@ export function ThreadDetailsPanel(props: ThreadDetailsPanelProps) {
|
||||
<div
|
||||
className={cn(
|
||||
"panel-glass overflow-hidden rounded-[20px]",
|
||||
props.mode === "popover" && "panel-glass-opaque",
|
||||
props.mode === "inline" ? "max-h-full" : "max-h-[calc(100dvh-6.5rem)]",
|
||||
)}
|
||||
data-thread-details-card
|
||||
|
||||
@@ -904,6 +904,10 @@ html[data-mobile-composer-route-transition="true"]::view-transition-old(t3-mobil
|
||||
backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturation));
|
||||
}
|
||||
|
||||
.panel-glass-opaque::before {
|
||||
background: var(--popover);
|
||||
}
|
||||
|
||||
.dialog-glass {
|
||||
border-color: color-mix(in srgb, var(--foreground) 10%, transparent);
|
||||
box-shadow: 0 24px 64px -24px rgb(0 0 0 / 65%);
|
||||
|
||||
@@ -19,6 +19,7 @@ import { ConnectOnboardingDialog } from "../components/cloud/ConnectOnboardingDi
|
||||
import { RelayClientInstallDialog } from "../components/cloud/RelayClientInstallDialog";
|
||||
import { SshPasswordPromptDialog } from "../components/desktop/SshPasswordPromptDialog";
|
||||
import { ProviderUpdateLaunchNotification } from "../components/ProviderUpdateLaunchNotification";
|
||||
import { LegacyThreadMigrationToast } from "../components/LegacyThreadMigrationToast";
|
||||
import { SlowRpcRequestToastCoordinator } from "../components/SlowRpcRequestToastCoordinator";
|
||||
import { ThemeEditorHost } from "../components/settings/ThemeEditorHost";
|
||||
import { Button } from "../components/ui/button";
|
||||
@@ -138,6 +139,7 @@ function RootRouteView() {
|
||||
<SshPasswordPromptDialog />
|
||||
<ConfirmDialogHost />
|
||||
<SlowRpcRequestToastCoordinator />
|
||||
{primaryEnvironmentAuthenticated ? <LegacyThreadMigrationToast /> : null}
|
||||
<HostedStaticEnvironmentBootstrap />
|
||||
{primaryEnvironmentAuthenticated ? <EventRouter /> : null}
|
||||
{primaryEnvironmentAuthenticated ? <ProviderUpdateLaunchNotification /> : null}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
type EditorId,
|
||||
type ServerConfig,
|
||||
type ServerConfigStreamEvent,
|
||||
type ServerLifecycleLegacyThreadMigrationPayload,
|
||||
type ServerLifecycleWelcomePayload,
|
||||
type ServerProvider,
|
||||
type ServerSettings,
|
||||
@@ -71,6 +72,18 @@ export const primaryServerWelcomeAtom = Atom.make(
|
||||
(get): ServerLifecycleWelcomePayload | null => get(primaryServerStateAtom).welcome,
|
||||
).pipe(Atom.withLabel("web-primary-server-welcome"));
|
||||
|
||||
export const primaryServerLegacyThreadMigrationAtom = Atom.make(
|
||||
(get): ServerLifecycleLegacyThreadMigrationPayload | null => {
|
||||
const environmentId = get(primaryEnvironmentIdAtom);
|
||||
if (environmentId === null) {
|
||||
return null;
|
||||
}
|
||||
return Option.getOrNull(
|
||||
AsyncResult.value(get(serverEnvironment.legacyThreadMigration({ environmentId, input: {} }))),
|
||||
);
|
||||
},
|
||||
).pipe(Atom.withLabel("web-primary-server-legacy-thread-migration"));
|
||||
|
||||
export const primaryServerSettingsAtom = Atom.make(
|
||||
(get): ServerSettings => get(primaryServerConfigAtom)?.settings ?? DEFAULT_SERVER_SETTINGS,
|
||||
).pipe(Atom.withLabel("web-primary-server-settings"));
|
||||
|
||||
@@ -428,7 +428,7 @@ export function serverConfigStateChanges(environmentId: EnvironmentId) {
|
||||
export function projectServerWelcome(
|
||||
current: Option.Option<ServerLifecycleWelcomePayload>,
|
||||
event: {
|
||||
readonly type: "welcome" | "ready";
|
||||
readonly type: "welcome" | "ready" | "legacyThreadMigration";
|
||||
readonly payload: unknown;
|
||||
},
|
||||
): readonly [
|
||||
@@ -718,6 +718,18 @@ export function createServerEnvironmentAtoms<R, E>(
|
||||
Stream.mapAccum(Option.none<ServerLifecycleWelcomePayload>, projectServerWelcome),
|
||||
),
|
||||
}),
|
||||
legacyThreadMigration: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
|
||||
label: "environment-data:server:legacy-thread-migration",
|
||||
tag: WS_METHODS.subscribeServerLifecycle,
|
||||
transform: (stream) =>
|
||||
stream.pipe(
|
||||
Stream.filterMap((event) =>
|
||||
event.type === "legacyThreadMigration"
|
||||
? Result.succeed(event.payload)
|
||||
: Result.failVoid,
|
||||
),
|
||||
),
|
||||
}),
|
||||
refreshProviders: createEnvironmentRpcCommand(runtime, {
|
||||
label: "environment-data:server:refresh-providers",
|
||||
tag: WS_METHODS.serverRefreshProviders,
|
||||
|
||||
@@ -565,6 +565,13 @@ export const ServerLifecycleWelcomePayload = Schema.Struct({
|
||||
});
|
||||
export type ServerLifecycleWelcomePayload = typeof ServerLifecycleWelcomePayload.Type;
|
||||
|
||||
export const ServerLifecycleLegacyThreadMigrationPayload = Schema.Struct({
|
||||
status: Schema.Union([Schema.Literal("running"), Schema.Literal("complete")]),
|
||||
totalThreadCount: NonNegativeInt,
|
||||
});
|
||||
export type ServerLifecycleLegacyThreadMigrationPayload =
|
||||
typeof ServerLifecycleLegacyThreadMigrationPayload.Type;
|
||||
|
||||
export const ServerLifecycleStreamWelcomeEvent = Schema.Struct({
|
||||
version: Schema.Literal(1),
|
||||
sequence: NonNegativeInt,
|
||||
@@ -581,9 +588,19 @@ export const ServerLifecycleStreamReadyEvent = Schema.Struct({
|
||||
});
|
||||
export type ServerLifecycleStreamReadyEvent = typeof ServerLifecycleStreamReadyEvent.Type;
|
||||
|
||||
export const ServerLifecycleStreamLegacyThreadMigrationEvent = Schema.Struct({
|
||||
version: Schema.Literal(1),
|
||||
sequence: NonNegativeInt,
|
||||
type: Schema.Literal("legacyThreadMigration"),
|
||||
payload: ServerLifecycleLegacyThreadMigrationPayload,
|
||||
});
|
||||
export type ServerLifecycleStreamLegacyThreadMigrationEvent =
|
||||
typeof ServerLifecycleStreamLegacyThreadMigrationEvent.Type;
|
||||
|
||||
export const ServerLifecycleStreamEvent = Schema.Union([
|
||||
ServerLifecycleStreamWelcomeEvent,
|
||||
ServerLifecycleStreamReadyEvent,
|
||||
ServerLifecycleStreamLegacyThreadMigrationEvent,
|
||||
]);
|
||||
export type ServerLifecycleStreamEvent = typeof ServerLifecycleStreamEvent.Type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user