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 (truncated) — Don't run user code while the inspector describes values with events disallowed by Andarist · Pull Request #224 · replayio/node

Conversation

@Andarist

@Andarist Andarist commented Nov 4, 2026

Copy link
Copy Markdown
Member

Port replayio/chromium-v8#317 (crash-0074) and replayio/chromium-v8#320
(crash-0042-2). Node's Replay-owned inspector session describes the values
of every console message inside V8InspectorImpl::forEachSession's
disallow-events scope. Describing an Error reads its stack and message
(descriptionForError), and describing a Date converts it to a string
(descriptionForDate -> Object::ConvertToString -> ToPrimitive); both can run
the program's code there. The JSInvoke gate in Execution::Invoke doesn't
catch it when the program's code is called from a builtin (a Date's own
toString() called from Date.prototype[@@toPrimitive], a page join() called
from Array.prototype.toString used as a stack getter) or isn't a JSFunction
(bound functions, proxies). That code runs unrecorded, so its results differ
when replaying.

The ConvertToString gate is only needed because this V8 converts Dates with
ToString to describe them; upstream V8 made that side-effect free in
25c69ecbc14, after which the gate can go. A diagnostic build that aborted
on any non-Date ConvertToString under the gate's condition passed the whole
node-recording suite.

Without events disallowed, or once the replay has diverged (pauses,
evaluations), nothing changes.

Not ported: replayio/chromium-v8#309 (crash-0043, addBinding with a
collected context). Node runs second-pass weak callbacks synchronously when
recording or replaying, so the inspector forgets a collected context in the
same GC and addBinding can't see an empty one there. Nor
replayio/chromium-v8#316 ObjectProtoToString gate: its only caller here
builds a console message's text in the program's own console call, with
events allowed, and a diagnostic build that aborted on it with events
disallowed passed the whole node-recording suite.

Sorry, something went wrong.

Uh oh!

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

All reactions
@Andarist @claude
Explain why Replay's own code must not run user JS
b36a21c
The checks that keep user JS from running while Replay's own code runs
(the JSInvoke gate, the progress warning, descriptionForError,
ConvertToString) all test the same condition. Name it MustNotRunUserJS
and document there why it exists: Replay's inspector session work runs
with events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. The comment also describes the alternative of
recording the session's work on both sides, and why recordings would then
show the program as if a debugger were attached. Same helper as
replayio/chromium-v8@27b55d29518.

Add a TODO to install Replay's session only when replaying, as Chromium
does, with what that needs: the session makes console calls run V8's
console method, whose message text runs user ToString.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Andarist
Andarist force-pushed the andarist/inspector-user-js-gates branch from 6a93eb9 to b36a21c Compare November 4, 2026 15:14
@Andarist
Andarist merged commit fbbcce5 into master Nov 4, 2026
2 of 3 checks passed

Uh oh!

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

@Andarist
Andarist deleted the andarist/inspector-user-js-gates branch November 4, 2026 15:16
bhackett1024 pushed a commit that referenced this pull request Nov 5, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
59548c5
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Brian Hackett <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
bhackett1024 added a commit that referenced this pull request Nov 5, 2026
@bhackett1024 @Andarist
Add JavaScript recording/replay runtime
c681c18
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
eddb111
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 @hbenl
@Andarist @loganfsmyth @claude
Add JavaScript recording/replay runtime
f4bb115
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
3633ca2
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 @hbenl
@Andarist @loganfsmyth @claude
Add JavaScript recording/replay runtime
be50d53
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
01cc91e
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 @hbenl
@Andarist @loganfsmyth @claude
Add JavaScript recording/replay runtime
a44753c
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 6, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
52d4519
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
e756535
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
746bd67
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
78d4330
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
7251503
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
b41a470
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 6, 2026
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
8db594d
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 @hbenl
@Andarist @loganfsmyth @claude
Add JavaScript recording/replay runtime
3b48e79
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
649bc00
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
b880008
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
c7b55b9
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
667b9fd
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
7dcd44d
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
d3c11b6
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
735344d
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
4b1e840
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist added a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
@bhackett1024 @claude
Block non-deterministic user JS while events are disallowed
ad7d836
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
ecbb2b1
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
6482fd0
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
015fdc0
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
6c32c31
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
fdd7dab
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
812cf5a
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
2de4fa8
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
b01dc52
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
bf8b546
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
5b80d4e
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
fab31c1
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
34385ac
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
9b25542
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
7f1c2c1
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
ce48482
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
3d1f255
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
f368256
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
332e955
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Describing an Error for the inspector does not read its name either, for the
same reason it does not read its message: both can run a getter the recording
did not.

