Skip to content

fix: the DAP session stays at a stop which comes while an answer, a refusal or a 'continued' event changes it - #2324

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/dap-serialize-resume-and-stop
Nov 28, 2026
Merged

lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:fix/dap-serialize-resume-and-stop

Conversation

@lagergren

@lagergren lagergren commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2322

Follow-up to #2321, for 0.30.2.

#2321 made an answer to Reverse Continue, Step Back or Reset Frame leave the session alone once the debug adapter had
reported a stop since the request. One window remained, as CodeRabbit noted on #2321:

  1. The answer comes first, which is the order DAP uses.
  2. The EDT handles it late, and the checks pass.
  3. The stop's suspension runs on a pool thread while sessionResumed() is still running.
  4. The resume clears the stop.

The first commit closes that window. The second and third commits close the two windows of the same shape that it
left, which the first version of this PR listed as not covered: the suspension again after a refused Resume or step,
and the resume at a continued event. Three commits, for a rebase merge.

Behaviour change

Before After
When the debug adapter answered Reverse Continue, Step Back or Reset Frame before it sent stopped, and the EDT handled the answer late, the stop could suspend the session while the answer resumed it. The resume then cleared the stop, and the session showed the program running, with no frames, until the next stopped event. The resume and the stop's suspension no longer interleave: the stop suspends the session once the resume is done. The behaviour of #2321 is unchanged: an answer after a stop leaves the session alone, the normal order resumes and then suspends, and a refusal leaves the session where it was.
When the debug adapter refused a Resume or a step, the client looked at the session and then suspended it again at the stop of the request. Another stop, such as one of another thread or of a child session, that suspended the session between the two was replaced by that older stop, whose values could no longer be set. The suspension again and the other stop's suspension no longer interleave: the other stop suspends the session afterwards, and the session stays there. A stop that suspended the session before still leaves it there, and an ended session is still left as it is.
A continued event looked at the session and then resumed it. A stop that the event didn't continue, such as one of another thread or of a child session, that suspended the session between the two was undone: the session showed the program running, without frames, until the next stopped event. The resume and that stop's suspension no longer interleave: the stop suspends the session once the event resumed it, and the session stays there. An event that continued the thread of the stop still resumes the session, and one of another thread still leaves it suspended and shows the threads again.

Design: a serial executor, not a lock

The new DAPSessionChanges is an Executor of about 15 lines of logic:

  • A change runs at once, on the calling thread, when no other change is running.
  • Otherwise it is queued, and the thread that is running changes runs it next.
  • No thread ever waits for it. A change is queued before its count is raised, so the running thread always finds it.
  • A change that submits another runs it after itself, in the same loop, without recursion.
  • The parent and child clients of a session share one instance.

These go through it:

  • in resumeWhenAnswered, the check of the suspend context and sessionResumed();
  • the stop's suspension: suspend(), with its positionReached, resumeIfContinued and hints;
  • breakpointReached, so that a breakpoint with a log expression is covered too;
  • second commit: in suspendAgain, after a refused Resume or step, the check of the session and positionReached;
  • third commit: in continued, the check of the session and sessionResumed(), or the refresh of the threads for an
    event of another thread.

DAPDropFrameHandler.restartFrame passes the executor along. The epoch check of #2321 stays where it was, on the thread
that handles the answer.

Why not a lock. Under a lock, the stop's thread would hold it inside positionReached, and two things there wait
for other threads:

  • In 2024.2, positionReachedInternal calls getTopFramePosition(), then DAPStackFrame.getSourcePosition(), then
    LocalSourceFiles.findFile. Off the EDT, that refreshes the file synchronously, and waits for the EDT's write action.
    An EDT that waited for the lock, to resume after a late answer, would then deadlock with it.
  • In 2024.2, every positionReached and breakpointReached also takes a read action
    (setBreakpointsDisabledTemporarily).

No thread waits for the executor, so there is no such cycle, whatever a listener does.

The listeners that run inside a change were audited for 2024.2, and for 2026.3, where the split debugger is
always on:

  • On 2024.2:
    • the debugger views, the evaluation and inspect dialogs and the inplace editor all hand off to the EDT, or run
      inline only when already on it;
    • the breakpoint path takes read actions;
    • the removal of a temporary breakpoint takes XBreakpointManagerImpl's own lock, without the EDT.
  • On 2026.3, the views get their events through an unlimited channel (trySend), and nothing on the calling thread
    waits for the EDT.
  • None of these waits involves the executor.

A trade-off for reviewers: a queued change runs on whichever thread is running changes, which can be the EDT,
LSP4J's thread or a pool thread. So a resume may run on a pool thread, or a stop's suspension on the EDT. These session
calls already run on those threads today:

  • suspendAgain runs positionReached on the EDT or on LSP4J's thread;
  • a breakpoint with a log expression runs breakpointReached on LSP4J's thread;
  • resumeIfContinued runs sessionResumed on a pool thread;
  • a continued event runs sessionResumed and rebuildViews on LSP4J's thread.

On the EDT, DAPStackFrame.getSourcePosition takes its existing branch that defers the position.

Tests of the first commit

The new DAPReverseDebuggingSessionTest.testAStopHandledWhileTheAnswerToReverseContinueResumesTheSessionOnTheEDTSuspendsTheSessionOnceItResumed
forces the order, without fixed sleeps or hooks in the product:

  1. The EDT handles the answer, which the DAP server sent first.
  2. Inside beforeSessionResume, the test sends stopped, and waits until the client has handled the stop's frames.
  3. It then asserts that the stop came after the resume, that the session is suspended at frame 2, and that the thread
    shows as stopped.
Run Result
New test, without the fix (IC 2024.2) fails: expected:<[resumed, suspended in the frame 2]> but was:<[suspended in the frame 2, resumed]>
New test, with the fix (IC 2024.2) passes, 5 runs out of 5
Simulated regression: an executor that runs each change at once all 6 new tests fail

New unit tests:

  • DAPSessionChangesTest, 3 tests;
  • in DAPClientReverseExecutionTest, a stop during the resume runs after it, and an answer during another stop leaves
    the session at that stop;
  • in DAPClientBreakpointReachedTest, a breakpoint stop that comes during another change is deferred.

All headless, with the counts from the JUnit XMLs, for 36 test classes: #2321's 6, the new class, every class that
covers the stop chain or positionReached, and the session-tree, pause and single-thread-step tests:

IntelliJ Tests Failures
IC 2024.2 256 0
IU 2026.3 (split debugger) 256 0
IU 2026.2.5.1 256 0

Tests of the second and third commits

The two windows are on LSP4J's thread, which also handles the frames of a stop, so a session test can't hold that
thread inside the window as the first commit's test holds the EDT. One unit test per window forces the order instead,
with a session proxy: another thread brings a stop's suspension in the window and returns at once.

Test Without serialization1 With it
DAPClientSuspendAgainTest.aStopWhichComesWhileTheSessionIsSuspendedAgainSuspendsItAfterwardsAndTheSessionStaysThere fails: expected: <[the stop of the refused request, the next stop]> but was: <[the next stop, the stop of the refused request]> passes
DAPClientContinuedTest.aStopOfAnotherThreadWhichComesWhileTheEventResumesTheSessionSuspendsItAfterwardsAndTheSessionStaysThere fails: expected: <[resumed, suspended]> but was: <[suspended, resumed]> passes

Headless, with the counts from the JUnit XMLs, for the 15 classes that cover the changes of the session, refusals,
continued events and the run states of the threads2:

IntelliJ Tests Failures
IC 2024.2 138 0
IU 2026.3 (split debugger) 138 0

The second commit compiles on its own, tests included.

