Skip to content

fix(session-tree): a function breakpoint no longer hangs a program that forks (#1219) - #1224

Open
debugmcpdev wants to merge 3 commits into
mainfrom
fix/js-fork-fnbp-hang
Open

debugmcpdev wants to merge 3 commits into
mainfrom
fix/js-fork-fnbp-hang

Conversation

@debugmcpdev

Copy link
Copy Markdown
Collaborator

Closes #1219.

What was wrong

With any function breakpoint set, a JavaScript program that forks never got its child session, and never ended. Measured (Windows 11, Node 24.14.1, js-debug v1.140.0) with the tree fixtures, a breakpoint on child.js:14 and one function breakpoint:

main (58f4014) this branch
fork adopted no: its row says running for 30 s, then disappears with "1 child process was released to run undebugged (adoption failed…)" yes, inside the launch hold
fork's first stop on line 14 never reported 2.6 s after the launch
program still running at 82 s (output stops at child start) ends with exit 0 at 3.1 s, after three stops

Two defects, one after the other:

  1. js-debug sends nothing back for a request it does not know, and it has no setFunctionBreakpoints (measured with a bare DAP driver: no response before or after the attach, Unknown request on its stderr). The program's own target never sees that request (MinimalDapClient serves it from the CDP bridge). A fork's connection has no bridge and was sent it raw, during the adoption and for a set_breakpoint {function} on a child id, and waited out the client's 30 s.
  2. The clean-up released nothing. The fork's attach request had itself timed out by then; the handshake went on to configurationDone anyway, js-debug bound the target to that connection and let the fork run, and the worker closed the socket and started a throwaway attach for a target that was no longer pending. The fork ran to its inherited line breakpoint and stayed there.

What changes

  • A js-debug fork is never sent setFunctionBreakpoints. An adapter that arms function breakpoints through the CDP bridge arms them in the session's own program only. A child's are answered where they are asked: at adoption a function_breakpoints_synced status reports each one unverified with "Function breakpoints are not armed in a child session…", and afterwards ChildConnections.unarmedFunctionBreakpoints answers the request from DapProxyWorker.forwardToChild. Python is unchanged: debugpy has the request.
  • A failed attach ends the handshake where it is. Every step after the attach is raced against the attach's failure, and the failure is also checked right before configurationDone is sent (a race alone lets a step that has already settled win). So the target is still pending when the throwaway attach asks for it.
  • A failure after configurationDone first tries a disconnect on the child's own connection, the one js-debug binds it to; when nothing acknowledges that, the throwaway attach follows as before. Only for the adoption's own failures under the throwaway lever: a handshake cancelled by close() keeps its path, and debugpy keeps refusing the held request.

Arming function breakpoints in forks is not part of this: it needs the per-target bridge in a fork, and something to hold the fork until a module-scoped name can resolve.

Not done here

Tests

  • tests/proxy/child-connections.test.ts: fifteen cases under "issue javascript (session tree): with a function breakpoint set, a program that forks hangs: the fork's adoption waits 30 s on a setFunctionBreakpoints js-debug never answers, fails, and leaves the fork paused under a closed connection #1219" (no request to a js-debug child, and each function breakpoint reported as not armed; the later request answered by the worker; debugpy still gets the request, and a debugpy attach refused after configurationDone still refuses the held request; a failed attach never reaches configurationDone, also when it fails inside the last step; a failure after configurationDone disconnects on the child's connection, counts as a release in flight, and falls back to the throwaway when unacknowledged; close() during such a handshake keeps its own path).
  • tests/proxy/dap-proxy-worker-child-sessions.test.ts: the worker answers a fork's setFunctionBreakpoints and sends it to neither connection.
  • tests/adapters/javascript/integration/javascript-subprocess-tree.test.ts: a real fork with a function breakpoint on the parent is adopted, stops on its line breakpoint, lists the function breakpoint as not armed, answers a second one the same way, and the tree ends with exit 0. On main the same steps are the first column above (run by hand, not as this test).

Review

Two independent reviews, each with a mutation pass, neither finding a critical defect.

  • The first (31 mutants on the first commit) found the main fix sound and asked for what the second commit does: the two branch guards had no test (the lever check that keeps debugpy on its path, the check that leaves close() alone), the race was not a gate, "sent" is not "bound" (hence the throwaway fallback), and the docs said a child is re-sent function breakpoints.
  • The second (12 mutants on the second commit only) found the delta correct and two things unpinned: the wait on the fallback throwaway, and the place of the attach check. The third commit pins both.

Every mutant either review reported as surviving and meaningful is now killed.

Gates

typecheck:all, lint, check-docs, changelog:check. The pre-push run on the pushed commit: unit 434 files, 9575 passed and 7 skipped; integration 47 files, 244 passed and 1 skipped (the JavaScript and Python tree, cascade and attach suites among them).

🤖 Generated with Claude Code

cynarlab and others added 3 commits November 22, 2026 14:19
…at forks (#1219)

With any function breakpoint set, a JavaScript program that forks was
never given its child session: the row said running for 30 s and then
disappeared, the answers said the child had been released to run
undebugged, and the program never ended. The fork was stopped on the
line breakpoint it had inherited, with no session to resume it.

Two defects, one after the other:

- js-debug has no setFunctionBreakpoints and sends nothing back for a
  request it does not know. The fork's connection was sent that request
  raw, during the adoption and for a set_breakpoint {function} on a
  child id. An adapter that arms function breakpoints through the CDP
  bridge arms them in the session's own program only, so a child's are
  now answered where they are asked: unverified, with a sentence, and
  nothing is sent. debugpy has the request; Python children keep it.

- The clean-up after the failed adoption released nothing: the handshake
  had gone on to configurationDone after its attach had already failed,
  so js-debug bound the target to a connection the worker then closed,
  and the throwaway attach asked for a target that was no longer
  pending. Every handshake step after the attach is now raced against
  the attach's failure, so a failed attach ends the handshake while the
  target is still pending. A failure after configurationDone lets the
  child go with a disconnect on its own connection.

Measured on Windows, Node 24.14.1, js-debug v1.140.0, with the tree
fixtures (parent.js, child.js:14, one function breakpoint): before, the
fork was still not adopted and the program still running at 82 s; after,
the fork stops on line 14 at 2.6 s and the program ends with exit 0.

Tests: five unit cases in child-connections.test.ts and one in
dap-proxy-worker-child-sessions.test.ts, each red on main's sources, and
one real-adapter case in javascript-subprocess-tree.test.ts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…onDone, a fallback for an unacknowledged disconnect, and the guards under test

The independent review found no critical defect and these:

- The race against the attach failure is not a gate: a step that had
  already settled wins over a failure queued beside it. The failure is now
  also recorded synchronously and checked before configurationDone goes out.
- "configurationDone sent" is not "configurationDone processed". When the
  disconnect on the child's own connection is not acknowledged (the socket
  is gone, or the adapter never read configurationDone and the target is
  still pending), the throwaway attach now follows, so this path releases
  whatever the old one could.
- The disconnect is best effort and the comments now say so: read from the
  upstream sources, js-debug does not resume a reported target it has not
  started yet when a disconnect reaches it first.
- Two guards had no test (the lever check that keeps debugpy on its own
  path, and the check that leaves a handshake cancelled by close() alone),
  nor had the release bookkeeping of the new path. Eight cases added; every
  surviving mutant the review named is now killed.
- session-tree.md said a child is re-sent the function breakpoints.

Not done here, filed as #1221: the session layer still words a failed
adoption as a release without the adapter's acknowledgement.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…f the attach check (#1219)

The second, narrow review of the #1219 fix found the change correct and two
things nothing held in place: the worker must stay live until the fallback
throwaway has detached (dropping the await passed every test), and the
attach check must sit right before configurationDone (moved ahead of the
steps, it passed too). One case each; both mutants are now killed. Two
comments say "bound" where they said "read".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.61017% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/proxy/child-connections.ts 96.29% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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