Runs fail with `setImmediate is not defined` in browsers and Convex's runtime once a program runs longer than ~1 ms
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start with src/runtime/driver.ts around the yielding path and src/vm.ts where the slice timing is defined, then inspect how Runtime.make accepts host configuration. Review the existing implementation in linked PR #102 and locate the runtime or browser tests covering long-running programs. Done means long executions yield successfully in browser and bare V8-like hosts, with an overridable host yield, while existing interrupt and timeout behavior remains covered.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When testing with v8 runtimes, Claude and I encountered the following. The below is written by Claude.
When a program runs long enough to hit a VM slice, Driver.run() yields with setImmediate
(src/runtime/driver.ts:63).
SLICE_MS is 1 (src/vm.ts:154), so any
program that runs for more than about 1 ms of VM time reaches that call. Browsers don't define setImmediate, and
neither do runtimes like Convex's default V8 runtime.
Short programs, host calls, and suspend → toBytes → fromBytes → resume all work fine in these environments. The
codebase also seems to anticipate non-Node hosts already (Buffer is only installed when the host has one,
globals.ts:184). This looks like the one place where it still assumes Node.
Repro
Tested on dev @ bf492e1, bundled with bun build src/index.ts --target=browser, running in headless Chromium 158:
import { Runtime } from "./psychoscript.browser.js"
const runtime = Runtime.make({ globals: () => ({}) })
console.log(await runtime.execute("return 1 + 1"))
// { ok: true, value: 2 }
console.log(await runtime.execute("let s = 0; for (let i = 0; i < 300000; i++) s += i; return s"))
// { ok: false, error: { kind: "ExecutionFailure", message: "setImmediate is not defined" } }
I got the same failure in Node 24 after delete globalThis.setImmediate (which mimics Convex's runtime, since its
timer setup only
defines setTimeout/setInterval).
Workaround
Shimming it before import fixes it. With this shim, every probe I ran passed in Chromium:
globalThis.setImmediate ??= (fn) => {
const c = new MessageChannel()
c.port1.onmessage = () => fn()
c.port2.postMessage(0)
}
Suggested fix
Use a portable default yield, and let the embedder override it:
const defaultYield = (): Promise<void> =>
new Promise((resolve) => {
if (typeof setImmediate === "function") setImmediate(resolve)
else if (typeof MessageChannel === "function") {
const { port1, port2 } = new MessageChannel()
port1.onmessage = () => {
port1.close()
resolve()
}
port2.postMessage(null)
} else Promise.resolve().then(() => resolve()) // bare V8 hosts: no queueMicrotask either
})
// e.g. Runtime.make({ yieldToHost: () => new Promise((r) => setTimeout(r, 0)) })
Why both:
- Bare V8 hosts like Convex's runtime have no
setImmediate,MessageChannelorqueueMicrotask. The
microtask fallback is the only yield that works in Convex queries/mutations. Those hosts definesetTimeoutbut
refuse to run the timer, so the callback never fires and the function fails. - A microtask yield can't be interrupted: timers and abort listeners never run while the guest is CPU-bound, so
timeoutMsstops working. In a Convex-like action, a 200 ms timeout let a loop run to completion at 793 ms; with a
setTimeout(r, 0)yield it stopped withTimeoutExceededat 206 ms. Hosts where timers do work (e.g. Convex
actions) should be able to pass that yield in.
- Ngôn ngữ chính
- Rust
- Star
- 470
- Fork
- 11
- Merge trung bình
- 4 giờ 10 phút
- Pull request đã merge (30 ngày)
- 89
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của anomalyco/psychoscript
-
fix(rust): large BigInts bypass Limits::max_heap_bytesCó thể đã có người làm @brxs đã nhận 2 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
anomalyco/psychoscript#113 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(rust): Returned::Block deadlocks single-threaded async executors under execute_asyncCó thể đã có người làm @brxs đã nhận 2 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
anomalyco/psychoscript#110 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(rust): duplicate fresh strings bypass Limits::max_heap_bytesCó thể đã có người làm @brxs đã nhận 2 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
anomalyco/psychoscript#109 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Importing psychoscript throws RangeError in Safari (WebKit/JavaScriptCore)Có thể đã có người làm @vibdev đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
anomalyco/psychoscript#100 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của anomalyco/psychoscript
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Top-right curve point in Color Grading cannot be dragged on macOS (scrollbar intercepts click)Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
storytold/filmcraft#5386 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement in-progress
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100