fix(runtime-quickjs): offload QuickJS executions to worker threads in selfhost to prevent event loop blocking - #1852
Closed
Adityakk9031 wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1616
Summary
Self-host executions in
@executor-js/runtime-quickjspreviously ran QuickJS synchronously on the Node.js/Bun server's main thread. When a CPU-bound execution was run (e.g.while (true) {}), it monopolized the main event loop until hittingtimeoutMs(up to 5 minutes by default), starving health probes, OAuth sessions, web UI, and concurrent MCP requests.This PR introduces optional worker thread execution to
@executor-js/runtime-quickjsand enables it for self-hosted instances:worker: true): Addedworker?: booleanoption toQuickJsExecutorOptions. When enabled,makeQuickJsExecutordelegates execution to a dedicatednode:worker_threads.Workerrunningpackages/kernel/runtime-quickjs/src/worker.ts.toolInvokerand yield results/errors back to the worker context.SelfHostCodeExecutorProviderinapps/host-selfhost/src/execution.tssetsworker: true.Verification
packages/kernel/runtime-quickjs/src/index.test.tscovering plain executions, bidirectional tool dispatches, tool error propagation, and CPU-bound loop preemption in worker threads.packages/kernel/runtime-quickjs: 32/32 tests passed (including all worker thread suites).apps/host-selfhost: 137/137 tests across 24 test files passed.bun run typecheck: 44/44 successful.bun run lint: 0 warnings, 0 errors.bun run format:check: All modified files formatted and verified.