Reading a property's descriptor can run user code too: node defines its
lazy globals (FormData, Headers, Request, Response, WebSocket, ...) with
SetLazyDataProperty, whose replace-on-access getter loads the module, and
on the global proxy the inspector does not report them as native
accessors. Replay's own session describes the global object for every
pause's scope chain with events disallowed, where loading undici needs
recorded calls the recording does not have. Report a lazy data property
that has not loaded yet as a native getter instead, as the inspector does
for other native accessors; a session a user or the program attached runs
with events allowed and still loads it.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
cd22b89
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 10, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
da59add
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
56f2645
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathered only when
replaying, so user JS run from there would change the program's state
where the recording didn't. It also describes the alternative of
recording the session's work on both sides, and why recordings would
then show the program as if a debugger were attached.

Execution::Invoke refuses to call such functions and logs a
NonDeterministicUserJSBlocked warning with the trigger, the progress,
the function's location and the JS stack. Invoke and the API callback
entry points (HandleApiCallHelper, InvokeApiFunction,
HandleApiCallAsFunctionOrConstructor) rewind any progress (and
progress assert data) made on such paths through
RecordReplayScrubDivergentProgressScope, the progress runtime function
warns once with the JS stack when it happens
(NonDeterministicUserJSUngated), and Error.prepareStackTrace is
skipped while events are disallowed.

The Invoke gate doesn't catch the program's code called from a builtin
or called through a bound function or a proxy, so the inspector's
value descriptions gate on the same condition: describing an Error
returns a placeholder instead of reading its stack and message, and
Object::ConvertToString returns the default [object Object] string
instead of running ToPrimitive, which this V8 reaches when it
describes a logged Date. Upstream V8 made Date descriptions
side-effect free (25c69ecbc14), after which the ConvertToString gate
can go.

Previews gate on it as well: to show a value instead of an accessor, V8
reads a getter that reports no script id, which is every callable the
Invoke gate misses, so Replay's own session leaves the property an
accessor for the viewer to call. V8 9.4 read it with CallFunctionOn()
and throw_on_side_effect, where a getter that did anything was skipped;
10.2 replaced that with a plain Get() guarded only by a list of DOM
attribute names. The Chromium fork gates the same site with an
allow-list of those names (replayio/chromium-v8@91c06b051a5).

Discard a function's baseline code with events disallowed: the heap
walk enters a safepoint whose GC tracer scope reads the clock, and
whether the function has baseline code when a breakpoint is set can
differ between recording and replaying.

Register as Replay sources exactly the scripts whose bytecode is
instrumented, and announce them to the recorder from a separate
RecordReplayAnnounceScript: queued until the first checkpoint, since the
recorder only takes sources from there on, and skipped with a warning if
events are disallowed, which announcing would record an event in. A
script is also registered as soon as a main-thread compile finishes it
(RecordReplayRegisterCompiledScript), not only when its function is
instantiated. When listing a script's possible breakpoints, recompile a
top-level function the GC collected, so the functions only its bytecode
referenced have their breakpoints again.

