Skip to content

fix: Windows spored monitor stops promptly on cancel; make check passes on macOS (#1104, #1060) - #1172

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/1104-1060-ci-health
Oct 19, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/1104-1060-ci-health

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1104
Fixes #1060

#1104: Monitor took ~14s to return after cancel on Windows

Cause: every Windows reader used exec.Command with no context: psOutput (CPU, network, disk, process, port-connection samples), quser, and msg.exe in sysWarnUsers. Since #1095 every tick evaluates idleness, so every tick starts several cold powershell -NoProfile processes, and Monitor can't return until they finish. The accelerator (nvidia-smi and the others) and DCV probes on the idle path also took context.Background() instead of the tick's context.

Fix: all OS probes in pkg/agent now go through probeOutput (pkg/agent/sysprobe.go). It uses exec.CommandContext with the caller's context, a 30s per-call timeout (sysProbeTimeout) so a wedged WMI query can't hold a tick, and WaitDelay, so a grandchild that inherited the stdout pipe can't stall Output() after the kill. The context is threaded through the idle chain: sampleIdleSignals, idleDecision, the session, process and port counters, gpuUtilization, getDCVConnectionCount, warnUsers and EvaluateIdle(ctx). Linux who, pgrep and wall get the same treatment. Exceptions:

  • runPreStop passes context.Background() to warnUsers. Its ctx is shadowed by the hook's timeout context, which may already have expired, and pre-stop runs whether or not the context was cancelled, matching its notifier calls.
  • The metrics collector's GetTerminalCount/GetLoggedInUserCount have no context in their interface, so they use Background, still bounded by the probe timeout.
  • The one-shot spored status uses Background.

The test's 10s wait is unchanged.

Tests:

  • TestProbeOutput_StopsWhenContextCancelled, _TimesOut and _GrandchildHoldingPipe run on every OS. The slow child is the test binary itself, re-run as a sleeping helper.
  • TestMonitor_CancelReachesIdleReaders: a CPU reader that blocks until its own context ends. Monitor must return within 5s of cancel.
  • TestPsOutput_StopsWhenContextCancelled (Windows only): real PowerShell Start-Sleep 60, cancelled after 1s.
  • Gate TestNoContextlessExecInAgent: AST scan of every non-test file in pkg/agent, all GOOSes (parsed, not built). It resolves the os/exec import name per file and fails on any <exec>.Command( call. Discovery fails if it parsed nothing, found no CommandContext, or didn't see all three sys_*.go files.

Watched failing against compiling reverts:

revert result
probeCmd back to exec.Command(name, args...) (with _ = ctx) all 3 probe tests FAIL at 7s
cmd.WaitDelay dropped (_ = sysProbeWaitDelay) GrandchildHoldingPipe FAILS
sampleIdleSignals passing context.Background() to cpuUsage TestMonitor_CancelReachesIdleReaders FAILS ("did not return within 5s")
quser back to exec.Command("quser").Output() in sys_windows.go (vetted with GOOS=windows) gate FAILS naming sys_windows.go:116
aliased osexec "os/exec" + osexec.Command("nvidia-smi", …) in metrics.go gate FAILS naming metrics.go:75

Not verified: I couldn't run Windows locally. Windows is covered by GOOS=windows go vet ./... and GOOS=windows go test -c ./pkg/agent/, and the Windows-only test runs for the first time in this PR's Test (Windows) job. I haven't measured whether one tick's work now fits comfortably under the 10s wait on the runner. If it still flakes, the next step is the issue's "one PowerShell process per tick".

#1060: make check failed on macOS (staticcheck SA4023)

The non-Linux sysMountLustre stubs built a fresh error, so on darwin and windows staticcheck could prove the function never returns nil and flagged fsx_mount.go's err != nil as constant. Both stubs now return a named sentinel, errLustreUnsupported, declared in a //go:build !linux file (on Linux it would be unused, U1000). Unlike running check-staticcheck with GOOS=linux, this doesn't narrow anything: staticcheck ./... now passes in full for darwin, windows and linux. CI is unchanged and still runs it on linux, unconditionally. TestSysMountLustre_FailsOffLinux pins the stub's contract: off Linux the mount fails with that error and never reports success.

Checks

  • GOTOOLCHAIN=go1.26.9 make check passes every step (fmt, vet, GOOS vet, staticcheck on darwin, hermetic tests, nested modules, tidy) except check-build-tags. That step also fails on unmodified origin/main in a fresh worktree, with the same 35 files under /private/tmp/..., so it's local-only noise.
  • semgrep scan --config=auto --error on the changed files is clean. The test helper's exec.Command has a justified nosemgrep.
  • go test -race on the new and adjacent tests passes.

…es on macOS (#1104, #1060)

processes and port connections; quser) and the msg.exe warning used
exec.Command with no context, so Monitor could not return until a tick's
in-flight PowerShell processes finished (~14s on the Windows runner, which
failed TestMonitor_SpotDetectionDoesNotGateTicker's 10s wait). All OS probes
in pkg/agent now go through probeOutput: exec.CommandContext bound to the
caller's context plus a 30s per-call timeout, with WaitDelay so a grandchild
holding the pipe cannot stall the wait. The context is threaded through the
idle chain (sampleIdleSignals, idleDecision, the session/process/port counts,
gpuUtilization, getDCVConnectionCount, warnUsers, EvaluateIdle). Linux who,
pgrep and wall get the same treatment.

New tests: probe cancel/timeout/grandchild-pipe via a helper child process
(all OSes); Monitor returns within 5s when cancelled mid-tick with a blocking
CPU reader; a real-PowerShell cancel test on Windows; and
TestNoContextlessExecInAgent, an AST gate over every GOOS's files in pkg/agent
that rejects exec.Command (import alias resolved).

(errLustreUnsupported, non-Linux file) instead of building one, so staticcheck
no longer reads the caller's err != nil as constant (SA4023). staticcheck now
passes in full for darwin, windows and linux; nothing was narrowed to Linux.

Fixes #1104
Fixes #1060
@scttfrdmn
scttfrdmn force-pushed the fix/1104-1060-ci-health branch from ed6aed4 to 92559cf Compare October 19, 2026 05:42
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.43243% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/agent.go 77.77% 9 Missing and 1 partial ⚠️
pkg/agent/sys_linux.go 72.72% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ce46ff1 into main Oct 19, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1104-1060-ci-health branch October 19, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant