Skip to content

fix(javascript): the server steps through skipped code itself; where a step lands is the program's to decide (#1130) - #1209

Merged
debugmcpdev merged 26 commits into
mainfrom
fix/js-server-stepper
Nov 21, 2026
Merged

debugmcpdev merged 26 commits into
mainfrom
fix/js-server-stepper

Conversation

@debugmcpdev

Copy link
Copy Markdown
Collaborator

Principle

A step answer is true. After step_into, step_over or step_out the program is paused where its own code next runs, or the answer says the step did not land. Where a step lands is decided by the program, never by the clock: the same step lands in the same place on any host. Time decides only whether the answer comes at once or as pending.

#513, #678/#687 and #1130 were the same cause seen three times: a stepper we do not control (js-debug's "smart stepper") deciding where a step ends.

What changes

  • js-debug's stepper is off for every session. smartStep keeps its meaning and its defaults (a launch follows justMyCode; an attach leaves it off unless the caller sets it). It now configures the server's own stepper, src/proxy/js-stepper.ts, which drives V8 over js-debug's CDP proxy.
  • One step in, one stop out. While a step is in skipped code the stepper issues the next engine step itself. step_over and step_out step out to the nearest frame of the program below. step_into walks on, and a pause in the program's code is the landing. "Skipped" is js-debug's own verdict on the frame, asked at each landing (remembered only for Node's own modules), so justMyCode, a caller's skipFiles, source maps and bundles count as before. js-debug's intermediate stopped and continued events are withheld, so the core, the mirror and the session tree see one step.
  • The walk of a step_into is bounded by engine steps only: 512. Then it steps out and says so. There is no time bound: a time bound made the landing depend on how long skipped code runs and on what an engine step costs on the host.
  • A walk that outlasts the 5 s grace window answers pending: true and says what the stepper last recorded: it is walking through skipped code, what ends the walk, and that pause_execution interrupts it. It no longer says "(e.g. stepping over a long-running call)".
  • When nothing of the program is on the stack (the last line of a request handler, a timer callback, a .then callback) the program is resumed, not walked through the internals of later tasks. The answer is the next stop, or pending: true with a sentence saying the step left its frame and will not land. That sentence is added only when the stepper recorded this.
  • A stopped from js-debug is attributed only after the CDP stream caught up. js-debug's DAP events and the engine's CDP events travel on two sockets; under Node 22 on Linux the stopped of a step's landing overtook the events before it, and a plain step_over was reported as "stopped on 'breakpoint'".
  • A pause asked for while a step is pending is reported as the pause, where the program is. One case is not yet so, here or on main: javascript: pause_execution during a pending step_into stops inside the server's own wake evaluation (repl:1), reported as a step #1208 (below).
  • A stop the program reaches while V8 is still answering the resume that ended a step (the step left the stack, and the next timer's callback has a breakpoint) is delivered as itself, after the step's record.
  • A forked child steps the way its root session does, launched or attached.

What it does not do

Measured

An A/B gate: 113 rows, each run three times on main (the behaviour of 0.26.0) and on this branch, landing lines enforced. Its rule: no row where main lands on the owed line and the branch does not. It passed on all four of: Windows 11 under Node 24.14.1 and under Node 22.23.2, and an Ubuntu 24.04 host (2 vCPUs, the shape of CI's Linux runner) under Node 22.23.2 and under Node 24.14.1, with the landings the same on all four. Which build each ran: all 113 rows on all four with the stepper as first built in this round; on Windows under Node 24 again on bf05b718 and on 51bd3e5d; on the Linux host under Node 22, the Linux sets (36 rows: the walks, require, the forked child and the attach, review 8's rows, the Node 22 row) on bf05b718 and on 51bd3e5d. On this head, Windows under Node 22.23.2: all 113 rows pass, 107 the same, 6 better.

step_into on main this branch
the first console.log of the process lost, the program ends the next line
a later console.log (#1130's own case) the next line the next line
emitter.emit to an on or once listener, [..].map(fn), express next() in the listener, callback or middleware the same
console.log(obj) where obj has a custom util.inspect function in that function the same
emitter.emit where a dependency's listener works for 3.5 s before the program's in the program's listener the same
a one-line for…of loop the header's next position, first iteration the same
a setTimeout line stays on the line the next line
the first step_into in a forked child lost, the session ends lands; the next steps land too
an attach with smartStep: true misses every step of the scenario lands every step
require of the program's own module, first load lost, the program ends lost, the program ends
require of a built-in module stops further down the same function the same place

step_over on every one of those lines, and step_out of the listener and of the callback, land correctly on both builds. In a bundle, a stop inside the bundled dependency does not change how the program's own lines of that script are stepped.

How long it takes (time from the call to the landing, the pending answer and the wait_for_stop after it included; three runs each):

step_into on Windows, main Windows, branch Linux, main Linux, branch
the first console.log lost 0.7 s lost pending, then 16.8 to 17.2 s
a later console.log (#1130) 0.2 s 0.3 s 5.1 to 5.2 s, at once pending, then 5.4 to 5.9 s
a custom util.inspect function 0.2 s 0.2 s 4.2 s 4.6 to 4.7 s
emit to an on / a once listener 0.1 s 0.1 s 0.8 to 0.9 s / 1.8 to 1.9 s 0.8 to 1.0 s / 2.0 to 2.1 s
express next() 0.1 s 0.1 s 0.8 to 0.9 s 1.0 to 1.1 s
a setTimeout line 0.1 s, wrong line 0.3 s 3.0 s, wrong line pending, then 7.2 to 7.7 s
require of a built-in 0.4 s 0.8 to 0.9 s pending, then 12 s pending, then 25 s

Two things in that table are worse than main in time, on Linux, and nowhere in landing:

Both are the 44 ms engine step (#1163). A bare client measured 2.4 ms per step on the same host with one extra request per step, so the time has a fix; it is not in this PR.

Tests

  • Unit: tests/proxy/js-stepper.test.ts runs the stepper against scripted CDP and DAP fakes (every way a chain ends, the walk's bound and its records, a stopped that overtakes the CDP events or arrives while the stream catches up, the verdict asked again in a bundle, the withheld events, a stop the program reaches while V8 answers the step's own resume); the wiring, policy and transform cases are beside them.
  • Real js-debug, in the integration project (CI runs no e2e): tests/adapters/javascript/integration/javascript-step-skipped-code.test.ts, 24 cases, host-independent. One of them fails on any host if the walk gets a clock bound back (Node's own code blocks 3.5 s before the program's listener). The rest: a step whose walk can outlast the grace window accepts a landing at once, or pending with the walking sentence followed by a wait_for_stop landing, and the line is asserted strictly either way. Only the steps V8 loses accept either a runtime with V8's fix or today's, and fail on any other stop.
  • Local gates on this head (Windows 11): npm run build, typecheck:all, lint, check-docs, changelog:check, check:personal-paths: exit 0. test:unit 9482 passed. The stepper's integration file 24 of 24 under Node 24.14.1 and under Node 22.23.2. On this head: the three JavaScript e2e files 35 of 35, the container suite 34 of 34 (image built from this tree). The pre-push hook ran lint, typecheck, a clean build, test:unit and test:integration again before this push. Its first run hit Flaky: javascript-subprocess-tree cap-0 case, the debuggee exits 0xC0000005 once under the pre-push integration run (Windows) #1119 once (the cap-0 fork case's debuggee exits 0xC0000005; that file makes no step call and passed 3 runs of 3 alone); its second run passed.
  • On the Ubuntu host, on 51bd3e5d (this head without the last commit's edge cases): the integration file 3 runs of 3 under Node 22.23.2 and once under Node 24.14.1; the A/B gate's Linux sets (36 rows) pass, 29 the same, 6 better, one row flaky on both builds as before (a continue answers either running or already paused); the timer row whose next stop came 37 to 39 ms after the step's resume lands 20 of 20 under Node 22 and under Node 24 (it passed before that fix too: the lost stop was reproduced in the unit fake only, and the hold-then-deliver path has not been seen to run through the real worker). On this head, Node 22.23.2: the integration file 2 runs of 2; that timer row 20 of 20; the JavaScript integration directory and the self-debug file, 52 tests, all pass.
  • Independent review: ten rounds over the branch's life; the first nine with real rows and a mutation pass, the tenth (on one code path) with unit probes. The first six broke the rescue of javascript: a step that leaves a function through a return inside try…finally never lands and the program runs on (step_out, and step_over off its last statement; V8 12.4 to 14.6) #1161 (removed); the seventh and eighth found rows worse than main (a stop in a bundled dependency poisoning the bundle; a time bound that let the clock decide where a step lands), fixed in the commits above. The ninth, on the delta of this round, found no row worse than main on either host under either Node version; it found javascript: pause_execution during a pending step_into stops inside the server's own wake evaluation (repl:1), reported as a step #1208 (on main too: filed, the docs corrected), a stop that could be lost while V8 answered a step's own resume (fixed), and five test gaps (closed, every mutant killed). The tenth, on that fix alone, found it holds on every path the server reaches, plus four edge cases around the same resume (fixed, each with a case that fails without its fix).

Issues

Closes #1130: the step that was lost lands, and the pending answer says what the step is doing. What #1130 measured as "about 6 s" on a Linux host is still about 5.5 s there until #1163 is fixed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8

cynarlab and others added 21 commits November 15, 2026 20:36
…aw NUL byte

The key that tells two function breakpoints apart joins a name and a
condition with a NUL character, and the source had the character itself
in a template literal. Git treated the file as binary (no diff, no
blame), and text tools refused to edit it.

The separator is now written as an escape. It is the same character at
run time, so nothing about the keys changes; the existing keyed cases
pin that, and a new case reads the source and fails on a raw NUL.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…ug's stepper is off (#1130, #1161)

A step lands where the program's code next runs, in bounded time, and is
never lost. One rule decides what a step skips, for step_into, step_over
and step_out alike, and one component applies it.

js-debug's smart stepper was that component. While a step landed in code
the session skips it stepped again by itself: with `breakOnAsyncCall`,
which moves the step to a later task and loses it (step_into on the first
console.log of simple_test.js ended the session), and one V8 step per
statement of the skipped code (131 for one console.log; ~6 s on a Linux
host, where every engine step costs ~46 ms). #513, #678/#687 and #1130
are that stepper deciding where a step ends.

So the adapter is always sent `smartStep: false`, and the start request's
`smartStep` is read as the session's choice. A session that chose it has
its stepIn / next / stepOut served by JsStepper, over the raw CDP socket
js-debug hands out for the target:

  - one CDP command per engine step, never with breakOnAsyncCall;
  - the verdict on a landing is js-debug's own mark on frame 0
    (stackTrace levels 1), asked at once: the session's one definition of
    skipped code (justMyCode, a caller's skipFiles, source maps);
  - skipped code on top: step_into repeats up to a budget of 24, which is
    how a call through Node's code reaches a callback of the program's,
    then steps out; step_over and step_out step out at once; with no
    program frame below the stack the step started on is gone, and the
    program is resumed;
  - js-debug's stopped / continued events are withheld by count (one
    stopped per pause it keeps, out of order), and one stopped goes out:
    reason `step` on a landing, js-debug's own on a real stop.

V8 itself loses a step that leaves a function through `return` inside
try...finally (#1161: V8 12.4, 13.6 and 14.6 with a bare CDP client;
step_out answered "Step completed as session exited"). Node's
Module.prototype.require has that shape. So a step never counts on V8
alone to come BACK to a frame: before it can leave one that way, the
stepper arms a net, up to 24 temporary CDP breakpoints on the break
positions of the program frame the step returns to (the nearest one
below, or the async parent), kept with that activation's depth. Any
position there is where V8's own step-out would stop, so a hit is a
landing. No net goes on the frame being stepped in: V8 reports no
statement boundaries, and a net there would stop a multi-line call
half-way. Every ender removes every net.

A step_into whose line called only skipped code says so in its answer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…tepper's unit cases (#1130)

js-debug's own stepper is off for the whole session, so a child the
program forks would have lost stepping through skipped code: its
connection is not the program target's, and had no stepper.

Each adopted child connection now gets one, on that child's own CDP
socket (js-debug hands one out per target). The session's choice is the
root's. Without a socket the child's steps stay the engine's plain ones.

Measured through the server on the subprocess-tree fixture: step_into
on the child's console.log line lands on the next line in 163 ms, with
the sentence that the line called only skipped code.

The stepper's 33 unit cases run it against a scripted V8 and a scripted
js-debug that behave as measured: one stopped per kept pause a moment
late, a continued per resume, the mark on frame 0. They cover each chain
ender, the budget and the cap, the return to the origin line, the nets
(armed before the first command, capped, on the async parent, not on a
frame that returns to itself, dropped in recursion, removed before a
real stop goes out), a pause js-debug resumes by itself, the relabel and
the events kept back.

The client's cases pin that the start request's smartStep is read as the
session's choice and that the adapter is always sent smartStep: false.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…he handler; what a pending step says (#1130)

Found by the e2e suite on the branch. A step_into issued inside express,
on the call that leads to the program's handler, answered pending: the
stepper looked for a frame of the program below the first skipped
landing, found none (express is called by Node) and resumed the program.
That is #687's load-bearing case: a request path enters the program by
calls, not returns.

"The stack the step started on is gone" is a conclusion about stepping
OUT. A step-in now walks on while it has budget, with or without a frame
of the program below, and the stepper resumes the program only when the
walk would have to step out and there is nowhere of the program's to
step out to. It looks at the whole stack once per chain, not at every
landing. Two unit cases were red on the committed stepper.

A pending JavaScript step no longer blames js-debug's smart stepper,
which is off. Issued from skipped code, it says the step does not stop
in skipped code, names the frame, and names the switch that steps inside
that code. Issued from the program's own code, it says the step left its
frame and nothing of the program has run since. A pending pause gets no
hint of this kind any more: nothing steps away from a pause.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…tion project (#1130, #1161)

CI runs no e2e, so the stepper's behaviour through a real server, the
real js-debug and a real Node is pinned where CI does run: twelve cases
on one fixture whose lines are found by marker.

Against main's sources (built in place, then restored) six of them fail:

  - step_into on the first console.log of the process, on a require of
    a module not yet loaded, and all three steps that leave a function
    through return inside try...finally (step_out; step_over off the
    finally block; step_out of an async function) answered
    "Step completed as session exited.";
  - step_into on a setTimeout line landed inside the timer's callback,
    a later task, with the lines after it already run.

The other six held before and must keep holding: a builtin calling the
program, a call through Node's code into the program's listener, a
step_out of a callback Node called, a breakpoint reached during a step,
a step off the last line of a callback Node called (the program is
resumed and the next breakpoint is what stops), and justMyCode: false
landing in Node's own code.

Each landing must also answer inside 4 s, so a step that would have gone
pending fails the case.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…our process (#1130, #1161)

The JavaScript guide's stepping section described js-debug's smart
stepper as the thing that steps through skipped code, and explained why
a launch kept it on. It is off for every session; the section now says
what each step does from each kind of line, what a session that chose
plain steps gets, which steps V8 itself loses and how the server catches
them (the temporary breakpoints it sets in the debuggee, when, how many
and for how long), what is not covered (#1162), and what a step costs on
Linux.

The tool reference follows: justMyCode for a JavaScript launch, what
step_into does there, the sentence a pending step may carry, and the
pending pause, which no longer has a JavaScript sentence of its own. The
justMyCode text of the start_debugging schema says the same, so the 24
tool-list snapshots change with it.

Two changelog fragments, one per issue.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…find (#1130, #1161)

The independent review of this branch, and the rows I ran while answering
it, found the stepper wrong in five ways. All five are the nets doing more
than a safeguard should.

A net could fail the step. With a skipFiles list that leaves out
<node_internals>, Node's own frames are program code, V8 refuses
getPossibleBreakpoints for them, and the rejection escaped: step_out of a
timer callback answered an error and left the session in `error`.
armReturnTarget now never throws and answers armed, unguarded or
nothing-below; unguarded means V8's own step goes on alone. A chain that
fails while V8 is paused reports where it is instead of nothing.

A net on an awaiter stopped in the wrong call. An async function the event
loop resumed returns to the function awaiting it, which is not on the
stack, so its net can only guard the FUNCTION. With three calls of it in
flight, step_out landed in a sibling. Measured with V8 alone: the link is
named `await` (a `Promise.then` or `Timeout` parent only scheduled the
code), V8's own step-out finds the call that awaited, and V8 loses the
step only when the function left has a return inside try...finally. So the
awaiter is netted only for that shape, the landing says it may be another
call's, and a `.then` or timer callback's step_out resumes the program.

A net stopped a step over an await in its caller. A function whose text
has `finally` was netted on every step-over, and a function that awaits
suspends: its caller ran on into the net. In a function that can suspend,
a step-over or step-in is now netted only on a return line and from its
finally on, never on a line that itself awaits. `finally` is read as a
clause, not as a word (a comment, a promise's .finally()).

The sentence on a step-in said more than was known. "The call ran only
skipped code" was attached after the step had gone on into the program's
own function, and for a require whose module body had run. It now says how
many engine steps the walk took, only when the step ends in the frame it
left.

A pause asked for during a pending step could be stepped away from. V8
reports a pause taken while a step is in flight as the step, so the pause
request itself now marks the chain: the next stop is the caller's, and
leaves as a pause.

Also: the look at the stack is repeated while js-debug says "not paused"
(it used to read that as an empty stack and resume), is made per landing
that has to step out (the awaiter of one frame is not the awaiter of the
next), and asks for the whole stack up to 200 frames; a late `stopped` is
dropped only when it can be the step's own; nothing is sent after a chain
is given up.

Unit: 40 new cases, 18 of them red on the stepper as committed; the rest
pin behaviour the review's mutation pass found unpinned.

Through a real server, js-debug and Node, in the project CI runs, on a new
fixture (async-steps.cjs): step_out of an async function lands in the call
that awaited it with three calls in flight; step_over on an await lands on
the next line though the function has a finally clause, and off the
finally block is caught at the awaiting function with the sentence that
says what that promises; step_out of a .then callback resumes the program;
step_out of a timer callback under a skipFiles list without
<node_internals> lands in Node's timer code. All four fail on the stepper
as committed (built in place, then restored), as does the case whose
sentence changed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…ff and take the root's choice; the wiring's unit cases (#1130)

Two things the review found in the wiring, and the coverage it found
missing.

The start request's smartStep was overridden after the parent's start was
snapshotted, so an attach session's child `attach` request, built from
that snapshot, went out with the caller's smartStep: true and turned
js-debug's own stepper back on beside the proxy's. The override now comes
first.

A forked child's stepper read the launch configuration only, so a child of
an attach root never got one. It now asks the root what its own start
request said (MinimalDapClient.stepsThroughSkippedCode), and falls back to
the launch configuration when the root cannot say.

The wiring had almost no unit coverage: 23 of the review's 30 wiring
mutants survived. New cases in the minimal-dap, child-session-manager,
child-connections, worker, policy and step-message suites kill 24 of the
25 listed (the last is equivalent: the branch it changes is unreachable
for a non-step stop). One test seam: ChildSessionOptions.cdpClientFactory.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
The review read every sentence of the stepping section against the code
and found ten false. Rewritten in the JavaScript guide, the tool reference
and both changelog fragments:

- what a step_into says when the walk stayed in skipped code, and that a
  call into native code says nothing;
- that a `debugger;` reached during a step is reported as the step's
  landing, and that a pause asked for during a pending step is the
  caller's;
- that a step off a function nothing of yours called or awaits answers
  with the next stop if one comes, and pending only if none does;
- that V8 "can" lose a step through try...finally, where the temporary
  breakpoints are set and where they are not, and what is left to V8 on
  purpose: recursion, a line that awaits, and the awaiting function of an
  async one;
- that a skipFiles list without <node_internals> makes Node's code program
  code to a step.

The sentence a pending step carries no longer claims nothing of the
program has run since; the justMyCode schema text follows the new wording
(24 tool-list snapshots).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…place (#1130, #1161)

The second review found the first round's fix incomplete twice, and both
were the shape that round had already fixed twice: a temporary breakpoint
below a function that suspends instead of returning.

- A step over a statement that awaits on a later line (`return {` with the
  awaits two lines down) was still netted, because only the paused line's
  text was read. The function suspended, its caller ran on into the net,
  and the step stopped in the caller.
- A step out of an async function still in its first run was netted on its
  caller by depth, like any step out. The caller was waiting at its own
  await, left the stack, and the net stopped in the next call of that
  function entered at the same depth: a sibling, with nothing said.

So the arming is no longer decided at four sites. One rule, in `guard()`,
before every command that can leave the frame on top:

  (a) A net only where V8 can lose the step and the frame cannot hand
      control down without returning. For a frame of the program that is
      read from its text: a finally clause, and from the paused line no way
      to suspend before the function exits (no await or yield ahead, no
      loop above that leads back to one). Measured with V8 alone: V8 keeps
      a step across an await and lands in the awaiting function even when
      the function then leaves through finally, so a function that can
      still suspend needs no rescue. Skipped code is netted without being
      read (V8 refuses the positions of Node's own scripts, and Node's
      loader has the shape): however control comes down from it, the
      program frame below is the landing. A step out is no longer netted
      unconditionally.

  (b) A net names one call only while the frame it guards stays on the
      stack. When that frame is itself waiting at an await for the call
      the step leaves, or is an awaiter that was never on the stack, the
      net guards the function, and the landing says the stop may be
      another call's. The sentence no longer claims the engine lost the
      step: the pause's reason does not say, and nothing is decided on it.

The awaiter is now found behind the empty `await` links V8 lists for a
function's later awaits. Also from the review: a resume V8 refuses when
the stack is gone reports where the step is instead of nothing; a pause
asked for while a landing is being judged gets no further command and is
reported as the pause.

Unit: 95 cases (19 new, 14 of the file red on the stepper as committed).
Real server: two new cases on async-steps.cjs, both red on the committed
build: a step over a statement that awaits on later lines lands on its
second await, and a step out of an async function in its first run lands
in the call that awaits it with three calls in flight.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…r sentences the second review found false (#1130, #1161)

The JavaScript guide, the tool reference and both fragments state the rule
as the code now applies it: from your own code only where the function has
a finally clause and cannot suspend before it exits; from skipped code
always; never on the frame being stepped in; and where the breakpoints
cannot name one call, the answer says so.

Corrected:

- "A step over an await that is the last thing a function does before it
  leaves through finally can be lost." It is not: measured with V8 alone,
  V8 keeps a step across an await. The pending-step sentence no longer
  offers that as a cause.
- A step out of a `.then` callback lands "nowhere": with another callback
  of the program queued behind it, V8's own step stops there.
- "The pending answer says the step left its frame": on a launch. An
  attach that steps through skipped code gets the generic sentence.
- A `setTimeout` line answers with the walk's sentence, as `console.log`
  does, and that sentence no longer says a callback the line only
  scheduled "ran".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
, #1161, #1174)

The third review found the one rule of the round before unsound in both
directions: it lost nine steps V8 loses that the round before had rescued,
and it still set nets below functions that suspend. Three rules in a row
failed the same way, for one reason: they read a function's text to guess
whether control coming back to the frame below means the function
returned or merely paused at an await, and text cannot say. Nor does CDP
name one call of a function, so a net on a frame that can leave the stack
can stop in another call.

So the nets are set only where a hit is a proof:

  (a) The frame being left is a plain function: not async, not a
      generator, not module code. That is read from its header, the text
      V8's functionLocation points at, for Node's own scripts as for the
      program's (V8 gives their source; it refuses only their break
      positions). Doubt reads as "can suspend". A plain function comes down
      only by returning, so control back below means it returned.
  (b) The frame guarded stays on the stack until it reaches a net
      position: a plain function does; an async one does unless it can
      suspend between the call returning and its next break location.
      Measured: V8 puts a break location at every statement's start and at
      every call, so that happens only when the calling statement awaits or
      yields, or the function suspends with no keyword there (`for await`,
      `await using`). src/proxy/js-statement-scan.ts reads that statement:
      strings and comments masked, the span found by brackets, semicolons
      and line breaks, and "it can" whenever it is unsure (an unterminated
      string, a template expression, a regular expression literal, a
      statement longer than 40 lines). Its first draft read the wrong span
      and took a comment on the line above ("after the await") for a
      suspension: safe, but it lost the `require` rescue in an async main.

Nothing off the stack is netted any more: the awaiter net, its sentence
(stepCaughtWhereItReturns) and the text tests for finally clauses, loops
and suspensions are gone. One text test is kept only to spare breakpoints:
a plain function whose text names nothing that closes through a finally
(`finally`, `for...of`, `using`) is not netted, and that test can only err
toward netting.

What that leaves lost, as in 0.26.0 and now filed as #1174: a step V8
loses while leaving an async function or a generator, and a step out of a
plain function whose caller awaits the call. The pending sentence names the
case. Measured with V8 alone: a step parked across an await survives an
unrelated breakpoint pause and resume, so nothing about async stepping is
worse than V8's own.

Also from the third review: a pause asked for while the stack turns out to
be gone, or while a net is being set, no longer resumes the program.

The cause in V8 is now understood and tracked in #1173 (the return
replayed after a finally carries no source position, so it is not a break
location).

Unit: tests/proxy/js-statement-scan.test.ts, 27 cases of the shapes the
reviews found and the ways the scan could be fooled. js-stepper: 122 cases.
The rule's cases are rewritten: function forms read from
headers as measured on Node 24, async and generator frames get no net
whatever they contain, plain frames get one whatever their comments say,
the implicit finally of for...of and using, an async caller that awaits
the call. Integration: the two cases that expected an async function's
lost step to be rescued now pin it as lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…1161, #1173, #1174)

The JavaScript guide, the tool reference and the #1161 fragment state the
provable rule: temporary breakpoints only below a plain function, on a
caller that stays on the stack until it reaches one. They name what that
leaves lost, as in 0.26.0: a step V8 loses while leaving an async function
or a generator, and a step out of a plain function whose caller awaits the
call (#1174). The cause in V8 is named, with its issue (#1173). The
pending-step sentence names that case among the reasons a step can be
pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
… as tokens; an async generator's return awaits (#1161)

The fourth review, judging outcomes against V8 alone, found three ways
the provable rule's implementation still landed a rescue in the wrong
call or iteration. The rule held; the code did not.

A net covered at most 24 break positions, taken from the call on and
wrapping to the function's start. In a bigger function the position
control comes back to could be outside it: a loop's top (the next
iteration was where it stopped), the code after a long else (the next
call was). A net now covers every break position of the function it
guards, or the function is not netted: above 100 positions the step is
V8's own. The first hit is then the first position the activation
reaches.

The header read kept only the text after the last delimiter, so a method
whose name is a string or computed key holding `:` or `,`
(`async 'GET /users/:id'(req)`) read as plain, and a step that suspended
in it was netted below. functionKind (js-statement-scan.ts) now reads the
header as tokens, backward from the parameter list: the name as one
token, whatever it is (identifier, private name, string, computed key),
then `*` and the modifiers, across a few lines and through comments. A
header it cannot read with confidence (a template expression in a
computed key) is unknown, and unknown means "can suspend".

An async generator's `return x` awaits x, with no keyword in the
statement, so its caller could leave the stack before any net position.
statementCanSuspend now counts a `return` in an async generator. It also
masks templates that span lines, reads an object literal after a spread,
keeps an argument list going past a brace that ends its line, and treats
a `//` after a lone slash on the line as unreadable (a regular expression
may hold it).

Measured on the reviewer's scenarios, with the value of a per-call
variable after each landing: the string-key, computed-key and
async-generator rows now behave as V8 alone; the loop rescue lands at the
loop's top in the same iteration (i=0), the if/else rescue after the else
in the same call (x=1), the async worker's in worker a, iteration 0.

Unit: header forms (the measured ones, the keys the old read lost,
headers split across lines) and the new scan shapes in
tests/proxy/js-statement-scan.test.ts; all-or-none and the unpinned
mutants of the fourth review in tests/proxy/js-stepper.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…e stepper stops reading source (#1161, #1174)

Five versions of the rule for where to set a net read the program's
source to tell a function that returns from one that suspends at an
await or yield. Each review fooled the reading: names with non-ASCII
letters, numeric keys, a string or computed key holding a delimiter, an
object literal whose brace starts its line, a template that spans lines.
V8 knows, and says so on every frame of a pause: `canBeRestarted` is false
for an async function, a generator and module code that may await, and
for every frame below one. Measured on Node 22, 24 and 26 over every
function form (declarations, expressions, arrows, methods, getters,
constructors, private and computed names, eval, new Function, ESM module
code with and without top-level await, Node's own async code): no frame
that can suspend reads as restartable.

So the rule is one V8 fact on the frame a net would guard: it can be
restarted. Then it and every frame above it, the one being left and any
skipped code between, are plain functions that come down only by
returning, and a hit in the guarded frame is the step coming back in the
same call. The header tokenizer and the statement scan
(src/proxy/js-statement-scan.ts) are deleted.

What that costs: a plain function with a try...finally (or Node's loader
behind a require) called from an async function is no longer rescued: the
async caller can suspend before any net position, and nothing V8 exposes
names one call of it. The step is V8's own there, and lost as in 0.26.0
(#1174). The first console.log of an async main still lands: V8 does not
lose that step.

Two holes in "all or none" are closed. Top-level code whose first token is
a function declaration got the nested function's positions for its own,
and a fallback that asked from the frame's line on, so a loop's top was
not netted and a rescue landed an iteration late: the positions are now
asked again from just past each nested function until they hold the
frame's own, or there is no net. And a net with a breakpoint V8 refused is
removed whole. Lines are split as V8 counts them (CR, LF, CRLF, U+2028,
U+2029), and a net that fired too deep (recursion) is not followed by new
ones while V8's own step-outs finish.

Measured on the fourth and fifth reviewers' scenarios with a per-call
variable: every rescue lands in the same call or iteration (constructor
and getter callers, recursion, loops, if/else, the top-level loop at i=0,
100 positions rescued, 101 not); every row they found wrong now behaves as
V8 alone.

Unit: the rule's cases rewritten on a scripted V8 that reports
canBeRestarted as measured, plus the top-level walk, a refused breakpoint
and a V8 that does not report the field. Integration: the rescue rows step
from a plain caller; a new case pins the async caller as lost.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…orary breakpoints (#1130, #1161, #1174)

Six reviews each found a wrong landing in the rescue for a step that leaves
a function through `return` inside `try…finally`: a breakpoint hit in the
caller cannot be told from a hit in a later call of the caller. The rescue
goes. A step V8 loses stays lost, the answer says the program ran on or
ended, and the docs give the workaround (a breakpoint where execution
should come back, then continue_execution).

- src/proxy/js-stepper.ts: the nets, the net branch of the verdict and
  their bookkeeping are removed. The walk through skipped code, the return
  target and the re-issue cap stay.
- The pending sentence, the tool reference, the JavaScript README and
  KNOWN_ISSUES say what is lost, on which Node versions, and where the fix
  is (V8 issue 569814973, tracked here as #1173).
- Measured without the rescue: a step_into on a `require` line is lost
  (Node's loader returns through try…finally). The docs and the changelog
  fragment said it lands; corrected. On a `require` of a built-in module
  this is worse than 0.26.0, which stops three lines late.
- Tests: the net cases leave the unit file. The integration file accepts a
  fixed runtime or today's for each step V8 loses, and names V8's stop in
  the next call of the function for a step_over off a finally block.
- changelog.d/1161.fixed.md is removed: #1161 is not fixed here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
… two bounds; a bundle's lines are asked about each time (#1130)

An independent review of this branch found the stepper worse than main in
four places. Each is now a row in an A/B gate (main against this branch,
three runs a row, kept outside the repository) and is fixed here.

- A bundle. js-debug's "skipped" verdict was remembered per script, but
  js-debug decides per original source: one stop in a bundled dependency
  made the program's own lines of that script count as skipped, and steps
  ran past them. The verdict is remembered only when js-debug names the
  source <node_internals>; everything else is asked at each landing.
- The walk. A step_into through skipped code gave up after 24 engine
  steps, before a once() listener (35 steps) or a custom util.inspect
  function. It now walks while it is inside two bounds, whichever comes
  first: 512 engine steps taken in skipped code, or 3 s from its first
  landing there. Then it steps out, and the message names the bound.
- The origin line. A step_into that came back to its origin line stepped
  in again, which ran a one-line loop through many iterations. In the
  traces V8's step-out lands on the caller's next break position, never
  back on the call it left, so a pause in program code is the landing.
- The pending sentence. "The step left the frame it started in" was added
  to steps that never left it. The stepper records the one case it knows
  (it resumed the program because nothing of the program was below) as a
  proxy event of its own, the sentence is added only then, and it says
  the step will not land.

The docs say what was measured, per host. On Linux an engine step costs
about 44 ms (#1163), so the time bound comes first there, at about 60
engine steps.

Measured: on Windows the gate passes, 101 rows, 96 the same as main and 5
better. On Linux (walk, require and review rows) one row is worse than
main and is not fixed here: a custom util.inspect function behind
console.log is entered by main after 4.5 s and not by this branch, whose
walk ends at 3 s. A step_into on a built-in require is lost there, where
main stops three lines late.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
… the clock's; a stopped is read only after the CDP stream caught up (#1130)

The walk of a step_into through skipped code is bounded by engine steps
only (512). The 3 s bound is gone: it counted the skipped code's own run
time, so a node_modules listener that worked for 3.5 s before calling the
program's handler made the step give up where main lands (review 8, C1),
and on Linux, where an engine step costs about 44 ms (#1163), the clock
decided whether a custom util.inspect function was entered.

A walk that outlasts the step's 5 s grace window answers pending and says
what the stepper last recorded: it is walking through skipped code and
what ends the walk. The stepper sends a record when a walk starts and when
it is no longer known to be going (its limit, a pause of js-debug's own
that js-debug resumed, a failed chain); the execution controller keeps the
latest record of the step and the JavaScript policy words it. An attach
session whose steps the stepper serves gets the recorded sentences too.

The pending answer of a step the stepper has such a record of (walking, or
left the stack) no longer opens with "still executing ... (e.g. stepping
over a long-running call) ... will become 'paused' when it completes",
which was the issue's complaint and contradicted "this step will not
land": it says the step has not landed, that wait_for_stop waits for the
next stop and that pause_execution interrupts it. A step with no record
keeps the generic lead (#1178).

Under Node 22 on Linux a plain step_over was reported as "stopped on
'breakpoint'": js-debug's DAP stopped for the step's landing overtook the
CDP resumed and paused that precede it on the other socket, and the
stepper took it for a pause js-debug had kept. Before a stopped is read as
"kept", the stepper now sends one request V8 answers over the CDP proxy
and reads its inbox again: every event forwarded before the answer is in
it.

A chain given up while its return target is being asked neither resumes
the program nor records a left stack.

Measured on Windows (Node 24 and 22) and on an Ubuntu 24.04 host (Node 22
and 24), 113 A/B rows each: no row where main lands on the owed line and
this build does not. On Linux the steps land in the same places as on
Windows and take longer: issue #1130's own case answers pending first and
lands after 5.4 to 5.9 s (main: 5.1 to 5.2 s), and a step_into on a
built-in require takes about 25 s to the place main reaches in 12 s. The
time is #1163's.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…'s own resume is delivered as itself; a pause during a pending step_into is not always the caller's (#1130, #1208)

When a step's stack is gone, the stepper resumes the program and records
that the step left the stack. The chain stayed current while that resume
was awaited, so a stopped for the program's next stop (a breakpoint in the
next timer's callback) that arrived before V8 answered the resume was
counted as the chain's own and withheld: lost, with V8 paused under a
session reported running. On Linux V8's answer can wait about 40 ms
(#1163), and the next stop came 37 to 39 ms after the step ended in a
measured row. Once the resume is out, a stopped beyond the chain's kept
pauses is the program's next stop: it is held until the chain's record is
out, then delivered as itself. Own and foreign stops are told apart by
count, as before; js-debug's continued for the resume stays the chain's.

The docs said a pause asked for during a walk is always the caller's. It
is not when the step_into is pending because the program is blocked in
native code or idle: the pause stops inside the expression the server
evaluates to wake the program (#1146), reported as a step at repl:1. That
is main's as well and is filed as #1208; the docs, the changelog fragment
and the message's comment now say so.

Tests: the fake CDP socket releases the events it held after a tick,
before the answer, so a catch-up that is not awaited reads none of them;
new unit cases for a failed catch-up, a stopped that arrives during the
catch-up, a chain that fails mid-walk (the failed record) and the stop
after the step's resume. A new integration case enters the program's
listener after Node's own code blocked 3.5 s before it: with a 3 s clock
bound on the walk it lands on the next line instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
…t in order, and only while the step stands (#1130)

Review of the previous commit, which holds a stop the program reaches
while V8 answers the step's own resume until the step's record is out:

- A resume whose answer is lost after V8 took it (a 5 s CDP timeout),
  with V8 now paused at the program's next stop, was taken for a refused
  resume: that stop was reported as the step's landing and then, held,
  as itself too. The step's landing is reported only when V8 is still
  paused where the step left it.
- A continued that resumes a held stop was withheld, so the parent could
  end thinking the program paused while it runs. It joins the held stop,
  in order.
- A step given up while its resume is answered (a new step, a continue,
  a disconnect) still sent its record and the held stop, which V8 had
  moved on from. Now it sends neither: the request that gave it up is the
  caller's, as for a step given up before its resume.

Only the first is reachable through the server; the parent refuses a
step or a continue unless the session is paused. Each has a unit case
that fails on the previous commit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn69pXrYMWc1JUwv5v8
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.84764% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/proxy/js-stepper.ts 97.26% 11 Missing ⚠️
src/proxy/child-session-manager.ts 90.90% 4 Missing ⚠️
src/proxy/child-connections.ts 94.23% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

… a step_over off a finally stops at the return first (#1173)

V8 landed the fix for the lost step out of a return inside try...finally
(crrev.com/c/8823312, V8 commit cba4bd578084, in V8 16.0). No Node release
has it yet. The JavaScript guide and KNOWN_ISSUES say so in place of "a fix
in review".

On a runtime with the fix (Node 24.14.1 with the V8 change applied to
deps/v8) two of the stepper's tests failed: a step_over off the end of a
finally block, sync and async, first stops once more at the end of the
return, in the same call, with its return value, and only the step after
that reaches the caller. Both tests now name that stop, pinned by the frame
beneath it so it cannot pass for the stop in a later call of the function,
and require the next step to land in the caller. Stock Node 24.14.1: 24 of
24; with the fix: 24 of 24 (22 of 24 before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cynarlab and others added 4 commits November 21, 2026 10:16
docs(javascript): V8 16.0 has the fix for the steps it loses; with it a step_over off a finally stops at the return first (#1173)
…/tests (#1130)

- Always force smartStep: false when stepsThroughSkippedCode is active, including on child-safe policies where childSessionManager is undefined.
- Account for js-stepper's owed flag synchronously in abandonChain() and clear skippedScripts/chain in detachCdp(); guard finish() against cancelled chains and empty callFrames.
- Dispose CDP client in ChildConnectionPool.openStepper() when post-connect setup fails or connection closes during requestCDPProxy.
- Fix stale attach/pause/stepNotLanded notes in docs/javascript/README.md and docs/tool-reference.md.
- Harden javascript-step-skipped-code integration tests (client callTimeoutMs, walkingStep on once-listener, stop.success check) and add unit regression tests.
@debugmcpdev

Copy link
Copy Markdown
Collaborator Author

Review & Hardening Summary

Reviewed #1209 and stacked #1210 (now merged into fix/js-server-stepper at 541ad96f, with expectAtTheReturn and next-call assertions hardened in fc752809).

Defects found & fixed in 87f85621

  1. Child-safe attach connections leaked smartStep: true (src/proxy/minimal-dap.ts): Removed && this.childSessionManager from the stepsThroughSkippedCode override guard and chained this.childSessionManager?.setStepThroughSkippedCode(...) so adopted child connections (createChildSafePolicy) always send smartStep: false. Exhibited live by self-debugging the pre-fix server through dev-proxy.mjs (ChildConnections.adopt → MinimalDapClient.sendRequest).
  2. Stepper state-machine edge cases (src/proxy/js-stepper.ts):
    • Accounted for this.owed synchronously in abandonChain() via an owedAccounted guard so lagging stopped events are withheld immediately and an abandoned chain finishing late cannot overwrite owed for a newer step.
    • Cleared skippedScripts and this.chain in detachCdp() without resurrecting owed.
    • Guarded finish() against cancelled chains during settle wait / failed Debugger.resume, and guarded isSkipped() against empty pause.callFrames.
  3. Child CDP connection lifecycle (src/proxy/child-connections.ts): Guarded openStepper() against child closure while requestCDPProxy is in flight and disposed the CDP socket if post-connect JsDebug.subscribe / Debugger.enable fails.
  4. Docs & test hardening (docs/javascript/README.md, docs/tool-reference.md, tests/adapters/javascript/integration/javascript-step-skipped-code.test.ts): Fixed stale attach/pause/stepNotLanded notes; raised stdio client callTimeoutMs above WALK_WAIT_MS, switched the once-listener test to walkingStep('step_into'), and asserted stop.success in the bundle test.

Verification

@debugmcpdev
debugmcpdev merged commit 57a4018 into main Nov 21, 2026
16 checks passed
@debugmcpdev
debugmcpdev deleted the fix/js-server-stepper branch November 21, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants