MCPcopy Index your code
hub / github.com/simstudioai/sim / executeTask

Function executeTask

apps/sim/lib/execution/isolated-vm-worker.cjs:567–1119  ·  view source on GitHub ↗

* Task-mode execution. Loads pre-built library bundles into the isolate, * exposes host-side brokers as isolate globals under `__brokers. (args)`, * runs the task bootstrap (which installs friendly names on globalThis), * executes user code, then runs `finalize` (must return a Uint8Array). T

(request, executionId)

Source from the content-addressed store, hash-verified

565 * resulting bytes are returned as base64 in `bytesBase64`.
566 */
567async function executeTask(request, executionId) {
568 const { code, timeoutMs, task } = request
569 const stdoutChunks = []
570 let stdoutLength = 0
571 let stdoutTruncated = false
572 let isolate = null
573
574 const appendStdout = (line) => {
575 if (stdoutTruncated || !line) return
576 const remaining = MAX_STDOUT_CHARS - stdoutLength
577 if (remaining <= 0) {
578 stdoutTruncated = true
579 stdoutChunks.push('[stdout truncated]\n')
580 return
581 }
582 if (line.length <= remaining) {
583 stdoutChunks.push(line)
584 stdoutLength += line.length
585 return
586 }
587 stdoutChunks.push(line.slice(0, remaining))
588 stdoutChunks.push('\n[stdout truncated]\n')
589 stdoutLength = MAX_STDOUT_CHARS
590 stdoutTruncated = true
591 }
592
593 let context = null
594 const releaseables = []
595
596 // Timer bookkeeping — hoisted out of the try so the finally can always
597 // sweep regardless of where execution throws.
598 let nextTimerId = 1
599 const timers = new Map()
600 const cleanupTimers = () => {
601 for (const entry of timers.values()) {
602 try {
603 if (entry.recurring) clearInterval(entry.nodeTimer)
604 else clearTimeout(entry.nodeTimer)
605 } catch {}
606 try {
607 entry.fnRef.release()
608 } catch {}
609 }
610 timers.clear()
611 }
612
613 // Phase timings (ms). Populated inline during execution; returned in
614 // every result shape so the host can log where time is spent per request.
615 const timings = {
616 setup: 0,
617 runtimeBootstrap: 0,
618 bundles: 0,
619 brokerInstall: 0,
620 taskBootstrap: 0,
621 harden: 0,
622 userCode: 0,
623 finalize: 0,
624 total: 0,

Callers 1

Calls 15

stringifyLogValueFunction · 0.85
appendStdoutFunction · 0.85
unwrapPrimitiveFunction · 0.85
sendIpcRequestFunction · 0.85
getBundleSourceFunction · 0.85
convertToCompatibleErrorFunction · 0.85
cleanupTimersFunction · 0.85
joinMethod · 0.80
releaseMethod · 0.80
parseMethod · 0.80
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected