Skip to content

test(process-container): probe PSEC environment handle lifetime - #1767

Draft
Carlos Alexandro Becker (caarlos0) wants to merge 7 commits into
mainfrom
test-windows-psec-lifetime-19663
Draft

Carlos Alexandro Becker (caarlos0) wants to merge 7 commits into
mainfrom
test-windows-psec-lifetime-19663

Conversation

@caarlos0

@caarlos0 Carlos Alexandro Becker (caarlos0) commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

📖 Description

Adds ignored Windows tests that call the process security environment (PSEC) API directly and record what one environment handle supports: sequential launches, concurrent launches, closing with a running or terminated child, and creation or launch failures. The tests print PSEC-OBSERVATION key=value lines, assert the observed behavior, and run in every scheduled ProcessContainer process job.

This is a probe only. It does not change how MXC creates, reuses, or closes environments, and it never deletes a container profile.

Observed behavior

Scheduled run 43555353623 ran all four tests on 10 hosts (Windows 24H2, 25H2, 26H2, prerelease 26H1 and the prerelease process-container image, each on x64 and arm64). PSEC was supported on every host, no test was skipped, and every host gave the same result. Run 43530387147 on an earlier probe revision gave the same results, except that it did not record whether the profile stays while a child runs after close.

All environments were created with flags 0 and a minimal policy, and every launch was short-lived.

  • One handle serves many launches. Sequential and concurrent launches on one handle succeed. A failed launch (missing program) does not stop later launches on the same handle.

  • Launches on one handle share state. Creating the environment makes one AppContainer profile before the first launch. Every launch sees the same TEMP, TMP and GetTempPath() inside that profile, and files written by one launch are visible to later and concurrent launches. A second handle gets a different profile.

  • TEMP is set by the launch. The child's LOCALAPPDATA is set inside the profile and TEMP/TMP under it. A TEMP or TMP value in the supplied environment block does not reach the child.

  • Close does not end running children. With flags 0, closing the handle while a child runs returns at once, and the child is still running 10 seconds later. The profile stays while that child runs and is removed within about 50 ms after the child ends. When all children have exited before close, the profile is already gone when close returns.

  • Failures leave nothing behind. Invalid, truncated, or unsupported-version specifications fail creation (0x8007000D, 0x80070032) without creating a profile. The brokered read/write directory keeps no package-SID entries.

MXC binds only the create, query-support, version-support and close exports, so the policy is fixed for the life of a handle. Per launch, only the command line, environment block, working directory, standard handles and creation flags can change.

Not measured: creation latency, several children or grandchildren alive at close, a child that never exits, a handle held for hours, job objects, the terminate-on-close flag, and use across different users or tokens.

Recommendation

Reuse of one PSEC handle is a reasonable subject for a separate production proposal. A launch trampoline is not needed for reuse, because the handle itself already supports repeated and concurrent launches. This PR does not implement either.

A production proposal would need to:

  • use one handle per session and per policy, create a new handle when the policy changes, and never share a handle across users or trust boundaries;
  • end every process launched in the environment, including grandchildren, and confirm that they exited before closing, or validate the terminate-on-close flag instead;
  • accept that commands on one handle share files and TEMP; a command that needs a fresh sandbox needs a new handle;
  • measure the cases listed above as not measured.

🔗 References

Refs github/copilot-agent-runtime#19663

🔍 Validation

The probe runs in the scheduled ProcessContainer process jobs. The bundle build checks that all four tests are discoverable, and the runner fails the job if any of them fails.

  • gh workflow run "Scheduled Validation Tests" --ref test-windows-psec-lifetime-19663 -f plan=nightly: started run 43555353623 on 9995425e. All four probe tests passed on all ten process hosts. The run as a whole failed because of other jobs not related to this change: WSLC host preparation, MicroVM, bubblewrap and seatbelt.
  • Local build, test, format and lint: not run. All validation for this change comes from CI.

✅ Checklist

  • Signed the Contributor License Agreement
  • Linked to an issue
  • For features or changes requiring a spec: linked the issue with maintainer-applied feature-accepted
  • For implementation: linked the required approved and merged design/API spec, or explained why no spec is required
  • Feature issue remains open unless this PR completes all agreed implementation, validation, and documentation
  • Updated documentation (if applicable)
  • Updated Copilot instructions (if build, architecture, or conventions changed)
  • If this PR changes Cargo.lock, the dependency-feed-check check passes (see pull request builds)

📋 Issue Type

  • Bug fix
  • Feature
  • Task

Add ignored Windows tests that drive the process security environment API
directly and record what one handle supports: sequential and concurrent
launches, close with a running or terminated child, and failure cases.
Run them in the scheduled ProcessContainer validation lane.

Refs github/copilot-agent-runtime#19663

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4e5e20fa-0d33-4b62-9fed-4f8b1bf849f0
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 21:29
@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 validation runner can misclassify passing probes as failures and abort subsequent suites, while the cleanup probe can mistake inaccessible directories for successful removal.

