Repository navigation
fix: Windows spored monitor stops promptly on cancel; make check passes on macOS (#1104, #1060) - #1172
Merged
Conversation
…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
force-pushed
the
fix/1104-1060-ci-health
branch
from
October 19, 2026 05:42
ed6aed4 to
92559cf
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1104
Fixes #1060
#1104: Monitor took ~14s to return after cancel on Windows
Cause: every Windows reader used
exec.Commandwith no context:psOutput(CPU, network, disk, process, port-connection samples),quser, andmsg.exeinsysWarnUsers. Since #1095 every tick evaluates idleness, so every tick starts several coldpowershell -NoProfileprocesses, andMonitorcan't return until they finish. The accelerator (nvidia-smiand the others) and DCV probes on the idle path also tookcontext.Background()instead of the tick's context.Fix: all OS probes in
pkg/agentnow go throughprobeOutput(pkg/agent/sysprobe.go). It usesexec.CommandContextwith the caller's context, a 30s per-call timeout (sysProbeTimeout) so a wedged WMI query can't hold a tick, andWaitDelay, so a grandchild that inherited the stdout pipe can't stallOutput()after the kill. The context is threaded through the idle chain:sampleIdleSignals,idleDecision, the session, process and port counters,gpuUtilization,getDCVConnectionCount,warnUsersandEvaluateIdle(ctx). Linuxwho,pgrepandwallget the same treatment. Exceptions:runPreStoppassescontext.Background()towarnUsers. Itsctxis shadowed by the hook's timeout context, which may already have expired, and pre-stop runs whether or not the context was cancelled, matching itsnotifiercalls.GetTerminalCount/GetLoggedInUserCounthave no context in their interface, so they use Background, still bounded by the probe timeout.spored statususes Background.The test's 10s wait is unchanged.
Tests:
TestProbeOutput_StopsWhenContextCancelled,_TimesOutand_GrandchildHoldingPiperun 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 PowerShellStart-Sleep 60, cancelled after 1s.TestNoContextlessExecInAgent: AST scan of every non-test file inpkg/agent, all GOOSes (parsed, not built). It resolves theos/execimport name per file and fails on any<exec>.Command(call. Discovery fails if it parsed nothing, found noCommandContext, or didn't see all threesys_*.gofiles.Watched failing against compiling reverts:
probeCmdback toexec.Command(name, args...)(with_ = ctx)cmd.WaitDelaydropped (_ = sysProbeWaitDelay)GrandchildHoldingPipeFAILSsampleIdleSignalspassingcontext.Background()tocpuUsageTestMonitor_CancelReachesIdleReadersFAILS ("did not return within 5s")quserback toexec.Command("quser").Output()insys_windows.go(vetted with GOOS=windows)sys_windows.go:116osexec "os/exec"+osexec.Command("nvidia-smi", …)inmetrics.gometrics.go:75Not verified: I couldn't run Windows locally. Windows is covered by
GOOS=windows go vet ./...andGOOS=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 checkfailed on macOS (staticcheck SA4023)The non-Linux
sysMountLustrestubs built a fresh error, so on darwin and windows staticcheck could prove the function never returns nil and flaggedfsx_mount.go'serr != nilas constant. Both stubs now return a named sentinel,errLustreUnsupported, declared in a//go:build !linuxfile (on Linux it would be unused, U1000). Unlike runningcheck-staticcheckwithGOOS=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_FailsOffLinuxpins the stub's contract: off Linux the mount fails with that error and never reports success.Checks
GOTOOLCHAIN=go1.26.9 make checkpasses every step (fmt, vet, GOOS vet, staticcheck on darwin, hermetic tests, nested modules, tidy) exceptcheck-build-tags. That step also fails on unmodifiedorigin/mainin a fresh worktree, with the same 35 files under/private/tmp/..., so it's local-only noise.semgrep scan --config=auto --erroron the changed files is clean. The test helper'sexec.Commandhas a justifiednosemgrep.go test -raceon the new and adjacent tests passes.