Skip to content

Commit 0209d33

Browse files
committed
fix fallbacks
1 parent ba6a01a commit 0209d33

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,10 +247,10 @@ describe('isolated-vm scheduler', () => {
247247
ownerKey: 'user:b',
248248
})
249249

250-
expect(second.error?.name).toBe('QueueFullError')
250+
expect(second.error?.message).toContain('at capacity')
251251

252252
const first = await firstPromise
253-
expect(first.error?.name).toBe('QueueTimeoutError')
253+
expect(first.error?.message).toContain('timed out waiting')
254254
})
255255

256256
it('enforces per-owner queued limit', async () => {
@@ -284,10 +284,10 @@ describe('isolated-vm scheduler', () => {
284284
ownerKey: 'user:hog',
285285
})
286286

287-
expect(second.error?.name).toBe('OwnerQueueLimitError')
287+
expect(second.error?.message).toContain('Too many concurrent')
288288

289289
const first = await firstPromise
290-
expect(first.error?.name).toBe('QueueTimeoutError')
290+
expect(first.error?.message).toContain('timed out waiting')
291291
})
292292

293293
it('enforces distributed owner in-flight lease limit when Redis is configured', async () => {
@@ -316,7 +316,7 @@ describe('isolated-vm scheduler', () => {
316316
ownerKey: 'user:distributed',
317317
})
318318

319-
expect(result.error?.name).toBe('OwnerInFlightLimitError')
319+
expect(result.error?.message).toContain('Too many concurrent')
320320
})
321321

322322
it('fails closed when Redis is configured but unavailable', async () => {
@@ -337,7 +337,7 @@ describe('isolated-vm scheduler', () => {
337337
ownerKey: 'user:redis-down',
338338
})
339339

340-
expect(result.error?.name).toBe('DistributedFairnessUnavailableError')
340+
expect(result.error?.message).toContain('temporarily unavailable')
341341
})
342342

343343
it('fails closed when Redis lease evaluation errors', async () => {
@@ -365,7 +365,7 @@ describe('isolated-vm scheduler', () => {
365365
ownerKey: 'user:redis-error',
366366
})
367367

368-
expect(result.error?.name).toBe('DistributedFairnessUnavailableError')
368+
expect(result.error?.message).toContain('temporarily unavailable')
369369
})
370370

