Runs fail with `setImmediate is not defined` in browsers and Convex's runtime once a program runs longer than ~1 ms
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- javascript, typescript
- Área
- backend-api-design
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Rust
- Estrellas
- 470
- Forks
- 11
- Merge medio
- 4 h 10 min
- PR fusionados (30 d)
- 89
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de anomalyco/psychoscript
-
fix(rust): large BigInts bypass Limits::max_heap_bytesPosiblemente ocupada @brxs la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
anomalyco/psychoscript#113 ·
Los mantenedores suelen responder en 1 día
-
fix(rust): Returned::Block deadlocks single-threaded async executors under execute_asyncPosiblemente ocupada @brxs la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
anomalyco/psychoscript#110 ·
Los mantenedores suelen responder en 1 día
-
fix(rust): duplicate fresh strings bypass Limits::max_heap_bytesPosiblemente ocupada @brxs la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
anomalyco/psychoscript#109 ·
Los mantenedores suelen responder en 1 día
-
Importing psychoscript throws RangeError in Safari (WebKit/JavaScriptCore)Posiblemente ocupada @vibdev la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
anomalyco/psychoscript#100 ·
Los mantenedores suelen responder en 1 día
Todos los issues de anomalyco/psychoscript
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Top-right curve point in Color Grading cannot be dragged on macOS (scrollbar intercepts click)Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
storytold/filmcraft#5386 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
enhancement in-progress
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100