Skip to content

fix: Vite SSR bindings out of JavaScript locals (#1215); attach verification keeps its window and its hint (#1213) - #1228

Open
debugmcpdev wants to merge 3 commits into
mainfrom
fix/riders-1215-1213
Open

debugmcpdev wants to merge 3 commits into
mainfrom
fix/riders-1215-1213

Conversation

@debugmcpdev

@debugmcpdev debugmcpdev commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1215 and #1213. Two small fixes from the same self-debugging run, independent of the session-tree PRs: one commit for #1215, two for #1213 (the fix, then the answers to its review).

#1215: Vite's module bindings filled the locals of a stop under vitest

Vite's SSR runner, which vitest runs every module through, binds each import of a module as __vite_ssr_import_<n>__ (beside __vite_ssr_exports__, __vite_ssr_import_meta__ and others) in the scope the module's functions close over. At a stop under vitest they took the stop snapshot's slots before the function's own variables and padded get_local_variables.

JsDebugAdapterPolicy.extractLocalVariables now leaves out names with the __vite_ssr_ prefix unless includeSpecial is set, the way the .NET policy leaves out compiler-generated names. A scope that held nothing else supplies nothing, so it is not listed as a contributing scope.

Measured with a real vitest run (vitest run tests/core/unit/session/tree-settle.test.ts, a breakpoint in src/session/execution/tree-settle.ts; Windows 11, Node 24.14.1):

main this branch
get_local_variables 11 names, two of them __vite_ssr_import_* 9 names, none
snapshot.locals the same 11 the same 9
includeSpecial: true 12 names, two __vite_ssr_import_* 12 names, two __vite_ssr_import_*

Only the measured prefix is filtered. Other runners' bindings (vitest's __vi_import_* for hoisted mocks, for one) were not observed and are not touched.

#1213: the attach verification outlived its window, and the timeout hint sent every session to restart_debugging

The message, from a run where the proxy worker was itself stopped at a breakpoint:

Attach did not become debuggable: no threads reported within 20000ms (last failure: Debug adapter did not respond to 'threads' request within 25s. This typically means the debug adapter has crashed or lost connection. Try restart_debugging to relaunch the session. …)

  • The window. The verification's threads request is bounded by the window and the worker keeps that bound. A worker that answers nothing at all is caught only by the parent's backstop, a five second margin later, so the verification returned after 25 s and quoted a longer time than it had been given. verifyAttachThreads now stops waiting when the window closes, plus 250 ms for the worker's own timeout to cross the IPC channel and remain the failure that is quoted.
  • What that does not do. The failure that follows still has to stop a worker that answers nothing: the stop drains the abandoned request for one second and then waits out the worker's stop bound. So attach_to_process as a whole still outlives verifyTimeout in that case, by less than before. This is the reviewer's reading of the code, not a measurement, and the changelog entry was reworded to claim only what is true.
  • The hint. ErrorMessages.dapRequestTimeout told every session to try restart_debugging, which replays a launch and refuses an attach session and a child session. My first version chose between two sentences from the proxy configuration's attach flag; the review showed that flag is also set by a launch with attach-shaped arguments (which restart_debugging does replay) and that a child session's requests travel on its root's worker. The layer that words the message cannot tell the kinds apart, so it no longer guesses: "To go on, start the program again: restart_debugging if this session was started with start_debugging, attach_to_process if it was attached (restart_debugging refuses an attach session); a child session comes back with its parent."

Not changed: the request keeps the whole remaining window as its bound (an adapter that answers threads slowly but within the window still succeeds, as before). An answer that reaches the parent more than 250 ms after that bound is now discarded where it used to be taken.

The live case (a worker stopped at a breakpoint) was not re-run; the unit test stands in for it with a request that nothing answers.

Review

One independent review of the #1213 commit with a mutation pass (8 mutants, 6 killed; of the two survivors one is equivalent and the other, the window timer's clear, now has a test). Nothing critical or important; its points are the second bullet, the hint, a stale comment, and the changelog wording, all answered in the third commit. The #1215 commit has had no independent review.

