fix(server): preserve active turns when switching provider instances#22754

open6
main
fix/issue-22748
opened3d agobyJJulius Marminge
View on GitHubTwo-way sync enabledPR last imported 2d ago
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: