fix(server): preserve active turns when switching provider instances#22754
0 / 4 viewed4 files changedLine totals unavailable
apps/server/src/orchestration-v2/Orchestrator.ts · Earlier revision 896c0e10 · right 2964
Original diff
@@ -2947,12 +2947,26 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
}),
),
);
- return yield* providerSwitchService
+ const plan = yield* providerSwitchService
.plan({
projection: providerContext!,
targetModelSelection: command.modelSelection,
})
.pipe(mapDispatchError(command));
+ if (plan.instanceChanged || plan.releaseProviderSessionIds.length > 0) {
+ const projection = yield* loadProjectionForCommand(command, ["runs"], {
+ turnItemTypes: [],
+ });
+ if (projection.runs.some(isBlockingRun)) {
+ return yield* new OrchestratorDispatchError({
+ commandId: command.commandId,
+ commandType: command.type,
+ cause: