You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pkg/agent: Monitor takes ~14s to return after cancel on the Windows runner, so #1102's 10s wait in TestMonitor_SpotDetectionDoesNotGateTicker fails #1104
Seen: Test (Windows) on PR #1103, which doesn't touch pkg/agent (run 39083879825, job 117546278626):
--- FAIL: TestMonitor_SpotDetectionDoesNotGateTicker (10.04s)
agent_test.go:656: Monitor did not return after its context was cancelled
#1102 (merged about an hour earlier) added that 10s wait for Monitor to return in the test's cleanup.
Timeline from the same log (shared log output):
~00:46:57: the test body ends and cleanup calls cancel();
00:47:07: the 10s wait gives up and the test fails;
00:47:07: monitor tick 1, then TTL expired … Terminating instance … Running cleanup tasks … Cleanup complete … Warning sent to users;
00:47:11: Context cancelled, stopping monitor.
So Monitor did return, but about 14s after cancellation. Either a tick already in flight runs work that doesn't watch the context, or the warning/cleanup path is slow on Windows. Both are plausible from the log; I haven't established which.
Why it matters beyond the test: spored's shutdown waits on this loop. If a tick can delay cancellation by 10+ seconds on Windows, that delay also exists on real Windows spores.
Options: make the tick's work honour the context (the real fix, if that's the cause), or give the test a wait that reflects Monitor's worst-case tick on Windows. Rerunning CI to get past it is not a fix.
I'm re-running the job for #1103, since this code isn't touched there.
Recurring: it failed again on #1083, a docs-only PR (job 117557620705), the same way. That's 2 of the last 3 Windows runs I've seen.
Likely mechanism, from the code (not yet measured):
Monitor exits only between ticks: select { case <-ctx.Done(): return; case <-ticker.C: a.checkAndAct(ctx) } (pkg/agent/agent.go:546). So it can't return until a checkAndAct already in flight finishes.
On Windows, every metric reader shells out to a freshpowershell -NoProfile process (psOutput, pkg/agent/sys_windows.go:26, using exec.Command, not CommandContext), or to quser / msg. None of them take the context, and a PowerShell cold start on a CI runner is seconds. A tick that runs several readers can plausibly exceed 10s.
Effect on a real Windows spore: shutdown, hibernate prep and ResumeStopped wait on the loop, so each can stall by the length of one tick.
Fix shape: make the Windows readers context-aware (exec.CommandContext with the tick's context). Better still, take every Windows sample from a single PowerShell process per tick rather than one process per reader. Raising the test's wait would hide the cost, not remove it.
Activity
scttfrdmn commentedon Oct 18, 2026
Recurring: it failed again on #1083, a docs-only PR (job 117557620705), the same way. That's 2 of the last 3 Windows runs I've seen.
Likely mechanism, from the code (not yet measured):
Monitorexits only between ticks:select { case <-ctx.Done(): return; case <-ticker.C: a.checkAndAct(ctx) }(pkg/agent/agent.go:546). So it can't return until acheckAndActalready in flight finishes.powershell -NoProfileprocess (psOutput,pkg/agent/sys_windows.go:26, usingexec.Command, notCommandContext), or toquser/msg. None of them take the context, and a PowerShell cold start on a CI runner is seconds. A tick that runs several readers can plausibly exceed 10s.--idle-timeout(to publishidle-state.json), then every tick now runs those PowerShell readers. Before, a test with an empty config barely shelled out at all. Worth confirming: runcheckAndActonce on the Windows runner and time it.Effect on a real Windows spore: shutdown, hibernate prep and
ResumeStoppedwait on the loop, so each can stall by the length of one tick.Fix shape: make the Windows readers context-aware (
exec.CommandContextwith the tick's context). Better still, take every Windows sample from a single PowerShell process per tick rather than one process per reader. Raising the test's wait would hide the cost, not remove it.fix: Windows spored monitor stops promptly on cancel; make check pass…