Repository navigation
fix: Set Value works in a DAP thread which is still stopped after another thread continued alone - #2221
Merged
lagergren merged 2 commits intoNov 25, 2026
Conversation
…ther thread continued alone
When the debug adapter said that a thread other than the stopped one
continued alone ('continued' with allThreadsContinued: false), Set Value
refused every value of the stop, also those of the threads which stay
stopped, with "The program has run since this value was shown": the
client ended the execution epoch on every 'continued' event.
Such an event now ends the epoch only for the thread which continued.
The debug adapters which run a thread alone by themselves (java-debug,
debugpy, vscode-js-debug) keep the references of the other threads, and
VS Code clears only the call stack of that thread. A stack frame carries
its thread and the version of the run states of the threads at its
stop, and sendInExecutionEpoch checks, with the lock which a resume of
the session takes, that the frame's thread hasn't left the stop since
(DAPThreadRunStates.leftStopSince). Set Value, Jump to Value Source and
Jump to Source send their requests through it, so the values of the
thread which continued alone, or exited, still refuse.
Everything else still ends the epoch for every thread:
- a 'continued' event of all threads;
- any 'stopped' event, also one with allThreadsStopped: true for a
thread which never left its stop, as a debug adapter may number the
references of each stop from 1 again;
- a resume or a step of the session, also one with singleThread: true:
GDB, the debug adapter which supports it, forgets the references of
every thread whenever the program resumes.
sendInExecutionEpoch(int, ...) stays, checking the epoch only, and a
frame which doesn't know its thread is checked against its epoch only.
Fixes redhat-developer#2185
…ead continued alone, and in no thread after a single-thread step, a stop of all threads or a continue of all threads A session test against a DAP server with the threads 'main' and 'worker', where 'main' stops with all threads: - the worker continues alone: a local and an Evaluate result of main are set with setVariable and setExpression, and show their new values; those of the worker refuse and send nothing; - Step Over with singleThread: true refuses the values of both threads; - the worker continues alone and stops again with allThreadsStopped: the values of both threads at the earlier stop refuse, and a local of main at the new stop is set; - a 'continued' event of all threads, and Resume, refuse the values of both threads. DAPExecutionEpochTest: a request whose references are no longer valid in the current epoch is not sent.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2221 +/- ##
=======================================
Coverage 55.39% 55.40%
=======================================
Files 842 842
Lines 35882 35894 +12
Branches 5629 5628 -1
=======================================
+ Hits 19878 19888 +10
- Misses 13116 13120 +4
+ Partials 2888 2886 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Nov 25, 2026
Collaborator
Author
|
@coderabbitai review |
Action not completed
|
Collaborator
Author
|
@coderabbitai review |
Action performed
|
lagergren
added a commit
to lagergren/lsp4ij
that referenced
this pull request
Nov 25, 2026
…only when it is blocked on the lock which the test's other thread holds waitUntilBlockedOrEnded returned as soon as a thread was BLOCKED. A thread is also blocked for a moment on other locks of the JVM, such as a lock of the coverage agent, or of a class which another thread of the test's application loads. ./gradlew check runs the whole suite in one JVM with the IDE's threads, so aRefusalDoesNotWaitWhileARequestOfAnEpochIsWritten failed on the Linux 2025.3 CI jobs of redhat-developer#2221 and redhat-developer#2220 with "expected: <TERMINATED> but was: <BLOCKED>", although the refusal took no lock that the test held. waitUntilBlockedByOrEnded now counts a thread as blocked only when the lock it waits for is held by the given owner: the thread that writes its request with the epoch's lock held (ThreadInfo.getLockOwnerId).
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
…only when it is blocked on the lock which the test's other thread holds (#2222) ## What `DAPExecutionEpochTest.aRefusalDoesNotWaitWhileARequestOfAnEpochIsWritten` (#2201) failed twice, on the Linux 2025.3 CI jobs of #2221 and #2220: ``` org.opentest4j.AssertionFailedError: the refusal waits for the request ==> expected: <TERMINATED> but was: <BLOCKED> ``` `resumeRefused` takes no lock that the test holds: it synchronizes only on its own set, which no other thread of the test holds. But `waitUntilBlockedOrEnded` returned as soon as the thread was `BLOCKED`. A thread is also blocked for a moment on other locks of the JVM, such as a lock of the coverage agent, or of a class that another thread of the test's application loads. `./gradlew check` runs the whole suite in one JVM with the IDE's threads, which is why it fails on CI and not when the class runs alone. The same helper could also let `aResumeWaitsUntilTheRequestOfTheEpochIsWritten` see `BLOCKED` too early. ## Change Test only. The helper is now `waitUntilBlockedByOrEnded(thread, owner)`. It counts a thread as blocked only when the lock it waits for is held by the owner (`ThreadInfo.getLockOwnerId`). The owner is the thread that writes its request with the epoch's lock held. A lock of the JVM held by another thread no longer counts, and no timing is involved. ## Tests - **Red:** with `resumeRefused` changed to synchronize on the epoch's lock, the test fails (`BLOCKED`), so it still guards that the reader thread never waits on the lock. - **Green:** with the real code, `DAPExecutionEpochTest` (13 tests) passes headless on IC 2024.2, 2025.3 and IU 2026.3. The `dap.*` tests pass on 2025.3, headless: 545 tests, 0 failures.
lagergren
added a commit
that referenced
this pull request
Nov 25, 2026
… session suspended where it was, and says why (#2223) Fixes #2183 ## What IntelliJ shows a debug session as running before it asks the debug process for Resume Program, Step Over, Step Into, Smart Step Into or Step Out. LSP4IJ then sent `continue`, `next`, `stepIn` or `stepOut` and dropped the answer. So when the debug adapter refused, as an adapter that can't resume one thread alone does: - the session showed the program running while it was still stopped, without frames or variables; - Resume and the steps stayed disabled until Pause; - nothing said why. The same happened at a breakpoint that doesn't suspend, to the `continue` that resumes the program from it, or after a reverse run (#2201) the `reverseContinue`. There the console said only "Cannot handle the breakpoint: …". ## Change The client now handles the answer. On an error, the console says why ("Cannot step over: <adapter's message>", and so on), as for a refused Step Back, Reverse Continue or Reset Frame. What the request changed before it was sent is undone, unless a newer event changed it since: - **Execution epoch:** the stop's epoch is current again (`DAPExecutionEpoch.resumeRefused`), so Set Value works at its frames. A Step Back, Reverse Continue or Reset Frame still pending at the stop keeps the epoch ended until the debug adapter refuses that too. - **Run states:** the threads that the request resumed get their run states back, and the Threads tab shows them stopped again. A thread that exited meanwhile stays exited, and a newer stop, or a `continued` event of all threads, wins. - **Suspend context:** the session is suspended again, with `positionReached`, at the suspend context that IntelliJ resumed it from, with the same frames. - This doesn't happen if the debug adapter said meanwhile that the program stopped or continued, or if another stop suspended the session. - XDebugger takes the same context again on 2024.2, 2025.3 and 2026.3, as a new stop. - A pending Run to Cursor breakpoint is removed, as at any stop. - **Non-suspending breakpoints:** the automatic `continue`, or `reverseContinue` after a reverse run, is handled the same way. The program is still stopped at the breakpoint, so the session is suspended there, unless a newer `stopped` or `continued` event came first, which the session then follows. CodeRabbit asked for this on #2201. - **`DAPExecutionEpoch.resumeRefused`** now returns whether the program is where it was when the request was sent. That means the epoch the request ended, or an earlier one, is current again, and no `stopped` or `continued` event came since. It merges #2201's handling of several refused requests. - **API:** `DAPClient` keeps `continue_(int)`, `next`, `stepIn` and `stepOut`, and gets overloads that take the suspend context, which `DAPDebugProcess` and Smart Step Into pass. Not in this PR: - Resume is pressed while a Reverse Continue is pending, the adapter accepts the Reverse Continue, and then refuses Resume. The session briefly shows the old stop again until the Reverse Continue's `stopped` event arrives, and Set Value there refuses as stale. Fixing that would mean recording accepted requests in `DAPExecutionEpoch`. It takes two quick clicks. - A `continue` answer with `allThreadsContinued: false` to a request without `singleThread` still counts as all threads. See #2221. ## Tests New `DAPRefusedResumeSessionTest`, 11 session tests with an in-process debug adapter that refuses chosen requests, can hold its answers, and can send a newer event right before a refusal: - **Refused Resume, Step Over, Step Into, Smart Step Into and Step Out:** the session is suspended at the same frame, the console says why, and Set Value works there. - **Refused automatic resume at a non-suspending breakpoint:** - a `continue` reached by Resume, and a `reverseContinue` reached by Reverse Continue: suspended at the breakpoint, the epoch current, the Threads tab "stopped", one pause; - each with a newer `stopped` event first: suspended only at the newer stop, with exactly one pause; - each with a newer `continued` event first: not suspended, the Threads tab "running", and the next stop suspends it. - **Combined with #2201:** - Resume refused while a Reverse Continue is pending: suspended again at the stop, whose epoch stays ended until the Reverse Continue is refused too. - The same, but the Reverse Continue is accepted: the session runs. - Reverse Continue refused while Resume is pending: the session runs, and is back at the stop once Resume is refused too. New unit tests in `DAPExecutionEpochTest`, `DAPClientSuspendAgainTest` and `DAPThreadRunStatesTest`. Red-green, headless: - Ignoring `resumeRefused`'s result makes the 4 newer-event tests fail. - Main's breakpoint handling makes the 6 breakpoint tests fail. - `==` instead of `<=` in `resumeRefused` makes the reverse-order tests fail. - With the change, all pass. On main at 4e15453, the changed classes pass headless on IC 2024.2, 2025.3 and IU 2026.3: 51 tests each. The `dap.*` tests pass on all three: 564 tests each, with 0 failures or skipped. ### After the review - **Several refused requests:** two pending Resumes or steps that are both refused restore the run states as if neither had been sent, in either order. Before, when the older one was refused first, the Threads tab showed a thread running that the adapter still had stopped. - Each run state that a request sets records the request, and the snapshot before a refused request is kept while a newer request's change is still shown. - Newer `stopped`, `continued` and `thread` events are never undone. - **Tests:** - New unit tests in `DAPThreadRunStatesTest`, and a two-thread session test with two non-suspending breakpoints whose automatic continues are both refused, in either order. Both fail without the change. - The changed classes pass headless on IC 2024.2, 2025.3 and IU 2026.3: 40 tests each. The `dap.*` tests pass on all three: 571 tests each, with 0 failures or skipped. - A randomized model test, not committed (20,000 runs of 30 steps), checked the run states against a replay without the refused requests. It passes, and the earlier code failed it. ## Behaviour change | Before | After | |---|---| | The debug adapter refuses Resume Program, Step Over, Step Into, Smart Step Into or Step Out: the session shows the program running though it is still stopped, with no frames or variables, Resume and the steps stay disabled until Pause, and nothing says why | The console says why ("Cannot step over: <adapter's message>", etc.). The session is suspended again where it was, with the same frames, Set Value works there, and the Threads tab shows the threads stopped | | At a breakpoint which doesn't suspend, the debug adapter refuses the `continue`, or after a reverse run the `reverseContinue`, which resumes the program: the session shows it running, and the console says only "Cannot handle the breakpoint: …" | The console says "Cannot resume the program: …" or "Cannot reverse continue: …", and the session is suspended at the breakpoint. If the adapter said meanwhile that the program stopped or continued, the session follows that event instead | | Resume is refused while a Step Back, Reverse Continue or Reset Frame is still pending | The session is suspended again at the stop, and its values can be set once the pending request is refused too. If the adapter accepts the pending request instead, the session runs | | Two threads stop alone at breakpoints that don't suspend, and the debug adapter refuses both automatic continues, the older first: the Threads tab shows one thread running while the adapter still has it stopped | Both threads show stopped, whichever refusal comes first |
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2185
What
After a thread other than the stopped one continued alone (
continuedwithallThreadsContinued: false), Set Value refused in the thread that was still stopped. It said "The program has run since this value was shown: show it again to set it."DAPClient.continuedended the execution epoch of #2150 on everycontinuedevent, of any thread. So every value of the stop counted as out of date, and so did Jump to Source and Jump to Value Source on them.The findings in #2185 show the design, checked against the debug adapters' sources:
supportsSingleThreadExecutionRequests.Change
continuedwithallThreadsContinued: falseno longer ends the execution epoch. The thread that continued is marked as having left its stop, as before, in the run states of feat: the Threads tab of a DAP debug session shows which threads run, which are stopped and which exited #2181.Frames carry their stop.
DAPStackFramekeeps the run-state version of its stop, whichDAPExecutionStackpasses, and its thread, from feat: terminate a thread from the context menu of the Frames view of a DAP debug session #2217.The new
DAPClient.sendInExecutionEpoch(DAPStackFrame, …)sends a request only while both of these hold, checked in the same lock as before:DAPThreadRunStates.leftStopSince).The thread that reads the debug adapter's messages still never waits on that lock: the run states are an atomic swap.
Callers:
DAPValueModifier(Set Value),DAPExpressionModifier(Set Value on an Evaluate result) andDAPLocations(Jump to Source, Jump to Value Source) now pass their frame.The epoch still ends for every thread on:
singleThread: trueone, which GDB needs;stoppedevent, includingallThreadsStopped: true, which adapters that renumber at every stop need;continuedevent of all threads;Compatibility: the existing
sendInExecutionEpoch(int, …)overloads and the publicDAPStackFrameconstructors are unchanged.Docs: one sentence in the Set Value section of
docs/dap/UserGuide.md.Not in this PR:
continueresponse withallThreadsContinued: false, to a request sent withoutsingleThread, still ends the epoch for all threads. IntelliJ resumes the session before Resume is sent, so no value of that stop is left to set. Undoing the run states set before the request fits with DAP: a Resume or a step that the debug adapter refuses leaves the session shown as running, and says nothing #2183's refused-resume handling.setVariablewas sent.Tests
New
DAPSetValueInAStoppedThreadSessionTest, 5 session tests with an in-process debug adapter of two threads. Every wait is bounded and has a message.maingetsetVariableandsetExpressionand show their new values. The worker's values refuse and send nothing.singleThread: truemakes both threads' values refuse.allThreadsStopped: true. Both threads' earlier values refuse, andmain's local at the new stop can be set.DAPExecutionEpochTestgets one unit test for the newsend.Red-green: without the change, the first test fails (
The local of 'main' is set). The other four pass either way: they guard behaviour that already worked. With the change, all pass.On main at 4e15453, the two classes pass headless on IC 2024.2, 2025.3 and IU 2026.3: 19 tests each. The
dap.*tests pass on all three: 551 tests each, with 0 failures or skipped.Behaviour change