Skip to content

Add public API for RemoteRunspace ShouldCloseOnPop - #28197

Open
Jordan Borean (jborean93) wants to merge 1 commit into
PowerShell:masterfrom
jborean93:runspace-poponclose
Open

Jordan Borean (jborean93) wants to merge 1 commit into
PowerShell:masterfrom
jborean93:runspace-poponclose

Conversation

@jborean93

Copy link
Copy Markdown
Collaborator

PR Summary

Adds a public method on Runspace that calls
RemoteRunspace.ShouldCloseOnPop = true. This allows 3rd party modules to implement their own Enter-PSSession ... equivalent cmdlet where the runspace is closed when someone exits the session. Right now the only way to achieve this is to either create the PSSession manually and pass it to Enter-PSSession -Session $s or use reflection to set the internal property.

PR Context

See the summary, it enables 3rd party modules to implement their own equivalent to Enter-PSSession for their own transports without relying on reflection and non-public APIs.

PR Checklist

Adds a public method on `Runspace` that calls
`RemoteRunspace.ShouldCloseOnPop = true`. This allows 3rd party modules
to implement their own `Enter-PSSession ...` equivalent cmdlet where the
runspace is closed when someone exits the session. Right now the only
way to achieve this is to either create the PSSession manually and pass
it to `Enter-PSSession -Session $s` or use reflection to set the
internal property.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 02:21
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused API addition is documented, validated, and covered by positive and negative integration tests.

0 open findings

What changed in this PR

Adds a supported API for marking remote runspaces to close after an interactive-session pop.

Changes:

  • Adds Runspace.SetShouldCloseOnPop().
  • Adds localized error handling for local runspaces.
  • Adds integration tests for close and retain behavior.
File Description
Connection.cs Exposes the public API.
remoterunspace.cs Clarifies internal flag documentation.
RunspaceStrings.resx Adds the local-runspace error message.
RunspaceShouldCloseOnPop.Tests.ps1 Tests validation and pop behavior.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants