From ec435c37ae2859511415b3142f1ba37c1cb7cb99 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 9 May 2026 18:12:07 -0700 Subject: [PATCH 1/4] fix(execution): cap isolate memory at 128MB and recycle workers every 100 executions --- apps/sim/lib/execution/isolated-vm-worker.cjs | 4 ++-- apps/sim/lib/execution/isolated-vm.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/sim/lib/execution/isolated-vm-worker.cjs b/apps/sim/lib/execution/isolated-vm-worker.cjs index 5f43c73140..00066c09bb 100644 --- a/apps/sim/lib/execution/isolated-vm-worker.cjs +++ b/apps/sim/lib/execution/isolated-vm-worker.cjs @@ -183,7 +183,7 @@ async function executeCode(request, executionId) { const externalCopies = [] try { - isolate = new ivm.Isolate({ memoryLimit: 256 }) + isolate = new ivm.Isolate({ memoryLimit: 128 }) if (executionId !== undefined) activeIsolates.set(executionId, isolate) context = await isolate.createContext() const jail = context.global @@ -529,7 +529,7 @@ async function executeTask(request, executionId) { let tPhase = tStart try { - isolate = new ivm.Isolate({ memoryLimit: 256 }) + isolate = new ivm.Isolate({ memoryLimit: 128 }) if (executionId !== undefined) activeIsolates.set(executionId, isolate) context = await isolate.createContext() const jail = context.global diff --git a/apps/sim/lib/execution/isolated-vm.ts b/apps/sim/lib/execution/isolated-vm.ts index b35687d437..e269e76aee 100644 --- a/apps/sim/lib/execution/isolated-vm.ts +++ b/apps/sim/lib/execution/isolated-vm.ts @@ -128,7 +128,7 @@ const DISTRIBUTED_MAX_INFLIGHT_PER_OWNER = Number.parseInt(env.IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER) || MAX_ACTIVE_PER_OWNER + MAX_QUEUED_PER_OWNER const DISTRIBUTED_LEASE_MIN_TTL_MS = Number.parseInt(env.IVM_DISTRIBUTED_LEASE_MIN_TTL_MS) || 120000 -const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 500 +const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 100 const MAX_BROKER_ARGS_JSON_CHARS = Number.parseInt(env.IVM_MAX_BROKER_ARGS_JSON_CHARS) || 262_144 const MAX_BROKER_RESULT_JSON_CHARS = Number.parseInt(env.IVM_MAX_BROKER_RESULT_JSON_CHARS) || 16_777_216 From 66c9d59681daea618bd9c94f098d3fde8fa8be9c Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 9 May 2026 18:15:07 -0700 Subject: [PATCH 2/4] fix(execution): set IVM_MAX_EXECUTIONS_PER_WORKER env default to 100 --- apps/sim/lib/core/config/env.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sim/lib/core/config/env.ts b/apps/sim/lib/core/config/env.ts index c95fa7fa99..69182fccbc 100644 --- a/apps/sim/lib/core/config/env.ts +++ b/apps/sim/lib/core/config/env.ts @@ -248,7 +248,7 @@ export const env = createEnv({ IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER:z.string().optional().default('2200'), // Max owner in-flight leases across replicas IVM_DISTRIBUTED_LEASE_MIN_TTL_MS: z.string().optional().default('120000'), // Min TTL for distributed in-flight leases (ms) IVM_QUEUE_TIMEOUT_MS: z.string().optional().default('300000'), // Max queue wait before rejection (ms) - IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('500'), // Max lifetime executions before worker is recycled + IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('100'), // Max lifetime executions before worker is recycled IVM_MAX_BROKER_ARGS_JSON_CHARS: z.string().optional().default('262144'), // Max JSON payload size for sandbox task broker args (isolate→host) IVM_MAX_BROKER_RESULT_JSON_CHARS: z.string().optional().default('16777216'),// Max JSON payload size for sandbox task broker results (host→isolate) IVM_MAX_BROKERS_PER_EXECUTION: z.string().optional().default('1000'), // Max broker calls per sandbox task execution From 525f19365ed0e6231031eac65d68fabde26645c7 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 9 May 2026 18:21:40 -0700 Subject: [PATCH 3/4] fix(execution): raise MAX_EXECUTIONS_PER_WORKER from 100 to 200 --- apps/sim/lib/core/config/env.ts | 2 +- apps/sim/lib/execution/isolated-vm.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sim/lib/core/config/env.ts b/apps/sim/lib/core/config/env.ts index 69182fccbc..056bccc7c5 100644 --- a/apps/sim/lib/core/config/env.ts +++ b/apps/sim/lib/core/config/env.ts @@ -248,7 +248,7 @@ export const env = createEnv({ IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER:z.string().optional().default('2200'), // Max owner in-flight leases across replicas IVM_DISTRIBUTED_LEASE_MIN_TTL_MS: z.string().optional().default('120000'), // Min TTL for distributed in-flight leases (ms) IVM_QUEUE_TIMEOUT_MS: z.string().optional().default('300000'), // Max queue wait before rejection (ms) - IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('100'), // Max lifetime executions before worker is recycled + IVM_MAX_EXECUTIONS_PER_WORKER: z.string().optional().default('200'), // Max lifetime executions before worker is recycled IVM_MAX_BROKER_ARGS_JSON_CHARS: z.string().optional().default('262144'), // Max JSON payload size for sandbox task broker args (isolate→host) IVM_MAX_BROKER_RESULT_JSON_CHARS: z.string().optional().default('16777216'),// Max JSON payload size for sandbox task broker results (host→isolate) IVM_MAX_BROKERS_PER_EXECUTION: z.string().optional().default('1000'), // Max broker calls per sandbox task execution diff --git a/apps/sim/lib/execution/isolated-vm.ts b/apps/sim/lib/execution/isolated-vm.ts index e269e76aee..dabf258f46 100644 --- a/apps/sim/lib/execution/isolated-vm.ts +++ b/apps/sim/lib/execution/isolated-vm.ts @@ -128,7 +128,7 @@ const DISTRIBUTED_MAX_INFLIGHT_PER_OWNER = Number.parseInt(env.IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER) || MAX_ACTIVE_PER_OWNER + MAX_QUEUED_PER_OWNER const DISTRIBUTED_LEASE_MIN_TTL_MS = Number.parseInt(env.IVM_DISTRIBUTED_LEASE_MIN_TTL_MS) || 120000 -const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 100 +const MAX_EXECUTIONS_PER_WORKER = Number.parseInt(env.IVM_MAX_EXECUTIONS_PER_WORKER) || 200 const MAX_BROKER_ARGS_JSON_CHARS = Number.parseInt(env.IVM_MAX_BROKER_ARGS_JSON_CHARS) || 262_144 const MAX_BROKER_RESULT_JSON_CHARS = Number.parseInt(env.IVM_MAX_BROKER_RESULT_JSON_CHARS) || 16_777_216 From eb6068b6a8dbd22b414168fb5ae49f0d561e28fe Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Sat, 9 May 2026 18:22:20 -0700 Subject: [PATCH 4/4] fix(execution): update memory limit error messages from 256 MB to 128 MB --- apps/sim/lib/execution/isolated-vm-worker.cjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/sim/lib/execution/isolated-vm-worker.cjs b/apps/sim/lib/execution/isolated-vm-worker.cjs index 00066c09bb..18828eebc6 100644 --- a/apps/sim/lib/execution/isolated-vm-worker.cjs +++ b/apps/sim/lib/execution/isolated-vm-worker.cjs @@ -388,7 +388,7 @@ async function executeCode(request, executionId) { stdout, error: { message: - 'Execution exceeded memory limit (256 MB). Reduce image sizes or split the work into smaller batches.', + 'Execution exceeded memory limit (128 MB). Reduce image sizes or split the work into smaller batches.', name: 'MemoryLimitError', }, } @@ -945,7 +945,7 @@ async function executeTask(request, executionId) { stdout, error: { message: - 'Execution exceeded memory limit (256 MB). Reduce image sizes or split the work into smaller batches.', + 'Execution exceeded memory limit (128 MB). Reduce image sizes or split the work into smaller batches.', name: 'MemoryLimitError', }, timings,