perf(client-runtime): halve server config bootstrap traffic (#8367)
Reuse one server config subscription for session bootstrap and live updates. Preserve environment theme opt-in, replay, deletion, slow subscriber recovery, and config stream failure handling. Co-authored-by: Adamulek123 <[email protected]>
This commit is contained in:
1 parent
e86604d337
commit
b883fc066e
20 files changed
+1053
-151
No files matched your search
@@ -32,6 +32,7 @@ function session(client: WsRpcProtocolClient): RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.never,
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -30,7 +30,6 @@ import * as Persistence from "../platform/persistence.ts";
|
||||
import type { WsRpcProtocolClient } from "../rpc/protocol.ts";
|
||||
import type { RpcSession } from "../rpc/session.ts";
|
||||
import {
|
||||
applyServerConfigProjection,
|
||||
makeEnvironmentServerConfigState,
|
||||
isLegacyUpdateHandoffLoss,
|
||||
matchesServerUpdateReadyEvent,
|
||||
@@ -42,6 +41,7 @@ import {
|
||||
serverUpdateStateForServerVersion,
|
||||
validateServerUpdateReadyEvent,
|
||||
} from "./server.ts";
|
||||
import { applyServerConfigProjection } from "./serverConfigProjection.ts";
|
||||
|
||||
const CONFIG = {
|
||||
availableEditors: [],
|
||||
@@ -73,6 +73,7 @@ function session(client: WsRpcProtocolClient): RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.succeed(CONFIG),
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -41,6 +41,14 @@ import {
|
||||
type EnvironmentRpcInput,
|
||||
} from "../rpc/client.ts";
|
||||
import { followStreamInEnvironment } from "./runtime.ts";
|
||||
import {
|
||||
applyServerConfigProjection,
|
||||
type ServerConfigProjection,
|
||||
withoutEnvironmentThemes,
|
||||
} from "./serverConfigProjection.ts";
|
||||
|
||||
// Exported server state includes this type in its inferred public return type.
|
||||
export type { ServerConfigProjection } from "./serverConfigProjection.ts";
|
||||
|
||||
export type ServerUpdateStage = "downloading" | "installing" | "resuming";
|
||||
|
||||
@@ -262,75 +270,6 @@ export function resolveServerUpdateProgressResult<E>(
|
||||
return Effect.fail(new ServerUpdateProgressIncompleteError({ targetVersion }));
|
||||
}
|
||||
|
||||
export interface ServerConfigProjection {
|
||||
readonly config: ServerConfig;
|
||||
readonly latestEvent: ServerConfigStreamEvent;
|
||||
readonly source: "cache" | "live";
|
||||
}
|
||||
|
||||
export function applyServerConfigProjection(
|
||||
current: Option.Option<ServerConfigProjection>,
|
||||
event: ServerConfigStreamEvent,
|
||||
): Option.Option<ServerConfigProjection> {
|
||||
switch (event.type) {
|
||||
case "snapshot": {
|
||||
// A snapshot never carries published themes -- the theme stream owns
|
||||
// them -- so taking it wholesale would clear the set on every reconnect
|
||||
// and repaint anyone wearing one until the follow-up event landed.
|
||||
// Only from a server that still streams them. Reconnecting to one that
|
||||
// predates the feature must drop the set rather than leave a palette on
|
||||
// screen that nothing will ever update again.
|
||||
const carried =
|
||||
event.config.environment.capabilities.environmentThemes === true && Option.isSome(current)
|
||||
? current.value.config.environmentThemes
|
||||
: undefined;
|
||||
return Option.some({
|
||||
config:
|
||||
carried === undefined ? event.config : { ...event.config, environmentThemes: carried },
|
||||
latestEvent: event,
|
||||
source: "live" as const,
|
||||
});
|
||||
}
|
||||
case "keybindingsUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
keybindings: event.payload.keybindings,
|
||||
issues: event.payload.issues,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "providerStatuses":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
providers: event.payload.providers,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "settingsUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
settings: event.payload.settings,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "environmentThemesUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
environmentThemes: event.payload.themes.length > 0 ? event.payload.themes : undefined,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
export function projectServerConfig(
|
||||
current: Option.Option<ServerConfigProjection>,
|
||||
event: ServerConfigStreamEvent,
|
||||
@@ -345,22 +284,6 @@ const cachedConfigSnapshotEvent = (config: ServerConfig): ServerConfigStreamEven
|
||||
config,
|
||||
});
|
||||
|
||||
/**
|
||||
* Keeps a complete server configuration available during reconnects. Server
|
||||
* config carries the provider/model catalogue used by task creation, so it is
|
||||
* useful—and safe—to retain after a transport session ends.
|
||||
*/
|
||||
/**
|
||||
* Published themes live only as long as the machine publishes them, so they
|
||||
* must not survive in the config cache: a restart or an offline load would
|
||||
* otherwise hand clients palettes the environment has already dropped.
|
||||
*/
|
||||
function withoutEnvironmentThemes(config: ServerConfig): ServerConfig {
|
||||
if (config.environmentThemes === undefined) return config;
|
||||
const { environmentThemes: _ephemeral, ...rest } = config;
|
||||
return rest;
|
||||
}
|
||||
|
||||
export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConfigState.make")(
|
||||
function* (environmentThemes?: boolean) {
|
||||
const supervisor = yield* EnvironmentSupervisor;
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
export interface ServerConfigProjection {
|
||||
readonly config: ServerConfig;
|
||||
readonly latestEvent: ServerConfigStreamEvent;
|
||||
readonly source: "cache" | "live";
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached config keeps the provider and model catalog available across reconnects.
|
||||
* Published themes are current machine state, so a cache could restore themes
|
||||
* that the machine no longer publishes. Replay sends themes as a separate event.
|
||||
*/
|
||||
export function withoutEnvironmentThemes(config: ServerConfig): ServerConfig {
|
||||
if (config.environmentThemes === undefined) return config;
|
||||
const { environmentThemes: _ephemeral, ...rest } = config;
|
||||
return rest;
|
||||
}
|
||||
|
||||
export function applyServerConfigProjection(
|
||||
current: Option.Option<ServerConfigProjection>,
|
||||
event: ServerConfigStreamEvent,
|
||||
): Option.Option<ServerConfigProjection> {
|
||||
switch (event.type) {
|
||||
case "snapshot": {
|
||||
// Wire snapshots never contain published themes. Keep the previous set
|
||||
// until a capable server sends its authoritative theme event. A legacy
|
||||
// server cannot send a later removal, so a downgrade must clear the set.
|
||||
const carried =
|
||||
event.config.environment.capabilities.environmentThemes === true && Option.isSome(current)
|
||||
? current.value.config.environmentThemes
|
||||
: undefined;
|
||||
return Option.some({
|
||||
config:
|
||||
carried === undefined ? event.config : { ...event.config, environmentThemes: carried },
|
||||
latestEvent: event,
|
||||
source: "live" as const,
|
||||
});
|
||||
}
|
||||
case "keybindingsUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
keybindings: event.payload.keybindings,
|
||||
issues: event.payload.issues,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "providerStatuses":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
providers: event.payload.providers,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "settingsUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
settings: event.payload.settings,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
case "environmentThemesUpdated":
|
||||
return Option.map(current, (projection) => ({
|
||||
config: {
|
||||
...projection.config,
|
||||
environmentThemes: event.payload.themes.length > 0 ? event.payload.themes : undefined,
|
||||
},
|
||||
latestEvent: event,
|
||||
source: "live",
|
||||
}));
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ function session(client: WsRpcProtocolClient): RpcSession.RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.succeed({ shellResumeCompletionMarker: true } as never),
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -50,6 +50,7 @@ function session(client: WsRpcProtocolClient): RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.never,
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -156,6 +156,7 @@ const makeHarness = Effect.fn("TestThreadPagination.makeHarness")(function* (opt
|
||||
initialConfig: Effect.succeed({
|
||||
threadSnapshotPagination: options?.paginationCapability !== false,
|
||||
} as never),
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -112,6 +112,7 @@ function testSession(
|
||||
? ({ threadResumeCompletionMarker: true } as never)
|
||||
: ({} as never),
|
||||
),
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -86,6 +86,7 @@ function session(client: WsRpcProtocolClient): RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.never,
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
@@ -84,6 +84,7 @@ function session(client: WsRpcProtocolClient): RpcSession {
|
||||
return {
|
||||
client,
|
||||
initialConfig: Effect.never,
|
||||
subscribeServerConfig: (input) => client.subscribeServerConfig(input),
|
||||
ready: Effect.void,
|
||||
probe: Effect.void,
|
||||
closed: Effect.never,
|
||||
|
||||
Reference in new issue
Block a user