Not covered

  • Normal steps and Continue: IntelliJ resumes the session itself (doResume, on the EDT) before LSP4IJ sends the
    request, so the step's own stop always comes after it. An unrelated stop already on its way, such as one of another
    thread, can still interleave with that doResume. The session then recovers at the step's own stop. The executor
    can't cover this, as doResume runs inside IntelliJ.
  • The selection of the stopped thread after a continued event of another thread (selectStoppedThread): it
    checks the session on the EDT and then calls setCurrentStackFrame, which in 2024.2 checks only that the session
    has a suspend context, not which one. A stop that suspends the session between the two would show a frame of the
    earlier stop as the current one. The selection must run on the EDT, and the executor may run a change on another
    thread, so it doesn't fit there.
  • Not audited: Code With Me's backend listener, for remote-development guests. It is already reached from these
    threads before this change.

Footnotes

  1. DAPSessionChanges.execute patched to run each change at once on the calling thread, as the code did before.
    All other tests of both classes pass with it. ↩

  2. DAPClientBreakpointReachedTest, DAPClientContinuedTest, DAPClientReverseExecutionTest,
    DAPClientSuspendAgainTest, DAPContinuedEventSessionTest, DAPContinuedEventsTest, DAPDropFrameHandlerTest,
    DAPExecutionEpochTest, DAPOutputLocationSessionTest, DAPRefusedResumeSessionTest,
    DAPReverseDebuggingSessionTest, DAPSessionChangesTest, DAPSetValueInAStoppedThreadSessionTest,
    DAPThreadRunStateSessionTest, DAPThreadRunStatesTest. ↩

…er to Reverse Continue, Step Back or Reset Frame resumes it

IntelliJ doesn't resume the session for Reverse Continue, Step Back or Reset Frame, so the client resumes it once the
debug adapter answers, unless the debug adapter said since the request that the program stopped or continued, or
another stop suspended the session. The answer is handled on LSP4J's thread, or on the thread which sent the request,
such as the EDT, when the debug adapter answered before that thread chained the handling to the request.

A stop suspends the session on another thread, once the client has its threads and frames. When the debug adapter
answered first, as DAP orders the answer and the 'stopped' event, and the EDT handled the answer late, both checks
passed, and the stop could then suspend the session before the EDT's sessionResumed() cleared it: the session showed
the program running, without frames, until the next 'stopped' event.

The resume and the suspension at a stop are now changes of the session which run one at a time, in the order in which
they come (DAPSessionChanges). No thread waits for another: a change runs right away on the thread which brings it,
unless another change runs, and then right after it, on that thread. A lock would make the EDT wait for a stop whose
listeners may wait for the EDT, as the synchronous refresh of the VFS does when the position of a frame is first
computed off the EDT. The clients of a tree of DAP sessions share these changes, as they share the session.

The answer still resumes the session before the 'stopped' event which follows it is handled, an answer which comes
after a stop still leaves the session there, and a refusal still leaves the session where it was.

The new session test makes the EDT handle the answer, which the DAP server sends first, and lets the client handle the
stop while the answer resumes the session.

Fixes redhat-developer#2322
@lagergren lagergren added this to the 0.30.3 milestone Nov 27, 2026
@lagergren lagergren added bug Something isn't working dap Debugging Adapter Protocol labels Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved debug-session behavior when stops arrive while a resume or reverse-execution action is in progress. The session now handles these overlapping events in a consistent order, helping preserve the correct suspended thread and frame.
    • Improved breakpoint handling during concurrent session activity, reducing the chance that breakpoint information is processed before earlier session changes are complete.
    • Improved handling of continued events and frame-drop actions when they overlap with incoming stops, helping ensure the session reflects the latest stop state.

DAP clients in a session tree now share a coordinator that serializes debug-session changes. Stop handling, breakpoint processing, continued events, and resume-after-answer paths use the coordinator. Tests cover queue ordering and overlapping stop and resume operations.

Changes: DAP session change serialization

