Repository navigation
[BREAKING] .NET: fix(hyperlight): propagate cancellation and limit execution - #10066
Vincent Biret (baywet) wants to merge 2 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3d6807e7-70a6-4c43-8dc1-7bab20376cd4
There was a problem hiding this comment.
🟡 Changes recommended
The cancellation regression test fails during warm-up under the checked-in serialization configuration, and its unbounded recovery call can hang the test runner if the execution lock leaks.
2 open issues
What changed in this PR
This test-only draft adds regression coverage for cancellation during Hyperlight guest execution and subsequent executor reuse. Production behavior is unchanged; the recorded run currently fails at the cancellation assertion.
Changes:
- Warms up a real JavaScript guest and verifies successful execution.
- Cancels the caller token from a registered host callback and expects cancellation to propagate.
- Adds a follow-up invocation to check executor reuse after cancellation.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.Hyperlight.UnitTests/SandboxExecutorTests.cs |
Adds the guest-execution cancellation and executor-reuse regression test. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 2005a2f87b09
Model: gpt-5.6-sol
Overview
The PR adds a real-sandbox regression test that proves guest entry, triggers caller cancellation from a host callback, and attempts to reuse the executor. Existing finally-based lock release and warm-snapshot restoration are strong lifecycle guards, but the current executor does not observe cancellation after guest execution starts, so the new enabled test deterministically fails. In addition, the test's tool-bearing warm-up requires serialization behavior disabled by the project's normal configuration, which can prevent the intended scenario from being reached at all.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (1 high, 1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: dotnet/tests/Microsoft.Agents.AI.Hyperlight.UnitTests/SandboxExecutorTests.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3d6807e7-70a6-4c43-8dc1-7bab20376cd4
| await Assert.ThrowsAnyAsync<OperationCanceledException>( | ||
| () => executor.ExecuteAsync(snapshot, "call_tool('cancel_run', {});", cancellation.Token)); |


Motivation & Context
Propagate caller cancellation into running Hyperlight guest execution and apply a finite execution limit. Preserve snapshot restoration and executor reuse after cancellation or timeout.
This maintainer-directed draft depends on hyperlight-dev/hyperlight-sandbox#275 and publication of an SDK package containing its cancellation-aware
Runoverload. Keep this PR in draft; the current released-package dependency does not compile the new calls.Description & Review Guide
ExecutionTimeoutSecondsoption with a 30-second default. Preserve caller cancellation, return an unsuccessful result for the configured timeout, and restore the warm snapshot before subsequent use. Bound recovery assertions and provide an explicit reflection-enabled KVM guest-test configuration while retaining ordinary reflection-disabled settings.HyperlightCodeActProviderOptions.ExecutionTimeoutSecondsto an appropriate larger positive value; an unlimited setting is not supported. Native execution and interruption callbacks finish before the execution semaphore is released. Runtime initialization and host tool callbacks cannot be interrupted, so host tools must enforce their own limits.Recorded commands and results, from
dotnetinside Ubuntu x64 SDK containers:Passed, zero warnings/errors. The temporary targets replace the NuGet SDK reference with the locally built upstream API project for validation only.
dotnet test --project tests/Microsoft.Agents.AI.Hyperlight.UnitTests -f net10.0 --no-build --no-restore \ -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets -p:HyperlightGuestTests=truePassed, all 62 tests, no skips.
HYPERLIGHT_RUN_GUEST_TESTS=trueand the built Python guest path were set;/dev/kvmwas passed through to a resource-limited, network-disabled container. This includes caller cancellation and recovery, the 30-second default, and captured one-second limits with recovery for JavaScript and Python/Wasm.dotnet build tests/Microsoft.Agents.AI.Hyperlight.IntegrationTests -f net10.0 --tl:off \ -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets -p:JsonSerializerIsReflectionEnabledByDefault=true dotnet test --project tests/Microsoft.Agents.AI.Hyperlight.IntegrationTests -f net10.0 --no-build --no-restore \ -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets -p:JsonSerializerIsReflectionEnabledByDefault=trueBoth passed: zero build warnings/errors, all 5 real Python/Wasm integration tests, no skips.
Ordinary reflection-disabled unit configuration, without KVM or guest opt-in:
dotnet build tests/Microsoft.Agents.AI.Hyperlight.UnitTests -f net10.0 --tl:off \ -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targets dotnet test --project tests/Microsoft.Agents.AI.Hyperlight.UnitTests -f net10.0 --no-build --no-restore \ -p:CustomAfterMicrosoftCommonTargets=/linked-sdk.targetsBoth passed: zero build warnings/errors, 58 passed, 4 explicitly gated guest cases skipped.
Formatting with the temporary SDK targets supplied through the
CustomAfterMicrosoftCommonTargetsenvironment property:All passed. Formatter output is included in the submitted changes.
Before implementation, the linked-SDK regression run failed for both intended behaviors: cancellation threw no exception, and the 32-second guest returned success instead of timing out. Guest warm-up succeeded. The same original regressions now pass.
Blocked with the current released SDK:
CS1501at both cancellation-awareRuncalls. This remains a draft pending the upstream SDK package release and dependency update. The full Agent Framework solution, Windows execution, and other target frameworks were not run.Related Issue
Related to hyperlight-dev/hyperlight-sandbox#9 and dependent on hyperlight-dev/hyperlight-sandbox#275. This maintainer-directed integration does not close the upstream tracker or duplicate the SDK implementation.
AI Assistance
AI assistance details: Copilot assisted with implementation, tests, documentation, validation, and this PR description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.