Repository navigation
Fix: Build agentop on Windows, and refuse what needs a Unix service - #2048
Conversation
Part of rossoctl#1520. agentop did not build for Windows: 10 calls in 7 files used Unix-only syscalls (Setsid, Kill, Flock, Access). They now go through small helpers with a Unix and a Windows half (proc_unix.go, proc_windows.go): - detached: Setsid, or a new process group with no console. - processAlive: kill -0, or OpenProcess plus GetExitCodeProcess. - terminate, terminateGroup: SIGTERM. On Windows they refuse: there is no SIGTERM, and a killed proxy skips its plugin stops and its ledger and archive flushes. - lockFile: Flock, or LockFileEx. - writable: access(W_OK), or creating and removing a temp file. On Windows, `agentop service`, `setup`, `uninstall` and `update` refuse up front and say to run `cortex --local` in a terminal: they need a service backend, a graceful stop and a way to replace a running .exe, which come later. observe, cost, export, exec, configure claude-code and doctor run. Tests compile on Windows: the test-only Unix calls go through killPID, groupAttr and getsid, and three fixtures single-quote the CA dir in YAML, where a Windows path's backslashes are escapes in double quotes. New tests: the refusal, processAlive, lockFile, writable, terminate. go-ci-windows builds and vets cmd/agentop and runs those tests and the opt-out launch tests. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Michal Jacovi <michal.jacovi@il.ibm.com>
From an independent review: setup also checks the shell profile, a file, with writable. On Windows the temp-file probe failed for a file, so it read as not writable. A file is now opened for appending and closed, which writes nothing; a directory keeps the probe. The processAlive comment states its two differences from kill -0. Test: a writable file reads as writable and is left unchanged. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Michal Jacovi <michal.jacovi@il.ibm.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 17 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The Windows build claim holds. I checked it at ab5c474: base (0847c58) fails GOOS=windows go build ./... in cmd/agentop on the Setsid, Kill, Flock and Access calls. On the head, go build and go vet ./... (tests included) are clean for windows, linux and darwin. On Unix the new helpers do exactly what the code they replace did: processAlive keeps pid > 0 and reads EPERM as gone, terminateGroup keeps the ESRCH tolerance, and lockFile still maps EWOULDBLOCK to held. The full linux go test ./... passes except TestServiceInstall_RefusesABrokenConfig. That test needs a systemd user bus, which my sandbox lacks, and it fails the same way on base. The CI agentop job passes it. The Windows half also looks right: LockFileEx with FAIL_IMMEDIATELY maps ERROR_LOCK_VIOLATION to held, closing the handle releases the lock, and STILL_ACTIVE is checked through a limited-query handle. Refusing service/setup/uninstall/update before dispatch means none of the refusing terminate* paths can be reached from a command that is supposed to run on Windows.
Nits only:
.github/workflows/ci.yaml: the comment abovego-ci-windows(around line 132) still says "agentop does not build yet". This PR adds a step to that job which builds it.- Not part of this PR, but worth noting for the next step:
codexDaemonAliveusesos.Process.Signal(0), which always fails on Windows. Soconfigure codexnever sees a running app-server daemon there. Now thatprocessAliveexists it could be built on that, if the Codex daemon turns out to matter on Windows.
Author: michaljacovi (CONTRIBUTOR association, admin permission on the repo, so maintainer)
Areas reviewed: Go (cmd/agentop platform helpers, call sites, tests), CI/GitHub Actions
Agent/IDE config (.claude/.vscode): none
Commits: 2 commits, all signed-off: yes
CI status: passing (the Windows job's "Build, vet and test cmd/agentop" step succeeded; the test names in its -run regex all exist and have no build constraints)
| @@ -260,7 +260,7 @@ func TestServiceLifecycle_RealLaunchd(t *testing.T) { | |||
| // pid is the supervisor's, and it stays the same while a new proxy takes over. | |||
| // syscall.Kill gets a pid from childPID, which never returns one below 2: kill(2) | |||
There was a problem hiding this comment.
nit: This comment still says syscall.Kill, but the call below is now killPID. It's still accurate on Unix, since killPID is syscall.Kill there, so feel free to leave it.
huang195
left a comment
There was a problem hiding this comment.
I agree with clawgenti's review. On Windows, terminate and terminateGroup refuse, and only service, setup, uninstall and update can get to them. Before dispatch, main refuses all four on Windows. configure codex does not get to terminateGroup either, because codexDaemonAlive is always false on Windows. I found two nits only.
| run: | | ||
| go build ./... | ||
| go vet ./... | ||
| go test -run 'TestRefuseUnsupported|TestProcessAlive|TestLockFile|TestWritable|TestTerminateRefusesOnWindows|TestNoRecordWanted|TestWithRecordOff|TestAddRecordOff' . |
There was a problem hiding this comment.
nit: go test -run with a name that matches no test still exits 0. If someone renames one of these tests, Windows CI stops running it and nobody sees it. You can add -v and check that each name has a --- PASS line, or you can accept the risk.
There was a problem hiding this comment.
Good catch. Fixed in #2050: the step runs with -v, and fails if any listed name has no --- PASS/--- SKIP line, so a renamed test can't drop out silently.
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com
| } | ||
|
|
||
| func alive(pid int) bool { return pid > 0 && syscall.Kill(pid, 0) == nil } | ||
| func alive(pid int) bool { return processAlive(pid) } |
There was a problem hiding this comment.
nit: alive now only calls processAlive. You can remove it and call processAlive directly. This is optional.
There was a problem hiding this comment.
Done in #2050: alive is gone, and its callers use processAlive directly.
Assisted-By: Claude (Anthropic AI) noreply@anthropic.com
Part of #1520. release-binaries.yaml builds windows/amd64 and windows/arm64 too: agentop.exe and cortex.exe (the same profile tags as the other cortex builds), each in its own .zip, named like the other archives (agentop_<tag>_windows_<arch>.zip). They are required like the other archives, listed in checksums.txt, attested, and uploaded with them. The release notes say Windows is a preview. docs/getting-started.md gets the Windows steps: download, check, unzip onto PATH, `cortex --local` in one terminal and `agentop observe` in another, and what does not run there yet. install.sh tells a Windows shell (MINGW, MSYS, Cygwin) to use the .zip instead. Needs #2048: agentop builds for Windows only with it. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Michal Jacovi <michal.jacovi@il.ibm.com>
…p alive Follow-up to #2048 (review nits): - go-ci-windows runs the listed agentop tests with -v, and fails if a name has no "--- PASS" or "--- SKIP" line: `go test -run` passes when a name matches nothing, so a renamed test dropped out silently. - alive was a one-line wrapper for processAlive; the callers use processAlive directly. Part of #1520. Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Michal Jacovi <michal.jacovi@il.ibm.com>
Part of #1520. The first step of the plan in #1520 (comment): compile fixes, so
agentopbuilds and its interactive commands run on Windows.Problem
cmd/agentopdid not build for Windows: 10 calls in 7 files used Unix-only syscalls (Setsid,syscall.Kill,Flock,Access).cmd/cortexalready builds and runs there (#1878).What changed
proc_unix.go,proc_windows.go). Unix behaviour is unchanged.detached:Setsid, or a new process group with no console.processAlive:kill -0, orOpenProcess+GetExitCodeProcess. Two known differences on Windows: another user's process often reads as alive (Unix's EPERM reads as gone), and one that exited with code 259 (STILL_ACTIVE) reads as running.terminate/terminateGroup: SIGTERM. On Windows they refuse (errNoGracefulStop). There is no SIGTERM there, and a killed proxy skips its plugin stops and its ledger and archive flushes. The stop path is blocker 1 in the plan.lockFile:Flock, orLockFileEx.writable:access(W_OK), or on Windows creating and removing a temp file in a directory, and opening a file for appending (setup checks the shell profile file), which writes nothing.agentop service,setup,uninstallandupdateexit 1 and say to runcortex --localin a terminal. They need a service backend, a graceful stop and a way to replace a running.exe, which are later steps.observe,cost,pricing,export,import,tools,exec(including--no-record) andconfigure claude-code.doctorruns, but its fix lines are still Unix ones (install.sh,export PATH); that's for the next step.killPID,groupAttr,sessionAttr,getsidandmkfifo(killpid_*_test.go). Three fixtures single-quote the CA dir in YAML: in a double-quoted string, a Windows path's backslashes are escapes.go-ci-windowsbuilds and vetscmd/agentop, and runs the new tests plus theexec --no-recordlogic tests.Size
30 files, +377 −47. Most files are one-line call-site changes.
How it was tested
go buildandgo vetofcmd/agentop;processAlivewith a live and an exited process,lockFileheld by a second open,writable,terminaterefusing) and the opt-out launch tests pass.configure claude-codeenable/disable andexecenv tests pass natively too. They are not yet in CI, because the remaining failures in those files are Unix test stubs (launchctl, chmod, symlinks).go vetfor linux and darwin; the Unix tests compile.agentop.exe:--versionworks;service statusandupdaterefuse with the message;costwith no proxy says Cortex isn't running;doctorruns and reports.Tested by hand on Windows 11
With
cortex.exe --localandagentop.exebuilt from this branch:cortex.exe --locallistens on 47600, 47601, 47602 and 47604, andGET /v1/sessionsanswers 200.agentop.exe observeconnects to the local Cortex on its own, shows the archived sessions, and navigates.agentop.exe exec -- clauderuns Claude Code through the TLS bridge, and its session is recorded.execprinted that~/.cortex/ca/bundle.crtdoes not exist yet. That is the known Windows trust-bundle gap (see below). Claude Code still worked, because it usesNODE_EXTRA_CA_CERTS, which exec keeps.Not in this PR
update. The stop path needs a design decision.doctor's probes and fix lines for Windows; the remaining Unix-only tests (skips, or Windows forms).install.ps1and a Windows release.zip.release-binaries.yamlstill builds only linux and darwin.core/peerprocfor Windows (process attribution).cmd/agentoppackage root, by name. The subpackages (tui,checklist,updatestatus, …) build and vet there, but their tests don't run yet.agentop setup --help(and the other three with--help) is refused on Windows too.Assisted-By: Claude (Anthropic AI) noreply@anthropic.com