2 open issues
What changed in this PR

Adds Windows-only probes for process security environment (PSEC) handle lifetime, providing evidence for future handle-reuse decisions without changing MXC’s production behavior or deleting container profiles.

Changes:

  • Adds ignored tests for sequential and concurrent launches, closing handles with children, and failure recovery.
  • Packages and runs the probes in scheduled ProcessContainer validation.
  • Documents the probes and their observation logs.

Windows runtime behavior was not verified during this review.

File Description
src/​mxc-sdk/​tests/​process_container_psec_lifetime.rs Adds direct PSEC lifetime probes and cleanup assertions.
scripts/​ci/​run_backend_validation_tests.ps1 Runs the four probes and checks required-test results.
scripts/​ci/​build-windows-sdk-test-bundle.ps1 Builds, packages, and verifies discovery of the probe tests.
docs/​development/​build-and-test/​ci-validation-infrastructure.md Documents scheduled execution and observation output.

Review effort: Balanced

fn removal_delay(path: &Path) -> Option<Duration> {
let started = Instant::now();
loop {
if !path.exists() {
The generated ProcessSecurityEnvironmentT is non-exhaustive outside
mxc-sdk, so the probe cannot construct it with a struct expression.

Refs github/copilot-agent-runtime#19663

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4e5e20fa-0d33-4b62-9fed-4f8b1bf849f0
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 21:40

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 --nocapture invocation breaks required-test result parsing, causing passing probes to be reported as failures and aborting the scheduled validation lane before remaining probes and suites.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Profile-removal timing misses cleanup before the post-join check

src/​mxc-sdk/​tests/​process_container_psec_lifetime.rs:710

[P2] The profile-removal timer starts only after waiting for the child, possibly terminating it, and joining the closing thread, so cleanup that takes two seconds after close can be reported as running_child_profile_removed_after_ms=0. Cleanup following a host-issued termination can also be mistaken for cleanup caused by close. Poll profile existence alongside child liveness from the close event, and distinguish observations before and after forced termination.

Review effort: Balanced

#1733 moved requested_sandbox_kind from TelemetryConfig to
ExecutionRequest, which left this contract test unable to compile on main.

Refs github/copilot-agent-runtime#19663

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4e5e20fa-0d33-4b62-9fed-4f8b1bf849f0
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 21:59

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 --nocapture option disrupts libtest result lines required by the validator, causing passing probes to be rejected and preventing the remaining probes and network/policy suites from running.

3 open issues

Review effort: Balanced

Scheduled run 43517524231 showed on all ten Windows process hosts that an
AppContainer launch derives LOCALAPPDATA, TEMP and TMP from the
LOCALAPPDATA in its environment block. An explicit TEMP/TMP does not
reach the child. Pass the host LOCALAPPDATA, as production does, and
assert the derived container TEMP/TMP instead of the disproved
hypothesis.

Run every probe case before failing, so one failed assertion does not
hide the other observations.

Refs github/copilot-agent-runtime#19663

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4e5e20fa-0d33-4b62-9fed-4f8b1bf849f0
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 13, 2026 23:53

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

Using --nocapture disrupts the result lines required by the test parser, causing passing probes to fail validation and blocking subsequent network and policy suites.

3 open issues

Review effort: Balanced

Scheduled run 43530387147 showed on all ten Windows process hosts that
CloseProcessSecurityEnvironment returns at once while a child runs and
does not end that child. Assert that observed behavior, and record
whether the profile directory exists while the child still runs.

The --nocapture output splits the libtest "test <name> ... ok" line, so
the required-test check rejected passing cases. --exact with the
pass/fail summary already proves that the named case passed.

Refs github/copilot-agent-runtime#19663

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4e5e20fa-0d33-4b62-9fed-4f8b1bf849f0
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 14, 2026 02:25

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 cleanup probe can falsely report successful removal when Path::exists() encounters a metadata error; it should use try_exists() and explicitly fail on lookup errors.

2 open issues
1 resolved since last review

Review effort: Balanced

…etime-19663

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

# Conflicts:
#	scripts/ci/build-windows-sdk-test-bundle.ps1
Copilot AI balanced review requested due to automatic review settings November 14, 2026 04:11

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 tests can falsely report successful marker writes and ACL cleanup because PowerShell write errors and failed icacls exit statuses are not handled.

3 open issues
1 resolved since last review

Review effort: Balanced

fn write_marker(token: &str) -> String {
format!(
"{REPORT} $m=Join-Path $t '{MARKER_FILE}'; try {{ Set-Content -LiteralPath $m -Value \
'{token}'; 'WROTE=True' }} catch {{ 'WROTE=False:'+$_.Exception.GetType().Name }};"
.arg(path)
.output()
.expect("run icacls");
String::from_utf8_lossy(&output.stdout).into_owned()

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