Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1150-session-tree-truth-and-turns.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`start_debugging` and `restart_debugging` now report an already-paused child session directly via `pausedChild` (including its `sessionId`, `location`, `context`, and stop `snapshot`) instead of claiming no breakpoint was reached yet, while keeping tree-wide breakpoint binding, child-debugging opt-out notes, and grandchild release counts truthful across the session tree (#1150).
1 change: 1 addition & 0 deletions changelog.d/1221-child-release-confirmation.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Failed child-session adoptions now count in `childrenReleased` and state that the child runs undebugged only when the debug adapter confirms the fallback release; unconfirmed releases are disclosed separately without claiming the child continues running (#1221).
1 change: 1 addition & 0 deletions changelog.d/1252-js-outer-block-locals.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
JavaScript stop snapshots and `get_local_variables` no longer merge outer lexical `Block` scopes listed after a function's `Local` scope when the function has locals of its own, preventing Vite/Vitest module-wrapper declarations from crowding out method locals (#1252).
35 changes: 26 additions & 9 deletions docs/architecture/session-tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,14 @@ exists). The agent then uses `sessionId` for inspection, stepping and continuing
([#849](https://github.com/debugmcp/mcp-debugger/issues/849)) is unchanged.
- Every answer on a session that has children carries `children: [{ sessionId, name, state, parentSessionId }]`,
the paused and the `pending: true` answers included, so a caller always sees what else is live or
paused and what to wait on next. The `start_debugging` answer carries the same list when a child
was adopted during the launch hold.
paused and what to wait on next. The `start_debugging` and `restart_debugging` answers carry the
same list when a child was adopted during the launch hold — and when an adopted child is already
genuinely `paused` while the launched root is `running`, they end the hold after a short settle
grace, name that paused child directly in `message` instead of claiming no breakpoint was reached
yet, and include `pausedChild: { sessionId, name, state: "paused", reason, location?, threadId?,
context?, note?, snapshot? }` so the agent can inspect, step, or continue the child immediately
without spending an extra `wait_for_stop` turn (issue #1150; `pausedChild` is never set when a
child is in `error` or `stopped`).
- A `wait_for_stop` on a child answers for that child and its own descendants only.

This was decided over the per-session alternative (each wait answers only its own stops): that
Expand Down Expand Up @@ -313,14 +319,19 @@ Two bounds keep that sane:
- A per-tree cap on live child sessions (`DEBUG_MCP_MAX_CHILD_SESSIONS`, default 32; `0` disables
child-session adoption). It excludes js-debug's mandatory first target, which implements the
root session and must still be adopted for launch to complete. Beyond the cap the release lever
runs (the child runs undebugged) and the parent's next answer says so (`childrenReleased: n`).
The count is never left unexplained (issue #1137): the cause of each release is recorded with it
(`releasedChildCauses`: child sessions off, the cap, a proxy that cannot host children, a failed
adoption), and every launch, restart and wait answer that carries the number ends its message
with one sentence built from the same record (`describeReleasedChildren`,
runs (the child runs undebugged) and the parent's and every ancestor's next answer says so
(`childrenReleased: n`, subtree-scoped so grandchild releases count on the root as well as on the
child, issue #1150). The count is never left unexplained (issue #1137): the cause of each
confirmed release is recorded with it (`releasedChildCauses`: child sessions off, the cap, a
proxy that cannot host children, a failed adoption whose fallback release the adapter confirmed),
and every launch, restart and wait answer that carries the number ends its message with one
sentence built from the same record (`describeReleasedChildren`,
`src/session/execution/tree-settle.ts`): how many, that they run undebugged, why — naming
`DEBUG_MCP_MAX_CHILD_SESSIONS` when it decided — and that a breakpoint only such a child reaches
will not hit.
will not hit. When a failed adoption's fallback release is **not** confirmed by the debug adapter
(issue #1221), it is not counted in `childrenReleased` and not called "released to run
undebugged"; `describeReleasedChildren` discloses that the child could not be adopted and whether
it continued running is not known.
- Ended children stay listed until closed, as above, and leave with their parent.

## Every adapter, surveyed
Expand Down Expand Up @@ -487,7 +498,13 @@ A child is a session of its own, and what is read about it is read where it is t
debugger on clears the run's decision; a child reads that decision as its root does (while
the proof by a verified breakpoint stays each session's own, so for a moment the two can
answer differently); and a child's exception arming is the live one, where it was a copy
taken at adoption. One thing does not follow: the notes of the root's launch are seeded into
taken at adoption. In addition (issue #1150), `Run` records `treeVerifiedBreakpointIds` whenever
any session in the tree verifies or hits a breakpoint (so the root's end summary marks child-bound
breakpoints `verified: true` in `unhitBreakpoints` and never warns that they "never bound during
this run"), and `childDebuggingOptedOut` when the launch/attach explicitly turned child adoption
off (`subProcess: false` on Python launch, `autoAttachChildProcesses: false` on JavaScript
launch/attach) so end summaries and unbound warnings qualify that child processes ran undebugged.
One thing does not follow: the notes of the root's launch are seeded into
the root's output only. The record is mutated in place and not replaced per run, so a child
row that outlives its run reads what its root reads; the readers that are new to children
are gated on a live state.
Expand Down
4 changes: 2 additions & 2 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ Two things are outside the hold. A `stopOnEntry` launch is answered at its entry

A breakpoint set, removed or cleared while a launch is still starting is delivered to the adapter as soon as the program is launched (issue #851).

**Sessions with children** (the session tree, issues #1081 and #1082): when a child session was adopted during the hold (a Python launch — debugpy's sub-process debugging is on by default; `dapLaunchArgs: { subProcess: false }` opts the launch out — where debugpy reports each process the program starts; a JavaScript launch — js-debug's `autoAttachChildProcesses` is on by default; `dapLaunchArgs: { autoAttachChildProcesses: false }` opts the launch out — where js-debug reports each Node process it forks), the answer carries `children: [{ sessionId, name, state, parentSessionId }]` — every descendant, depth first in adoption order, each with its state and the session that spawned it. `childrenReleased: n` says how many children reported this run were released to run undebugged (beyond `DEBUG_MCP_MAX_CHILD_SESSIONS`, or an adoption that failed) — and the `message` of the same answer says what that means and why (issue #1137), e.g. "1 child process was released to run undebugged (child sessions are off: DEBUG_MCP_MAX_CHILD_SESSIONS=0): a breakpoint only it reaches will not hit.", so a pending answer's "has not reached 1 breakpoint(s) yet" is not read as a promise for a breakpoint only the released child could reach — and `childrenClosed: n` that the start tore down a previous live run and closed its children with it. All three sit at the top level beside `pending` and in `data`, and are absent when there is nothing to say, so a session with no children answers as before. The launch answer is about the launched session itself; a child's stop is collected by [`wait_for_stop`](#wait_for_stop), which answers with `sessionId` naming the child.
**Sessions with children** (the session tree, issues #1081, #1082, #1150 and #1221): when a child session was adopted during the hold (a Python launch — debugpy's sub-process debugging is on by default; `dapLaunchArgs: { subProcess: false }` opts the launch out — where debugpy reports each process the program starts; a JavaScript launch — js-debug's `autoAttachChildProcesses` is on by default; `dapLaunchArgs: { autoAttachChildProcesses: false }` opts the launch out — where js-debug reports each Node process it forks), the answer carries `children: [{ sessionId, name, state, parentSessionId }]` — every descendant, depth first in adoption order, each with its state and the session that spawned it. When an adopted child is already genuinely `paused` while the launched root is `running`, the hold ends after a short settle grace (~50 ms), `message` names the paused child session directly instead of saying no breakpoint was reached yet, and `pausedChild: { sessionId, name, state: "paused", reason, location?, threadId?, context?, note?, snapshot? }` delivers that child's stop landing and bounded snapshot in the same call so you can inspect, step, or continue `pausedChild.sessionId` immediately without spending an extra `wait_for_stop` turn (`pausedChild` is never set for a child in `error` or `stopped`). `childrenReleased: n` says how many children reported anywhere in this session's subtree this run were confirmed released to run undebugged (beyond `DEBUG_MCP_MAX_CHILD_SESSIONS`, or a failed adoption whose fallback release the debug adapter confirmed) — and the `message` of the same answer says what that means and why (issue #1137), e.g. "1 child process was released to run undebugged (child sessions are off: DEBUG_MCP_MAX_CHILD_SESSIONS=0): a breakpoint only it reaches will not hit."; when a failed adoption's fallback release was not confirmed by the adapter (issue #1221), it is not counted in `childrenReleased` and `message` states that whether the child continued running is not known — and `childrenClosed: n` says that the start tore down a previous run and closed its children with it. `children`, `pausedChild`, `childrenReleased` and `childrenClosed` sit at the top level beside `pending` and in `data` (`pausedChild.snapshot` is omitted from `data.pausedChild` just like a root `snapshot`), and are absent when there is nothing to say, so a session with no children answers as before.

**JavaScript launch configuration:** Both launch option objects accept js-debug settings;
`adapterLaunchConfig` wins when a key appears in both. The effective `stopOnEntry` value controls
Expand Down Expand Up @@ -587,7 +587,7 @@ See the [JavaScript configuration guide](javascript/README.md#custom-configurati
- The sentence distinguishes a clean run (`ran to completion (exit code 0)`), a non-zero exit (`exited with code N`) and a debuggee that reported no code at all (`ended without reporting an exit code` — attach targets, signal-killed debuggees, adapters that send no `exited` event and state the code nowhere else).
- `data.exitCode` is present only when the debuggee reported one. `data.unhitBreakpoints` lists every line breakpoint the program ran past (`file`, `line` as bound, `requestedLine` when the adapter moved it, `verified`); logpoints the adapter supports are left out, since they log and run on. Verified line and function breakpoints that were never hit are named in the sentence; breakpoints that never bound keep their #467 `warning`.
- When a stop and the exit arrived in the same tick (a breakpoint hit as the program ended), the breakpoints were not all missed: the list is withheld and the sentence names the stop (`after a stop the launch could not report (last stop: breakpoint)`), which `list_debug_sessions` also shows as `lastStop`.
- The same holds for the session's tree (issue #1128): when a child session stopped during the run, the parent can no longer say which breakpoints were missed — each child has its own copy of the breakpoints and its own stops. The list is withheld and the sentence counts the tree's stops instead, every stop the agent could see on a child, whatever its reason (`The program ran to completion (exit code 0). Its child sessions stopped 2 times during this run.`), whether or not the child is still listed. What remains root-only: when children were adopted but none stopped, `unhitBreakpoints[].verified` is the launched process's own flag, so a breakpoint that bound only in a child reads `verified: false` there.
- The same holds for the session's tree (issues #1128, #1150): when a child session stopped during the run, the parent can no longer say which breakpoints were missed — each child has its own copy of the breakpoints and its own stops. The list is withheld and the sentence counts the tree's stops instead, every stop the agent could see on a child, whatever its reason (`The program ran to completion (exit code 0). Its child sessions stopped 2 times during this run.`), whether or not the child is still listed. When children were adopted and none stopped, `unhitBreakpoints[].verified` (and the unbound-at-exit `warning`) reflects whether the breakpoint bound in **any** session of the tree, so a breakpoint that bound only in an adopted child reads `verified: true` and never triggers a false unbound warning; and when child-process debugging was explicitly turned off (`subProcess: false` on a Python launch or `autoAttachChildProcesses: false` on JavaScript), the end summary and any unbound warning qualify that child processes ran undebugged.
- `restart_debugging` returns the same fields for a relaunch that ends the same way.

**Exit code:** when the debuggee terminates, the exit code reported by the adapter is surfaced as `exitCode` in `list_debug_sessions` (and, for a launch that ended before reporting a pause, as `data.exitCode` above), so a crash (non-zero) is distinguishable from a clean exit. Adapters that never send `exited` still get one where the debugger states the code some other way: js-debug through the launch shim's recorded code (#247), rdbg through the adapter process's own exit status (#258), Delve before 1.27 through its `Process N has exited with status S` console line (#753 — in debug mode Delve prints it only in reply to `disconnect`, so the proxy sends the disconnect before forwarding `terminated`; Delve 1.27+ sends `exited` itself). No line, no code: nothing is guessed.
Expand Down
13 changes: 11 additions & 2 deletions packages/shared/src/interfaces/adapter-policy-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,17 @@ export const JsDebugAdapterPolicy = {
collectedRefs.push(scope.variablesReference);
};

const firstLocalIndex = frameScopes.findIndex(isLocalScope);
const localScopes = frameScopes.filter(isLocalScope);
for (const scope of frameScopes.filter(isLocalLikeScope)) {
// V8 lists inner lexical Block scopes ahead of Local, and enclosing outer
// lexical Block scopes — such as Vite SSR's module wrapper — after Local
// (issue #1252). When Local exists on the frame, only Block scopes inside
// the function (index < firstLocalIndex) belong to the primary merge; outer
// Block scopes join the empty-Local fallback below alongside Closure.
const innerLocalLikeScopes = firstLocalIndex === -1
? frameScopes.filter(isLocalLikeScope)
: frameScopes.filter((scope, index) => isLocalScope(scope) || (index < firstLocalIndex && isBlockScope(scope)));
for (const scope of innerLocalLikeScopes) {
collect(scope);
}
// ESM top-level: js-debug gives a `for (let i...)` or `catch (e)` at module
Expand Down Expand Up @@ -754,7 +763,7 @@ export const JsDebugAdapterPolicy = {
// the same frame; try those in usefulness order before the session layer
// walks down to a caller.
const fallbackGroups: Array<(scope: DebugProtocol.Scope) => boolean> = [
isClosureScope,
(scope) => isClosureScope(scope) || isBlockScope(scope),
isModuleScope
];
for (const matches of fallbackGroups) {
Expand Down
Loading
Loading