Repository navigation
Report async work to the dependency graph - #240
Merged
Merged
Conversation
Domiii
force-pushed
the
dominik/node-dg-async
branch
from
November 17, 2026 13:20
27ab060 to
47cdee4
Compare
Async ops (async_hooks) are reported to the Replay dependency graph with
the shapes Chromium uses, so the backend's dependency chains connect I/O,
timers, ticks and microtasks to the code that scheduled them.
- An op's init adds a node and each of its callbacks runs in a dependency
execution of a run node, between push_async_context and
pop_async_context. The op class decides the kinds (AsyncOp,
src/node_dependency_graph.h): Timeouts are timerScheduled -baseTimer->
timerFired, queueMicrotask() is enqueueMicrotask -scheduler->
runMicrotask, everything else asyncInit{type} -scheduler-> asyncCallback.
The main script runs in a marker{ExecuteScript} node, created after the
first checkpoint, which is the root of the chains.
- Init sites: AsyncWrap::EmitAsyncInit for native ops, and the JS ops'
constructors (Timeout, Immediate, nextTick, AsyncResource). Windows: the
C++ and JS async id stack push/pop/clear. Destroys erase the op.
- Windows mirror the async id stack by slot and save the dependency
execution depth when they begin. Shrinking the stack unwinds to it, which
also ends executions whose end was skipped (a termination escaping a
promise reaction job, a stack clear after a fatal exception).
- queueMicrotask() takes its AsyncResource path while instrumented, so the
microtask has an async op.
Prod behavior. Unrecorded runs: the JS sites check a boolean that is false
and make no binding calls; queueMicrotask() is unchanged; the C++ sites
check a cached flag and return. Recordings (with the dependency-graph
feature, the default): JS paths depend only on
v8::recordreplay::DependencyGraphInstrumented(), which is recorded, so they
are the same when recording and replaying. The binding calls return after
checking a cached flag; nodes, edges and the op map only exist when
replaying. The only JS-visible change in recordings is queueMicrotask()
taking the path it takes whenever AsyncLocalStorage or async hooks are in
use: an async id and an AsyncResource per microtask, and its frames in
error stacks. The binding results JS sees are the same when recording and
replaying.
Domiii
force-pushed
the
dominik/node-dg-async
branch
from
November 17, 2026 13:37
04fefac to
57ad6a5
Compare
…backend#13900) and the weak-ref harness fix (backend#13901)
Domiii
force-pushed
the
dominik/node-dg-async
branch
from
November 17, 2026 14:43
57ad6a5 to
89884a1
Compare
Domiii
marked this pull request as ready for review
November 17, 2026 15:07
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
setImmediate,process.nextTickandqueueMicrotask.await fetch()cannot reach the socket read, nor the main script.Model: async_hooks
push_async_context(id)andpop_async_context(id).InternalCallbackScope.MakeCallback,CallbackScopeand N-API callbacks use it.emitBeforeandemitAfter.pushAsyncContextandpopAsyncContext.AsyncResource#runInAsyncScopeuse them.Op classes
AsyncOp. The class decides the kinds.kGenericasyncInit{type}asyncCallbackschedulerkTimerTimeouttimerScheduled{duration, singleShot}timerFiredbaseTimerkMicrotaskqueueMicrotaskenqueueMicrotaskrunMicrotaskschedulerkScriptmarker{ExecuteScript, StartExecution}typeis the async_hooks provider type, e.g.TCPWRAP.kScriptmarker is the root of every chain.{1, 0}callback scope ofStartExecution.PROMISEids exist only with async_hooks promise tracking. node#239 covers promises.Sites
AsyncWrap::EmitAsyncInit, before the no-init-hooks returnAsyncReset,node::EmitAsyncInit, N-API async contexts.kGenericinit node.AsyncWrap::EmitDestroy, and JSemitDestroyScriptafter the invalid id returnAsyncHooks::push_async_context,pop_async_context,clear_async_id_stack, and JSpushAsyncContext,popAsyncContextTimeoutandinsertGuarded,Immediate,nextTick,AsyncResourcenewAsyncIdthat create a resource.StartExecution, after the first checkpointBalance
clearAsyncIdStackafter a fatal exception drops windows without popping them.queueMicrotask while recording
AsyncResource('Microtask').kMicrotask.asyncIdvalues shift.AsyncResourceand one bound function per microtask.runMicrotaskandrunInAsyncScopeframes appear in error stacks.Gates
internal/async_hooks.prepareExecutionsets it fromDependencyGraphInstrumented().DependencyGraphEnabled().Coverage
MakeCallback, timers, immediates, ticks,AsyncResource,queueMicrotask.readStartor write that caused them.timeout.refresh()keeps the originaltimerSchedulednode.triggerAsyncIdis not an edge.EventEmitter#emitandEventTarget#dispatchEvent, asdispatchEventexecutions.Data
linux-node-20261117-57ad6a5448fc-ebf9f47bec04-dev(BKruntime-node-build-and-testRFC: Remove Ryan's Freelist feature nodejs/node#569).await, 1e5queueMicrotask, 1e5nextTick, 1e4setImmediate, 1e4fs.stat, recorded.RECORD_REPLAY_DISABLE_FEATURES=["dependency-graph"]queueMicrotask: about 0.25 µs more per microtask, from the slow path.nextTick: about 30 ns more per tick.setImmediateandfs.stat: within noise.UnboundSymbolcrash instatfsis fixed upstream by backendaf54141a7e(Eslint 4.1.0 nodejs/node#13895). This PR'sREPLAY_BACKEND_REVcontains that fix.Merge order
REPLAY_BACKEND_REVto the backend master commit that contains backend#13900.