From 88e91b0b488985fb99bfc992d4ec639565337f63 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 02:00:01 -0800 Subject: [PATCH 1/2] feat(scripts): server metrics reconnect a user's devices by default and keep the 20-client storm behind --stress Co-Authored-By: Claude Opus 5.5 --- docs/internals/16_performance-regressions.md | 2 + scripts/server-metrics-report.ts | 21 ++-- scripts/server-metrics.ts | 117 ++++++++++++------- 3 files changed, 93 insertions(+), 47 deletions(-) diff --git a/docs/internals/16_performance-regressions.md b/docs/internals/16_performance-regressions.md index 135fb95ea6905..befd6fa1c2dbb 100644 --- a/docs/internals/16_performance-regressions.md +++ b/docs/internals/16_performance-regressions.md @@ -40,6 +40,8 @@ heap, and first-request latency against a fake Anthropic API and the real `claud - Steer server work by `working`: many worktree threads editing files at once with one client subscribed to all of them. Turns per minute that stay flat as threads are added mean the server, not the agents, is the bottleneck. +- Upper bounds no user hits daily, such as 20 clients reconnecting at once, run only with + `--stress`; the default reconnect is a user's 3 devices holding 10 threads each. - Test macOS, Windows, and Linux with `--no-agent-scope`: Linux systemd agent scopes mask per-process polling paths that other platforms run. diff --git a/scripts/server-metrics-report.ts b/scripts/server-metrics-report.ts index 70a6e52ec73c4..4615a804a6dff 100644 --- a/scripts/server-metrics-report.ts +++ b/scripts/server-metrics-report.ts @@ -61,6 +61,15 @@ const WorkingPoint = Schema.Struct({ }); export type WorkingPoint = typeof WorkingPoint.Type; +const Reconnect = Schema.Struct({ + clients: Schema.Number, + threadsPerClient: Schema.optional(Schema.Number), + /** Drop to every subscription delivering its snapshot again. */ + resubscribedMs: Schema.Number, + loopDelayP99Ms: Schema.Number, + loopDelayMaxMs: Schema.Number, +}); + /** One pass over the scenarios. */ export const Measured = Schema.Struct({ /** What else the machine was doing during the pass; never compared, only warned about. */ @@ -77,13 +86,10 @@ export const Measured = Schema.Struct({ Schema.Struct({ /** The quiet window by subscribed thread count. */ attached: Schema.Record(Schema.String, Window), - /** Every client drops and reconnects at once. */ - storm: Schema.Struct({ - clients: Schema.Number, - resubscribedMs: Schema.Number, - loopDelayP99Ms: Schema.Number, - loopDelayMaxMs: Schema.Number, - }), + /** A user's few devices, each holding the shell, VCS status and threads, drop and reconnect. */ + reconnect: Schema.optional(Reconnect), + /** With --stress: 20 clients holding one thread each drop and reconnect at once. */ + storm: Schema.optional(Reconnect), }), ), /** @@ -328,6 +334,7 @@ const isMetric = (metric: string) => metric === "busy.projects" || metric === "busy.ballastMB" || metric.endsWith(".clients") || + metric.endsWith(".threadsPerClient") || metric.endsWith(".threads") || metric === "busy.largeThread.messages" || metric.startsWith("scaling.points") diff --git a/scripts/server-metrics.ts b/scripts/server-metrics.ts index 54fc28693b3fd..cf8b85fa4e146 100644 --- a/scripts/server-metrics.ts +++ b/scripts/server-metrics.ts @@ -95,7 +95,10 @@ const EDIT_MARKER = "[[edit-files]]"; const PIPELINE_TURNS = 50; /** Threads working at once in each window of the working scenario. */ const WORKING_THREADS = [5, 10, 20]; -/** Clients that drop and reconnect at once in the clients scenario. */ +/** A user's devices: clients that drop and reconnect at once, each holding this many threads. */ +const RECONNECT_CLIENTS = 3; +const RECONNECT_THREADS = 10; +/** Clients that drop and reconnect at once in the opt-in storm, each holding one thread. */ const STORM_CLIENTS = 20; /** Event-loop delay sampling interval; each sample wakes the loop once. */ const LOOP_RESOLUTION_MS = 10; @@ -1346,6 +1349,48 @@ const attachClient = Effect.fn("serverMetrics.attachClient")(function* ( }; }); +/** + * Attaches one client per entry, each holding the shell, VCS status and its threads, lets them + * settle, then drops all of them at once and reconnects them: the time until every subscription + * delivered its snapshot again, and the loop delay across it. + */ +const reconnectAll = Effect.fn("serverMetrics.reconnectAll")(function* ( + server: Server, + token: string, + clientThreads: ReadonlyArray>, +) { + // Each client gets its own scope so they can be dropped on cue; the server's scope still closes + // any left open when a step fails or is interrupted. + const clientScope = Effect.acquireRelease(Scope.make(), (scope, exit) => + Scope.close(scope, exit), + ); + const attachAll = (scopes: ReadonlyArray) => + Effect.forEach( + scopes, + (scope, index) => + attachClient(server, token, clientThreads[index] ?? []).pipe(Scope.provide(scope)), + { concurrency: "unbounded" }, + ); + const clients = yield* Effect.forEach(clientThreads, () => clientScope); + const first = yield* attachAll(clients); + yield* Effect.sleep(Duration.seconds(10)); + yield* Effect.forEach(first, (client) => client.healthy, { discard: true }); + yield* server.loopStart; + const dropped = yield* nowMs; + yield* Effect.forEach(clients, (scope) => Scope.close(scope, Exit.void), { + concurrency: "unbounded", + discard: true, + }); + const reopened = yield* Effect.forEach(clientThreads, () => clientScope); + const second = yield* attachAll(reopened); + const resubscribedMs = Math.round((yield* nowMs) - dropped); + const loop = yield* server.loopRead; + // The first cohort again: a loss between its check and the drop happened in the reconnect. + yield* Effect.forEach([...first, ...second], (client) => client.healthy, { discard: true }); + yield* Effect.forEach(reopened, (scope) => Scope.close(scope, Exit.void), { discard: true }); + return { resubscribedMs, loopDelayP99Ms: round(loop.p99), loopDelayMaxMs: round(loop.max) }; +}); + /** * Short turns back to back on one thread: how long a send takes to reach the API, how long the * end of the reply takes to become a finished run the CLI sees (turn end and checkpoint), the time @@ -1537,6 +1582,8 @@ interface RunOptions { /** A seeded base dir for the busy scenario. */ readonly seed: string | undefined; readonly ballastMB: number; + /** Also runs the upper-bound stress cases, such as the 20-client reconnect storm. */ + readonly stress: boolean; /** Where full CPU and allocation profiles go; none are written without it. */ readonly profileDir: string | undefined; } @@ -1640,7 +1687,11 @@ const runOnce = Effect.fn("serverMetrics.runOnce")(function* (options: RunOption yield* withServer("clients", (server) => Effect.gen(function* () { const token = yield* server.issueToken; - const most = Math.max(STORM_CLIENTS, ...options.threads); + const most = Math.max( + RECONNECT_THREADS, + options.stress ? STORM_CLIENTS : 0, + ...options.threads, + ); const threads = yield* openThreads(server, 0, most); const attached: Record = {}; for (const count of options.threads) { @@ -1653,49 +1704,27 @@ const runOnce = Effect.fn("serverMetrics.runOnce")(function* (options: RunOption }), ); } - // Each client gets its own scope so the storm can drop them on cue; the server's scope - // still closes any left open when a step fails or is interrupted. - const clientScope = Effect.acquireRelease(Scope.make(), (scope, exit) => - Scope.close(scope, exit), + const reconnect = yield* reconnectAll( + server, + token, + Array.from({ length: RECONNECT_CLIENTS }, () => threads.slice(0, RECONNECT_THREADS)), ); // Every client holds the shell, VCS status and one thread, then all drop and come back. - const clients = yield* Effect.forEach(threads.slice(0, STORM_CLIENTS), () => clientScope); - const first = yield* Effect.forEach( - clients, - (scope, index) => - attachClient(server, token, threads.slice(index, index + 1)).pipe(Scope.provide(scope)), - { concurrency: "unbounded" }, - ); - yield* Effect.sleep(Duration.seconds(10)); - yield* Effect.forEach(first, (client) => client.healthy, { discard: true }); - yield* server.loopStart; - const dropped = yield* nowMs; - yield* Effect.forEach(clients, (scope) => Scope.close(scope, Exit.void), { - concurrency: "unbounded", - discard: true, - }); - const reopened = yield* Effect.forEach(clients, () => clientScope); - const second = yield* Effect.forEach( - reopened, - (scope, index) => - attachClient(server, token, threads.slice(index, index + 1)).pipe(Scope.provide(scope)), - { concurrency: "unbounded" }, - ); - const resubscribedMs = Math.round((yield* nowMs) - dropped); - const loop = yield* server.loopRead; - // The first cohort again: a loss between its check and the drop happened in the storm. - yield* Effect.forEach([...first, ...second], (client) => client.healthy, { discard: true }); - yield* Effect.forEach(reopened, (scope) => Scope.close(scope, Exit.void), { - discard: true, - }); + const storm = options.stress + ? yield* reconnectAll( + server, + token, + threads.slice(0, STORM_CLIENTS).map((thread) => [thread]), + ) + : undefined; measured.clients = { attached, - storm: { - clients: STORM_CLIENTS, - resubscribedMs, - loopDelayP99Ms: round(loop.p99), - loopDelayMaxMs: round(loop.max), + reconnect: { + clients: RECONNECT_CLIENTS, + threadsPerClient: RECONNECT_THREADS, + ...reconnect, }, + ...(storm ? { storm: { clients: STORM_CLIENTS, ...storm } } : {}), }; }), ); @@ -2112,6 +2141,12 @@ const runFlags = { ), Flag.withDefault(768), ), + stress: Flag.Boolean("stress").pipe( + Flag.withDefault(false), + Flag.withDescription( + "Also run upper bounds no user hits daily: clients drops 20 clients at once and reconnects them. Compare stress numbers only with stress numbers.", + ), + ), soak: Flag.Int("soak").pipe( Flag.withSchema(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0))), Flag.withDescription( @@ -2130,6 +2165,7 @@ interface RunFlags { readonly busyProjects: number; readonly busyThreads: number; readonly busyBallast: number; + readonly stress: boolean; } const toRunOptions = Effect.fn("serverMetrics.toRunOptions")(function* ( @@ -2156,6 +2192,7 @@ const toRunOptions = Effect.fn("serverMetrics.toRunOptions")(function* ( profileDir, seed: undefined, ballastMB: flags.busyBallast, + stress: flags.stress, }; return options; }); From dc9c94214b51b5b6266448846779623b9dfad5e9 Mon Sep 17 00:00:00 2001 From: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com> Date: Mon, 23 Nov 2026 05:01:47 -0800 Subject: [PATCH 2/2] fix(scripts): the default reconnect takes the storm's noise floors until it has an A/A run Co-Authored-By: Claude Opus 5.5 --- scripts/server-metrics-report.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/server-metrics-report.ts b/scripts/server-metrics-report.ts index 4615a804a6dff..c0edb68319994 100644 --- a/scripts/server-metrics-report.ts +++ b/scripts/server-metrics-report.ts @@ -271,7 +271,9 @@ export const NOISE_RULES: ReadonlyArray = [ informational(/^(rest|quiet|streaming|clients\.attached\.\d+)\.loopDelay(P99|Max)Ms$/), informational(/^(rest|quiet|clients\.attached\.\d+)\.gc(Count|PauseMs)$/), informational(/^(streaming|pipeline)\.gcPauseMs$/), - informational(/^(pipeline\.loopDelayMaxMs|clients\.storm\.loopDelayP99Ms|quiet\.cpuPct)$/), + informational( + /^(pipeline\.loopDelayMaxMs|clients\.(storm|reconnect)\.loopDelayP99Ms|quiet\.cpuPct)$/, + ), informational(/^scaling\.(cpuPct|wakeups)PerThread$/), informational(/^clients\.attached\.\d+\.(cpuPct|wakeupsPerSec)$/), informational(/^(firstWord\..*|pipeline\.turnEndMs)\.p90$/), @@ -300,7 +302,8 @@ export const NOISE_RULES: ReadonlyArray = [ { pattern: /^firstWord\./, floor: 600, gate: true }, { pattern: /^pipeline\.(toRequestMs|turnEndMs)\.median$/, floor: 300, gate: true }, { pattern: /^pipeline\.(toRequestMs\.p90|msPerTurn)$/, floor: 600, gate: true }, - { pattern: /^clients\.storm\.resubscribedMs$/, floor: 200, gate: true }, + // The reconnect had no A/A run yet and takes the storm's floors. + { pattern: /^clients\.(storm|reconnect)\.resubscribedMs$/, floor: 200, gate: true }, { pattern: /^rest\.cpuPct$/, floor: 1, gate: true }, { pattern: /cpuPct$/, floor: 3.5, gate: true }, { pattern: /^(rest|quiet)\.wakeupsPerSec$/, floor: 12, gate: true },