From 4e720e0f1422fc5766c2d1a5b422c6a3d67fa15f Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 3 Dec 2026 05:55:13 -0800 Subject: [PATCH 1/4] Document ProcessContainer termination waits 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 #1532 --- .../process-container/process-termination.md | 42 +++++++++++++++++++ docs/schema.md | 4 ++ 2 files changed, 46 insertions(+) create mode 100644 docs/backends/process-container/process-termination.md diff --git a/docs/backends/process-container/process-termination.md b/docs/backends/process-container/process-termination.md new file mode 100644 index 000000000..08a1d3f3f --- /dev/null +++ b/docs/backends/process-container/process-termination.md @@ -0,0 +1,42 @@ +# ProcessContainer process termination + +> **Audience:** MXC consumers and developers + +This page is the Windows `processcontainer` answer for how long MXC waits, what a timeout means, and what is still running when the call returns. The request field is `process.timeout`. + +## Waiting for the command + +`process.timeout` is a number of milliseconds. `0` means the wait for the root process to exit has no deadline. A positive value is that deadline. When it expires, the run result is a timeout (`script timed out after ms`). Teardown then starts. The timeout does not, by itself, mean the process tree has exited. + +## Ending the tree + +On timeout, on drop of the run handle, and after the root has already exited, MXC calls `TerminateJobObject` on the job that contains the root and the descendants created after the root was assigned to that job. The root is created suspended and resumed only after that assignment. + +MXC then polls job accounting for 5 seconds. That window is fixed. It is not a request field and it does not change with schema version. + +If the job still reports active processes, stderr gets a warning that starts with `sandbox job did not fully drain within the teardown window (continuing)`. The run result is unchanged: a child exit code stays that exit code, and a timeout stays a timeout. + +MXC then waits with no deadline until the root process handle is signaled. `wait` and `Drop` do this before they release the sandbox. The call does not return the timeout, and does not finish drop, until that wait returns. If the root never becomes signaled, the call does not return. + +There is no request field, flag, or execution mode that puts a deadline on that last wait, or that confirms every descendant has exited. + +Two launch failures are different: + +- If the job cannot be created or the suspended root cannot be assigned, MXC terminates that root and waits with no deadline for its handle, then rejects the launch. The sandbox does not run. +- If resuming the root fails, MXC uses a strict 5-second drain. A job that does not report zero active processes in that window is included in the launch error. + +## Telling settlement from the warning + +A returned exit code or a returned timeout means the root process handle was signaled. It does not mean the 5-second poll saw zero active processes. + +Incomplete drain is not its own exit code and does not replace the exit code or the timeout. The stderr warning is the record that the poll stopped while the job still reported active processes. Nothing in the request turns that warning into a failed result. + +## No separate custodian + +MXC does not give the caller a second process, a job handle, or an API that bounds settlement or counts descendants. The job stays inside the runner. + +The job is created with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`. When that handle closes, the kernel ends processes still in the job. The runner closes the handle after the unbounded root wait returns, so stopping the MXC process from outside is not a settlement API. + +## Builds + +This is the current Windows `processcontainer` backend on every host where that backend runs. Schema version does not select a different wait. Which Windows builds can run the backend is in [Windows OS-version support](os-version-support.md). diff --git a/docs/schema.md b/docs/schema.md index 5282c8b49..64dd167be 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -422,6 +422,10 @@ container is created. WSL Container execution in an existing container (`exec`) in-container path instead. See [`docs/backends/wslc/wsl-container-getting-started.md`](backends/wslc/wsl-container-getting-started.md). +### Process timeout + +`process.timeout` is milliseconds. `0` waits with no deadline for the root process to exit. On Windows ProcessContainer, that deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. See [ProcessContainer process termination](backends/process-container/process-termination.md). + ### Environment `process.env` and `process.inheritDefaultEnv` combine as follows from From e09589e66f6db2e97ff5522a237f5d08fc0db802 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 3 Dec 2026 06:13:31 -0800 Subject: [PATCH 2/4] Document the timeout values and cleanup paths 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. --- .../process-container/process-termination.md | 33 +++++++++++++------ docs/schema.md | 4 ++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/docs/backends/process-container/process-termination.md b/docs/backends/process-container/process-termination.md index 08a1d3f3f..fa98f5ea8 100644 --- a/docs/backends/process-container/process-termination.md +++ b/docs/backends/process-container/process-termination.md @@ -2,23 +2,32 @@ > **Audience:** MXC consumers and developers -This page is the Windows `processcontainer` answer for how long MXC waits, what a timeout means, and what is still running when the call returns. The request field is `process.timeout`. +This page is how Windows `processcontainer` waits, what a timeout means, and what is still running when a call returns. The request field is `process.timeout`. These statements are for a completed runner `wait`. They do not describe every SDK wrapper. The [Node V1 API](../../api-reference/node/v1/api.md) is the exception called out below. ## Waiting for the command -`process.timeout` is a number of milliseconds. `0` means the wait for the root process to exit has no deadline. A positive value is that deadline. When it expires, the run result is a timeout (`script timed out after ms`). Teardown then starts. The timeout does not, by itself, mean the process tree has exited. +`process.timeout` is milliseconds. + +- `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. +- `1` through `4294967294` are finite waits, in milliseconds. + +When a finite wait expires inside blocking `wait`, the run result is a timeout (`script timed out after ms`). That result does not, by itself, mean the process tree has exited. + +`try_wait` only polls the root process. It does not apply `process.timeout`, and it does not terminate descendants after the root exits. The timeout clock starts when blocking `wait` runs. `kill` and `kill_for_timeout` terminate the job and poll it, then leave the final root wait to a later `wait` or to `Drop`. ## Ending the tree -On timeout, on drop of the run handle, and after the root has already exited, MXC calls `TerminateJobObject` on the job that contains the root and the descendants created after the root was assigned to that job. The root is created suspended and resumed only after that assignment. +On timeout, on `kill` / `kill_for_timeout`, and inside `wait` and `Drop`, MXC calls `TerminateJobObject` on the job that contains the root and the descendants created after the root was assigned to that job. The root is created suspended and resumed only after that assignment. -MXC then polls job accounting for 5 seconds. That window is fixed. It is not a request field and it does not change with schema version. +Each of those calls then polls job accounting for up to 5 seconds. The window is per call, not per run. A timeout that kills, then waits, then drops the handle can poll more than once and can emit more than one warning. The window is fixed. It is not a request field and it does not change with schema version. -If the job still reports active processes, stderr gets a warning that starts with `sandbox job did not fully drain within the teardown window (continuing)`. The run result is unchanged: a child exit code stays that exit code, and a timeout stays a timeout. +If that poll still reports active processes, or if the accounting query itself fails, the MXC host process writes a warning to its own stderr. The text starts with `sandbox job did not fully drain within the teardown window (continuing)`. The write is best-effort. It is not a structured SDK warning and it is not a separate capture of the command's stderr. `wxc-exec` prints it on the same stderr stream as the command, so a command can print a line that looks like the warning. SDK callers that do not read the host process stderr can miss it. -MXC then waits with no deadline until the root process handle is signaled. `wait` and `Drop` do this before they release the sandbox. The call does not return the timeout, and does not finish drop, until that wait returns. If the root never becomes signaled, the call does not return. +The run result is unchanged when the poll is only a warning: a child exit code stays that exit code, and a timeout stays a timeout. -There is no request field, flag, or execution mode that puts a deadline on that last wait, or that confirms every descendant has exited. +`wait` and `Drop` then wait with no deadline until the root process handle is signaled, unless `TerminateJobObject` already failed. There is no request field that puts a deadline on that last wait, or that confirms every job process has exited. + +If `TerminateJobObject` fails, `terminate_and_reap` does not wait on the root. `wait` returns that failure instead of the exit code or the timeout. `Drop` logs `failed to terminate sandbox process tree during drop` and then releases the handles it owns. A root wait that returns without `WAIT_OBJECT_0` is also a failure, and that path does not confirm an exit code. Two launch failures are different: @@ -27,15 +36,19 @@ Two launch failures are different: ## Telling settlement from the warning -A returned exit code or a returned timeout means the root process handle was signaled. It does not mean the 5-second poll saw zero active processes. +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. + +Incomplete drain is not its own exit code and does not replace the exit code or the timeout. The stderr warning is only a best-effort host log. Nothing in the request turns that warning into a failed result. -Incomplete drain is not its own exit code and does not replace the exit code or the timeout. The stderr warning is the record that the poll stopped while the job still reported active processes. Nothing in the request turns that warning into a failed result. +Node's ProcessContainer PTY is outside those result rules. It returns the `wxc-exec` exit code, including a failure before any sandbox root existed, and `wait().timedOut` is `false` even when the executor timed out. See [Node V1 API](../../api-reference/node/v1/api.md). ## No separate custodian MXC does not give the caller a second process, a job handle, or an API that bounds settlement or counts descendants. The job stays inside the runner. -The job is created with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`. When that handle closes, the kernel ends processes still in the job. The runner closes the handle after the unbounded root wait returns, so stopping the MXC process from outside is not a settlement API. +The job is created with `JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE`. Stopping the MXC host process closes that handle even while the runner is blocked in the root wait, and the kernel then ends processes still in the job. That is not a confirmation that those processes have exited. + +On the normal path, the job handle is released when the run handle is dropped or freed. `wait` returning does not by itself close the job. ## Builds diff --git a/docs/schema.md b/docs/schema.md index 64dd167be..1614f1020 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -424,7 +424,9 @@ in-container path instead. See ### Process timeout -`process.timeout` is milliseconds. `0` waits with no deadline for the root process to exit. On Windows ProcessContainer, that deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. See [ProcessContainer process termination](backends/process-container/process-termination.md). +On Windows ProcessContainer, `process.timeout` is milliseconds. `0` and `4294967295` wait with no deadline for the root process to exit. `1` through `4294967294` are finite waits. That deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. See [ProcessContainer process termination](backends/process-container/process-termination.md). + +Other backends do not use that rule. W365 Agents sends `0` to the service, and the service picks a finite default (normally 300,000 ms). See [W365 Agents](backends/w365agents/w365agents-backend.md). ### Environment From 24d3fb8cb36dec394a152e421059d7947a3e5abe Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 3 Dec 2026 08:07:23 -0800 Subject: [PATCH 3/4] Scope the timeout numbers to the native runner wait 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. --- docs/backends/process-container/process-termination.md | 7 ++++--- docs/schema.md | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/backends/process-container/process-termination.md b/docs/backends/process-container/process-termination.md index fa98f5ea8..f6512f434 100644 --- a/docs/backends/process-container/process-termination.md +++ b/docs/backends/process-container/process-termination.md @@ -2,14 +2,15 @@ > **Audience:** MXC consumers and developers -This page is how Windows `processcontainer` waits, what a timeout means, and what is still running when a call returns. The request field is `process.timeout`. These statements are for a completed runner `wait`. They do not describe every SDK wrapper. The [Node V1 API](../../api-reference/node/v1/api.md) is the exception called out below. +This page describes how the native Windows ProcessContainer runner waits, what a timeout means, and what is still running when `wait` returns. The request field is `process.timeout`. These statements are for that blocking `wait`. They do not describe every SDK wrapper. The [Node V1 API](../../api-reference/node/v1/api.md) is the exception called out below. ## Waiting for the command `process.timeout` is milliseconds. -- `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. -- `1` through `4294967294` are finite waits, in milliseconds. +- 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. +- Node and .NET `MxcProcess` handles measure a positive timeout, including `4294967295`, from handle creation. That value is a finite timeout on those handles. `try_wait` only polls the root and does not enforce the timeout. When a finite wait expires inside blocking `wait`, the run result is a timeout (`script timed out after ms`). That result does not, by itself, mean the process tree has exited. diff --git a/docs/schema.md b/docs/schema.md index 1614f1020..10a0f7112 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -424,9 +424,11 @@ in-container path instead. See ### Process timeout -On Windows ProcessContainer, `process.timeout` is milliseconds. `0` and `4294967295` wait with no deadline for the root process to exit. `1` through `4294967294` are finite waits. That deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. See [ProcessContainer process termination](backends/process-container/process-termination.md). +`process.timeout` is milliseconds, and what `0` means depends on the backend. -Other backends do not use that rule. W365 Agents sends `0` to the service, and the service picks a finite default (normally 300,000 ms). See [W365 Agents](backends/w365agents/w365agents-backend.md). +For the native ProcessContainer runner's blocking `wait`, `0` and `4294967295` wait with no deadline, and `1` through `4294967294` are finite. That deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. `try_wait` only polls the root and does not enforce the timeout. Node and .NET `MxcProcess` handles measure a positive value, including `4294967295`, from handle creation, so that value is a finite timeout there. See [ProcessContainer process termination](backends/process-container/process-termination.md). + +WSL Container and LXC also treat `0` as no timeout. W365 Agents sends `0` to the service, and the service picks a finite default (normally 300,000 ms). See [W365 Agents](backends/w365agents/w365agents-backend.md). ### Environment From e8d62fa69b06ec34685bb62bd41b2ee39461c365 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Fri, 4 Dec 2026 15:40:36 -0800 Subject: [PATCH 4/4] Distinguish Node PTY and .NET timeout enforcement 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. --- docs/backends/process-container/process-termination.md | 6 ++++-- docs/schema.md | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/backends/process-container/process-termination.md b/docs/backends/process-container/process-termination.md index f6512f434..ff8b0a689 100644 --- a/docs/backends/process-container/process-termination.md +++ b/docs/backends/process-container/process-termination.md @@ -2,7 +2,7 @@ > **Audience:** MXC consumers and developers -This page describes how the native Windows ProcessContainer runner waits, what a timeout means, and what is still running when `wait` returns. The request field is `process.timeout`. These statements are for that blocking `wait`. They do not describe every SDK wrapper. The [Node V1 API](../../api-reference/node/v1/api.md) is the exception called out below. +This page describes how the native Windows ProcessContainer runner waits, what a timeout means, and what is still running when `wait` returns. The request field is `process.timeout`. These statements are for that blocking `wait`. In-process Node handles, Node ProcessContainer PTY, and .NET handles apply the same field differently. Those differences are in the next section. ## Waiting for the command @@ -10,7 +10,9 @@ This page describes how the native Windows ProcessContainer runner waits, what a - 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. -- Node and .NET `MxcProcess` handles measure a positive timeout, including `4294967295`, from handle creation. That value is a finite timeout on those handles. `try_wait` only polls the root and does not enforce the timeout. +- 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. When a finite wait expires inside blocking `wait`, the run result is a timeout (`script timed out after ms`). That result does not, by itself, mean the process tree has exited. diff --git a/docs/schema.md b/docs/schema.md index 10a0f7112..bc2043872 100644 --- a/docs/schema.md +++ b/docs/schema.md @@ -426,7 +426,7 @@ in-container path instead. See `process.timeout` is milliseconds, and what `0` means depends on the backend. -For the native ProcessContainer runner's blocking `wait`, `0` and `4294967295` wait with no deadline, and `1` through `4294967294` are finite. That deadline covers the wait for the command to finish. It does not cover confirming that every descendant has exited after teardown. `try_wait` only polls the root and does not enforce the timeout. Node and .NET `MxcProcess` handles measure a positive value, including `4294967295`, from handle creation, so that value is a finite timeout there. See [ProcessContainer process termination](backends/process-container/process-termination.md). +For ProcessContainer, the value bounds the wait for the command to finish. It does not bound the later teardown wait, and it does not confirm that every descendant has exited. Sentinel values and the Node and .NET handle rules are in [ProcessContainer process termination](backends/process-container/process-termination.md). WSL Container and LXC also treat `0` as no timeout. W365 Agents sends `0` to the service, and the service picks a finite default (normally 300,000 ms). See [W365 Agents](backends/w365agents/w365agents-backend.md).