Tests

  • tests/unit/shared/adapter-policy-js.test.ts: the bindings are left out, a look-alike program name stays, a scope emptied by the filter is not a contributing scope, includeSpecial lists them.
  • tests/core/unit/session/attach/attach-verification.test.ts (new; verifyAttachThreads had no unit test of its own): the threads answer and its bound, polling again on zero threads, returning by the window's end when nothing answers, the worker's own timeout still quoted, no unhandled rejection from the abandoned request, the adapter going away, no timer left behind.
  • tests/unit/utils/error-messages.test.ts: the one wording, naming each way back.

Gates

typecheck:all, lint, check-docs, changelog:check. The pre-push run on the pushed commit: unit 435 files, 9568 passed and 7 skipped; integration 47 files, 243 passed and 1 skipped.

🤖 Generated with Claude Code

cynarlab and others added 2 commits November 22, 2026 16:52
Vite's SSR runner, which vitest runs every module through, binds each import
of a module as __vite_ssr_import_<n>__ (beside __vite_ssr_exports__,
__vite_ssr_import_meta__ and others) in the scope the module's functions
close over. At a stop under vitest they took the stop snapshot's slots before
the function's own variables and padded get_local_variables.

They are the transform's, not the program's, the way a C# display class is
the compiler's: JsDebugAdapterPolicy.extractLocalVariables leaves them out
unless includeSpecial is set, and a scope that held nothing else supplies
nothing (so it is not listed as a contributing scope).

Measured with a real vitest run, a breakpoint in tree-settle.ts: 11 locals
with two __vite_ssr_import_* among them before, 9 and none after;
includeSpecial lists them as before.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…n is not sent to restart_debugging (#1213)

Two defects in one error message:

  Attach did not become debuggable: no threads reported within 20000ms
  (last failure: Debug adapter did not respond to 'threads' request within
  25s. ... Try restart_debugging to relaunch the session. ...)

- The verification's threads request is bounded by the window, and the
  worker keeps that bound. A worker that answers nothing at all (here it was
  itself stopped at a breakpoint) is caught only by the parent's backstop, a
  five second margin later, so the call outlived its verifyTimeout and
  quoted a longer time than the one it had been given. verifyAttachThreads
  now stops waiting when the window closes (plus 250 ms for the worker's own
  timeout to cross the IPC channel and be the failure that is quoted), and
  the abandoned request's late rejection is handled.
- dapRequestTimeout told every session to try restart_debugging, which
  replays a launch and refuses an attach session. The proxy manager knows
  how it was started: for an attach the message says to attach again with
  attach_to_process.

verifyAttachThreads had no unit test of its own; it has one now.

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

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…t hint that is true for every session (#1213)

An independent review of the previous commit, with a mutation pass. Nothing
critical or important.

- The hint. The previous commit chose between "restart_debugging" and
  "attach_to_process" from the proxy configuration's attach flag. That flag
  is also set by a launch whose arguments are attach-shaped, which
  restart_debugging does replay; and a child session's requests travel on
  its root's worker, so a child was sent to a tool that refuses a child id.
  The layer that words this cannot tell the kinds apart, so it no longer
  guesses: one sentence names each way back and whose it is. The flag on
  ProxyManager is gone.
- The changelog said attach_to_process "answers by its verifyTimeout". Read
  from the code by the reviewer: the verification now returns at its window
  (plus the 250 ms grace), but the failure that follows still has to stop a
  worker that answers nothing, which drains the abandoned request for one
  second and then waits out the worker's stop bound. The entry says what is
  true: the verification keeps to its window and no longer contradicts
  itself.
- The comment on sendThreadsRequestBounded explained why the request was
  never raced against a local timer. That price is paid again in the one
  case the request's own bound cannot cover; the comment says so.
- A test that the window's timer is cleared when the debugger answers (a
  mutant that dropped the clear survived).

Not changed: an answer that reaches the parent more than 250 ms after the
request's bound is now discarded where it used to be taken.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

javascript: Vite SSR synthetic module bindings (__vite_ssr_import_*) flood get_local_variables and snapshot.locals when debugging Vitest

2 participants