Skip to content

Document ProcessContainer termination waits - #1908

Open
Sebastien Tardif (SebTardif) wants to merge 4 commits into
microsoft:mainfrom
SebTardif:docs/1532-process-termination
Open

Sebastien Tardif (SebTardif) wants to merge 4 commits into
microsoft:mainfrom
SebTardif:docs/1532-process-termination

Conversation

@SebTardif

@SebTardif Sebastien Tardif (SebTardif) commented Dec 3, 2026 •

Copy link
Copy Markdown

Description

Windows ProcessContainer does not document how process.timeout relates to process-tree teardown. Callers can see an unbounded WaitForSingleObject in the runner and a 5-second job drain that is only a warning, and they cannot tell which of those waits the request controls.

This adds ProcessContainer process termination and a short pointer from the schema. It records the current behavior:

  • For the native runner's blocking wait, process.timeout values 0 and 4294967295 have no deadline. That deadline bounds the wait for the root to exit on its own. In-process Node handles, Node ProcessContainer PTY, and .NET handles apply the field differently. The page states those cases.
  • After that, TerminateJobObject runs, job accounting is polled for 5 seconds, and a job that is still not empty is an stderr warning. The exit code or the timeout result is not replaced.
  • The root process handle is then waited with no deadline, on both wait and Drop, before the sandbox is released. No request field bounds that wait or confirms every descendant has exited.
  • Job-setup failure and ResumeThread failure are launch failures. The resume failure uses the strict 5-second drain.
  • There is no caller-facing job handle or custodian. JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE runs when the runner closes the job, which is after that root wait returns.
  • The waits are the same on every host where this backend runs. Schema version does not pick a different one.

References

Closes #1532

Validation

Documentation only. Compared with get_timeout_milliseconds, kill_process_tree, terminate_and_reap, the job-setup and ResumeThread failure paths, and JOB_EMPTY_WAIT_TIMEOUT in the current runner. Also compared Node in-process polling, Node ProcessContainer spawnWithPty, and .NET Wait / WaitAsync. No runtime test.

No spec: this describes behavior that is already shipped. No schema, API, or enforcement change.

Checklist

  • Linked to an issue
  • No spec is required: documentation of existing termination waits
  • Updated documentation
  • Bug fix is not the type; this is a task that answers a documentation request

Issue Type

  • Task
Microsoft Reviewers: Open in CodeFlow

process.timeout bounds only the wait for the root to exit. After
TerminateJobObject, job accounting is polled for 5 seconds and a
remaining process is a stderr warning. The root handle is then waited
with no deadline before the call returns.

Answer the questions in issue 1532 in the processcontainer backend doc
and point schema readers at it.

Closes microsoft#1532
@SebTardif
Sebastien Tardif (SebTardif) requested a review from a team as a code owner December 3, 2026 13:55
Copilot AI max review requested due to automatic review settings December 3, 2026 13:55

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

Unresolved documentation errors misrepresent timeout behavior, termination and cleanup guarantees, and warning reliability across backends and execution paths.

8 open issues
What changed in this PR

Documents existing Windows ProcessContainer termination behavior for #1532 without changing runtime behavior.

Changes:

  • Explains process timeouts, teardown waits, drain warnings, and external-custody limitations.
  • Adds schema guidance linking to the backend documentation.
File Description
docs/​schema.md Adds timeout guidance and a termination-documentation link.
docs/​backends/​process-container/​process-termination.md Describes termination waits, cleanup reporting, and settlement limitations.

Review effort: Max

Comment thread docs/schema.md Resolved
4294967295 is an infinite WaitForSingleObject, and 0 is converted
to that same value. Each kill polls the job for up to 5 seconds.
try_wait does not enforce the timeout. A failed TerminateJobObject
skips the root wait. The stderr warning is best-effort host output.
Node ProcessContainer PTY does not report timedOut.
Copilot AI max review requested due to automatic review settings December 3, 2026 14:13

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 documentation contains misleading timeout and cancellation claims that could cause callers to misunderstand deadline enforcement and whether workloads have terminated.

3 open issues
1 previously missed issue

In code that hasn't changed since last review

Low severity Clarify cancellation does not stop the sandbox

docs/​backends/​process-container/​process-termination.md:7

