The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 12:00 UTC
perf(server): preparing a run is 15x faster and uses 200x less memory (#27105)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 29, 2026 at 13:23 UTC
22c37a8da4567d59b0759396dd5412b28da9ab4a
1 file changed
+19
-14
apps/server/src/orchestration-v2/ThreadLaunchService.ts
+19
-14
@@ -1063,12 +1063,14 @@ const make = Effect.gen(function* () {
1063
"ThreadLaunchService.prepareRun",
1064
)(function* (input) {
1065
const scheduled = yield* Effect.gen(function* () {
1066
- const projection = yield* threads.getThreadProjection(input.threadId);
1067
- const run = projection.runs.find((candidate) => candidate.id === input.runId);
1066
+ const { thread, runs } = yield* threads.getThreadRecords(input.threadId, ["runs"], {
1067
+ runIds: [input.runId],
1068
+ });
1069
+ const run = runs.find((candidate) => candidate.id === input.runId);
1070
const workspacePreparation = run?.workspacePreparation;
1071
if (run?.status !== "preparing" || workspacePreparation === undefined) return;
1072
if (!(yield* reservePreparation(input.commandId))) return;
1071
- yield* scheduleRunPreparation(input, projection, run, workspacePreparation).pipe(
1073
+ yield* scheduleRunPreparation(input, thread, run, workspacePreparation).pipe(
1074
Effect.onError(() => releasePreparation(input.commandId)),
1075
);
1076
}).pipe(Effect.exit);
@@ -1090,30 +1092,33 @@ const make = Effect.gen(function* () {
1092
return dispatched;
1093
});
1094
1093
- const scheduleRunPreparation = (
1095
+ const scheduleRunPreparation = Effect.fn("ThreadLaunchService.scheduleRunPreparation")(function* (
1096
input: ThreadLaunchPreparationInput,
1095
- projection: OrchestrationV2ThreadProjection,
1097
+ thread: OrchestrationV2ThreadProjection["thread"],
1098
run: OrchestrationV2ThreadProjection["runs"][number],
1099
workspacePreparation: ThreadLaunchWorkspaceStrategy,
1098
- ) => {
1099
- const message = projection.messages.find((candidate) => candidate.id === run.userMessageId);
1100
+ ) {
1101
+ const { messages } = yield* threads.getThreadRecords(input.threadId, ["messages"], {
1102
+ messageIds: [run.userMessageId],
1103
+ });
1104
+ const message = messages.find((candidate) => candidate.id === run.userMessageId);
1105
const reuse =
1106
workspacePreparation.type === "worktree" &&
1102
- projection.thread.worktreePath !== null &&
1103
- projection.thread.branch !== null
1107
+ thread.worktreePath !== null &&
1108
+ thread.branch !== null
1109
? {
1110
strategy: {
1111
type: "existing_worktree" as const,
1107
- worktreePath: projection.thread.worktreePath,
1108
- branch: projection.thread.branch,
1112
+ worktreePath: thread.worktreePath,
1113
+ branch: thread.branch,
1114
},
1115
reusedWorktree: { baseRef: workspacePreparation.baseRef },
1116
}
1117
: null;
1113
- return schedulePreparation(
1118
+ return yield* schedulePreparation(
1119
{
1120
commandId: input.commandId,
1116
- projectId: projection.thread.projectId,
1121
+ projectId: thread.projectId,
1122
workspaceStrategy: reuse?.strategy ?? workspacePreparation,
1123
...(reuse === null ? {} : { reusedWorktree: reuse.reusedWorktree }),
1124
...(message === undefined
@@ -1129,7 +1134,7 @@ const make = Effect.gen(function* () {
1134
input.threadId,
1135
run.id,
1136
);
1132
- };
1137
+ });
1138
1139
return ThreadLaunchService.of({ launch, checkWorktreeBase, retryPreparation, prepareRun });
1140
});