Layer / File(s) Summary
Shared session-change coordinator
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPSessionChanges.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPSessionChangesTest.java
DAPSessionChanges queues changes in submission order. Clients in a session tree share the coordinator. Tests check execution ordering and thread behavior.
Stop and continued-event updates
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientBreakpointReachedTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientContinuedTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientSuspendAgainTest.java
Stop, breakpoint, continued-event, and suspension-restoration paths schedule session updates through the coordinator. Tests cover breakpoint evaluation and concurrent stop handling.
Resume-after-answer and frame restart
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPDropFrameHandler.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientReverseExecutionTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPDropFrameHandlerTest.java, src/test/java/com/redhat/devtools/lsp4ij/dap/stepping/DAPReverseDebuggingSessionTest.java
Resume-after-answer and frame-restart completion use the coordinator. Tests cover delayed answers, overlapping stops, and reverse execution during stop handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Adapter as Debug Adapter
  participant Client as DAPClient
  participant Changes as DAPSessionChanges
  participant Session as Debug Session
  Adapter->>Client: Return reverse execution answer
  Client->>Changes: Queue resume check
  Adapter->>Client: Send stopped event
  Client->>Changes: Queue stop handling
  Changes->>Session: Resume if the suspend context is unchanged
  Changes->>Session: Apply stop position
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to b04ed

This change serializes DAP session stop and resume handling through a shared coordinator, so a late answer, a refused request, or a continued event no longer undoes a newer stop. The review found no remaining concrete defects, and the PR reports tests passing on the supported IDE versions. The documented limits are accepted scope, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: the DAP session stays at a stop that arrives while an answer, a refused request, or a 'continued' event changes the session. The changeset adds the DAPSessionChanges …
Description check Passed The description matches the changeset. It explains the race in resumeWhenAnswered and the stop's positionReached suspension, the three commits (answer, refused resume or step, continued event), the DA…
Linked Issues check Passed #2322 asks that the check-and-resume in DAPClient.resumeWhenAnswered and the stop's suspension (positionReached) be mutually exclusive, by a lock or a shared serial executor, without deadlock on 2024.…
Out of Scope Changes check Passed The changed areas relate to the race in #2322. They are DAPClient stop, resume and breakpoint wiring, DAPDropFrameHandler passing the executor, the new DAPSessionChanges class, and tests for these cha…
Full details: Title check

Explanation

The title states the main change: the DAP session stays at a stop that arrives while an answer, a refused request, or a 'continued' event changes the session. The changeset adds the DAPSessionChanges serial executor and routes resume, suspension, breakpoint, suspendAgain, and continued handling through it, which matches this title. The title is long (109 characters) but still specific.

Full details: Description check

Explanation

The description matches the changeset. It explains the race in resumeWhenAnswered and the stop's positionReached suspension, the three commits (answer, refused resume or step, continued event), the DAPSessionChanges executor design, the rejected lock alternative, the tests added, and the known limits. It fits the lenient bar for this check.

Full details: Linked Issues check

Explanation

#2322 asks that the check-and-resume in DAPClient.resumeWhenAnswered and the stop's suspension (positionReached) be mutually exclusive, by a lock or a shared serial executor, without deadlock on 2024.2 and the 2026.x split debugger. The reviewed head still adds the shared DAPSessionChanges executor. The previous review verified its behavior: a change runs at once when none is running, otherwise it is queued and run by the active thread, and no thread waits. The check-and-resume in resumeWhenAnswered and the stop's suspend()/positionReached path run through it. DAPDropFrameHandler.restartFrame forwards the executor. The required test, DAPReverseDebuggingSessionTest.testAStopHandledWhileTheAnswerToReverseContinue..., forces answer-first order on the EDT and releases the stop's stackTrace inside beforeSessionResume, without fixed sleeps. The PR reports that it fails without the fix on IC 2024.2 and passes 5 of 5 with it. The commits since the previous review (suspendAgain and continued) extend the same serialization; they do not remove the first-commit behavior. The reported validation covers IC 2024.2, IU 2026.3 and IU 2026.2.5.1. The deadlock audit of listeners is stated in the PR description and was not independently verified here, and the 2026.2 test run is reported only in the PR text.

Full details: Out of Scope Changes check

Explanation

