Fix metrics test cancellation race - #1816
Conversation
Cancel the guest from a host callback so metric assertions do not depend on scheduling delays. Fixes #1815 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The updated test expects 5 metrics but does not currently assert all expected metric keys, which can allow incorrect metric emission to slip through.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes flakiness in the host-side metrics test by canceling guest execution deterministically from a host callback, avoiding timing-based sleeps and asserting the expected cancellation error and emitted duration metrics.
Changes:
- Replace time-delayed cancellation (sleep + thread) with a host-function callback that triggers cancellation at a deterministic point.
- Update the test to call
CallHostThenSpinand assertExecutionCanceledByHost. - Extend metrics assertions to include the guest function name change and the new host callback duration metric.
File summaries
| File | Description |
|---|---|
| src/hyperlight_host/src/metrics/mod.rs | Makes the metrics test cancellation deterministic via a host callback and adjusts expected metrics/labels accordingly. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ludfjig
left a comment
There was a problem hiding this comment.
good idea calling kill from a host function (I guess slightly changes behavior in that we don't re-enter the vm rather than interrupt runnign vm, but metric is emitted in either case)
Check HostPrint and CancelGuest histograms so every expected metric key is covered. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
Summary
The metrics test cancels its guest from a host callback. Cancellation targets the intended call without depending on scheduling delays. The test asserts
ExecutionCanceledByHostand the callback duration metric.Fixes #1815.
Validation
function_call_metrics.just fmt-applyandjust clippypass.