Skip to content

Return the frame for a new stop and track resumes without a response command (#201, #202) - #203

Open
Fekete Gábor (feketegabor) wants to merge 2 commits into
microsoft:mainfrom
Ecobit-Consulting:fix/201-202-state-after-stop
Open

Fekete Gábor (feketegabor) wants to merge 2 commits into
microsoft:mainfrom
Ecobit-Consulting:fix/201-202-state-after-stop

Conversation

@feketegabor

Copy link
Copy Markdown

Summary

Two fixes for the state DebugMCP returns right after the debuggee stops in VS Code. Fixes #201 and #202.

The first state after a stop is read before VS Code has selected a frame (#201)

  • DebugSessionTracker sees the DAP stopped event before VS Code has fetched the call stack and updated vscode.debug.activeStackItem. A state read in that gap was paused: true with no frame, stack or location, or carried the previous stop's frame ID.
  • The tracker now also observes onDidChangeActiveStackItem and remembers for which stop a frame was selected. getCurrentDebugState() waits, bounded by 2 s, until the latest stop has its frame.
  • A stop that never gets a frame (the frameless case from get_debug_status tool returns the wrong status when already stopped at a breakpoint #157) is waited for once and then reported as a frameless pause, as before. Trackers built without the event and executors without a tracker never wait, so existing tests behave as they did.

A successful resume response with "command": null was ignored (#202)

  • Business Central's AL adapter answers next and continue with {"command": null, "success": true, "body": null} and sends no continued event, so the tracking added for A successful continue or step response should clear the tracked paused state (adapters need not send a continued event) #177 never applied: the session stayed marked as paused during a step.
  • Resume responses are now matched by request_seq. An empty or differently cased command no longer rules a response out, and a null body is treated as absent. A command that names another request is still rejected, as the existing test expects.
  • When a state read is overtaken by an execution transition and the session is stopped again, it is repeated (at most three times) instead of being returned as the new stop without a frame.

One visible change: continue_execution against such an adapter now returns as soon as the target is running, like other adapters, instead of blocking until the next stop or the operation timeout.

Validation

🤖 Generated with Claude Code

The session tracker observes a DAP `stopped` event before VS Code has
requested the call stack and selected a frame for it. A state read in that
gap reported `paused: true` with no frame, stack trace or location, and a
continue that stopped again at once returned the previous stop's frame ID
with no frame name or location. An immediate second `get_debug_status` was
correct.

This is not specific to one adapter: it reproduces with the built-in Node
debugger on 2.4.4 (first status after a breakpoint hit is empty; the state
returned by continue carries the stale frame).

The tracker now also observes `onDidChangeActiveStackItem` and records the
stop for which a frame was selected. `getCurrentDebugState()` waits, bounded
by a 2 s grace period, until the latest stop has its frame. A stop that never
gets one (no readable stack, or a stop that keeps the existing focus) is
waited for once and then reported as a frameless pause, as before. Trackers
constructed without the event, and executors without a tracker, never wait.

Fixes microsoft#201

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…states

Found with a DAP trace of a live Business Central (AL) session. The AL adapter
answers `next` and `continue` with

    {"type":"response","request_seq":14,"command":null,"success":true,"body":null}

The tracker required `command` to equal the request's command, so the
successful-response tracking from microsoft#177 never applied: the session stayed
marked as paused for the whole step. The handler's first poll therefore sent a
`stackTrace` request while the target was running; the adapter answered it
only when the step had finished, by which time the new stop had been
observed. The read was discarded as spanning a transition, but came back
carrying the new stop's sequence and no frame, which the handler took for the
completed step: every `step_over` returned `paused: true` with an empty stack.

- Match resume responses by `request_seq`. An empty (`null` or absent) or
  differently cased `command` no longer rules a response out, and a `null`
  body is treated as absent. A command naming another request still does.
- When a state read is overtaken by an execution transition and the session
  is stopped again, read again (at most three times) instead of returning the
  new stop without a frame.

`continue_execution` against such a session now returns as soon as the target
is running, like every other adapter, instead of blocking until the next stop
or the operation timeout.

Fixes microsoft#202

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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.

The first state after a stop is read before VS Code has selected a frame

1 participant