GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Tell the driver which dlopen() loads an addon by Andarist · Pull Request #168 · replayio/node

Conversation

@Andarist

@Andarist Andarist commented Oct 4, 2026

Copy link
Copy Markdown
Member

pairs with https://github.com/replayio/backend/pull/13453

The driver only let addons be loaded from paths containing node_modules when recording, and refused others without a dlerror() message, which crashed DLib::Open() while building its error.

Call the driver's RecordReplayMarkNextDlopenAsAddon() before loading an addon, so that it is attached wherever it is, and fall back to a generic message when dlerror() has none.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Andarist and others added 2 commits October 4, 2026 16:58
@Andarist @claude
Tell the driver which dlopen() loads an addon
804a40a
The driver only let addons be loaded from paths containing node_modules
when recording, and refused others without a dlerror() message, which
crashed DLib::Open() while building its error.

Call the driver's RecordReplayMarkNextDlopenAsAddon() before loading an
addon, so that it is attached wherever it is, and fall back to a generic
message when dlerror() has none.

Requires a driver with RecordReplayMarkNextDlopenAsAddon(), so
REPLAY_BACKEND_REV needs to be bumped once it is released.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Andarist @claude
Pass the addon's name when marking its dlopen() for the driver
84a53d3
The driver only applies the mark to a dlopen() of that name, so a mark
whose dlopen() wasn't intercepted can't apply to a later library.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Andarist
Andarist marked this pull request as ready for review October 5, 2026 08:27
@Andarist
Andarist requested a review from Domiii October 5, 2026 08:27
Andarist and others added 2 commits October 5, 2026 08:30
@Andarist @claude
Pin REPLAY_BACKEND_REV to the driver with RecordReplayMarkNextDlopenA…
74d2b6f
…sAddon

Backend nodejs#13453 added the RecordReplayMarkNextDlopenAsAddon() export which
this branch calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Andarist @claude
Drop the fallback for a NULL dlerror() in DLib::Open
d2ab02f
Addon dlopen() calls are marked for the driver, so it doesn't refuse
them, and the driver makes dlerror() report refused ones anyway. A failed
dlopen() always has an error, as upstream assumes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Andarist
Andarist merged commit 751262c into master Oct 5, 2026
2 of 3 checks passed

Uh oh!

There was an error while loading. Please reload this page.

bhackett1024 added a commit that referenced this pull request Nov 5, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
c92c470
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
2446e79
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist @claude
Add Node.js record/replay driver integration and API
3d9b0a5
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.

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,
#168, #169, #176, #178, #181 and #215.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
6903662
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
bc8ca58
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
5b1420b
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
108088d
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist
Add Node.js record/replay driver integration and API
2419347
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.

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,
#168, #169, #176, #178, #181 and #215.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
d678b42
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
74a4dd6
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
77b7028
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides. A module which
registered with NAPI_VERSION_EXPERIMENTAL still gets its finalizer inline,
which is what node does for it as well.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
56dedab
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
d7d4f20
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
e1b1832
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
ab28e14
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
56e7ef5
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
5d2e12c
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides. A module which
registered with NAPI_VERSION_EXPERIMENTAL still gets its finalizer inline,
which is what node does for it as well.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
f0bbf51
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
02d9913
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
8eeac5d
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
4c326d7
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
be64421
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
c5cb3f0
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
9acf768
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
c732679
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
2713281
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
6ebba30
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
d316977
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
723482f
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 11, 2026
@bhackett1024 @Andarist
Add NAPI and native addon recording support
55c9c6d
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 11, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
11960cb
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 11, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
3b07d7c
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 12, 2026
@bhackett1024 @Andarist @claude
Add NAPI and native addon recording support
d2fc920
Patch native addon registration for recording/replaying, add pointer
registration for addon handles, and serialize module content for
deterministic addon loading. Mark an addon's dlopen() for the driver
with the addon's name, so the driver attaches the addon wherever it is
loaded from instead of only under node_modules.

Record/replay whether a weak N-API reference's value is still alive. A
module reading one with napi_get_reference_value gets its value or,
once the GC collected it, nothing, and the GC runs at other points
when replaying, so the module could see a value the recording didn't
or the other way around. References the module creates in calls the
driver replays (RecordReplayIsInsideInterceptedCallback says which
those are) get an id and have their values held strongly when
replaying; the ids of references whose values the GC collected are
recorded whenever the module reads a reference, and the replay clears
exactly those references then. A collected reference's finalizer, and
its deletion when it deletes itself, are deferred to the next GC poll
on both sides through node's deferred finalization, with a stub
standing in for a finalizer the replayed call was not given, since
module finalizers never run when replaying.

A module's finalizer is module code, which node does not run from the GC: it
hands it to the environment's second pass, an immediate
(napi_env__::InvokeFinalizerFromGC). The deferred finalization hands it there
too rather than calling Finalize() itself, so that a finalizer never runs
nested inside whatever the module was doing when the poll was reached -- its
own napi_make_callback, say -- which never happens without the recorder.
Reaching that deferral from the GC is what a tracked reference cannot do,
since the GC runs at points which differ between recording and replaying;
reaching it from the poll is the same point on both sides.

Node 20 splits Reference::New into Reference, ReferenceWithData and
ReferenceWithFinalizer factories, and the references with finalizers are
exactly the latter two, so each factory tracks its reference rather than the
base one alone; the record/replay bookkeeping carries its own env and asks the
subclass that owns the finalizer about it, since node 20 keeps both off
Reference. Nothing tracked means nothing deferred to a GC poll, and
napi-add-finalizer-collected and napi-external-finalizers-collected then see
no finalizations at all, because without the deferral they only run at
environment teardown.

Node 24 splits the reference classes further, so the record/replay tracking
follows its factories rather than a single New().

Rebase note: native addon code does not run when replaying. The addon's
node_module struct is restored from the recording, and the exports
value returned by its init function is mapped back through
RegisterPointer/PointerId. Any new upstream path that calls an addon's
register/init function needs the same treatment or must invalidate the
recording, as the legacy nm_register_func path does. Everything a
module can observe about the GC's timing (whether a weak reference
still has a value, when a finalizer runs) has to be recorded and
replayed at fixed points instead of being left to the replay's own GC.

Includes later changes from #167, #168, #171 and #197.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Domiii Domiii Awaiting requested review from Domiii

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@Andarist
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.