The changed areas relate to the race in #2322. They are DAPClient stop, resume and breakpoint wiring, DAPDropFrameHandler passing the executor, the new DAPSessionChanges class, and tests for these changes. The second and third commits extend the same serialization to suspendAgain (after a refused Resume or step) and to continued events. These windows have the same shape as the #2322 window: a resume or suspension of the session interleaves with a newer stop. The PR description explains this link and lists the uncovered paths (normal Continue and steps during IntelliJ doResume, selectStoppedThread, Code With Me backend listener). No unrelated change was identified in the reviewed summary. The summary was not checked against the full diff for the suspendAgain and continued hunks.

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: 8375e1e1-a6d9-4999-b031-0918dc1becba
Commits

Reviewing files that changed from the base of the PR and between abbd227 and b04edea.

Files selected for processing: 4

  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPSessionChanges.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientContinuedTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPClientSuspendAgainTest.java
Files skipped from review as they are similar to previous changes: 1

  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPSessionChanges.java

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

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.34483% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.61%. Comparing base (29884d7) to head (b04edea).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...m/redhat/devtools/lsp4ij/dap/client/DAPClient.java 66.66% 11 Missing and 2 partials ⚠️
...evtools/lsp4ij/dap/client/DAPDropFrameHandler.java 16.66% 5 Missing ⚠️
.../devtools/lsp4ij/dap/client/DAPSessionChanges.java 61.53% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2324      +/-   ##
==========================================
- Coverage   58.64%   58.61%   -0.04%     
==========================================
  Files         848      849       +1     
  Lines       36679    36704      +25     
  Branches     5763     5765       +2     
==========================================
+ Hits        21510    21513       +3     
- Misses      12170    12188      +18     
- Partials     2999     3003       +4     

☔ 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.

…s while the session is suspended again

When the debug adapter refuses a Resume or a step, which IntelliJ resumed the session for, the client suspends the
session again at the stop where the program still is, unless the session ended or another stop suspended it meanwhile.
It looked at the session and then suspended it, on the thread which handles the refusal. Another stop, such as one of
another thread or of a child session, which suspended the session on another thread between the two, was then
replaced by the stop of the refused request: the session showed that older stop, whose values could no longer be set,
instead of the newer one.

The suspension again is now a change of the session (DAPSessionChanges), as the suspension at a stop is. A stop which
comes while the session is looked at suspends it afterwards, and the session stays at that stop. A stop which
suspended the session before still leaves it there, and a session which ended is still left as it is.

The new test lets another stop come on another thread as the session is suspended again. It fails when the changes
run at once on the thread which brings them, as before.

Refs redhat-developer#2322
…ad which comes while the event resumes it

A 'continued' event resumes the session when the session is suspended at a stop of the client which received it, and
the event continued the thread of that stop. The client looked at the session and then resumed it, on LSP4J's thread.
A stop which the event didn't continue, such as one of another thread or of a child session, and which suspended the
session on another thread between the two, was then undone: the session showed the program running, without frames,
although it was stopped there, until the next 'stopped' event.

The resume is now a change of the session (DAPSessionChanges), as the suspension at a stop is. Such a stop suspends
the session once the event resumed it, and the session stays there. An event which continued the thread of the stop
where the session is still resumes it, and an event of another thread still leaves the session suspended, and shows the
threads again.

The new test lets a stop of another thread come on another thread as the event resumes the session. It fails when the
changes run at once on the thread which brings them, as before.

Refs redhat-developer#2322
@lagergren lagergren changed the title fix: the session stays suspended at a stop which comes while the answer to Reverse Continue, Step Back or Reset Frame resumes it fix: the DAP session stays at a stop which comes while an answer, a refusal or a 'continued' event changes it Nov 28, 2026
@lagergren lagergren modified the milestones: 0.30.3, 0.30.2 Nov 28, 2026
@lagergren
lagergren merged commit 0c5aa98 into redhat-developer:main Nov 28, 2026
12 checks passed
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: serialize the resume after an answer with the suspension of a stop, so that a late-handled answer can't undo a stop

1 participant