Title: Write event on configurationDone for attach requests · Issue #2245 · PowerShell/PowerShellEditorServices · GitHub
Open Graph Title: Write event on configurationDone for attach requests · Issue #2245 · PowerShell/PowerShellEditorServices
X Title: Write event on configurationDone for attach requests · Issue #2245 · PowerShell/PowerShellEditorServices
Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary On attach scenarios, it is not possible to wait for all the breakpoints set by the client to be set i...
Open Graph Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary On attach scenarios, it is not possible to wait for all the b...
X Description: Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary On attach scenarios, it is not possible to wait for all the b...
Opengraph URL: https://github.com/PowerShell/PowerShellEditorServices/issues/2245
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Write event on configurationDone for attach requests","articleBody":"### Prerequisites\n\n- [x] I have written a descriptive issue title.\n- [x] I have searched all [issues](https://github.com/PowerShell/PowerShellEditorServices/issues?q=is%3Aissue) to ensure it has not already been requested.\n\n### Summary\n\nOn attach scenarios, it is not possible to wait for all the breakpoints set by the client to be set in the remote runspace. A client could have something like\n\n```powershell\n$originalRunspaces = Get-Runspace\n\nRead-Host -Prompt \"Please attach to process $pid with runspace $([Runspce]::DefaultRunspace.Id)\"\n\n# Waits for VSCode to attach to runspace, an extra runspace will be created by\n# Enter-PSHostProcess\nwhile ($true) {\n $newRunspace = Get-Runspace | Where-Object { $_.Id -notin $runspaces.Id } | Select-Object -First 1\n if ($newRunspace) {\n break\n }\n Start-Sleep -Milliseconds 300\n}\n\n\u0026 .\\script.ps1\n```\n\nBut this only checks that PSES has attached to the named pipe. It won't wait for PSES to have called `Debug-Runspace` on the target runspace and more importantly any breakpoints inside `script.ps1` to be set. It's also error prone if you cannot control when the attach actually happens as the additional runspace check could have occurred before the first `Get-Runspace` call.\n\nWhat would be ideal is for a well known event to be created by PSES when `configurationDone` was received so that the client only had to do\n\n```powershell\n# Attach to this runspace somehow\n\n$e = Wait-Event -SourceIdentifier PSES.ConfigurationDone -Timeout 30\nif ($e) {\n $e | Remove-Event\n}\nelse {\n throw \"Timed out waiting for attach event\"\n}\n```\n\n### Proposed Design\n\nMy proposal requires some changes to PowerShell itself but I wanted to see if the general idea was acceptable before trying to propose the change there. The benefit of using an event is that no custom functions needed to be loaded, and subsequently checked by the code, and `Wait-Event` has a simple timeout operation.\n\nUltimately what needs to happen is for PowerShell to expose a `__New-Event` command, similar to the new `__Set-PSBreakpoint` commands, that is treated specially by the PSRemoting server. This would be able to do the following but without having to spin up a new pipeline.\n\n```\n$runspace = Get-Runspace -Id $runspaceId\n$runspace.Events.GenerateEvent($SourceId, $Sender, $EventArgs, $EventData)\n```\n\nWe cannot just have PSES run this script or call `New-Event` directly as the runspace pipeline is busy running `Debug-Runspace`. The only time it can run commands is if the caller ran `Wait-Debugger` which is not ideal as it will pause the execution and require the client to continue on manually.\n\nAn alternative that I haven't tried out yet is to delay `Debug-Runspace` until after `configurationDone` is sent. This would allow both the breakpoints and event to be manually emited as commands on the runspace specified without having to block the pipeline with `Debug-Runspace`. I am not sure if that will be possible though but it could be an option that doesn't require any changes to PowerShell itself.","author":{"url":"https://github.com/jborean93","@type":"Person","name":"jborean93"},"datePublished":"2025-07-23T04:29:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/2245/PowerShellEditorServices/issues/2245"}
| 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:88c818e4-ed1e-7994-7eb9-9571cb043aa5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC34:52C87:617002:8753D0:6A5854CC |
| html-safe-nonce | 48993fdd4600487a8545150a9c3f6063f953f10365bb394cedb45629d76753f9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzM0OjUyQzg3OjYxNzAwMjo4NzUzRDA6NkE1ODU0Q0MiLCJ2aXNpdG9yX2lkIjoiNzg1NjM0MjI1MjUwMzE5Mjc4MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b74fd162fc7477ffd9715766bf4fab39eb44713c4d33ef03ddca3263a09f9e8f |
| hovercard-subject-tag | issue:3254816605 |
| 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/2245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/033cbbf109ff1fb9b8eadf6cfbfa9b52a439e49ac90a88ca0e442ccd842c6068/PowerShell/PowerShellEditorServices/issues/2245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/033cbbf109ff1fb9b8eadf6cfbfa9b52a439e49ac90a88ca0e442ccd842c6068/PowerShell/PowerShellEditorServices/issues/2245 |
| og:image:alt | Prerequisites I have written a descriptive issue title. I have searched all issues to ensure it has not already been requested. Summary On attach scenarios, it is not possible to wait for all the b... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jborean93 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| 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 | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width