Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions apps/server/src/orchestration-v2/ThreadLaunchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,12 +1066,14 @@ const make = Effect.gen(function* () {
"ThreadLaunchService.prepareRun",
)(function* (input) {
const scheduled = yield* Effect.gen(function* () {
const projection = yield* threads.getThreadProjection(input.threadId);
const run = projection.runs.find((candidate) => candidate.id === input.runId);
const { thread, runs } = yield* threads.getThreadRecords(input.threadId, ["runs"], {
runIds: [input.runId],
});
const run = runs.find((candidate) => candidate.id === input.runId);
const workspacePreparation = run?.workspacePreparation;
if (run?.status !== "preparing" || workspacePreparation === undefined) return;
if (!(yield* reservePreparation(input.commandId))) return;
yield* scheduleRunPreparation(input, projection, run, workspacePreparation).pipe(
yield* scheduleRunPreparation(input, thread, run, workspacePreparation).pipe(
Effect.onError(() => releasePreparation(input.commandId)),
);
}).pipe(Effect.exit);
Expand All @@ -1093,30 +1095,33 @@ const make = Effect.gen(function* () {
return dispatched;
});

const scheduleRunPreparation = (
const scheduleRunPreparation = Effect.fn("ThreadLaunchService.scheduleRunPreparation")(function* (
input: ThreadLaunchPreparationInput,
projection: OrchestrationV2ThreadProjection,
thread: OrchestrationV2ThreadProjection["thread"],
run: OrchestrationV2ThreadProjection["runs"][number],
workspacePreparation: ThreadLaunchWorkspaceStrategy,
) => {
const message = projection.messages.find((candidate) => candidate.id === run.userMessageId);
) {
const { messages } = yield* threads.getThreadRecords(input.threadId, ["messages"], {
messageIds: [run.userMessageId],
});
const message = messages.find((candidate) => candidate.id === run.userMessageId);
const reuse =
workspacePreparation.type === "worktree" &&
projection.thread.worktreePath !== null &&
projection.thread.branch !== null
thread.worktreePath !== null &&
thread.branch !== null
? {
strategy: {
type: "existing_worktree" as const,
worktreePath: projection.thread.worktreePath,
branch: projection.thread.branch,
worktreePath: thread.worktreePath,
branch: thread.branch,
},
reusedWorktree: { baseRef: workspacePreparation.baseRef },
}
: null;
return schedulePreparation(
return yield* schedulePreparation(
{
commandId: input.commandId,
projectId: projection.thread.projectId,
projectId: thread.projectId,
workspaceStrategy: reuse?.strategy ?? workspacePreparation,
...(reuse === null ? {} : { reusedWorktree: reuse.reusedWorktree }),
...(message === undefined
Expand All @@ -1132,7 +1137,7 @@ const make = Effect.gen(function* () {
input.threadId,
run.id,
);
};
});

return ThreadLaunchService.of({ launch, checkWorktreeBase, retryPreparation, prepareRun });
});
Expand Down
Loading