Skip to content

Fix: Build cmd/cortex and keep the session archive and cost ledger on Windows - #1878

Merged
mrsabath merged 4 commits into
rossoctl:mainfrom
michaljacovi:windows-pr
Nov 16, 2026
Merged

mrsabath merged 4 commits into
rossoctl:mainfrom
michaljacovi:windows-pr

Conversation

@michaljacovi

@michaljacovi michaljacovi commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1520.

Problem

On Windows, cmd/cortex did not compile, and once it did, the session archive
kept nothing:

  • core/bootstrap used syscall.SIGUSR1 (the log-level toggle), which Windows
    does not define.
  • 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: cmd/cortex logged
    "costledger: append failed" on the first append of each day, and
    TestSyncDir_MakesANewDayFileNameDurableOnThisPlatform and
    TestWriteLines_SyncsTheDirectoryOncePerNewDayFile failed on Windows.
  • 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
    (TestPrune_RestoringDoesNotDiscardALiveDayFile).
  • A rename (Rekeyed) moves the session directory while its segment is still
    open. 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

  • StartSignalToggle moves to signaltoggle_unix.go, with a no-op for
    non-unix platforms (Windows, js, wasip1). There the level stays at what
    LOG_LEVEL set. Its test moves to signaltoggle_unix_test.go.
  • The archive and the ledger open the directory through openDir: os.Open
    everywhere else, unchanged, and on Windows CreateFile with
    GENERIC_READ|GENERIC_WRITE and FILE_FLAG_BACKUP_SEMANTICS
    (syncdir_windows.go, std syscall, no new dependency). FlushFileBuffers
    on that handle succeeds as a normal user, so the directory really is
    flushed. It is not skipped. The two openDir copies (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.
  • mergeDayFiles closes the source before removing it.
  • On Windows, rename closes the session's segment before moving the
    directory (closeWriterBeforeRename, split by build tag like openDir). 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.
  • Tests: the failed-clear and failed-delete tests make the rename fail through
    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.
  • CI: a new go-ci-windows job on windows-latest builds core and
    cmd/cortex (local profile). It vets and tests core/bootstrap,
    core/session/archive and core/cost/ledger, so this does not regress. It
    runs only those packages' tests, because others still use Unix-only APIs
    (see below). It runs without -race, because the race detector needs cgo
    and 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), at 676557d3:

  • go build ./... in core and go build -tags <local profile> ./... in
    cmd/cortex pass.
  • go vet and go test for ./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 vet for the same packages also passes with GOOS=linux and
    GOOS=darwin, and their test binaries compile. I have not run them on
    Linux or macOS; CI does.
  • End to end: cortex --local with a Claude Code session routed through it
    (HTTPS_PROXY plus NODE_EXTRA_CA_CERTS, against a LiteLLM gateway). The
    session's segment is written to session.archive.dir. After a restart,
    GET /v1/sessions/{id}/events/{seq}?raw=1 returns the full request body and
    the 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/agentop does not build yet (Setsid, syscall.Kill, as Feat: Support running Cortex natively on Windows (no WSL) #1520 lists).
    So there is no agentop setup or service: cortex runs in the foreground.
  • cmd/cortex tests still use SysProcAttr.Setpgid (restart_test.go).
  • Process attribution is off (peerproc: unsupported on this host).
  • The TLS bridge writes no CA trust bundle ("no system root bundle found"),
    so tools that take SSL_CERT_FILE/REQUESTS_CA_BUNDLE have nothing to point
    at. Node clients work through NODE_EXTRA_CA_CERTS.
  • The archive's 0600/0700 modes mean nothing on Windows. Access there rests on
    the profile directory's ACL. It probably deserves its own issue, since the
    archive holds raw prompts.
  • .claude/skills has directories with a colon in their names
    (orchestrate:ci, skills:scan, ...). Windows cannot create those, so a
    plain clone or checkout fails there ("invalid path"). go-ci-windows works
    around it with a sparse checkout that leaves out .claude/, plus
    core.protectNTFS=false for the checkout step. A contributor on Windows
    needs the same steps. Renaming those directories (for example
    orchestrate-ci) would fix it for everyone.
  • With core.autocrlf=true (the Git for Windows default),
    TestHostRule_Golden fails on a CRLF checkout of its golden file. A
    .gitattributes rule for testdata would fix it.

Assisted-By: Claude (Anthropic AI) [email protected]

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]>
@michaljacovi
michaljacovi requested review from a team, huang195 and rubambiza as code owners November 16, 2026 15:06
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The pull request adds Windows CI coverage, platform-specific directory operations, and Windows handling for archive renames and platform-dependent tests. It also separates Unix signal-toggle behavior from the non-Unix implementation.

Changes: Windows platform support