Cancellation can return while the sandbox is still active: .NET V1 MxcContainer.RunAsync cancellation stops awaiting native execution, and MxcProcess.WaitAsync cancellation does not kill the workload. Document this distinction from a completed native wait, and point callers to Kill or Dispose on a live process handle when termination is needed. Neither operation guarantees bounded settlement.

8 resolved since last review

Review effort: Max

Comment thread docs/schema.md Resolved
Comment thread docs/schema.md Resolved
The opening sentence now says this page describes the native runner
wait. 4294967295 is infinite only for that blocking wait. Node and
.NET MxcProcess handles measure it from handle creation. WSL Container
and LXC also treat 0 as no timeout. W365 Agents remains the service
that picks a finite default.
Copilot AI max review requested due to automatic review settings December 3, 2026 16:07

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

Timeout documentation omits Node’s infinite-timeout behavior and .NET’s wait-dependent enforcement, while duplicating detailed rules across pages.

2 open issues
3 resolved since last review

Review effort: Max

Comment thread docs/schema.md Resolved
MGudgin
Gudge (MGudgin) previously approved these changes Dec 4, 2026

@MGudgin Gudge (MGudgin) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the documentation against the native ProcessContainer runner and the Node and .NET timeout paths at 24d3fb8. No findings.

Node ProcessContainer spawnWithPty forwards the request to wxc-exec, so
0 and 4294967295 have no deadline on that path. An in-process Node
handle still measures a positive value, including 4294967295, from
creation. .NET checks that same value only while Wait or WaitAsync is
running.

The schema section keeps the timeout-versus-teardown distinction and
links to the backend page for the values.

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 documentation overstates deadline enforcement, describes unsupported .NET PTY creation, and omits that cancelling .NET waits can leave child processes running without explicit cleanup.

4 open issues
2 resolved since last review

Review effort: Max


- For the native runner's blocking `wait`, `0` and `4294967295` both wait with no deadline. The runner passes `4294967295` to `WaitForSingleObject`, and that value is `INFINITE`. `0` is converted to the same value before the wait.
- For that same `wait`, `1` through `4294967294` are finite waits, in milliseconds.
- An in-process Node `MxcProcess` measures a positive timeout, including `4294967295`, from handle creation. Polling starts when the handle is created and enforces that deadline until the handle settles.
- For that same `wait`, `1` through `4294967294` are finite waits, in milliseconds.
- An in-process Node `MxcProcess` measures a positive timeout, including `4294967295`, from handle creation. Polling starts when the handle is created and enforces that deadline until the handle settles.
- Node ProcessContainer `spawnWithPty` does not start that deadline. It passes the request to `wxc-exec`, so the native runner rules above apply on that path. `0` and `4294967295` have no deadline there.
- A .NET `MxcProcess`, including its PTY handle, measures a positive timeout, including `4294967295`, from handle creation. `0` sets no managed deadline. The deadline is checked only while `Wait` or `WaitAsync` runs. `TryGetExitCode` does not enforce it, so a process that is not being waited on can run past the deadline.
Comment on lines +11 to +15
- For the native runner's blocking `wait`, `0` and `4294967295` both wait with no deadline. The runner passes `4294967295` to `WaitForSingleObject`, and that value is `INFINITE`. `0` is converted to the same value before the wait.
- For that same `wait`, `1` through `4294967294` are finite waits, in milliseconds.
- An in-process Node `MxcProcess` measures a positive timeout, including `4294967295`, from handle creation. Polling starts when the handle is created and enforces that deadline until the handle settles.
- Node ProcessContainer `spawnWithPty` does not start that deadline. It passes the request to `wxc-exec`, so the native runner rules above apply on that path. `0` and `4294967295` have no deadline there.
- A .NET `MxcProcess`, including its PTY handle, measures a positive timeout, including `4294967295`, from handle creation. `0` sets no managed deadline. The deadline is checked only while `Wait` or `WaitAsync` runs. `TryGetExitCode` does not enforce it, so a process that is not being waited on can run past the deadline.

## Telling settlement from the warning

For a completed runner `wait`, a returned exit code or a returned timeout means the root process handle was signaled. It does not mean a 5-second poll saw zero active processes.

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.

Documentation: Bounded process-tree termination and settlement guarantees

3 participants