Skip to content

fix: a stop while suspended lists each thread once, and only the threads of the session that stopped - #2124

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-one-execution-stack-per-thread
Nov 23, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-one-execution-stack-per-thread

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2118

What

When the debug adapter sent stopped while the session was suspended, the Frames view listed each thread again, and each later stop added them once more.

Cause

  • DAPClient.getSuspendContext reused the session's DAPSuspendContext when the session was suspended, and called addToExecutionStack for every thread, which always appends.
  • The reuse dates from when each stop added only the stopped thread. Since 0fbcf3a each stop adds every thread from threads, so the reuse only duplicates.
  • The child sessions that startDebugging starts share one debug session, so the reused context could belong to another session's client. The new stop's stacks and frames then took that client: their requests, and Resume and the steps, went to the other session's connection.

Change

  • Each stop gets a new DAPSuspendContext of the client that stopped (createSuspendContext, private). The threads are read again at each stop anyway.
  • DAPSuspendContext and all public signatures are unchanged.

Why a new context, not replacing stacks by thread id:

  • IntelliJ treats each positionReached as a new stop. On 2024.2, 2025.3 and 2026.3, XDebugSessionImpl takes the context's active stack and its top frame as current, and on a paused event the Frames view clears its thread list and reads it again. So keeping the old context kept no selection.
  • 2026.3 checks a frame selection from the Frames view against the current context by identity (setCurrentStackFrame(expectedSuspendContext, …)). One context object for two stops defeats that check.
  • Thread ids are per DAP session, so a key of thread id alone would mix the threads of a session tree.
  • DAP: support the Continued event #2106 plans to resume only when the session's context belongs to the client that sent continued. With a context per stop, the context's client is the one whose stop is shown.

Behaviour changes

  • Each thread is listed once, however many stops come while the session is suspended.
  • The other threads of a new stop load their frames when selected, as at a first stop.
  • In a session tree, a stop lists only the threads of the session that stopped, and its frames, steps and resumes go to its own connection.
  • A breakpoint hit that doesn't suspend, arriving while the session is suspended, no longer changes which thread Resume and the steps act on.
  • The last two come from reading the code: no test drives them.

Test

DAPSecondStopWhileSuspendedSessionTest (new) attaches a debug session to a DAP server in the test process. The program has the threads main and worker, and the server stops only the thread that hits a breakpoint (allThreadsStopped: false):

  • main stops, and while the session is suspended, worker stops;
  • the test checks that the session shows worker's frame;
  • it checks that the context lists main and worker once each, both through computeExecutionStacks, as the Frames view reads it, and through getExecutionStacks().

On main it fails: expected:<[main, worker]> but was:<[main, worker, main, worker]>.

2024.2 2025.3 IU 2026.3
The new test on main fails fails fails
dap tests with the fix 345 pass 345 pass 345 pass
Full suite with the fix 1860 tests, 0 failures, 7 skipped

…ads of the session that stopped

Fixes redhat-developer#2118

A stopped event while the debug session was suspended added every thread to the session's suspend context again, so
the Frames view listed each thread once more at each such stop. In a tree of sessions ('startDebugging'), that context
could be another session's: the frames, steps and resumes of the new stop then went to that session's connection.

Each stop now gets a new suspend context of the client that stopped, with the threads it has just read. IntelliJ takes
each positionReached as a new stop anyway: it selects the context's active stack and its top frame, and the Frames view
clears its thread list.
@lagergren lagergren added this to the 0.30.2 milestone Nov 22, 2026
@lagergren lagergren added bug Something isn't working dap Debugging Adapter Protocol labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Corrected debugger behavior when a second thread stops while the session is already paused. The selected frame now updates to the newly stopped thread, and threads are listed only once.

Each DAP stop now creates a fresh suspend context instead of reusing the session’s existing context. A regression test covers a second thread stopping while the session remains suspended.

Changes: DAP suspend context updates

Layer / File(s) Summary
Create a context for each stop
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
Each stop creates a new DAPSuspendContext and populates its execution stacks with the reported threads.
Verify a second stop while suspended
src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPSecondStopWhileSuspendedSessionTest.java
The test stops main, then worker while suspended. It checks that each thread appears once and that the selected frame belongs to worker.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to fa7f8