Layer / File(s) Summary
Platform-specific signal toggle
core/bootstrap/*
StartSignalToggle now has a Unix implementation and a no-op implementation for other platforms. A Unix-specific test checks the INFO-to-DEBUG-to-INFO transitions.
Windows directory and archive operations
core/cost/ledger/*, core/session/archive/*
The ledger and archive use platform-specific helpers to open directories. On Windows, archive renames close the open segment before moving the directory. Tests skip Unix permission checks where needed and use platform-specific rename blocking. The ledger closes a source file before removing it.
Windows CI job
.github/workflows/ci.yaml, .github/CLAUDE.md
A Windows job builds core and cmd/cortex, then vets and tests bootstrap, session archive, and cost ledger without -race. The CI documentation describes the job.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • Issue 1520 — The changes move the SIGUSR1 toggle out of the general bootstrap file and add Windows-specific filesystem and test handling, addressing the issue’s stated Windows support objectives.

Suggested reviewers: esnible

Merge Risk: Minimal · up to fcabf

This change adds Windows build and persistence support and keeps Unix behavior the same. No actionable merge-blocking issue remains after review.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main theme of the changeset: making cmd/cortex build and keeping the session archive and cost ledger working on Windows. The changeset does this through a Windows CI job, a signal …
Full details: Title check

Explanation

The title names the main theme of the changeset: making cmd/cortex build and keeping the session archive and cost ledger working on Windows. The changeset does this through a Windows CI job, a signal toggle moved to Unix-only files, Windows directory handles for archive and ledger sync, and Windows-aware tests. The title is specific and matches the PR objectives. It omits the signal-toggle move, but that is a secondary detail.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 33546de8-91b4-4997-b9cf-94590c374479
Commits

Reviewing files that changed from the base of the PR and between 676557d and fcabf64.

Files selected for processing: 21

  • .github/CLAUDE.md
  • .github/workflows/ci.yaml
  • core/bootstrap/bootstrap.go
  • core/bootstrap/bootstrap_test.go
  • core/bootstrap/signaltoggle_other.go
  • core/bootstrap/signaltoggle_unix.go
  • core/bootstrap/signaltoggle_unix_test.go
  • core/cost/ledger/store.go
  • core/cost/ledger/syncdir_other.go
  • core/cost/ledger/syncdir_windows.go
  • core/cost/ledger/writer_test.go
  • core/session/archive/archive.go
  • core/session/archive/clear_test.go
  • core/session/archive/delete_test.go
  • core/session/archive/meta_test.go
  • core/session/archive/perm_test.go
  • core/session/archive/prior_test.go
  • core/session/archive/segment.go
  • core/session/archive/segment_test.go
  • core/session/archive/syncdir_other.go
  • core/session/archive/syncdir_windows.go
Files with no reviewable changes: 2

  • core/bootstrap/bootstrap.go
  • core/bootstrap/bootstrap_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 16, 2026
…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]>
@michaljacovi michaljacovi changed the title Fix: Build the laptop proxy and keep the session archive and cost ledger on Windows Fix: Build cmd/cortex and keep the session archive and cost ledger on Windows Nov 16, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread .github/workflows/ci.yaml
# 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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .github/workflows/ci.yaml
env:
GOWORK: "off"
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-tags

I 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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread core/cost/ledger/store.go
"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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • openDir is the right diagnosis. Windows flushes a directory only through
    a handle opened for writing with FILE_FLAG_BACKUP_SEMANTICS, so os.Open's
    read-only handle fails Sync with "Access is denied". The fix uses std
    syscall, adds no dependency, and both syncDir implementations close their
    handle (errors.Join(serr, cerr) in the archive). Unix behaviour is
    untouched — syncdir_other.go is exactly os.Open. It is fixed, not skipped,
    which matters for a durability path.
  • mergeDayFiles close-before-unlink is correct. The retained
    defer func() { _ = in.Close() }() becomes a harmless second close
    (ErrClosed, discarded), and the explicit close lands after out.Sync(), so
    the ordering that protects the rows is preserved.
  • The rename close is consistent with the surrounding code: renameEntry
    already calls closeWriter on both its paths, and the new call sits after the
    renameEntry early-return and before writeMeta/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 the os.Geteuid() == 0 guards left in the two rename tests: Geteuid
    returns -1 on Windows, so they do not short-circuit the new blockRenames
    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)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@mrsabath
mrsabath merged commit ea6bed1 into rossoctl:main Nov 16, 2026
39 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 16, 2026
michaljacovi pushed a commit to michaljacovi/cortex that referenced this pull request Nov 16, 2026
…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]>
@michaljacovi

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

  • must-fix (checkout): fixed in a2a42ab, and the Windows job is now green. Sparse checkout alone isn't enough: Git for Windows rejects the colon paths in the index even as skip-worktree entries. So the step also sets core.protectNTFS=false, scoped to the step via GIT_CONFIG_*. With .claude/ excluded, nothing under it is written to disk.
  • runtime.GOOS check: now a build-tagged closeWriterBeforeRename (rename_windows.go / rename_other.go) in 191e843.
  • build-tag convention: kept on purpose. Each split follows what differs. SIGUSR1 is missing on plan9/js/wasip1 too, so signaltoggle needs unix/!unix. Only Windows needs a write handle to flush a directory or refuses to rename one with an open file, so openDir and closeWriterBeforeRename use windows/!windows, and every other platform keeps the original code.
  • blockRenames: now holds every segment open, and the release closes them all.
  • openDir duplication: left as is for now; happy to extract a shared helper if you prefer.
  • GENERIC_WRITE: agreed. A flush only follows creating a file in that directory, so write access is already needed.

@michaljacovi

Copy link
Copy Markdown
Contributor Author

Thanks for merging! Two small follow-ups:

mrsabath pushed a commit that referenced this pull request Nov 16, 2026
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]>
huang195 pushed a commit that referenced this pull request Nov 16, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants