Skip to content

fix: Rerun of a DAP debug session that still runs saves the documents where it can, instead of reporting "Write-unsafe context" - #2397

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-rerun-saves-write-safe
Dec 1, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-rerun-saves-write-safe

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2396.

Cause

  • The runner saves first: DAPDebugRunner.execute calls FileDocumentManager.saveAllDocuments() before the run, as the program may read the files. IntelliJ's execution classes don't save them on that path.
  • Rerun of a running session: ExecutionManagerImpl.restartRunProfile stops the session, waits until its process has ended, and runs the configuration again from an alarm. That isn't a write-safe context, so TransactionGuard reported "Write-unsafe context" at the save.
  • In tests: that error failed the run with "Error running '…'".
  • In the IDE: most likely an internal error at each such Rerun.

Fix

  • Where writing is allowed (the action of a first run, or a Rerun after the session ended): the runner saves the documents at once and runs as before.
  • Otherwise: it saves them in an invokeLater with ModalityState.nonModal(), which is write-safe, and starts the run after the save. The promise it returns follows that run, or fails with its error.
  • Unchanged: the rest of execute, the installation path included, is now executeSaved.

Tests

  • DAPRerunTest:

    • starts a DAP debug session attached to an in-process DAP server;
    • reruns it while it runs, as the Rerun button of its tab does: ExecutionUtil.restart with the session's descriptor as the content to reuse;
    • checks that the configuration runs again with a session of its own, and that the earlier one stopped.

    Without the fix, it fails with "Error running 'rerun': Write-unsafe context!".

  • Whole suite: 2,861 tests, 0 failures, 7 skipped.

  • 2026.3: the DAP run tests pass, 5 tests.

… where it can, instead of reporting "Write-unsafe context"

DAPDebugRunner.execute saved the documents first. Rerun of a session that
still runs stops it, waits until its process has ended, and runs the
configuration again from an alarm, which isn't write-safe: saving there
reported "Write-unsafe context", and failed the run in tests. The runner
now saves at once where writing is allowed, and otherwise in a write-safe
invokeLater, before the run starts.

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

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Rerunning a debug configuration now starts a fresh session and stops the previous session.
    • Debug runs now save pending document changes before execution, including when saving must be scheduled on the application thread.

DAPDebugRunner now handles document saving and execution when the current context does not allow writing. A new integration test reruns an active DAP session and checks that the rerun creates a new session and stops the original.

Changes: DAP rerun execution

Layer / File(s) Summary
Write-safe execution scheduling
src/main/java/com/redhat/devtools/lsp4ij/dap/DAPDebugRunner.java
When writing is allowed, the runner saves documents and executes directly. Otherwise, it schedules both actions in non-modal state, ties the callback to project disposal, and forwards the result or error.
Active-session rerun regression test
src/test/java/com/redhat/devtools/lsp4ij/dap/DAPRerunTest.java
The integration test reruns an active attach session through IntelliJ’s rerun flow. Its loopback DAP server supports the test, which checks that the new session differs from the original and the original stops.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 492de

This change fixes rerunning a still-running DAP debug session, which previously failed with a write-unsafe context error. A regression test covers that scenario, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: rerunning a still-running DAP debug session no longer fails with "Write-unsafe context" because documents are saved in a write-safe way. It uses the fix: prefix and ma…
Description check Passed The description is on topic. It gives the cause (saving documents in a non-write-safe rerun context), the fix (immediate save when writing is allowed, otherwise an invokeLater with nonModal state), th…
Linked Issues check Passed Issue #2396 requires that rerunning a still-running DAP session does not report "Write-unsafe context" from DAPDebugRunner.execute, and that documents are still saved before the run. The reviewed head…
Out of Scope Changes check Passed The PR changes two files according to the supplied summary: DAPDebugRunner.java (+26/-1, the save-and-defer logic and the extracted executeSaved method) and the new test DAPRerunTest.java (+185). Both…
Full details: Title check

Explanation

The title names the main change: rerunning a still-running DAP debug session no longer fails with "Write-unsafe context" because documents are saved in a write-safe way. It uses the fix: prefix and matches the described fix and the linked issue. It is long (127 characters), but it is one clear sentence.

Full details: Description check

Explanation

The description is on topic. It gives the cause (saving documents in a non-write-safe rerun context), the fix (immediate save when writing is allowed, otherwise an invokeLater with nonModal state), the new DAPRerunTest, and test results. It links issue #2396.

Full details: Linked Issues check

Explanation

Issue #2396 requires that rerunning a still-running DAP session does not report "Write-unsafe context" from DAPDebugRunner.execute, and that documents are still saved before the run. The reviewed head implements this in DAPDebugRunner.execute: when TransactionGuard.isWritingAllowed() is true (first run, or rerun after the session ended), it calls FileDocumentManager.saveAllDocuments() and then executeSaved(). Otherwise, it schedules the save and executeSaved() in ApplicationManager.invokeLater with ModalityState.nonModal(), tied to the project disposal, and forwards the result or error through an AsyncPromise. The installation path and the rest of the execution flow moved unchanged into executeSaved(). The issue's reproduction test, DAPRerunTest, is added in the PR (per the PR summary). I did not read the test file at the reviewed head, and I did not run the test suite. The test result claims in the PR description are therefore not independently verified.

Full details: Out of Scope Changes check

Explanation

The PR changes two files according to the supplied summary: DAPDebugRunner.java (+26/-1, the save-and-defer logic and the extracted executeSaved method) and the new test DAPRerunTest.java (+185). Both are directly tied to #2396. The extraction of executeSaved is a necessary refactor to run the same logic after the deferred save. No unrelated changes were identified. The diff could not be read directly because the changed blobs are missing from the checkout, so this verdict relies on the supplied summary and the reviewed head file contents.

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: bec2a977-e7d7-4cc1-97fa-031d962e0d64
Commits

Reviewing files that changed from the base of the PR and between 0c53bb1 and 492dee9.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/dap/DAPDebugRunner.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/DAPRerunTest.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 Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.80%. Comparing base (0c53bb1) to head (492dee9).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...com/redhat/devtools/lsp4ij/dap/DAPDebugRunner.java 75.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2397      +/-   ##
==========================================
- Coverage   59.82%   59.80%   -0.02%     
==========================================
  Files         860      860              
  Lines       37690    37701      +11     
  Branches     5919     7810    +1891     
==========================================
  Hits        22547    22547              
- Misses      12051    12071      +20     
+ Partials     3092     3083       -9     

☔ 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 Dec 1, 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 Dec 1, 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 653f7b3 into redhat-developer:main Dec 1, 2026
16 of 17 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: Rerun of a debug session that still runs reports "Write-unsafe context"

1 participant