Each debugger stop now builds a fresh suspend context, so a second thread stopping while the session is suspended no longer produces duplicate thread entries. A regression test covers this scenario. No concrete merge-blocking risk was identified; the session-tree routing behavior is not covered by a test.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a stop while suspended now lists each thread once, and only the threads of the stopping session are listed. This matches the raw summary (new DAPSuspendContext per sto…
Description check Passed The description states the problem (Frames view lists threads again on each stop while suspended), the cause (reused DAPSuspendContext and always-appending addToExecutionStack, plus shared context acr…
Linked Issues check Passed Issue #2118 requires that a second stop while the session is suspended lists each thread once and shows the newer stop. The reported change in DAPClient.java creates a new DAPSuspendContext for each s…
Out of Scope Changes check Passed The change touches DAPClient.java (about +9/-7 lines, with no public signature changes) and adds one test class. The stop-routing effects described in the PR (per-client stacks, frames, steps and resu…
Full details: Title check

Explanation

The title names the main change: a stop while suspended now lists each thread once, and only the threads of the stopping session are listed. This matches the raw summary (new DAPSuspendContext per stop) and the objectives (duplicate thread entries fix, session-tree scoping).

Full details: Description check

Explanation

The description states the problem (Frames view lists threads again on each stop while suspended), the cause (reused DAPSuspendContext and always-appending addToExecutionStack, plus shared context across session tree), the change (createSuspendContext per stop), behaviour changes, and a new test. It relates directly to the changeset.

Full details: Linked Issues check

Explanation

Issue #2118 requires that a second stop while the session is suspended lists each thread once and shows the newer stop. The reported change in DAPClient.java creates a new DAPSuspendContext for each stop, built from the client that stopped and from the threads read for that stop (getThreads(true)). This matches the issue's first suggested fix. The reused context, which caused the duplicate stacks through addToExecutionStack, is no longer used when the session is suspended. The new test DAPSecondStopWhileSuspendedSessionTest covers the scenario: it checks the selected worker frame and that main and worker each appear once through computeExecutionStacks and getExecutionStacks(). The test reportedly fails on main without the fix, which supports the regression coverage. Related issue #2106 is background only and is not required here. Limitation: the repository tool could not return the changed blobs, so the code was not read directly. This verdict relies on the PR description and the change summary for the DAPClient.java edit.

Full details: Out of Scope Changes check

Explanation

The change touches DAPClient.java (about +9/-7 lines, with no public signature changes) and adds one test class. The stop-routing effects described in the PR (per-client stacks, frames, steps and resumes, and non-suspending breakpoint hits no longer changing the active thread) follow from the same per-stop context and are not separate features. The test class supports the issue's scenario. No unrelated files are reported in the summary. Limitation: the changed blobs could not be read, so the full file list and the hunks were not checked directly against the summary.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5b7be9f8-e6d7-4294-8aac-984aacef3ce6
Commits

Reviewing files that changed from the base of the PR and between 01c7a2a and fa7f8f8.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPSecondStopWhileSuspendedSessionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 50.57%. Comparing base (e927901) to head (fa7f8f8).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2124      +/-   ##
==========================================
+ Coverage   50.48%   50.57%   +0.08%     
==========================================
  Files         816      816              
  Lines       33871    33897      +26     
  Branches     5287     5289       +2     
==========================================
+ Hits        17101    17142      +41     
+ Misses      14114    14106       -8     
+ Partials     2656     2649       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit d0affa0 into redhat-developer:main Nov 23, 2026
9 checks passed
lagergren added a commit to lagergren/lsp4ij that referenced this pull request Nov 24, 2026
…h continued before it was shown doesn't suspend it

DAPContinuedEventSessionTest (new) attaches a debug session to a DAP
server in the test process. Its program has the threads 'main' and
'worker', and the server stops only the thread it names. Once 'main' has
stopped:
- 'continued' of all threads resumes the session, and the next stop's
  suspend context has one execution stack per thread (redhat-developer#2124 already gives
  each stop a context of its own: the duplicate threads redhat-developer#2106 feared don't
  happen);
- 'continued' of 'main' alone ('allThreadsContinued: false') resumes it;
- 'continued' of 'worker' alone leaves it suspended at 'main', and asks
  for the threads again;
- with the session running, the server sends 'stopped' and 'continued'
  back to back, and answers 'threads' only once both are written, so the
  client reads 'continued' before it can suspend the session. A session
  listener records each stop the session is suspended at: the stop which
  continued is never one of them, and the next stop is shown.

Without the check of DAPContinuedEvents, the last test fails: the session
is suspended at the stop which continued, then at the next one.

Refs redhat-developer#2106
lagergren added a commit that referenced this pull request Nov 24, 2026
…h continued before it was shown doesn't suspend it

DAPContinuedEventSessionTest (new) attaches a debug session to a DAP
server in the test process. Its program has the threads 'main' and
'worker', and the server stops only the thread it names. Once 'main' has
stopped:
- 'continued' of all threads resumes the session, and the next stop's
  suspend context has one execution stack per thread (#2124 already gives
  each stop a context of its own: the duplicate threads #2106 feared don't
  happen);
- 'continued' of 'main' alone ('allThreadsContinued: false') resumes it;
- 'continued' of 'worker' alone leaves it suspended at 'main', and asks
  for the threads again;
- with the session running, the server sends 'stopped' and 'continued'
  back to back, and answers 'threads' only once both are written, so the
  client reads 'continued' before it can suspend the session. A session
  listener records each stop the session is suspended at: the stop which
  continued is never one of them, and the next stop is shown.

Without the check of DAPContinuedEvents, the last test fails: the session
is suspended at the stop which continued, then at the next one.

Refs #2106
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dap Debugging Adapter Protocol

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAP: a second stopped event while suspended lists every thread twice

1 participant