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 — Describe node's deferred finalization from V8's GC poll by Andarist · Pull Request #197 · replayio/node

Conversation

@Andarist

@Andarist Andarist commented Oct 27, 2026

Copy link
Copy Markdown
Member

replay-node polled for what the GC collected three times per microtask checkpoint: V8's ReplayGCPoll (WeakRefs, FinalizationRegistries), DeferredFinalization's own microtasks-completed callback, and one per napi_env for cleared N-API references. Each recorded its own value, in an order that depended on callback registration.

V8's poll now takes embedder participants
(v8::replayio::ReplayGCPollParticipant, synced from replayio/chromium-v8): it records one "GC.poll" value per poll, with a bit saying whether an active participant has something pending, and then calls the participants in the order they were added. DeferredFinalization is such a participant instead of registering its own callback.

The N-API checkpoint flush is gone. The only reader of a reference's value, napi_get_reference_value, flushes the cleared references itself, and a collected tracked reference is finalized at the next GC poll on both sides, which resets its handle. Ids of finalized or deleted references are dropped from the recording-side set, so it no longer grows without reads.

The recording format changes: node's values come after V8's in each poll, and DeferredFinalization.poll is only recorded when GC.poll says so.

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 26, 2026 23:07
@Andarist @claude
Describe node's deferred finalization from V8's GC poll
459ac4a
replay-node polled for what the GC collected three times per microtask
checkpoint: V8's ReplayGCPoll (WeakRefs, FinalizationRegistries),
DeferredFinalization's own microtasks-completed callback, and one per
napi_env for cleared N-API references. Each recorded its own value, in an
order that depended on callback registration.

V8's poll now takes embedder participants
(v8::replayio::ReplayGCPollParticipant, synced from replayio/chromium-v8):
it records one "GC.poll" value per poll, with a bit saying whether an active
participant has something pending, and then calls the participants in the
order they were added. DeferredFinalization is such a participant instead
of registering its own callback.

The N-API checkpoint flush is gone. The only reader of a reference's value,
napi_get_reference_value, flushes the cleared references itself, and a
collected tracked reference is finalized at the next GC poll on both sides,
which resets its handle. Ids of finalized or deleted references are dropped
from the recording-side set, so it no longer grows without reads.

The recording format changes: node's values come after V8's in each poll,
and DeferredFinalization.poll is only recorded when GC.poll says so.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Andarist @claude
Name every caller of the GC poll and its participants in its comments
48523b5
The poll also runs when the embedder calls Isolate::ClearKeptObjects(), which
is how node reaches it when a callback scope closes, and an active
participant makes it record as a tracked WeakRef or registration does.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@Andarist
Andarist merged commit 1a198b3 into master Oct 27, 2026
2 of 3 checks passed

Uh oh!

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

@Andarist
Andarist deleted the claude/gc-poll-participants branch October 27, 2026 12:47
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]>
bhackett1024 pushed a commit that referenced this pull request Nov 5, 2026
@Andarist
Finalize what the GC collects at deterministic points
0f67773
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Add
recordreplay::DeferredFinalization, owned by the Environment and added
to V8's GC poll as a participant: the GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Andarist @bhackett1024 @claude
Add deferred finalization for what the GC collects
2d5cdfd
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
cac4bc9
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
6f80406
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Add
recordreplay::DeferredFinalization, owned by the Environment and added
to V8's GC poll as a participant: the GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 6, 2026
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
983b9bb
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Add
recordreplay::DeferredFinalization, owned by the Environment and added
to V8's GC poll as a participant: the GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Andarist
Add deferred finalization for what the GC collects
64c3164
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 6, 2026
@Andarist
Finalize what the GC collects at deterministic points
8bd9159
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 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
@Andarist
Finalize what the GC collects at deterministic points
7d7dcdd
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Add
recordreplay::DeferredFinalization, owned by the Environment and added
to V8's GC poll as a participant: the GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Andarist
Finalize what the GC collects at deterministic points
4f25dcc
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Add
recordreplay::DeferredFinalization, owned by the Environment and added
to V8's GC poll as a participant: the GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Andarist @bhackett1024 @claude
Add deferred finalization for what the GC collects
7219101
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 6, 2026
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
236a9f6
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
b7d0188
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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
@Andarist
Add deferred finalization for what the GC collects
0d30a73
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
14a75cb
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist @bhackett1024 @claude
Finalize what the GC collects at deterministic points
69a62e6
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
44aba7b
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
5757063
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
40b2194
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
f50164b
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
de34183
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
bc32eea
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
449fc30
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
9d5bb64
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
0989aa0
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
22c9870
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
af93ec9
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
fa51411
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
5443bca
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
252cf10
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
7a3667f
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
05949d2
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
900f560
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
f9f2afb
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
761ba5c
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Andarist
Add deferred finalization for what the GC collects
5e827a5
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown.
recordreplay::DeferredFinalization, owned by the Environment, is added
to V8's GC poll as a participant: a GC's callback only notes what it
collected, and the poll writes the notes into the recording and runs
the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

This commit adds the mechanism, its ReplayGCPollParticipant contract
with V8 and the Environment's instance of it. The finalizers that track
objects with it follow, starting with the N-API references in the next
commit.

Rebase note: IsActive() and the number of values the poll records on a
participant's behalf have to be the same when recording and replaying,
so nothing here may depend on the replay's own heap.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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 added a commit that referenced this pull request Nov 10, 2026
@Andarist
Finalize what the GC collects at deterministic points
959e3bb
Old space GCs run at points the replay does not reproduce, and which
objects die in one differs between the two, so cleanup from a weak
callback was dropped or leaked until teardown. Track what the GC
collects with the Environment's recordreplay::DeferredFinalization: the
GC's callback only notes what it collected, and the poll writes the
notes into the recording and runs the cleanup from there. When replaying, what the GC would collect is
kept alive until the poll names its id, so the cleanup runs in the same
state on both sides.

The notes are the async ids of resources the GC destroyed, so
async_hooks destroy hooks fire again, and the ids of tracked
Finalizables: BaseObjects (FileHandle, DirHandle, open HandleWraps,
IntervalHistogram), N-API references and external Buffers' free
callbacks. An object created where no id could be assigned keeps the
earlier handling and its LeakMemory diagnostic.

Where liveness is JS-visible it is recorded rather than read from the
replay's own heap: WeakReference, an active handle's owner, an async
context's resource. A legacy addon initializer reached through its
well-known symbol invalidates the recording, as the self-registering
ones already did.

An external Buffer's free callback is module code too, so
CallbackInfo::RecordReplayFinalize schedules an immediate for it instead of
running it where the poll was reached, for the same reason the deferred N-API
finalizers are handed to the environment: node's own deleter schedules one
(see OnBackingStoreFree), and the poll is reached at the same point when
recording and replaying, so the immediate it schedules is too.

Rebase note: nothing a weak callback, a backing store deleter or
another GC-driven path does may be observable; it either notes an id
for the GC poll or leaks through EnterLeakMemory, and only objects
created where events are recorded get an id. Check new upstream
finalizers, and keep every JS-visible answer about what is still alive
coming from the recording.

From #164, #171 and #197.

Co-authored-by: Brian Hackett <[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

No reviews

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.