371371
it('applies weighted owner scheduling when draining queued executions', async () => {

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

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,24 @@ export interface IsolatedVMError {
5252
lineContent?: string
5353
}
5454

55-
const POOL_SIZE = Number.parseInt(env.IVM_POOL_SIZE)
56-
const MAX_CONCURRENT = Number.parseInt(env.IVM_MAX_CONCURRENT)
57-
const MAX_PER_WORKER = Number.parseInt(env.IVM_MAX_PER_WORKER)
58-
const WORKER_IDLE_TIMEOUT_MS = Number.parseInt(env.IVM_WORKER_IDLE_TIMEOUT_MS)
59-
const QUEUE_TIMEOUT_MS = Number.parseInt(env.IVM_QUEUE_TIMEOUT_MS)
60-
const MAX_QUEUE_SIZE = Number.parseInt(env.IVM_MAX_QUEUE_SIZE)
61-
const MAX_FETCH_RESPONSE_BYTES = Number.parseInt(env.IVM_MAX_FETCH_RESPONSE_BYTES)
62-
const MAX_FETCH_RESPONSE_CHARS = Number.parseInt(env.IVM_MAX_FETCH_RESPONSE_CHARS)
63-
const MAX_FETCH_URL_LENGTH = Number.parseInt(env.IVM_MAX_FETCH_URL_LENGTH)
64-
const MAX_FETCH_OPTIONS_JSON_CHARS = Number.parseInt(env.IVM_MAX_FETCH_OPTIONS_JSON_CHARS)
65-
const MAX_ACTIVE_PER_OWNER = Number.parseInt(env.IVM_MAX_ACTIVE_PER_OWNER)
66-
const MAX_QUEUED_PER_OWNER = Number.parseInt(env.IVM_MAX_QUEUED_PER_OWNER)
67-
const MAX_OWNER_WEIGHT = Number.parseInt(env.IVM_MAX_OWNER_WEIGHT)
68-
const DISTRIBUTED_MAX_INFLIGHT_PER_OWNER = Number.parseInt(
69-
env.IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER
70-
)
71-
const DISTRIBUTED_LEASE_MIN_TTL_MS = Number.parseInt(env.IVM_DISTRIBUTED_LEASE_MIN_TTL_MS)
55+
const POOL_SIZE = Number.parseInt(env.IVM_POOL_SIZE) || 4
56+
const MAX_CONCURRENT = Number.parseInt(env.IVM_MAX_CONCURRENT) || 10000
57+
const MAX_PER_WORKER = Number.parseInt(env.IVM_MAX_PER_WORKER) || 2500
58+
const WORKER_IDLE_TIMEOUT_MS = Number.parseInt(env.IVM_WORKER_IDLE_TIMEOUT_MS) || 60000
59+
const QUEUE_TIMEOUT_MS = Number.parseInt(env.IVM_QUEUE_TIMEOUT_MS) || 300000
60+
const MAX_QUEUE_SIZE = Number.parseInt(env.IVM_MAX_QUEUE_SIZE) || 10000
61+
const MAX_FETCH_RESPONSE_BYTES = Number.parseInt(env.IVM_MAX_FETCH_RESPONSE_BYTES) || 8_388_608
62+
const MAX_FETCH_RESPONSE_CHARS = Number.parseInt(env.IVM_MAX_FETCH_RESPONSE_CHARS) || 4_000_000
63+
const MAX_FETCH_URL_LENGTH = Number.parseInt(env.IVM_MAX_FETCH_URL_LENGTH) || 8192
64+
const MAX_FETCH_OPTIONS_JSON_CHARS =
65+
Number.parseInt(env.IVM_MAX_FETCH_OPTIONS_JSON_CHARS) || 262_144
66+
const MAX_ACTIVE_PER_OWNER = Number.parseInt(env.IVM_MAX_ACTIVE_PER_OWNER) || 200
67+
const MAX_QUEUED_PER_OWNER = Number.parseInt(env.IVM_MAX_QUEUED_PER_OWNER) || 2000
68+
const MAX_OWNER_WEIGHT = Number.parseInt(env.IVM_MAX_OWNER_WEIGHT) || 5
69+
const DISTRIBUTED_MAX_INFLIGHT_PER_OWNER =
70+
Number.parseInt(env.IVM_DISTRIBUTED_MAX_INFLIGHT_PER_OWNER) ||
71+
MAX_ACTIVE_PER_OWNER + MAX_QUEUED_PER_OWNER
72+
const DISTRIBUTED_LEASE_MIN_TTL_MS = Number.parseInt(env.IVM_DISTRIBUTED_LEASE_MIN_TTL_MS) || 120000
7273
const DISTRIBUTED_KEY_PREFIX = 'ivm:fair:v1:owner'
7374
const QUEUE_RETRY_DELAY_MS = 1000
7475
const DISTRIBUTED_LEASE_GRACE_MS = 30000
@@ -611,7 +612,7 @@ function cleanupWorker(workerId: number) {
611612
pending.resolve({
612613
result: null,
613614
stdout: '',
614-
error: { message: 'Worker process exited unexpectedly', name: 'WorkerError' },
615+
error: { message: 'Code execution failed unexpectedly. Please try again.', name: 'Error' },
615616
})
616617
workerInfo.pendingExecutions.delete(id)
617618
}
@@ -848,7 +849,7 @@ function dispatchToWorker(
848849
resolve({
849850
result: null,
850851
stdout: '',
851-
error: { message: 'Failed to send execution request to worker', name: 'WorkerError' },
852+
error: { message: 'Code execution failed to start. Please try again.', name: 'Error' },
852853
})
853854
resetWorkerIdleTimeout(workerInfo.id)
854855
// Defer to break synchronous recursion: drainQueue → dispatchToWorker → catch → drainQueue
@@ -866,8 +867,8 @@ function enqueueExecution(
866867
result: null,
867868
stdout: '',
868869
error: {
869-
message: `Execution queue is full (${MAX_QUEUE_SIZE}). Please retry later.`,
870-
name: 'QueueFullError',
870+
message: 'Code execution is at capacity. Please try again in a moment.',
871+
name: 'Error',
871872
},
872873
})
873874
return
@@ -877,8 +878,9 @@ function enqueueExecution(
877878
result: null,
878879
stdout: '',
879880
error: {
880-
message: `Owner queue limit reached (${MAX_QUEUED_PER_OWNER}). Please retry later.`,
881-
name: 'OwnerQueueLimitError',
881+
message:
882+
'Too many concurrent code executions. Please wait for some to complete before running more.',
883+
name: 'Error',
882884
},
883885
})
884886
return
@@ -892,8 +894,8 @@ function enqueueExecution(
892894
result: null,
893895
stdout: '',
894896
error: {
895-
message: `Execution queued too long (${QUEUE_TIMEOUT_MS}ms). All workers are busy.`,
896-
name: 'QueueTimeoutError',
897+
message: 'Code execution timed out waiting for an available worker. Please try again.',
898+
name: 'Error',
897899
},
898900
})
899901
}, QUEUE_TIMEOUT_MS)
@@ -973,8 +975,9 @@ export async function executeInIsolatedVM(
973975
result: null,
974976
stdout: '',
975977
error: {
976-
message: `Owner in-flight limit reached (${DISTRIBUTED_MAX_INFLIGHT_PER_OWNER}). Please retry later.`,
977-
name: 'OwnerInFlightLimitError',
978+
message:
979+
'Too many concurrent code executions. Please wait for some to complete before running more.',
980+
name: 'Error',
978981
},
979982
}
980983
}
@@ -983,8 +986,8 @@ export async function executeInIsolatedVM(
983986
result: null,
984987
stdout: '',
985988
error: {
986-
message: 'Distributed fairness is temporarily unavailable. Please retry.',
987-
name: 'DistributedFairnessUnavailableError',
989+
message: 'Code execution is temporarily unavailable. Please try again in a moment.',
990+
name: 'Error',
988991
},
989992
}
990993
}

0 commit comments

Comments
 (0)