Title: Remote PSSession disconnects after launch debugging session ends · Issue #2263 · PowerShell/PowerShellEditorServices · GitHub
Open Graph Title: Remote PSSession disconnects after launch debugging session ends · Issue #2263 · PowerShell/PowerShellEditorServices
X Title: Remote PSSession disconnects after launch debugging session ends · Issue #2263 · PowerShell/PowerShellEditorServices
Description: Prerequisites I have written a descriptive issue title. I have searched all open and closed issues to ensure it has not already been reported. I have read the troubleshooting guide. I am sure this issue is with PowerShell Editor Services...
Open Graph Description: Prerequisites I have written a descriptive issue title. I have searched all open and closed issues to ensure it has not already been reported. I have read the troubleshooting guide. I am sure this ...
X Description: Prerequisites I have written a descriptive issue title. I have searched all open and closed issues to ensure it has not already been reported. I have read the troubleshooting guide. I am sure this ...
Opengraph URL: https://github.com/PowerShell/PowerShellEditorServices/issues/2263
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Remote PSSession disconnects after launch debugging session ends","articleBody":"### Prerequisites\n\n- [x] I have written a descriptive issue title.\n- [x] I have searched all [_open and closed_ issues](https://github.com/PowerShell/PowerShellEditorServices/issues?q=is%3Aissue) to ensure it has not already been reported.\n- [x] I have read the [troubleshooting](https://github.com/PowerShell/vscode-powershell/blob/main/docs/troubleshooting.md) guide.\n- [x] I am sure this issue is with _PowerShell Editor Services itself_ and does not reproduce in a standalone [PowerShell](https://github.com/PowerShell/PowerShell/issues/new/choose) instance, and is not an issue with my editor.\n- [x] I have verified that I am using the latest version of PowerShell Editor Services.\n- [x] If this is a security issue, I have read the [security issue reporting guidance](https://github.com/PowerShell/vscode-powershell/blob/main/SECURITY.md).\n\n### Summary\n\nWhen using remote PowerShell debugging from VS Code server (Linux → Windows over PSSession over SSH) with a launch configuration and path mappings, the remote PSSession unexpectedly drops immediately after the debug session finishes. As soon as any command is run post-debugging, the user gets kicked back to the local session.\n\n### Technical Analysis\n\nAfter investigating the PowerShellEditorServices codebase, I traced the issue through this execution flow:\n\n1. **Launch sessions never set `ExecutionCompleted = true` when they finish normally.** Unlike Attach sessions (which set this via `OnExecutionCompletedAsync` in `LaunchAndAttachHandler.cs:493`), Launch sessions execute via `ConfigurationDoneHandler.LaunchScriptAsync()` which has no equivalent completion handler.\n\n2. When the debug session ends, `DisconnectHandler` checks `ExecutionCompleted` (`DisconnectHandler.cs:55-58`)\n\n3. Because `ExecutionCompleted` is still `false`, it calls `_debugService.Abort()`\n\n4. `Abort()` calls `SetDebugResuming(DebuggerResumeAction.Stop)` (`PowerShellDebugContext.cs:97`)\n\n5. `SetDebugResuming()` calls `_psesHost.SetExit()` (`PowerShellDebugContext.cs:115`)\n\n6. `SetExit()` sets `_shouldExit = true` on the remote frame when it's a REPL with multiple frames (`PsesInternalHost.cs:360-371`)\n\n7. The next time the run loop executes (`RunExecutionLoop`, around line 917), it sees `_shouldExit == true` for a remote, non-nested REPL frame and calls `PopPowerShell()` (`PsesInternalHost.cs:917-922`)\n\n8. `PopPowerShell()` pops the remote REPL frame and detects the runspace change, which causes it to pop from `_runspaceStack`, exiting the PSSession (`PsesInternalHost.cs:763-790`)\n\n### Root Cause\n\nLaunch sessions do not set `ExecutionCompleted = true` when the debugged script finishes. This causes `DisconnectHandler` to treat a normal completion as an abort scenario, calling `Abort()` which ultimately sets `_shouldExit = true` on the remote REPL frame, causing the PSSession to exit.\n\n### Proposed Fix\n\nSet `ExecutionCompleted = true` in `ConfigurationDoneHandler.LaunchScriptAsync()` after script execution completes:\n\n```csharp\nawait _executionService.ExecutePSCommandAsync(\n command,\n CancellationToken.None,\n s_debuggerExecutionOptions).ConfigureAwait(false);\n\n// Fix: Mark execution as completed for launch sessions\nif (_debugStateService is not null)\n{\n _debugStateService.ExecutionCompleted = true;\n}\n\n_debugAdapterServer?.SendNotification(EventNames.Terminated);\n```\n\nThis aligns the behavior of Launch sessions with Attach sessions, which already set this flag in `OnExecutionCompletedAsync`.\n\n\n### PowerShell Version\n\n```console\n$PSVersionTable \n\nName Value\n---- -----\nPSVersion 7.5.4\nPSEdition Core\nGitCommitId 7.5.4\nOS Rocky Linux 8.10 (Green Obsidian)\nPlatform Unix\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\nPSRemotingProtocolVersion 2.3\nSerializationVersion 1.1.0.1\nWSManStackVersion 3.0\n```\n\n### Editor Version\n\n```console\nemacs --version\n\nGNU Emacs 30.1.90\n```\n\n### PowerShell Editor Services Version\n\n```console\n$pseditor.EditorServicesVersion\n\nMajor Minor Build Revision\n----- ----- ----- --------\n4 4 0 0\n```\n\n### Steps to Reproduce\n\n**Steps to Reproduce**\n\nSet up VS Code server on Linux\nConfigure launch debugging with path mappings\nEstablish remote PSSession to Windows machine over SSH\nSet breakpoint\nStart a launch-based debug session\nLet the debug session complete normally\nRun any command in the remote session\nObserve that the PSSession drops and returns to local session\n**Expected Behavior**\nThe remote PSSession should remain active after a launch debug session completes, allowing continued work in the remote context.\n\n**Actual Behavior**\nThe remote PSSession drops immediately after the first command is run following debug session completion.\n\n### Visuals\n\n_No response_\n\n### Logs\n\n_No response_","author":{"url":"https://github.com/alexmet82","@type":"Person","name":"alexmet82"},"datePublished":"2025-12-01T16:18:43.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2263/PowerShellEditorServices/issues/2263"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e8094a2c-faef-b51b-11f7-baac0b3c1000 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E70C:372616:492875F:672C0FE:6A56F751 |
| html-safe-nonce | a6dbcf96f600abd88c71f40fd26f444f463b66e47e7feea88350ca9d747c7e28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzBDOjM3MjYxNjo0OTI4NzVGOjY3MkMwRkU6NkE1NkY3NTEiLCJ2aXNpdG9yX2lkIjoiNzYwMDg4ODY4MTkyNDUwMzg1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8fdb2f9992b153b3c3b189bb1c6c7479287bda8c711742e9f113f6103cb3d1fd |
| hovercard-subject-tag | issue:3681766624 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShellEditorServices/2263/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9ec01be7e3e69402b2f30deeefffa3b9190a5d8a9ed494d5d36a1c177794e4d7/PowerShell/PowerShellEditorServices/issues/2263 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9ec01be7e3e69402b2f30deeefffa3b9190a5d8a9ed494d5d36a1c177794e4d7/PowerShell/PowerShellEditorServices/issues/2263 |
| og:image:alt | Prerequisites I have written a descriptive issue title. I have searched all open and closed issues to ensure it has not already been reported. I have read the troubleshooting guide. I am sure this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | alexmet82 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb29e5f807bd95e41196adfbc6d28f9af12d89830d8b684f3e871774ddff2fc |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShellEditorServices git https://github.com/PowerShell/PowerShellEditorServices.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 36031537 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShellEditorServices |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36031537 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShellEditorServices |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b056788a129fb0194b61f2ebb4c43f6a9f4dfd27 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width