Skip to content

Commit edf33d8

Browse files
t3dotggclaude
andcommitted
fix(server): cleanup's thread snapshot read runs on the reader worker
The one full snapshot read left in each sweep blocked the event loop on the main SQLite connection. On a 3.8 GB database that froze the server for about 2 seconds per sweep. Mark it readOnly so it runs on the reader worker, as ThreadPullRequestService already does. The recheck under each worktree's lease does not use this read, so it still sees the writer's latest state. Taken from #19421. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 692b1fa commit edf33d8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎apps/server/src/storageCleanup.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { isFilesystemRoot, managedWorktreesDirectories } from "./worktreesDirect
4646
import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";
4747
import { withWorkspaceLease } from "./workspace/workspaceLease.ts";
4848
import * as HostProcess from "@t3tools/shared/HostProcess";
49+
import * as NodeSqliteClient from "@t3tools/shared/nodeSqliteClient";
4950

5051
const decodeCleanupThread = Schema.decodeUnknownEffect(
5152
Schema.fromJsonString(OrchestrationV2AppThreadJson),
@@ -251,8 +252,12 @@ const make = Effect.gen(function* () {
251252

252253
// Active threads only: archived threads are not candidates and do not count
253254
// as sharing a worktree. The recheck's getThreadWorktreePaths reads the same set.
255+
// The snapshot takes seconds on large databases, so it runs on the reader
256+
// worker instead of the event loop.
254257
const readThreads = Effect.fn("StorageCleanup.readThreads")(function* () {
255-
const { threads } = yield* projections.getShellSnapshot({ location: "active" });
258+
const { threads } = yield* projections
259+
.getShellSnapshot({ location: "active" })
260+
.pipe(NodeSqliteClient.readOnly);
256261
const projects = yield* projectStore.listShells();
257262
return { projects, threads };
258263
});

0 commit comments

Comments
 (0)