Skip to content

Make PSEventManager.AddForwardedEvent public - #28199

Open
Jordan Borean (jborean93) wants to merge 2 commits into
PowerShell:masterfrom
jborean93:runspace-event-forwarding
Open

Jordan Borean (jborean93) wants to merge 2 commits into
PowerShell:masterfrom
jborean93:runspace-event-forwarding

Conversation

@jborean93

Copy link
Copy Markdown
Collaborator

PR Summary

Exposes PSEventManager.AddForwardedEvent publicly so third-party remoting transports can forward events from their sessions into the caller's event queue, the same way New-PSSession, Invoke-Command and Start-Job do.

The public method adds a copy of the event and returns it, so the event passed in is not modified. The built-in cmdlet handlers now use the public method, so the event in the session/job runspace queue keeps the origin ID rather than one mutated by AddForwardedEvent.

PR Context

Custom transports using RunspaceConnectionInfo and ClientSessionTransportManagerBase receive forwarded events in remoteRunspace.Events.ReceivedEvents, but AddForwardedEvent was internal. Modules could only call GenerateEvent, which loses the original ComputerName, RunspaceId and TimeGenerated, or use reflection.

PSEventManager still has internal abstract members, so it can't be subclassed outside the assembly and this isn't a breaking change.

PR Checklist

Exposes `PSEventManager.AddForwardedEvent` publicly so third-party
remoting transports can forward events from their sessions into the
caller's event queue, the same way `New-PSSession`, `Invoke-Command`
and `Start-Job` do.

The public method adds a copy of the event and returns it, so the
event passed in is not modified. The built-in cmdlet handlers now
use the public method, so the event in the session/job runspace
queue keeps the origin ID rather than one mutated by
`AddForwardedEvent`.

Custom transports using `RunspaceConnectionInfo` and
`ClientSessionTransportManagerBase` receive forwarded events in
`remoteRunspace.Events.ReceivedEvents`, but `AddForwardedEvent` was
internal. Modules could only call `GenerateEvent`, which loses the
original `ComputerName`, `RunspaceId` and `TimeGenerated`, or use
reflection.

`PSEventManager` still has internal abstract members, so it can't be
subclassed outside the assembly and this isn't a breaking change.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 02:52
@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.

🟡 Changes recommended

The out-of-process test does not verify the captured originating runspace ID.

1 open finding
What changed in this PR

Exposes safe event forwarding for third-party remoting transports while preserving source-event metadata.

Changes:

  • Adds public PSEventManager.AddForwardedEvent.
  • Copies events before assigning local identifiers.
  • Adds forwarding and metadata-preservation tests.
File Description
EventManager.cs Adds the public copy-based forwarding API.
remoterunspace.cs Retains internal in-place forwarding behavior.
New-Event.Tests.ps1 Tests public and built-in forwarding paths.

🧠 Review effort: Balanced


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

Comment thread test/powershell/Modules/Microsoft.PowerShell.Utility/New-Event.Tests.ps1 Outdated
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