Repository navigation
Fix: Build cmd/cortex and keep the session archive and cost ledger on Windows - #1878
Conversation
StartSignalToggle used syscall.SIGUSR1, which Windows does not define, so core/bootstrap and every binary that imports it (cmd/cortex) failed to compile with GOOS=windows. Move the toggle to signaltoggle_unix.go and add a no-op for !unix: on Windows the log level stays at what LOG_LEVEL set. The test that sends SIGUSR1 moves with it, to signaltoggle_unix_test.go, so the package's tests also build on Windows. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
On Windows the archive kept nothing. createSegment fsyncs the session directory after creating a segment, and the fsync failed with "Access is denied": os.Open gives a read-only handle, and Windows flushes a directory only through a handle opened for writing with FILE_FLAG_BACKUP_SEMANTICS. So every new segment was removed again and every event was lost. The cost ledger's syncDir failed the same way, so the first append of each day logged "costledger: append failed". Both packages now open the directory through openDir: os.Open on every other platform, and CreateFile with those flags on Windows (syncdir_windows.go). FlushFileBuffers on that handle succeeds as a normal user, so the directory is flushed rather than skipped. The ledger's mergeDayFiles removed its source while the source was still open (the Close was deferred), and Windows will not remove an open file. So a prune that merged a condemned day file back failed and left the file to be judged again. It now closes the source before removing it. A rename (Rekeyed) then failed too: it moves the session directory while the session's segment is still open, and Windows will not rename a directory with an open file in it. The history stayed under the old id until the next start. On Windows the segment is now closed first, and the next event opens a new one under the new directory. A reader that holds a segment open (a Page read) still makes a rename or a delete fail there: the rename falls back to the old directory until the next start, and the delete reports the error. Tests: the two tests that make a clear or a delete fail by a read-only root now hold a segment open instead on Windows, where the permission is ignored. Four tests read or set Unix permission bits (the archive's and the ledger's file modes, and a read-only data directory) and now skip on Windows. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
…ger there Add go-ci-windows on windows-latest. It builds all of core and cmd/cortex with the local profile, and vets and tests core/bootstrap, core/session/archive and core/cost/ledger, the packages fixed for Windows. It does not run the rest of core or cmd/cortex's tests: some of them still use Unix-only APIs (Setpgid, SIGUSR1). cmd/agentop does not build on Windows yet. The job runs without -race, because the race detector needs cgo and a C toolchain on the runner. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…dows rejects go-ci-windows failed in actions/checkout, before the build: "invalid path '.claude/skills/orchestrate:ci/SKILL.md'". .claude/skills has directories with a colon in their names, which Windows cannot create, and Git for Windows refuses such paths in the index (core.protectNTFS), even as skip-worktree entries of a sparse checkout. The job's checkout is now sparse (non-cone: everything but .claude/), and its step sets core.protectNTFS=false through GIT_CONFIG_COUNT/KEY/VALUE. actions/checkout copies the step's environment into every git call it makes, so the setting applies to its fetch and checkout and to nothing after them. Nothing under .claude/ is written to disk, and the job does not need it. Reproduced on Windows with the action's own sequence (init, a blob:none fetch, core.sparseCheckout with the patterns appended to info/sparse-checkout, then checkout --force -B). The sparse checkout alone fails with the same error. Adding the GIT_CONFIG_* variables makes it succeed, with a clean status and no .claude/ directory. A later plain git status, which go build's VCS stamping runs, works without the variables. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
A careful, well-documented Windows port: the build-tag signal toggle, the openDir CreateFile/FILE_FLAG_BACKUP_SEMANTICS directory flush, close-before-remove in mergeDayFiles, and close-before-rename are all correct, Unix behavior is unchanged (openDir is exactly os.Open on non-Windows), and the test skips are justified (mode bits read back as 0666 on Windows) rather than regression-hiding. Supply-chain-wise the workflow change is clean: both actions pinned by full SHA matching the rest of the file, permissions: contents: read, no secrets, no pull_request_target.
One must-fix (CI): the new go-ci-windows job cannot ever go green as written — it fails at actions/checkout before any Go command runs, because the repo tracks .claude/skills/orchestrate:ci/SKILL.md (and 7 sibling orchestrate:* colon-named paths), and : is reserved in NTFS paths, so git cannot check out the repo on Windows at all. The job's build/vet/tests are skipped, which means this PR's Windows claims (the openDir fix, the rename close, the test skips) are currently unverified by CI. Adding a sparse-checkout excluding .claude to this job would fit inside this PR; renaming the colon-named skill directories repo-wide is the fuller fix but belongs elsewhere.
The rest are suggestions/nits.
Author: michaljacovi (FIRST_TIME_CONTRIBUTOR — first-time; highest scrutiny applied, every changed file read in full)
Areas reviewed: Go (core/bootstrap, core/session/archive, core/cost/ledger), CI workflow, tests
Agent/IDE config (.claude/.vscode): none changed by the PR (repo's pre-existing .claude/ paths noted in the CI finding above)
Commits: all signed-off: yes
CI status: failing — new Go CI (Windows build, archive and ledger) job (see must-fix); all other checks pass
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| # and cmd/cortex still have Unix-only tests (Setpgid, SIGUSR1), and agentop does not build | ||
| # yet. No -race: the race detector needs cgo and a C toolchain on the runner. | ||
| go-ci-windows: | ||
| name: Go CI (Windows build, archive and ledger) |
There was a problem hiding this comment.
must-fix — The go-ci-windows job fails at the checkout step, before any Go command runs: job annotations show git.exe ... exit code 128 and invalid path '.claude/skills/orchestrate:ci/SKILL.md'. The repo tracks 8 colon-named paths under .claude/skills/orchestrate:* (verified via the git tree API on main), and : is a reserved character in NTFS paths, so git cannot check out this repository on Windows at all. Consequence: this job's vet/tests are skipped, so the PR's Windows behavior is unverified by CI. Suggested fix: add a sparse-checkout to this job excluding .claude (e.g. git sparse-checkout set --no-cone '/*' '!/.claude' after checkout, or actions/checkout with sparse-checkout config), or rename the orchestrate:* skill directories repo-wide in a separate PR. Why it matters now: the job as added can never go green, so it gates the merge of the very change that introduced it.
| // first; the next event opens a new one under newDir. A reader that holds a segment open | ||
| // (a Page read) still makes the rename fail there: the history then stays in the old | ||
| // directory, under the new id, until adopt moves it at the next start. | ||
| if runtime.GOOS == "windows" { |
There was a problem hiding this comment.
suggestion — This change uses a runtime.GOOS == "windows" runtime check while the rest of the PR splits behavior with build-tag files (openDir, signaltoggle). A closeWriterBeforeRename helper behind build tags (like openDir) would be more idiomatic and keeps the hot path branch-free. Behavior is correct as written — closeWriter syncs and closes before writeMeta and os.Rename, and the existing adopt-at-next-start fallback covers a failed rename — so cosmetic only.
| // through a handle opened for writing with FILE_FLAG_BACKUP_SEMANTICS. os.Open gives a | ||
| // read-only handle, and Sync on it fails with "Access is denied". | ||
| func openDir(dir string) (*os.File, error) { | ||
| p, err := syscall.UTF16PtrFromString(dir) |
There was a problem hiding this comment.
nit — openDir is duplicated across core/session/archive and core/cost/ledger (you flagged this in the PR body and offered to extract a shared helper — reasonable either way for ~20 lines). Also: the syncdir files split on !windows while signaltoggle splits on !unix (so js/wasip1/plan9 take the os.Open fallback for syncdir but the no-op signal toggle). Harmless on those targets; picking one convention would read better.
| } | ||
| } | ||
|
|
||
| // blockRenames makes a rename that creates an entry in root, or that moves sessionDir, fail |
There was a problem hiding this comment.
nit — blockRenames holds only the first .jsonl.zst open on Windows. Sufficient for the current tests (one segment each) but brittle if a test grows a second segment. Also noted: openDir's GENERIC_WRITE means a directory flush now needs write access to the directory on Windows (POSIX fsyncs through a read-only handle); not reachable in practice since you must create a file in the dir to need the flush.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The code changes hold up. Against base, GOOS=windows go build ./... in core fails (undefined: syscall.SIGUSR1). At head, core and cmd/cortex (local profile tags) build for windows, linux and darwin. GOOS=windows go vet passes for bootstrap, session/archive and cost/ledger, and their windows test binaries compile. On Linux, go test -race passes for bootstrap and session/archive, including the new blockRenames path. cost/ledger has one failure, TestMidnightTransitions_EveryFixtureIsStillTheDayItClaimsToBe (America/Havana). It fails the same way on base, from this host's tzdata, so it is unrelated. The Windows-only rename close is consistent with deleteSession and clearAll, which already close the writer before their renames, and the mergeDayFiles close-before-unlink is correct.
One must-fix: the new go-ci-windows job never gets past checkout, so the regression guard this PR adds does not run (details inline).
Author: michaljacovi (FIRST_TIME_CONTRIBUTOR, repo permission admin, so maintainer)
Areas reviewed: Go (bootstrap, session archive, cost ledger), CI/GitHub Actions, Docs
Agent/IDE config (.claude/.vscode): none (.github/CLAUDE.md is docs only)
Commits: 3 commits, all signed-off: yes
CI status: failing. Go CI (Windows build, archive and ledger) fails at checkout. Everything else passes.
| env: | ||
| GOWORK: "off" | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
There was a problem hiding this comment.
must-fix: This job fails at checkout on windows-latest (run 43892862124, job 133388433716): invalid path '.claude/skills/orchestrate:ci/SKILL.md', then git exits with 128. The tree has ten paths with : under .claude/skills/ (orchestrate:ci, orchestrate:plan, ..., skills:validate). Git for Windows (core.protectNTFS) refuses to create them, so setup-go, the build, vet and the tests are all skipped. The guard against regressions never runs.
A sparse checkout of just what the job uses avoids those paths:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# The tree has paths Windows cannot create (.claude/skills/orchestrate:ci/...);
# check out only what this job builds.
sparse-checkout: |
core
cmd/cortex
scripts/profile-tagsI checked a cone-mode sparse checkout of those three directories at this head. GOOS=windows go build ./... and go vet for the three packages in core pass, and so do go -C ../../scripts/profile-tags run . local and the tagged go build in cmd/cortex. I could not run it on a Windows runner, so please confirm the job goes green. The other route is renaming the skill directories, but that is a larger change outside this PR's scope.
clawgenti
left a comment
There was a problem hiding this comment.
Tracking marker for the review above (#pullrequestreview-5922562700, which omitted this marker).
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Windows build/test support for core, cmd/cortex, the session archive and the cost ledger. The signal-toggle split into unix/!unix build-tagged files, the openDir abstraction for Windows directory flush, the eager close before os.Remove in mergeDayFiles, and the platform-aware blockRenames test helper are all correct and well-commented. No blocking issues found.
Author: michaljacovi (FIRST_TIME_CONTRIBUTOR — first-time; every changed file read in full per the elevated-scrutiny rule)
Areas reviewed: Go (core/bootstrap, core/cost/ledger, core/session/archive), CI (GitHub Actions), docs (.github/CLAUDE.md)
Agent/IDE config (.claude/.vscode): none. Note: .github/CLAUDE.md is a repo docs file, not an agent-config file; the sparse-checkout that excludes .claude/ from the Windows job was checked and is benign (it works around colon-named skill directories, with core.protectNTFS scoped to that one step).
Commits: 4 commits, all signed-off: yes
CI status: passing (incl. the new Windows job)
Two non-blocking notes as inline comments. Thanks for a careful first contribution — the comments explaining why each Windows behavior differs (write-handle flush, rename-with-open-file, ACLs vs mode bits) are exactly what this codebase's style asks for.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| "kept", filepath.Base(dst), "mergedFrom", filepath.Base(src), | ||
| "cause", "the host clock moved far enough for a day to be condemned and then written again", | ||
| "effect", "both sets of rows are in the surviving file; a per-minute total is the sum of what each held") | ||
| // Closed before the unlink: Windows will not remove a file that is still open. |
There was a problem hiding this comment.
nit — the eager _ = in.Close() before os.Remove(src) is needed on Windows (the deferred close runs after the unlink), but the defer func() { _ = in.Close() }() above now closes an already-closed handle. That is harmless in os.File (the second close returns ErrClosed and is ignored), so this works — but a one-line comment saying the early close is deliberate and the defer becomes a no-op would save the next reader the double-take.
| // openDir opens a directory so that syncDir can flush it. Windows flushes a directory only | ||
| // through a handle opened for writing with FILE_FLAG_BACKUP_SEMANTICS. os.Open gives a | ||
| // read-only handle, and Sync on it fails with "Access is denied". | ||
| func openDir(dir string) (*os.File, error) { |
There was a problem hiding this comment.
suggestion — GENERIC_READ|GENERIC_WRITE on the directory handle means syncDir now fails on a directory the process cannot write to, where the Unix path (os.Open, read-only) succeeds and fsyncs. That is consistent with the "best effort, errors reported" contract in the comment, and a read-only archive directory is not a configuration this code targets — but if it ever shows up in the field as noise, FILE_GENERIC_WRITE could be narrowed (e.g. FILE_WRITE_DATA is what flush needs on NTFS). Not blocking; just a note for whoever debugs it first.
clawgenti
left a comment
There was a problem hiding this comment.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
mrsabath
left a comment
There was a problem hiding this comment.
Summary
A careful Windows port with an unusually honest PR description. I verified the
substance rather than taking the description's word for it, and it holds up.
The earlier must-fix is resolved. The previous review flagged that
go-ci-windows could never go green, because the repo tracks colon-named
.claude/skills/orchestrate:* paths that NTFS rejects, so actions/checkout
failed before any Go command ran — leaving every Windows claim in this PR
unverified by CI. Commit a2a42ab fixes exactly that with a non-cone
sparse-checkout excluding /.claude/ plus a step-scoped
core.protectNTFS=false. I confirmed on the latest run that the job's checkout
succeeds, all three Go steps execute, and the tests genuinely run rather than
mass-skipping:
ok github.com/rossoctl/cortex/core/bootstrap 0.357s
ok github.com/rossoctl/cortex/core/session/archive 10.850s
ok github.com/rossoctl/cortex/core/cost/ledger 5.391s
The 10.9s and 5.4s runtimes are the point: the regression guard this PR adds is
now real, not nominally green.
On the code itself:
openDiris the right diagnosis. Windows flushes a directory only through
a handle opened for writing withFILE_FLAG_BACKUP_SEMANTICS, soos.Open's
read-only handle failsSyncwith "Access is denied". The fix uses std
syscall, adds no dependency, and bothsyncDirimplementations close their
handle (errors.Join(serr, cerr)in the archive). Unix behaviour is
untouched —syncdir_other.gois exactlyos.Open. It is fixed, not skipped,
which matters for a durability path.mergeDayFilesclose-before-unlink is correct. The retained
defer func() { _ = in.Close() }()becomes a harmless second close
(ErrClosed, discarded), and the explicit close lands afterout.Sync(), so
the ordering that protects the rows is preserved.- The
renameclose is consistent with the surrounding code:renameEntry
already callscloseWriteron both its paths, and the new call sits after the
renameEntryearly-return and beforewriteMeta/os.Rename, so it cannot
close a writer the entry path still needs. - The test skips are justified, not regression-hiding.
skipWithoutUnixModes
guards tests that read mode bits, which read back as 0666 on Windows. I also
checked theos.Geteuid() == 0guards left in the two rename tests:Geteuid
returns-1on Windows, so they do not short-circuit the newblockRenames
path.
Supply chain is clean: both actions pinned by full SHA matching every other pin
in the file, workflow-level permissions: contents: read, no secrets, no
pull_request_target.
The "Not in this PR" section is the right call — agentop, process attribution
and the CA bundle are genuinely separate work. Two items in it deserve their own
issues rather than living only in a PR body: the colon-named skill directories
(a contributor on Windows hits the same checkout wall this job works around),
and the archive's 0600/0700 modes meaning nothing on Windows while it holds raw
prompts.
Three suggestions/nits inline. None blocks merge.
Areas reviewed: Go (core/bootstrap, core/session/archive, core/cost/ledger), CI/GitHub Actions, tests, docs
Commits: 4, all signed-off, conventional prefixes, all subjects under 72 chars
CI status: all checks passing, including the new Go CI (Windows build, archive and ledger)
Verification note: this sandbox could not git fetch the repo, so rather than
read a possibly-stale local clone I pulled every file I checked at
a2a42ab through the GitHub API.
| if runtime.GOOS != "windows" { | ||
| if err := os.Chmod(root, 0o500); err != nil { | ||
| t.Fatal(err) | ||
| } |
There was a problem hiding this comment.
suggestion: blockRenames both returns release and registers it with t.Cleanup, so on the Windows branch the segment handle gets closed twice. That is benign in itself — the second f.Close() just returns ErrClosed, and it is discarded — but the two call sites disagree about which mechanism they are relying on: clear_test.go calls release() explicitly (it has to, since it records more events afterwards and then asserts on what is on disk), while delete_test.go discards the return and leans on the cleanup. The asymmetry reads as an oversight rather than a decision.
Either drop the t.Cleanup and let the caller own the release, or keep the cleanup and make release idempotent (sync.Once, or release = func() {} after firing), so the contract is unambiguous. The Unix branch has the same shape with os.Chmod, where a double Chmod back to 0700 is equally harmless — so whichever way you go, it is worth it being the same way on both branches.
| // openDir opens a directory so that syncDir can flush it. Windows flushes a directory only | ||
| // through a handle opened for writing with FILE_FLAG_BACKUP_SEMANTICS. os.Open gives a | ||
| // read-only handle, and Sync on it fails with "Access is denied". | ||
| func openDir(dir string) (*os.File, error) { |
There was a problem hiding this comment.
suggestion: this openDir and the one in core/cost/ledger/syncdir_windows.go are byte-identical, including the doc comment — as are the two syncdir_other.go files. You pre-empt this in the PR description and offer to extract them, and I would take yourself up on it.
The reason is less about the ~20 duplicated lines and more about what happens next: these are CreateFile flag choices on a durability path, so if the share mode or FILE_FLAG_BACKUP_SEMANTICS handling ever needs adjusting, it has to be found and changed in two places, and the second one is easy to miss precisely because nothing references it from the first. A small internal helper (core/internal/fsutil, or wherever core would naturally grow its first shared file helper) would make that a single edit.
Not a blocker, and I would not hold the PR for it — but "core has no shared file helper yet" is a reason to create one, not a reason to duplicate.
| // first; the next event opens a new one under newDir. A reader that holds a segment open | ||
| // (a Page read) still makes the rename fail there: the history then stays in the old | ||
| // directory, under the new id, until adopt moves it at the next start. | ||
| if runtime.GOOS == "windows" { |
There was a problem hiding this comment.
nit: this is a runtime branch on a compile-time fact, and it is the one place in the PR that resolves a platform difference at runtime rather than through a build tag — everything else (signaltoggle_*.go, syncdir_*.go) uses tags.
Consider a closeBeforeRename constant in the existing syncdir_windows.go / syncdir_other.go pair (true / false), then if closeBeforeRename { a.closeWriter(s) }. Same behaviour, consistent with the rest of the file set, and on Unix the compiler drops the branch entirely instead of carrying a runtime.GOOS comparison through a hot-ish path. It also removes the runtime import that this hunk adds to archive.go.
Purely stylistic — the current code is correct, and the comment above it is genuinely good: documenting that a concurrent Page read can still defeat the rename, and that it degrades to the existing failed-move behaviour, is exactly what a reader needs here.
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Re-review at a2a42ab. The previous must-fix is resolved. The go-ci-windows job now gets past checkout and passes: checkout, Build core, the vet+test step for bootstrap/session/archive/cost/ledger (40s), and the cmd/cortex local-profile build all show success on job 133396490181. On the previous run (job 133388433716) every step after checkout was skipped. I couldn't download the raw log text from this sandbox (the log blob host is unreachable from here), so I'm relying on step-level status and timing. The sparse checkout is safe, and core.protectNTFS=false reaches git only through the checkout step's env:, so no later step sees it. Disabling it gives a fork PR nothing new, because the job already runs the PR's own Go code under a contents: read token. Leaving .claude/ out doesn't affect the build. The only go:embeds are under core/plugins/script/ (all:entries, sdk/cortex.py). profile-tags globs only cmd/cortex/plugins_*.go, and the only Go code that references .claude/ is cmd/agentop (not built in this job) and profile-tags tests (not run). No tracked path outside .claude/ has an NTFS-illegal character, a reserved name, or a trailing dot.
I found no new issues in the rest of the diff. The Windows close-before-rename in rename runs on the archive's single writer goroutine, so no writer races it. After a successful move s.dir is newDir and s.w is nil, so the next write opens its segment under the new directory. After a failed move both stay on the old directory, and adopt finishes the move at the next start. writeMeta runs after the close, so the closed segment is listed. In mergeDayFiles, the early close followed by the deferred one is harmless (already noted by others). The test changes are sound. On Windows, blockRenames holds a segment open, so the Rename in clearAll and deleteSession really fails. Its cleanup runs before the t.TempDir removal (LIFO), so the temp dir can be deleted. GOOS=windows build of core, go vet of the three packages, and test compiles for windows/darwin all pass. js/wasm vet of bootstrap passes too, which covers the !unix stub. On Linux, go test -race of the three packages passes. The one exception is TestMidnightTransitions_EveryFixtureIsStillTheDayItClaimsToBe, which fails the same way at the base commit because this sandbox has different tzdata for America/Havana, so it's unrelated. I ran the two blockRenames tests as an unprivileged user so the Unix chmod branch actually executes, and both pass. The open nits from other reviewers (duplicated openDir, the double close, runtime.GOOS vs a build tag, GENERIC_WRITE, blockRenames holding only the first segment) still apply and I'm not repeating them here.
Author: michaljacovi (FIRST_TIME_CONTRIBUTOR — first-time by association; repo admin, reviewed as maintainer)
Areas reviewed: Go (bootstrap, session/archive, cost/ledger), CI/GitHub Actions, Docs
Agent/IDE config (.claude/.vscode): none (.github/CLAUDE.md is docs; the CI job only excludes .claude/ from its checkout)
Commits: 4 commits, all signed-off: yes
CI status: passing (Windows job included)
…segment in blockRenames From the review of rossoctl#1878: - rename's runtime.GOOS check becomes closeWriterBeforeRename, in rename_windows.go and rename_other.go, the way openDir is split. The behaviour is the same: on Windows the open segment is closed before the directory moves, and elsewhere nothing changes. - The build tags stay as they are, each matching what differs. The SIGUSR1 toggle splits on unix/!unix, because SIGUSR1 is a Unix signal and also missing on plan9, js and wasip1. openDir and closeWriterBeforeRename split on windows/!windows, because only Windows needs a write handle to flush a directory, or refuses to rename one with a file open in it. Every other platform, plan9, js and wasip1 included, keeps the original code. - On Windows, blockRenames now holds every segment of the session open, not just the first, and its release closes them all. Part of rossoctl#1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
|
Thanks for the review!
|
|
Thanks for merging! Two small follow-ups:
|
main's go-ci-windows job fails since #1876 and #1878 merged: this test, from #1876, makes the erase fail with chmod 0500 on the data directory. Windows ignores that permission, so the erase succeeds and LastSeq is 0 instead of 4. Neither PR's CI saw the other: #1876 ran before the Windows job existed, and #1878 ran before the test existed. It now skips on Windows through skipWithoutUnixModes, like the other archive tests that rely on Unix permission bits. Part of #1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]> Co-authored-by: Michal Jacovi <[email protected]>
…segment in blockRenames From the review of #1878: - rename's runtime.GOOS check becomes closeWriterBeforeRename, in rename_windows.go and rename_other.go, the way openDir is split. The behaviour is the same: on Windows the open segment is closed before the directory moves, and elsewhere nothing changes. - The build tags stay as they are, each matching what differs. The SIGUSR1 toggle splits on unix/!unix, because SIGUSR1 is a Unix signal and also missing on plan9, js and wasip1. openDir and closeWriterBeforeRename split on windows/!windows, because only Windows needs a write handle to flush a directory, or refuses to rename one with a file open in it. Every other platform, plan9, js and wasip1 included, keeps the original code. - On Windows, blockRenames now holds every segment of the session open, not just the first, and its release closes them all. Part of #1520. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Michal Jacovi <[email protected]>
Part of #1520.
Problem
On Windows,
cmd/cortexdid not compile, and once it did, the session archivekept nothing:
core/bootstrapusedsyscall.SIGUSR1(the log-level toggle), which Windowsdoes not define.
createSegmentfsyncs the session directory after creating a segment, andthe fsync failed with "Access is denied".
os.Opengives a read-onlyhandle, and Windows flushes a directory only through a handle opened for
writing with
FILE_FLAG_BACKUP_SEMANTICS. So every new segment was removedagain, and every event was lost.
syncDirfailed the same way:cmd/cortexlogged"costledger: append failed" on the first append of each day, and
TestSyncDir_MakesANewDayFileNameDurableOnThisPlatformandTestWriteLines_SyncsTheDirectoryOncePerNewDayFilefailed on Windows.mergeDayFilesremoved its source while the source was stillopen (the
Closewas deferred), and Windows will not remove an open file.So a prune that merged a condemned day file back failed
(
TestPrune_RestoringDoesNotDiscardALiveDayFile).Rekeyed) moves the session directory while its segment is stillopen. Windows will not rename a directory with an open file in it, so the
history stayed under the old id until the next start.
What changed
StartSignalTogglemoves tosignaltoggle_unix.go, with a no-op fornon-unix platforms (Windows, js, wasip1). There the level stays at what
LOG_LEVELset. Its test moves tosignaltoggle_unix_test.go.openDir:os.Openeverywhere else, unchanged, and on Windows
CreateFilewithGENERIC_READ|GENERIC_WRITEandFILE_FLAG_BACKUP_SEMANTICS(
syncdir_windows.go, stdsyscall, no new dependency).FlushFileBufferson that handle succeeds as a normal user, so the directory really is
flushed. It is not skipped. The two
openDircopies (archive and ledger,about 20 lines each) are deliberate: both packages are internal, and core
has no shared file helper yet. I'm happy to move them into a shared package
if you prefer.
mergeDayFilescloses the source before removing it.renamecloses the session's segment before moving thedirectory (
closeWriterBeforeRename, split by build tag likeopenDir). The next event opens a new segment under the new directory.Behaviour on Unix is unchanged. A reader that holds a segment open (a Page
read) still makes a rename or a delete fail on Windows: the rename falls back
to the old directory until the next start (as it already does after any
failed move), and the delete reports the error. There is no retry.
a read-only root, which Windows ignores. On Windows they now hold the
session's segments open instead (
blockRenames). Four tests read or set Unix permission bits(the archive's and the ledger's file modes, and a read-only data
directory) and skip on Windows.
go-ci-windowsjob onwindows-latestbuilds core andcmd/cortex(local profile). It vets and testscore/bootstrap,core/session/archiveandcore/cost/ledger, so this does not regress. Itruns only those packages' tests, because others still use Unix-only APIs
(see below). It runs without
-race, because the race detector needs cgoand a C toolchain on the runner, and I could not check that the runner has
one. Its checkout is sparse and leaves out
.claude/(see below).Size
23 files, +305 −76. About half is the toggle moving to its own file with its
test, and the test helpers.
How it was tested
On Windows 11 (amd64, Go 1.27.0,
GOWORK=off), at676557d3:go build ./...in core andgo build -tags <local profile> ./...incmd/cortexpass.go vetandgo testfor./bootstrap/... ./session/archive/... ./cost/ledger/...pass. Before this change, 8 archive tests failed there(3 rename tests, 2 failed-rename tests and 3 mode tests), and so did 4
ledger tests (the 2 directory-sync tests, the prune merge and a mode test).
go vetfor the same packages also passes withGOOS=linuxandGOOS=darwin, and their test binaries compile. I have not run them onLinux or macOS; CI does.
cortex --localwith a Claude Code session routed through it(
HTTPS_PROXYplusNODE_EXTRA_CA_CERTS, against a LiteLLM gateway). Thesession's segment is written to
session.archive.dir. After a restart,GET /v1/sessions/{id}/events/{seq}?raw=1returns the full request body andthe full SSE response from disk. The day's first ledger file is written, with
no "costledger: append failed".
Not in this PR (seen on Windows, for #1520)
cmd/agentopdoes not build yet (Setsid,syscall.Kill, as Feat: Support running Cortex natively on Windows (no WSL) #1520 lists).So there is no
agentop setupor service:cortexruns in the foreground.cmd/cortextests still useSysProcAttr.Setpgid(restart_test.go).peerproc: unsupported on this host).so tools that take
SSL_CERT_FILE/REQUESTS_CA_BUNDLEhave nothing to pointat. Node clients work through
NODE_EXTRA_CA_CERTS.the profile directory's ACL. It probably deserves its own issue, since the
archive holds raw prompts.
.claude/skillshas directories with a colon in their names(
orchestrate:ci,skills:scan, ...). Windows cannot create those, so aplain clone or checkout fails there ("invalid path").
go-ci-windowsworksaround it with a sparse checkout that leaves out
.claude/, pluscore.protectNTFS=falsefor the checkout step. A contributor on Windowsneeds the same steps. Renaming those directories (for example
orchestrate-ci) would fix it for everyone.core.autocrlf=true(the Git for Windows default),TestHostRule_Goldenfails on a CRLF checkout of its golden file. A.gitattributesrule fortestdatawould fix it.Assisted-By: Claude (Anthropic AI) [email protected]