Repository navigation
fix(javascript): a fork's logpoints go to the fork's session, never its stdout; get_output lists the tree (#1212) - #1230
Open
debugmcpdev wants to merge 10 commits into
Open
debugmcpdev wants to merge 10 commits into
debugmcpdev wants to merge 10 commits into
Conversation
…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>
…ices (#1212) js-debug hands out one raw CDP socket per target. The program's own target got two things of the proxy's on it, composed inside ChildSessionManager: the bridge (the logpoint binding, function breakpoints) and the proxy's stepper, which listens on the socket the bridge opens. A forked target got a socket for its stepper alone, composed a second time inside ChildConnections. JsTargetServices is that composition, once. This commit moves the program's own target onto it and changes nothing else: ChildSessionManager keeps its two fields, now read off the composition, and its suites pass untouched. The fork connections follow in the next commit. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…hannel, never its stdout (#1212) mcp-debugger compiles a JavaScript logpoint into a breakpoint condition that hands the message to a CDP binding, and only the program's own target had the binding. In a forked process the condition fell back to console.log. With the fork's stdio piped, the text went down the pipe its parent reads: measured, a parent that parses that pipe reported a corrupted protocol and exited 3 instead of 0, and no session showed the lines. - Every fork connection gets JsTargetServices: its own CDP socket with the logpoint binding and the proxy's stepper on it. What the binding delivers leaves as the fork's own output event. - The socket is asked for the moment the fork's configurationDone is answered, not after the attach: js-debug answers requestCDPProxy from then on and lets the fork run about 20 ms later. The binding now goes out with the subscription, before either is answered. - The compiled logpoint no longer prints. A hit while the binding is absent is kept in the process (1000 messages; the rest are counted) and delivered in order by the next hit, or by one evaluation the bridge sends right after Runtime.addBinding. No stop, hold or resume is added anywhere. - A fork's terminated and closed status wait for one round trip on its CDP socket (bridge.settle(), at most 500 ms): its last lines were measured to arrive about 1 ms after the adapter's terminated, and the parent takes a child's output until its end. Through the server, a fork that hits two logpoints and exits at once: 12 of 12 runs with the wait, 0 of 12 without. - A target whose socket cannot be opened, or whose binding is refused, says once in its output that its logpoints are not delivered. That also replaces the program target's silent fall-back to console.log. - detach() during an attach that is still opening its socket leaves none behind (a fork that ends at once). Function breakpoints stay unarmed in a fork (#1219): nothing syncs them onto the fork's socket. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…sts the tree (#1212) A logpoint's line is on the session of the process that hit it: debugpy already delivered a child's on the child's connection only, and js-debug forks now do the same. A caller that reads only the launch session could not tell that another session held lines. - get_output on a session with descendants carries `children`, the list the launch, restart and wait answers carry (SessionManagerCore.treeChildrenOf). A session with no tree answers as before. - A JavaScript child's note no longer reads as "nothing here, read the launch session": it says its stdout and stderr are on the launch session, and that its own entries are the lines of the logpoints it hit, and notices. The output resource's pointer line is reworded the same way. - The get_output description says where a logpoint's lines are read. - Tree suite: the logpoint case reads the fork's session through the launch session's `children`; a new case forks a child whose stdout the parent parses (fixtures parent_piped.js, child_piped.js) and asserts the protocol is intact, exit 0, and the four lines are on the fork's session in order. - Docs, the fork spike notes (the measurements), CLAUDE.md, changelog. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…sent; bound and clear what a process keeps (#1212) Four things an advisor read of the previous commits turned up. - The "logpoints are not delivered" line fired for any target whose CDP socket did not open, a fork that ends before its socket is up among them: a warning about nothing. The bridge is now told when its target is sent a logpoint (JsTargetServices.noteBreakpoints, from the adoption's breakpoints, a later setBreakpoints on a child, and the program target's own sends) and says the line when both hold, in whichever order. - settle() waited up to its timeout for an attach in flight and then up to its timeout again for the round trip. One deadline now covers both, so "at most 500 ms" is true. - What a process keeps while the binding is absent is bounded in characters as well as in count (1,000,000 and 1000), sits on globals that are not enumerable (a test runner's global-leak check does not see them), and is deleted when the debugger lets go of the process, beside removeBinding. - The barrier's comment and the docs said its answer follows everything the target sent. It follows what js-debug's proxy had relayed when it took the request; that the proxy has relayed everything by the time the adapter reports the target's end is what the 12 of 12 against 0 of 12 measurement shows, not something a protocol promises. Worded that way. Also measured, for the program's own target (an ES module that hits two logpoints and exits at once, 12 runs each): its end loses nothing before or after; its first statement's logpoint went out through the program's stdout in 12 of 12 runs on main and is delivered on the debugger's channel in 12 of 12 now. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An independent review with a mutation pass (45 mutants) found no critical defect and one important one. - An attach that failed after the binding went in rolled its socket back and left the binding in the process: it lives on the adapter's own session with the target, so every later hit called it, queued nothing and reached nobody, in silence, and a test pinned that silence as "delivered". The rollback now takes the binding out again (bounded) before the socket goes, so later hits are kept like any target's without a channel, and the session is told. When the binding cannot be taken out the process has ended, which is what failed the attach: measured, a fork that logs twice and exits at once fails Debugger.enable with "Connection is closed" after both lines arrived. That case says nothing; the first version of this fix warned there, in 12 of 12 runs, about lines that had been delivered. - The compiled logpoint cannot throw out of its condition any more. js-debug reports a throwing condition through the program's console.error and can be set to pause on one. A frozen global object or a shadowed globalThis now costs the kept message and nothing else, and with the binding in the message is delivered whatever the queue did. - A link of a held end that throws no longer takes the later links with it (the last one removes the connection, and a root's worker waits for that). - Wording: the warning says the channel "is not available" (it also covers a refused binding); the docs no longer say the kept messages are always deleted (only for a process the debugger has a socket to) or always counted (only when the binding goes in); two stale comments. Tests for the review's surviving mutants: a drain by a hit gives the character budget back, a flush that lost nothing says nothing, the warning state resets when the channel comes up, a detach during connect stays silent for a target that holds a logpoint, settle's default bound, and the program target's logpoint note in ChildSessionManager. Docs: the Linux measurements (Ubuntu 24.04, Node 22 and 24: the same results as Windows) and what the barrier's round trip does not cover. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…Binding leaves it in (#1212) The previous commit's rollback, its comment, its message and the README all assumed that Runtime.removeBinding removes the binding's function, so that a later hit would be kept in the process again. It does not. Measured on Node 24.14.1, straight to the inspector: after removeBinding, typeof of the binding is still 'function', a call does not throw, and the function is there for the next socket too. The method only ends the notifications. A compiled logpoint decides by that typeof, so after a rollback every later hit was neither delivered nor kept. - JS_LOGPOINT_UNBIND deletes the function from the global object and answers whether it is gone. The rollback evaluates it (bounded) and tells the session only when the answer is yes: a process that has ended cannot answer, and one whose global cannot be changed keeps the function, where "kept" would be untrue. - JS_LOGPOINT_CLEAR, evaluated when the debugger lets go of a process, takes the function out too. - A process that is released to run on is cleaned BEFORE the adapter's disconnect. Measured through the server with a long-lived process that reports on itself: the clear that detach() sends arrives nowhere after a detach from an attached process, because the adapter has closed the target's CDP socket by then, and the process kept the function (as it does on main, where removeBinding was the only attempt). MinimalDapClient now awaits ChildSessionManager.beforeRelease() ahead of a disconnect with terminateDebuggee false, and ChildConnections.close() awaits the same for a child that runs on. After a detach, and after closing a fork's session, the process has neither the function nor a queue. Docs and the changelog say what was measured instead of what was assumed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…#1212) A second independent review, of the two commits after the first one, with a mutation pass (19 mutants). Nothing critical. - The rollback told a process that had ended apart from every other outcome by "the function is confirmed gone", and so stayed silent for a live process whose main thread was blocked for longer than the unbind's bound: its logpoints were then lost without a word. The one case that says nothing is now exactly the one it was meant to be. An error answer or a closed socket is a process that has ended; an answer of any kind, or no answer in time (CdpCallTimeoutError, new, so a timeout is not told apart by its text), is a process that is still there, and it is told. - The awaited release added to ChildConnections.close() is gone. It repeated the clear that letting go of the services already sends before the disconnect (measured: it lands, the fork is left with neither the function nor a queue), and the await sat after the connection had stopped counting as live, where the worker's shutdown could overtake the disconnect. - The root's release is bounded at 250 ms instead of 500: it runs inside the disconnect's own deadline on the close path. - Tests for what the mutants showed untested: the root's release path through ChildSessionManager and JsTargetServices, a held end whose message cannot be sent, the unbind's answer for a function that cannot be removed. Measured and written down, with its follow-up filed as #1233: the logpoints stay set until the adapter itself has detached, a few milliseconds after the clean-up, and one that hits in between is kept and never read. A logpoint hit about a hundred times a second left one or two messages at each of six detaches; an idle one leaves none. The changelog also no longer says a fork used to keep the function (on main a fork never had it). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1212 (the logpoint half and the note; the console-output half is now #1225).
Built on #1224 (the branch starts at its tip; the first three commits listed here are that PR's until it merges).
What was wrong
mcp-debugger compiles a JavaScript logpoint into a breakpoint condition that hands the message to a CDP binding. Only the program's own target had the binding. In a forked process the condition fell back to
console.log, which writes to the fork's stdout: the program's own, and often a pipe its parent reads.Measured (Windows 11, Node 24.14.1, js-debug v1.140.0), a parent that forks a child with
silent: trueand parses its stdout as one JSON object per line, two logpoints in the child:LOGPOINT first statement,LOGPOINT tick n=0..2protocol corrupted: […], exit 3protocol ok 3, exit 0get_outputon the launch sessionchildrenlists the forkget_outputon the fork's sessionentries: [], "this process's output is on its launch session's buffer" (untrue: its stdout is the pipe)A logpoint changed the program's behaviour and exit code, and showed its lines nowhere.
What changes
One mechanism for every target.
JsTargetServices(src/proxy/js-target-services.ts) is the composition the program's own target already had insideChildSessionManager: the target's CDP socket, the bridge on it (the logpoint binding, function breakpoints) and the proxy's stepper listening on the same socket.ChildSessionManagernow builds that class (first commit, no behaviour change, its suites untouched) and so does every fork connection inChildConnections, which until now opened a socket for the stepper alone.A logpoint never prints, and nothing pauses for one.
configurationDoneis answered, not after the attach. js-debug answersrequestCDPProxyfrom then on and lets the fork run about 20 ms later; the binding now goes out with the subscription, before either is answered. Measured with a bare DAP driver: the fork's first statement goes through the binding in 24 of 24 warm runs, also with every core busy.Runtime.addBinding. Theconsole.logfall-back is gone.__mcpDebuggerLogpointin it (CDP'sRuntime.removeBindingonly ends the notifications:typeofstays'function'). Here the function and anything that was kept are taken out before the adapter is told to disconnect, and the process reports neither. The same holds after closing a fork's session. One measured exception: the logpoints stay set until the adapter itself has detached, a few milliseconds later, and one that hits in between is kept and never read. A logpoint hit about a hundred times a second left one or two messages at each of six detaches; an idle one leaves none. Removing the logpoints from the adapter before the clean-up would close that window: javascript: a logpoint hit between the release clean-up and the adapter's detach leaves a kept message in the process #1233.A fork's end waits for its last lines. They come on the CDP socket and were measured to arrive about 1 ms after the adapter's
terminatedon the DAP socket.ChildConnectionsholds a fork'sterminatedand its closed status behind one round trip on the CDP socket (bridge.settle(), one deadline of 500 ms; the method is one of js-debug's own proxy domain, which the proxy answers itself with an error at once, so the target is asked nothing). The answer follows what the proxy had relayed when it took the request. That the proxy has relayed everything by the time the adapter reports a target's end is not promised by any protocol: the table is the evidence. Through the server, a fork that hits two logpoints and exits at once:The lines are read where the process is, and the launch session says so (the ruling on 2026-11-22: the child's own buffer;
get_outputon a session with children lists them).get_outputon a session with descendants carrieschildren, the list the launch, restart andwait_for_stopanswers carry. A session with no tree answers exactly as before.noteused to say that its output is on the launch session's buffer, which is false for a child whose stdio is a pipe. It now says: what the process writes to inherited stdio is on the launch session, what it writes to a pipe is read by its parent process only, and its own entries are the lines of the logpoints it hit, and notices. The output resource's pointer line is reworded the same way.get_outputdescription gains one sentence (hence the 24 tool-list snapshot files, one line each).What an agent sees differently
stdoutentries glued to program output ("LOGPOINT tick n=0\n{\"n\":1}"). They are nowconsoleentries on the fork's session. The launch session's answer lists the fork.worker_threadsworker is a target of its own and went the same way: its logpoint lines moved from the process's stdout to the worker's session (measured).console.logsilently. They are now not delivered, and the session's output says so once ([mcp-debugger] Warning: logpoints that hit in this process are not delivered…). The line is said only for a process that was sent a logpoint, so a fork that ends before its socket is up says nothing about a channel it never needed.stdoutentry on main (theconsole.logfall-back: the binding was not in yet) in 12 of 12, and as aconsoleentry (the debugger's channel) in 12 of 12 here. Its end loses nothing before or after.What is still lost
The lines of a process whose CDP socket never opens (it is told, as above). In the bare-driver measurement that was only the driver's own cold first WebSocket; through the server it did not happen in the 12 exits-at-once runs. Closing this for good needs js-debug to hold a child target until the client is ready, which is an upstream change.
Where this departs from the plan
The plan said one mechanism for the program's target and for forks, with
ChildConnections(which Python shares) losing its JavaScript-specific code behind a neutral per-connection hook. What is unified: the composition itself (socket, bridge, binding, flush, stepper,settle, the logpoint notice) is one class, and both callers build it. What is not:ChildConnectionsstill buildsJsTargetServicesitself, from the policy's two flags, as it built the stepper before. No hook was introduced: with one adapter that has such services it would have been an interface with one implementation.ChildSessionManagerhas its event chain (entry stops and function-breakpoint stops are relabelled there);ChildConnectionshasinOrderand the held end. The hold is inChildConnectionsonly: measured, the program's own target loses nothing at its end.ChildSessionManagerstill calls the bridge'sattachToChilddirectly, inside its own guards, notservices.attach.Not done here
Tests
tests/unit/shared/js-logpoint.test.ts: the compiled condition never namesconsoleand never throws; kept messages are delivered first and in order; the bounds in count and characters; the globals are not enumerable; the flush and clear expressions.tests/proxy/cdp-function-breakpoint-bridge.test.ts: the binding sent before the subscription is answered; one flush right after the binding; the sentence when messages did not fit; the not-delivered sentence (once; only for a target that was sent a logpoint, in either order; again after the channel had been up; not when the process ended); the rollback taking the binding out;detach()during an attach leaves no socket and clears what was kept;settle()(one round trip that asks the target nothing, an error answers it, resolves only on the answer, no socket, an attach in flight, one deadline, the default bound).tests/proxy/child-connections.test.ts: the socket is asked for before the attach is answered; a logpoint is the child's ownoutput; the end is held behind the last lines and leaves in order (output,terminated,exited, closed status); a fork that ends while its socket is opening;close()does not wait; a debugpy child is untouched; a failed adoption closes the socket.tests/core/unit/server/*,tests/core/unit/session/session-manager-child-sessions.test.ts:childrenonget_output, the note, the resource line,treeChildrenOf.tests/adapters/javascript/integration/javascript-subprocess-tree.test.ts: the logpoint case reads the fork's session through the launch session'schildren; a new case with the strict-parsing parent (fixturesparent_piped.js,child_piped.js).Review
An advisor read of the first three commits, then one independent review with a mutation pass (45 mutants, 36 killed) of the first four. Neither found a critical defect.
settle(), the kept messages bounded in characters, hidden from enumeration and cleared at detach, and the barrier's claim worded as what it is. It also asked for the program's own target and Linux to be measured; both are above.console.errorand can be set to pause on one); a held end's chain survives a link that throws; the docs' over-claims about what is deleted and counted; two stale comments.Runtime.removeBindingto take the binding out so that later hits would be kept. Measured against Node's inspector, it leaves the function in place, so those hits were neither delivered nor kept. The rollback now deletes the function and tells the session only when the process confirms it is gone. The same measurement showed that the clean-up sent at detach arrived nowhere for an attached root (the adapter had already closed the target's socket), which is what the release-before-disconnect above fixes. A second independent review covered the fifth and sixth commits (19 mutants) and found nothing critical. Its points are answered in the seventh: the rollback stayed silent for a live process that was only slow to answer (it now tells every process that is still there, and stays silent only for one that has ended); an awaited release I had added to closing a fork repeated what letting go of its services already sends and could let the worker's shutdown overtake the disconnect, so it is gone; and tests for the release path, which had none that failed without it. The seventh commit itself has not been reviewed.left <= 0against< 0insettle(), and the held end ignoringconnection.closed, where a closed connection'ssettle()resolves at once).Gates
typecheck:all,lint,check-docs,changelog:check. The pre-push run on the pushed commit (Windows 11, Node 24.14.1): unit 434 files, 9628 passed and 7 skipped; integration 47 files, 245 passed and 1 skipped. One earlier push of this branch hit the known flake #1119 (the cap-0 tree case, the program exiting 0xC0000005); the same file then passed three times in a row, and the sighting is on that issue. The JavaScript e2e files on the final build (logpoints, smoke, function breakpoints, attach), which CI does not run on a PR: 4 files, 50 passed. On the Linux box (Ubuntu 24.04, 2 vCPU), the sixth commit under Node 22.23.2 and 24.14.1 (the seventh was measured on Windows only): the tree suite 9 of 9 each, the live rows in the table above, and the two measurements behind the sixth commit (Runtime.removeBindingleaves the function in the process on both Node versions; after a detach and after closing a fork's session the process has neither the function nor a queue).🤖 Generated with Claude Code