Skip to content

Report a timeout after ExecSandboxProcess::kill_for_timeout - #1929

Open
adpa-ms wants to merge 3 commits into
mainfrom
user/adibpa/copilot-exec-timeout-outcome
Open

adpa-ms wants to merge 3 commits into
mainfrom
user/adibpa/copilot-exec-timeout-outcome

Conversation

@adpa-ms

@adpa-ms adpa-ms commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

📖 Description

SandboxProcess::kill_for_timeout promises that a later exit is reported as a timeout. ExecSandboxProcess, which backs container lifecycle executions, kept the trait's default, a plain kill. So when the Node SDK's own deadline fired first, Node reported timedOut: true with the killed process's exit code instead of -1. With telemetry active, the engine's wrapper already reported a timeout.

ExecSandboxProcess now records the request before it kills, and reports any later exit as ErrorKind::TimedOut, even after a refused kill. A timeout the backend reports and a waiter failure are unchanged. Only callers of kill_for_timeout see a difference, and Node is the only SDK that calls it. .NET's deadline calls Kill() instead (#1896).

W365 cannot end a remote process, and its design forbids reporting a timeout without evidence that the remote command stopped. So W365 keeps a plain timeout kill, and behaves as before.

🔗 References

Fixes #1895

🔍 Validation

  • Trial run of the isolation-session jobs on five Windows platforms, x64 and arm64: 9 of 10 passed. The tenth failed only the post-exit output check ([IsolationSession] Output still being relayed after the workload exits is dropped when delivery stalls for 5 seconds #1898), which never requests a timeout kill.
  • state_aware_exec_killed_for_a_caller_timeout_reports_a_timeout (src/mxc-sdk/tests/isolation_session.rs) runs a real IsolationSession exec without the engine's telemetry wrapper, which reports the timeout itself when telemetry is active. In a release build it passed 10 of 10 runs, and failed 4 of 4 with exit code 1 when the override was disabled.
  • native_execution_failure_and_disposal_fixture (src/mxc-sdk/tests/w365_lifecycle/execution.rs) expects a W365 exit received before a refused kill_for_timeout to stay an exit, and fails with TimedOut if W365 uses ExecSandboxProcess::from_exec_handle. It passes in all seven W365 fixture jobs; builds that collect telemetry skip the case.
  • cargo test -p mxc-sdk --lib exec_stream passes, and fails if any part of the override is removed or reordered, or if waiter failures become timeouts.

✅ Checklist

📋 Issue Type

  • Bug fix
Microsoft Reviewers: Open in CodeFlow

ExecSandboxProcess kept the trait's default kill_for_timeout, a plain
kill, so an exec that its caller's deadline ended reported the killed
process's exit code. Record the request, then kill, and report an exit
observed afterwards as ErrorKind::TimedOut with the message "sandbox
execution timed out", the text TelemetryProcess uses: the kill may have
been refused, so the message claims no termination. A timeout the
backend reports and a waiter failure are unchanged.

Verified: cargo fmt --all -- --check; cargo clippy -p mxc-sdk
--all-targets --all-features --locked -- -D warnings; cargo test -p
mxc-sdk --lib --locked exec_stream; a mutation check, 7 of 7 mutations
detected; Build run 47223511072; trial run 47223712482, where 9 of 10
isolation-session jobs passed and the other failed only the post-exit
output check (#1898).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2a155d40-78af-49e8-a116-b24a41698eb7
@adpa-ms
adpa-ms requested a review from a team as a code owner December 4, 2026 00:22
Copilot AI max review requested due to automatic review settings December 4, 2026 00:23
@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

Timeout handling can replace confirmed or already-observed exit results with TimedOut, breaking SDK behavior, and lacks deterministic caller-deadline regression coverage.

3 open issues
What changed in this PR

Updates lifecycle execution timeout reporting to address the Node SDK exit-code inconsistency in #1895.

Changes:

  • Records timeout requests before termination and reports subsequent exits as timeouts.
  • Adds regression tests for accepted and refused kills, repeated waits, and preserved waiter failures.
File Description
src/​mxc-sdk/​src/​core/​mxc_common/​exec_stream.rs Adds timeout tracking, result classification, and regression tests.

Review effort: Max

state_aware_exec_killed_for_a_caller_timeout_reports_a_timeout builds
an exec's ExecSandboxProcess from the IsolationSession backend as the
engine does, without the engine's telemetry wrapper, requests a timeout
kill, and expects ErrorKind::TimedOut. Release builds route telemetry,
and with it active the wrapper reports the timeout itself, so a test
through the public API passes without the override.

Verified on a development host with IsolationSession, in a release
build: the test passed 10 of 10 runs, and failed 4 of 4 with exit code
1 with the override's request recording disabled; isolation_session.rs
passed; cargo fmt --all -- --check; cargo clippy -p mxc-sdk
--all-targets --all-features --locked -- -D warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2a155d40-78af-49e8-a116-b24a41698eb7
Copilot AI max review requested due to automatic review settings December 4, 2026 02:16

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 regression test can falsely pass when timeout termination fails to stop ping, because the wait can reach the workload’s natural exit.

1 open issue
3 resolved since last review

Review effort: Max

Comment thread src/mxc-sdk/tests/isolation_session.rs Resolved

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

A critical SDK regression can silently discard queued process output when timeout handling cancels readers after exit.

1 open issue
1 resolved since last review

Review effort: Max

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

Reporting TimedOut after W365 refuses a timeout kill conflicts with its documented remote-termination requirement, requiring maintainers and W365 owners to approve the compatibility tradeoff.

No open issues 🎉

1 resolved since last review

Review effort: Max

@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.

Summary

Requesting changes for finding 1 from the review of 17767b5. The same W365 case is already discussed in this inline thread; this review references it rather than adding a duplicate inline comment.

High — SDK breaking change: preserve W365's confirmed remote exit

Location: src/mxc-sdk/src/core/mxc_common/exec_stream.rs:375

Attribution: introduced_by_change on the telemetry-inactive path. The new timeout_requested conversion changes a successful W365 terminal result that the base adapter preserved.

A Rust caller can obtain a MxcProcess through v1::dev::spawn_in_container_json. If W365 has published a genuine remote EXIT before the caller's deadline expires, but the adapter has not consumed it, kill_for_timeout() returns remote_termination_unsupported. After the caller handles that refusal, wait() previously returned WaitResult::Exited(code); it now returns WaitResult::TimedOut, discarding the confirmed remote result.

I have considered the author's response: the generic timeout method promises permanent timeout classification, telemetry-active execution already behaved this way, and Node/.NET do not start their managed W365 deadline. The objection is specifically the existing W365 contract: local deadlines must not produce WaitResult::TimedOut without evidence of remote timeout termination. This patch newly applies the conflicting behavior with telemetry inactive as well.

The Rust path is part of the existing supported surface: V1 Dev spawn returns MxcProcess, the V1 reference lists kill_for_timeout(), and the versioning policy includes V1.Dev and process handles in supported V1. #[doc(hidden)] and experimental backend opt-in do not remove that callable path.

Fix: Preserve W365's backend-reported exit after a refused timeout kill while keeping the intended timeout behavior for locally terminable backends. Add a fixture regression for remote EXIT followed by timeout-kill refusal and final wait, explicitly with telemetry inactive.

Verified clean and validation

  • cargo test -p mxc-sdk --lib --locked exec_stream passed: 34 tests, including the new timeout classification tests.
  • cargo fmt --all -- --check passed.
  • The added real-backend regression compiled, but explicitly skipped locally because IsolationSession is unavailable on this host. The W365 ordering above was verified through source and contract inspection, not a live-W365 reproduction.
  • Rechecked the PR merge-base/head diff and confirmed line 375 is newly added. Supporting W365 implementation and contract/API references are byte-identical across that range.

Verified pre-existing — not attributed to this PR

  • The telemetry-active wrapper already reclassifies this W365 outcome; that pre-existing behavior is not a second blocker attributed to this patch.
  • Generic cached-exit reclassification follows the timeout method's documented contract and is not included as a finding.

Only finding 1 is submitted; the optional Low test-watchdog suggestion is excluded.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. label Dec 4, 2026
W365 cannot end a remote process, and its design forbids reporting a
timeout without evidence that the remote command stopped, so a W365
exit received before a refused kill_for_timeout must stay an exit.
ExecSandboxProcess::from_unkillable_exec_handle wraps a handle whose
terminator cannot end the process: its kill_for_timeout records no
timeout request. The engine's W365 exec path uses it, so W365 behaves
as it did before the override; other backends keep it.

native_execution_failure_and_disposal_fixture now has W365 deliver an
exit before a refused kill_for_timeout and expects wait() to return
that exit. The case runs only in builds that collect no telemetry:
where telemetry is collected, the engine's telemetry wrapper reports
the exit as a timeout.

Verified: the fixture test failed with TimedOut on 17767b5 and passes
with this change, in a debug build, which runs the case, and in a
release build, which collects telemetry and skips it; cargo fmt --all
-- --check; cargo clippy -p mxc-sdk --all-targets --all-features
--locked -- -D warnings; cargo test -p mxc-sdk --lib --locked
exec_stream; a mutation check, 9 of 9 mutations detected; no new
rustdoc warnings in the changed files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 2a155d40-78af-49e8-a116-b24a41698eb7
@adpa-ms

adpa-ms commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

[AgentAssisted] Fixed in 2dd6f48. W365 keeps a plain timeout kill, so an EXIT it received before a refused kill_for_timeout is reported as that exit, as on main; backends whose kill ends the process keep the timeout classification. native_execution_failure_and_disposal_fixture now covers the case: after the fixture's EXIT, kill_for_timeout() returns remote_termination_unsupported and wait() returns Exited(7), where 17767b5 returned TimedOut. It runs only in builds that collect no telemetry; release builds that collect it, such as the Windows workspace test jobs, skip it.

@microsoft-github-policy-service microsoft-github-policy-service Bot added Needs-Attention Requires attention or a decision from the MXC maintainers. and removed Needs-Author-Feedback Waiting for additional information or action from the issue or pull-request author. labels Dec 5, 2026
@adpa-ms
adpa-ms requested review from Gudge (MGudgin) and a max review from Copilot December 5, 2026 03:12

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

Cross-runtime changes to Rust/Node V1 timeout results and a telemetry-dependent W365 exception need maintainer consensus after P0 SDK-compatibility concerns were declined.

No open issues 🎉

Review effort: Max

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

Needs-Attention Requires attention or a decision from the MXC maintainers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A timeout enforced by the Node SDK can report the killed process's exit code

3 participants