The baseline JIT's progress and instrumentation runtime calls take the
accumulator as their last argument and return it
(Runtime_RecordReplayBaselineExecutionProgress,
Runtime_RecordReplayBaselineInstrumentation and its generator
variant): the calling frame's baseline code can be discarded while the
call is on the stack, and the frame then resumes in the interpreter
with the call's result as its accumulator.
Runtime_RecordReplayBaselineTargetProgressReached is called once the
counter that baseline code increments inline reaches the target
progress. Instrumentation sites are reported to the recorder by
function index rather than by bytecode offset.

Reading a property's descriptor can run user code too: node defines its
lazy globals (FormData, Headers, Request, Response, WebSocket, ...) with
SetLazyDataProperty, whose replace-on-access getter loads the module, and
on the global proxy the inspector does not report them as native
accessors. Replay's own session describes the global object for every
pause's scope chain with events disallowed, where loading undici needs
recorded calls the recording does not have. Report a lazy data property
that has not loaded yet as a native getter instead, as the inspector does
for other native accessors; a session a user or the program attached runs
with events allowed and still loads it.

Rebase note: new C++-to-JS entry points need a
RecordReplayScrubDivergentProgressScope, and user callbacks invoked
from V8 internals need the same MustNotRunUserJS() gating. The
invariant is about the program's state, not about one entry point:
anything Replay's own session can reach that would run user JS (an
accessor, a toString, a Symbol.toPrimitive) has to be gated, not just
the paths that go through Execution::Invoke. Upstream keeps reworking how a
preview decides to read a getter; whatever that condition becomes, it
has to keep the gate ahead of it, since the side-effect helper it calls
can run user JS itself.

From #128, #132, #159, #202, #203, #206, #207, #211, #217 and #224.

Co-authored-by: Mateusz Burzyński <[email protected]>
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 JavaScript recording/replay runtime
bd575f1
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[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 JavaScript recording/replay runtime
3ae9861
Add the lib/internal/recordreplay/ module with main entry point,
message handling, object inspection, console preview generation,
source map support, and utilities for the recording/replay system.
Add the internal/recordreplay modules to the expected list in
test-bootstrap-modules.

Report a console message's level from the type of its
Runtime.consoleAPICalled event ("log", "warning", "error", ...),
mapped the way Chromium's replay command handlers do, since the event
carries no level field and every message was reported as "info".

Describe a scope binding CDP gives no value for as an unavailable
value: Runtime.getProperties omits the value of a binding the
inspector can't describe, such as a register that was dead at an await
and holds V8's stale_register marker after the function's optimized
code was deoptimized, and passing the missing value on threw, so
Pause.getScope returned no scope at all.

Record next to the session setup why Replay's session is installed on
both sides here, unlike Chromium, which installs it only when
replaying: connecting it makes the inspector agent active, so console
calls run V8's console method, whose message text converts Dates,
Errors, functions and RegExps with ToString, i.e. user JS, and that
has to stay the same when recording and replaying.

Rebase note: this is new code under lib/internal/recordreplay/, so
conflicts should only come from the list in test-bootstrap-modules
(the bootstrap hook that loads it is a separate commit). The commands
implemented here must keep matching the driver's expectations and the
process.recordreplay methods they call, and anything this code runs
that touches the program's own objects must stay inside a pause, where
the replay has diverged, rather than running while Replay's session
describes a value.

Includes later changes from #152, #204 and #224.

Co-authored-by: Holger Benl <[email protected]>
Co-authored-by: Mateusz Burzyński <[email protected]>
Co-authored-by: Logan Smyth <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Andarist pushed a commit that referenced this pull request Nov 11, 2026
@Domiii @Andarist
Block non-deterministic user JS while events are disallowed
bf97eff
While events are disallowed (GC, compilation, driver commands) and the
replay has not diverged, user JS from registered scripts must not run:
it would advance the progress counter differently than when recording.
That condition is v8::replayio::MustNotRunUserJS(). Its comment
documents why it exists: Replay's inspector session work runs with
events disallowed and console message data is gathe

[Page truncated to keep GeezerVison snappy.]

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.