[Prototype] Node 18: let node-fibers run await continuations on a fiber (V8 microtask dispatch) - #7
Draft
jbaczuk-qualia wants to merge 1 commit into
Draft
jbaczuk-qualia wants to merge 1 commit into
jbaczuk-qualia wants to merge 1 commit into
Conversation
Prototype for running the code after an `await` inside a fiber. The microtask runner now offers fulfill/reject reaction jobs whose continuation-preserved embedder data (CPED) is set to the embedder via a new callback (include/v8-microtask-dispatch.h). The embedder can run the job later on another stack with RunDispatchedMicrotask, which keeps the usual bookkeeping (context, CPED, promise hooks, exceptions). Unmangled C entry points let addons find the API with dlsym and still load on unpatched node. After a reaction job V8 now restores the previous CPED instead of clearing it, so a job run on a fiber leaves the fiber's marker in place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
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.
Summary
R&D prototype: lets node-fibers run the code after an
await(and.thencallbacks) on a fiber when that code was registered inside a fiber. Today it resumes on the main stack, so a fiber-only call afterawaitfails withCan't wait without a fiber:Based on
znewsham/custom-v18(f031bb860e, the source ofnodejs-dev:f031bb860e, v18.16.1, V8 10.2). One commit, V8 only:deps/v8/include/v8-microtask-dispatch.h(new)SetMicrotaskDispatchCallback/RunDispatchedMicrotask, plus unmangledv8_qualia_*C entry points so an addon can find them withdlsymand still load on unpatched nodedeps/v8/src/builtins/builtins-microtask-queue-gen.ccRuntime::kDispatchMicrotask; if the embedder took the job, skip it. After a reaction job, restore the previous CPED instead of clearing it, so a job run on a fiber leaves the fiber's marker in placedeps/v8/src/runtime/runtime-promise.cc,runtime.hRuntime_DispatchMicrotask: moves the job into a private single-jobMicrotaskQueue(a GC root) and offers it to the embedder callback.RunDispatchedMicrotaskruns that queue through the normalRunMicrotasksbuiltin, so context entry, CPED, promise hooks (async_hooks / AsyncLocalStorage) and exception reporting are unchangedNo effect unless an embedder registers a callback and something sets CPED (nothing in node 18 does). The fibers side is qualialabs/node-fibers#6 (and the
Promise.awaitside, qualialabs/shared-packages#265).Testing
Built in a
dev-qualia:latestcontainer (arm64, glibc of the qli5 image), with the fibers PR:.then, AsyncLocalStorage across the hop,Promise.alloverlap, errors, fiberless code untouched, microtask order): 11/11 pass;FIBERS_AWAIT_DISPATCH=0fails the expected 7 (same as stock node).test/: identical results on stock vs patched node (pool.js/cleanup.jssegfault on both, the known pthreadcoro_destroybug).Risk / open questions
CORO_PTHREAD).--no-async-context-frame).PromiseResolveThenableJobTaskis not dispatched (the reaction it creates carries the outer promise's CPED, so user continuations are still tagged).🤖 Generated with Claude Code