Skip to content

Commit 124f10b

Browse files
t3dotggclaude
andcommitted
perf(shell): a resume never sends more rows than a fresh snapshot
After #24723 a fresh snapshot keeps about 25 settled threads, so the 500-row replay cap let resumes cost more than a snapshot. The cap now matches the settled rows a snapshot keeps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4d04673 commit 124f10b

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎apps/server/src/orchestration-v2/ShellStream.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function activeShellRowsForSubscriber(
116116
};
117117
}
118118

119-
const NEWEST_SETTLED_KEPT = 25;
119+
export const NEWEST_SETTLED_KEPT = 25;
120120

121121
/**
122122
* Opted-in snapshots keep the 25 newest settled top-level threads (and ties) and count the rest per

‎apps/server/src/ws.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ it.effect("shell resume sends each touched aggregate once, or a snapshot past it
381381
assert.deepEqual(yield* resume(gone + 1), ["snapshot", "synchronized"]);
382382

383383
const first = yield* insert("project", "project:0", "project.meta-updated");
384-
for (let index = 1; index <= 500; index += 1) {
384+
for (let index = 1; index <= 25; index += 1) {
385385
yield* insert("project", `project:${index}`, "project.meta-updated");
386386
}
387387
assert.deepEqual(yield* resume(gone), ["snapshot", "synchronized"]);
388388
const capped = yield* resume(first);
389-
assert.equal(capped.length, 501);
389+
assert.equal(capped.length, 26);
390390
assert.equal(capped.at(-1), "synchronized");
391391
}).pipe(Effect.scoped, Effect.provide(ReplayTestLayer)),
392392
);

‎apps/server/src/ws.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ import * as ScheduledTasks from "./scheduledTasks/ScheduledTaskService.ts";
124124
import * as SecretRequests from "./secrets/SecretRequests.ts";
125125
import * as GuestShareService from "./guest/GuestShareService.ts";
126126
import {
127+
NEWEST_SETTLED_KEPT,
127128
archivedShellStreamItemFromThreadShell,
128129
buildActiveShellSnapshot,
129130
bufferShellLiveStream,
@@ -575,9 +576,10 @@ const serverWsRpcs = Array.from(ServerWsRpcGroup.requests.values());
575576
const SplitWsRpcGroup = RpcGroup.make(...serverWsRpcs.filter(isSplitWsRpc));
576577
const OtherWsRpcGroup = RpcGroup.make(...serverWsRpcs.filter(isOtherWsRpc));
577578
// A shell resume decodes no payloads: one indexed scan of the gap finds the touched projects and
578-
// threads, then their current rows are read. Past either cap a snapshot is about as cheap.
579+
// threads, then their current rows are read. Past either cap a snapshot is about as cheap: a
580+
// snapshot holds at least the newest settled threads, while touched rows are often ones it omits.
579581
const SHELL_RESUME_MAX_GAP = 100_000;
580-
const SHELL_RESUME_MAX_TOUCHED = 500;
582+
const SHELL_RESUME_MAX_TOUCHED = NEWEST_SETTLED_KEPT;
581583

582584
function toAuthAccessStreamEvent(
583585
change: PairingGrantStore.BootstrapCredentialChange | SessionStore.SessionCredentialChange,

0 commit comments

Comments
 (0)