Skip to content

feat(sdk): expose retained Windows query process handles - #1524

Draft
Vineeth Sai Narajala (vineethsai7) wants to merge 3 commits into
microsoft:mainfrom
vineethsai7:codex/duplicate-query-process-handle
Draft

Vineeth Sai Narajala (vineethsai7) wants to merge 3 commits into
microsoft:mainfrom
vineethsai7:codex/duplicate-query-process-handle

Conversation

@vineethsai7

@vineethsai7 Vineeth Sai Narajala (vineethsai7) commented Oct 18, 2026 •

Copy link
Copy Markdown

Rust SDK embedders need to query and wait on the exact Windows workload process already retained by MXC. The current public process API exposes an integer PID, which requires another lookup for those operations. This adds MxcProcess::duplicate_query_process_handle() and a default SandboxProcess method returning Unsupported.

BaseContainer duplicates its retained process handle with PROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE, returning a non-inheritable OwnedHandle. The caller owns the duplicate while MXC retains process lifecycle and cleanup responsibility. Telemetry, warning and DACL wrappers forward the operation. Other backends retain the unsupported default. The API uses the retained process object throughout.

Refs #1521. This draft proposes the API shape for maintainer feedback; the initial implementation covers BaseContainer.

Validation: Windows SDK build and five selected tests passed against these exact five changed source files. Tests cover the unsupported default, forwarding through all three wrappers, operation after stdio transfer, and a query/wait duplicate that survives closure of its source duplicate and has inheritance disabled. The native unit queries the current test process; it creates no contained workload. The validation workflow requires the exact five passing test names and is confined to a separate contributor branch, outside this PR.

rustfmt and git diff --check passed. Full upstream CI and maintainer review remain pending.

Microsoft Reviewers: Open in CodeFlow

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

Native failure diagnostics must be preserved, and regression coverage should verify the absence of broader handle rights.

2 open issues
What changed in this PR

Adds Windows-only Rust SDK access to an owned query-and-wait handle for the retained workload process, addressing #1521 without reopening its PID.

Changes:

  • Implements restricted, non-inheritable handle duplication for BaseContainer.
  • Forwards the operation through process wrappers; other backends default to unsupported.
  • Adds forwarding, ownership, inheritance, and wait tests.
File Description
src/​mxc-sdk/​src/​sandbox.rs Exposes the public method and tests stdio independence.
src/​mxc-sdk/​src/​core/​mxc_engine/​mod.rs Adds telemetry and warning wrapper forwarding.
src/​mxc-sdk/​src/​core/​mxc_common/​sandbox_process.rs Defines the trait method and unsupported default.
src/​mxc-sdk/​src/​backends/​process_container/​common/​dispatcher.rs Adds DACL wrapper forwarding and coverage.
src/​mxc-sdk/​src/​backends/​process_container/​common/​base_container_runner.rs Implements handle duplication and native tests.

Review effort: Balanced

Comment thread src/mxc-sdk/src/backends/process_container/common/base_container_runner.rs Outdated
@vineethsai7

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI balanced review requested due to automatic review settings October 19, 2026 02:15

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.

🔵 Needs a closer look

The public API addition needs the required SDK README and versioned Rust reference updates.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Low severity Document MxcProcess operation in Rust API references

src/​mxc-sdk/​src/​sandbox.rs:287

The maintained MxcProcess method list in docs/api-reference/rust/v1/types.md:313–328 omits this operation, and src/mxc-sdk/README.md does not describe it. Please update both alongside the public API, documenting its Windows-only signature, current BaseContainer support, Unsupported behavior elsewhere, restricted access rights, and caller ownership without transferring sandbox cleanup responsibility. Also note the intentional Rust-only availability relative to .NET and Node.

2 resolved since last review

Review effort: Balanced

@vineethsai7

Copy link
Copy Markdown
Author

Addressed both review points in commit 46c3beef: DuplicateHandle failures now preserve the underlying Win32 error (and retain the HRESULT for other facilities), and the inert current-process test uses NtQueryObject to verify the duplicated handle has exactly query-limited-information and synchronize rights.

The separate fork-only validation run compiled the SDK with locked dependencies and passed all five fixed query/forwarding unit tests (3 + 1 + 1, zero failures). It did not run a sandbox or child workload, and its validation workflow is excluded from this PR. The PR’s CLA check is passing.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 05:34

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.

🔵 Needs a closer look

The draft native-handle API needs maintainer sign-off and upstream Windows validation beyond the reported selected tests.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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