Skip to content

DAP: Rerun of a debug session that still runs reports "Write-unsafe context" #2396

Done

Description

@lagergren

What happens

Rerun of a DAP debug session that is still running reports an internal error from TransactionGuard:

Write-unsafe context! Model changes are allowed from write-safe contexts only. Please ensure you're using invokeLater/invokeAndWait with a correct modality state (not "any").
	at com.intellij.openapi.application.TransactionGuardImpl.assertWriteActionAllowed
	at com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl.saveAllDocuments
	at com.redhat.devtools.lsp4ij.dap.DAPDebugRunner.execute(DAPDebugRunner.java:84)
	at com.intellij.execution.runners.AsyncProgramRunner$execute$1.invoke
	...
	at com.intellij.execution.impl.ExecutionManagerImpl$restartRunProfile$1.run

In tests, the logged error fails the run: "Error running '…': Write-unsafe context!". In the IDE, LOG.error doesn't throw, so the run most likely goes on, but IntelliJ reports an internal error at each such Rerun.

Why

  • The runner saves the documents: DAPDebugRunner.execute has called FileDocumentManager.saveAllDocuments() first since DAP support was added. IntelliJ's execution classes don't save them on that path, so the call is needed: the program may read the files.
  • Rerun starts from where saving isn't allowed: when the session still runs, ExecutionManagerImpl.restartRunProfile stops it, waits until its process has ended, and then runs the configuration again from an alarm, which isn't a write-safe context.
  • Not affected: a first run, and a Rerun after the session has ended, start from the action, which is write-safe.

Reproduce

Start a DAP debug session, and press Rerun in its tab while it runs. DAPRerunTest, in the fix, does it with an in-process DAP server and fails without the fix.

Activity

  1. added this to the 0.30.3 milestone on Dec 1, 2026
  2. added
    bug
    dap
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdap

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions