Repository navigation
Conversation
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
from
October 4, 2026 11:03
50f84bc to
9342a9b
Compare
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
from
October 5, 2026 12:48
9342a9b to
ba833eb
Compare
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
from
October 5, 2026 15:25
ba833eb to
bf92d07
Compare
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
3 times, most recently
from
October 6, 2026 10:33
fa8d825 to
9602947
Compare
Andarist
marked this pull request as ready for review
October 6, 2026 10:44
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
from
October 6, 2026 10:51
9602947 to
58394b9
Compare
Andarist
force-pushed
the
claude/gc-finalizers-replay
branch
from
October 7, 2026 09:52
58394b9 to
95a78f1
Compare
Domiii
approved these changes
Oct 7, 2026
| // between recording and replaying, and notes it in the crash report | ||
| // diagnostics. Matches recordreplay::EnterLeakMemory in the Chromium fork. | ||
| inline bool EnterLeakMemory(const char* label) { | ||
| if (!v8::recordreplay::IsRecordingOrReplaying("leak-references", label)) { |
There was a problem hiding this comment.
(Oh shit, I just only now realized that the determnator called this leak-references. Stupid bots.)
The GC collects them at points which differ between recording and replaying. FileHandle's destructor closed the fd from the GC and scheduled a process warning from JS, so a program that leaks a FileHandle ran JS in the recording that the replay doesn't have. Override OnGCCollect instead of guarding the destructor, as HandleWrap does, so that only the GC path leaks: an explicit close() is unaffected, and the cleanup hook still closes the handle when the environment is torn down. DirHandle previously leaked in its destructor, so it never closed at teardown either. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…replaying Reference::SecondPassCallback runs inside the GC, and scheduled the finalizer with a refed SetImmediate. That bumps the JS-visible immediate ref count, starts the idle handle, and runs addon code at a tick which depends on GC timing. Every collected N-API function (CallbackBundle) and wrapped object goes through it. When recording/replaying, leave such a reference unfinalized. It stays on the env's reference list, so ~napi_env__ finalizes it at environment teardown like any reference that is still alive then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AsyncWrap::EmitDestroy returned early for every caller when recording or replaying, so destroy hooks never fired, also for deterministic callers like AsyncResource#emitDestroy(), parser.free() and explicit closes. GC-originated destroys (DestroyParam weak callbacks, wraps deleted by the GC) run with events disallowed, so drop only those. Skip the interrupt used to drain a very large list, as interrupts are not replayed at the same points; the immediate still drains it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Observing 'gc' entries installs GC callbacks which deliver an entry to JS from an immediate after every GC. GCPerformanceEntry::Notify calls JS directly, so this never reached the invalidation in the Notify binding which covers the other performance entries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The WeakReference binding, used by diagnostics_channel and domain, held its target weakly in both the recording and the replay. Whether get() found the target depended on when the GC ran, which differs when replaying. E.g. a diagnostics channel which only its subscriber referred to was collected by the recording's GC, and the replay kept calling the subscriber, diverging from the recording. When recording, keep the target weak and record whether it is alive each time the binding is used. When replaying, hold the target strongly and let it go where the recording saw it collected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When recording/replaying, the handle of an owner the GC collected is leaked and stays listed (HandleWrap::OnGCCollect). Which owners the GC collected differs when replaying, so process.getActiveResourcesInfo() could list different handles, and process._getActiveHandles() aborted in GetOwner() on a leaked handle. Record whether each ref'd handle's owner is alive where the list is built, and skip the ones that aren't. The only owner the GC collects is IntervalHistogram (monitorEventLoopDelay()); hold it strongly when replaying, so that it lives until the recording saw it collected. Also add recordreplay::AreEventsAvailable() for node's own record/replay checks, and use it in WeakReference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Node only holds the resource a binary module gives napi_async_init weakly, and once the GC collects it, callbacks in the context get a new resource without the AsyncLocalStorage store that was active when the context was created. The GC runs at other points when replaying, so replayed callbacks could see the old resource and store where the recording saw new ones. For contexts created in calls the driver replays, the replay holds the resource strongly. Each time a callback runs in the context, whether the resource was collected is recorded, and the replay drops it where the recording found it collected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…/replaying They were leaked whether or not they had been closed. Destroying an open one closes the fd and schedules a process warning, which must not happen at a GC-dependent point, but destroying a closed one only frees memory. Every fs.promises operation that opened and closed a handle kept its object and cleanup hook until teardown. Leak a collected handle only while it is open. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit 4e9a2469ea50217c9810df08586694d20d9fe835)
A function a vm.Script created can call import() after the script object was dropped. ImportModuleDynamically then looks the ContextifyScript up by its id without checking that it is still there, and passes its object to the importModuleDynamically callback. With old space GC enabled under record/replay, a dropped script's wrapper is collected, its map entry erased, and the recording crashes at a point the replay doesn't reach. Don't make the wrapper weak when recording/replaying; the cleanup hook frees it when the environment is torn down. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit dea48a444f25d5278784b61dbd666c03d7cedd1e)
When recording, the GC's second pass leaves a reference whose value it collected unfinalized, for ~napi_env__ to finalize at environment teardown. The replay's RecordReplayFlushClearedRefs still finalized such references at the recorded point, so a reference the module then deleted was freed at once when replaying but kept until teardown when recording. Only reset the persistent when replaying, like the weak callback's first pass does when recording. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit 272fe856ec6ee86e9d0690790255249d0085c5b6)
…rk does The Chromium fork gates such leaks on the "leak-references" feature with a label and notes each in the crash report diagnostics (recordreplay::EnterLeakMemory). Node leaked on a bare IsRecordingOrReplaying(). Add node::recordreplay::EnterLeakMemory and use it for the FileHandle, DirHandle, HandleWrap and ContextifyScript objects the GC collects and for Buffer callback infos. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> (cherry picked from commit fd3801462749cee74e59045a3426e8553bd83825)
Andarist
added a commit
that referenced
this pull request
Nov 6, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 6, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 6, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. CDP messages from the inspector are accepted as Latin-1: node 26 hands them over in that encoding, and decoding them as UTF-8 corrupted any message with a byte above 0x7f. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
pushed a commit
that referenced
this pull request
Nov 10, 2026
Add src/node_recordreplay.cc with Replay's node integration: loading the driver (InitializeRecordReplay and OpenDriverHandle, from RECORD_REPLAY_DRIVER or the copy embedded in the binary), the symbol table of driver function pointers, attaching the recorder with the build ID, recording the command line arguments and the argv metadata, and RecordReplayFinishRecording, which appends the recording ID to RECORD_REPLAY_RECORDING_ID_FILE unless the recording is unusable. The node::recordreplay namespace holds the helpers the rest of node uses: callback region scopes, whether the recording has finished, whether a call is inside a callback the driver intercepts, whether events are available (recording or replaying, with events neither disallowed nor passed through and no divergence) or recorded, and ThrowIfEventsUnavailable, which makes an operation that cannot be replayed throw instead of running unrecorded. Expose the recording primitives to JavaScript as process binding methods: RecordReplayLog, the CDP message pair (a callback for responses and events, and sending a message through a process-owned inspector session), the annotation hook, assertions, script ignoring, the recording ID, the current execution point and elapsed time, and the external references for all of them. Replay's own session connects, dispatches and delivers messages to the frontend as replay code with events disallowed, so none of that work can diverge, and the session is reset from AtExit, where node normally waits for external debugger frontends to disconnect: process.exit() skips Environment destruction, so the session would otherwise survive until static destruction, after V8's platform has been disposed. That also disables the debugger, which leaves WebAssembly modules tiered down (see V8Debugger::disable). In node.cc, initialize record/replay and mark the sibling group map ordered before anything else, apply the old space limit the driver asks for (REPLAY_RECORD_MAX_OLD_SPACE_MB / REPLAY_REPLAY_MAX_OLD_SPACE_MB, read through RecordReplayMaxOldSpaceMb) as a V8 flag after the command line's, so that the arguments and process.execArgv stay the same when replaying, print the build ID and exit for --print-build-id, create the first checkpoint on the main thread before the entry script runs, and leave V8's WebAssembly trap handler disabled while recording/replaying, so V8 keeps emitting bounds checks instead of relying on a SIGSEGV the recorder treats as a crash. libuv keeps a pointer into argv for the process title rather than copying it, so whichever argv uv_setup_args() sees decides the title. Start() calls it before InitializeOncePerProcess(), where the driver replaces the arguments with the recording's, so a replay reported its own argv[0] instead. Node sends that title to a debugger frontend as the execution context's name, where it diverged from the recording's and the write to the frontend's socket was a different length, so the replay sets the arguments up again once the driver has installed them. Rebase note: nearly all of this is new code in src/node_recordreplay.cc, so conflicts should only come from the call sites, which are one line each. InitializeRecordReplay() must run early in InitializeOncePerProcess, before V8, OpenSSL and the platform are initialized, and the driver's old space limit is applied after node has processed the command line's V8 options, so that it wins. The --print-build-id early return sits with the other print-and-exit options, and StartExecution creates a checkpoint on the main thread before running the entry script. The process methods are only added to the process_methods binding, so upstream changes to how bindings register methods (for example env->SetMethod(target, ...) becoming SetMethod(context, target, ...) in later v16 releases) must be applied to these registrations too, and the method names must stay in sync with lib/internal/bootstrap/node.js. Includes later changes from #123, #130, #151, #155, #164, #166, #167, Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. recordreplay::DeferredFinalization, owned by the Environment, is added to V8's GC poll as a participant: a GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. This commit adds the mechanism, its ReplayGCPollParticipant contract with V8 and the Environment's instance of it. The finalizers that track objects with it follow, starting with the N-API references in the next commit. Rebase note: IsActive() and the number of values the poll records on a participant's behalf have to be the same when recording and replaying, so nothing here may depend on the replay's own heap. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Andarist
added a commit
that referenced
this pull request
Nov 10, 2026
Old space GCs run at points the replay does not reproduce, and which objects die in one differs between the two, so cleanup from a weak callback was dropped or leaked until teardown. Track what the GC collects with the Environment's recordreplay::DeferredFinalization: the GC's callback only notes what it collected, and the poll writes the notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is kept alive until the poll names its id, so the cleanup runs in the same state on both sides. The notes are the async ids of resources the GC destroyed, so async_hooks destroy hooks fire again, and the ids of tracked Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps, IntervalHistogram), N-API references and external Buffers' free callbacks. An object created where no id could be assigned keeps the earlier handling and its LeakMemory diagnostic. Where liveness is JS-visible it is recorded rather than read from the replay's own heap: WeakReference, an active handle's owner, an async context's resource. A legacy addon initializer reached through its well-known symbol invalidates the recording, as the self-registering ones already did. An external Buffer's free callback is module code too, so CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of running it where the poll was reached, for the same reason the deferred N-API finalizers are handed to the environment: node's own deleter schedules one (see OnBackingStoreFree), and the poll is reached at the same point when recording and replaying, so the immediate it schedules is too. Rebase note: nothing a weak callback, a backing store deleter or another GC-driven path does may be observable; it either notes an id for the GC poll or leaks through EnterLeakMemory, and only objects created where events are recorded get an id. Check new upstream finalizers, and keep every JS-visible answer about what is still alive coming from the recording. From #164, #171 and #197. Co-authored-by: Brian Hackett <bhackett1024@gmail.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
No description provided.