Skip to content

Commit 33bf94a

Browse files
committed
fix(execution): mirror retirement check in send-failure path and fix pool sizing
1 parent 5ad269b commit 33bf94a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

apps/sim/lib/execution/isolated-vm.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,12 @@ async function acquireWorker(): Promise<WorkerInfo | null> {
839839
const existing = selectWorker()
840840
if (existing) return existing
841841

842-
const currentPoolSize = workers.size + spawnInProgress
842+
// Count only non-retiring workers toward pool occupancy so that a replacement
843+
// can be spawned pre-emptively while a retiring worker is still draining its
844+
// in-flight executions. Retiring workers stay in `workers` until they drain,
845+
// but they no longer accept new work, so they shouldn't block new spawns.
846+
const activeWorkerCount = [...workers.values()].filter((w) => !w.retiring).length
847+
const currentPoolSize = activeWorkerCount + spawnInProgress
843848
if (currentPoolSize < POOL_SIZE) {
844849
try {
845850
return await spawnWorker()
@@ -903,7 +908,11 @@ function dispatchToWorker(
903908
stdout: '',
904909
error: { message: 'Code execution failed to start. Please try again.', name: 'Error' },
905910
})
906-
resetWorkerIdleTimeout(workerInfo.id)
911+
if (workerInfo.retiring && workerInfo.activeExecutions === 0) {
912+
cleanupWorker(workerInfo.id)
913+
} else {
914+
resetWorkerIdleTimeout(workerInfo.id)
915+
}
907916
// Defer to break synchronous recursion: drainQueue → dispatchToWorker → catch → drainQueue
908917
queueMicrotask(() => drainQueue())
909918
}

0 commit comments

Comments
 (0)