Skip to content

Refactor: Split the Windows rename step by build tag - #1888

Merged
huang195 merged 1 commit into
rossoctl:mainfrom
michaljacovi:windows-rename-buildtag
Nov 16, 2026
Merged

huang195 merged 1 commit into
rossoctl:mainfrom
michaljacovi:windows-rename-buildtag

Conversation

@michaljacovi

Copy link
Copy Markdown
Contributor

Follow-up to #1878 (review nits that landed just after the merge). Part of #1520.

Its go-ci-windows run will be red until #1887 merges. That PR fixes a
chmod-based test from #1876 that fails on Windows. This PR does not cause
the failure.

What changed

  • rename's runtime.GOOS == "windows" check becomes
    closeWriterBeforeRename, split by build tag into 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 happens.
  • The build tags stay as they are, each matching what differs. The SIGUSR1
    toggle splits on unix/!unix, because SIGUSR1 is missing on Windows,
    plan9, js and wasip1. openDir and closeWriterBeforeRename split on
    windows/!windows, because only Windows needs the write handle or the
    close. Every other platform 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.

How it was tested

On Windows 11 (amd64, Go 1.27.0, GOWORK=off), on top of ea6bed14:

  • go build ./... in core passes.
  • go vet ./session/archive/... passes with GOOS windows, linux and darwin.
  • go test ./session/archive/... passes the TestRekeyed*, failed-clear and
    failed-delete tests. The one failure is
    TestWriteSession_FailedEraseKeepsNumbering, the same as on main, which
    Fix: Skip a chmod-based archive test on Windows #1887 fixes. The linux and darwin test binaries compile.

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

…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
michaljacovi requested a review from a team as a code owner November 16, 2026 17:11
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: 22c6d4e3-b347-48d4-8c41-0ee5508f2923
Commits

Reviewing files that changed from the base of the PR and between ea6bed1 and addc92b.

Files selected for processing: 4

  • core/session/archive/archive.go
  • core/session/archive/perm_test.go
  • core/session/archive/rename_other.go
  • core/session/archive/rename_windows.go
  • 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

@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

This follows up on the #1878 review nits and gets them right. The runtime.GOOS branch in rename is now closeWriterBeforeRename, split by build tag into rename_windows.go and rename_other.go. That matches the existing syncdir_windows.go/syncdir_other.go (windows/!windows) pair, and the behaviour hasn't changed. The Windows variant still calls closeWriter before writeMeta and os.Rename, and the !windows one is an empty method. On Windows, blockRenames now holds every .jsonl.zst segment open. Its release is idempotent (held = nil), so the explicit release() in clear_test.go and the t.Cleanup path no longer double-close.

What I verified locally (Go 1.26.10, GOWORK=off):

  • go build ./... in core passes with GOOS windows, linux and darwin. go test -c ./session/archive/ compiles for all three.
  • go vet ./session/archive/... passes for windows, linux, darwin, freebsd, js/wasm and wasip1/wasm. plan9 fails in core/model (syscall.ECONNREFUSED), which this PR doesn't touch.
  • gofmt -l is clean, and runtime is still used elsewhere in archive.go's package, so dropping the import is safe.
  • On linux, go test ./session/archive/... and the -race run of the rename/rekey/failed-* tests pass, apart from TestWriteSession_FailedEraseKeepsNumbering. That test fails the same way on base ea6bed14. It depends on chmod, and my sandbox runs as root.
  • The red go-ci-windows check fails in the vet/test step. That matches the PR description's note about TestWriteSession_FailedEraseKeepsNumbering, and the Windows job on #1887's head (which adds skipWithoutUnixModes to that test) is green. So this PR doesn't cause the failure.

Author: michaljacovi (CONTRIBUTOR association, admin repo permission: maintainer)
Areas reviewed: Go (core/session/archive: build tags, rename path, Windows test helper)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: passing except go-ci-windows (pre-existing failure fixed by #1887); some Go CI jobs still pending

I found no issues.

@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

This picks up both review points from #1878 that landed after the merge, and
the implementation is better than what I suggested. Behaviour is unchanged on
every platform.

The build-tag split is behaviour-identical. I checked the call site at
addc92b: closeWriterBeforeRename(s) sits in the same position as the old
runtime.GOOS block — after the renameEntry early return, before
writeMeta/os.Rename — so it still cannot close a writer the entry path
needs. The runtime import is correctly dropped, and rename_other.go's
unnamed (*sessionState) parameter is the right idiom for a no-op. The
windows/!windows split now matches openDir, and the description's
reasoning for keeping SIGUSR1 on unix/!unix is right: that one is about a
signal missing on plan9, js and wasip1 too, so the tag genuinely differs. Each
split matches what it is actually guarding, which is the useful property —
better than making them uniform for its own sake.

blockRenames is now properly idempotent, and holding every segment rather
than the first is a real improvement I did not ask for: a session with a rolled
segment would previously have left the later ones unheld, so the rename could
have succeeded and the test would have failed for the wrong reason. Setting
held = nil inside release means the explicit call plus the t.Cleanup
registration no longer double-close, and registering the cleanup before the
opens is the correct order, since the closure captures held by reference.

The red Windows job is not this PR's fault. I verified this rather than
accepting it: this PR does not touch import_test.go, yet fails only
TestWriteSession_FailedEraseKeepsNumbering; main is already red at the
shared base ea6bed14; and #1887 — which touches only that file — is green.
So the dependency is exactly as the description states, and it is stated up
front, which is the right way to ship a PR that cannot be green yet.

Merge order: #1887 first, then re-run this job here before merging. I would
not merge this on a red job even knowing why it is red — once #1887 lands, this
job should go green on a re-run and confirm the refactor on the platform it is
about.

One nit inline, on a leftover from my own earlier suggestion. Nothing blocking.

Areas reviewed: Go (core/session/archive), tests
Commits: 1, signed-off, conventional prefix, 70-char subject
CI status: one failure — Go CI (Windows build, archive and ledger), inherited from main and fixed by #1887, not caused by this PR. All other checks pass.

Verification note: this sandbox could not git fetch, so I read every file I
checked at addc92b through the GitHub API rather than from a possibly-stale
local clone.

for _, f := range held {
f.Close()
}
held = nil

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: held = nil is the right fix and makes the Windows branch properly idempotent — the explicit release() in clear_test.go plus the t.Cleanup registration now close each handle exactly once.

The leftover is that the Unix branch above (line 32-33) still has the asymmetry I originally flagged: release = func() { os.Chmod(root, 0o700) } is both returned and registered with t.Cleanup, so on Unix an explicit release() still means two Chmod calls. It is completely harmless — chmod to the same mode twice is idempotent in effect, which is presumably why it did not seem worth touching — but it does mean the helper now has two branches with different guarantees, and the Windows one is the one a reader will check for the pattern.

If you want them to match, the smallest change is to clear the closure's work the same way:

done := false
release = func() {
    if done {
        return
    }
    done = true
    os.Chmod(root, 0o700)
}

or just let both branches build a release and wrap the whole thing in a single sync.OnceFunc before returning, which would collapse the duplication rather than mirror it. Entirely your call — I would not hold the PR for it, and "the Unix path's double call is provably harmless" is a legitimate answer.

@huang195 huang195 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

The split keeps the same behavior. On Windows, rename closes the segment before it moves the directory. On other platforms, it does nothing. rename_{windows,other}.go follows the syncdir_{windows,other}.go pattern. The new blockRenames is also safer: if os.Open fails in the loop, t.Cleanup now closes the files that the loop opened before.

I found no problems in the code. I have no inline comments.

CI: the Windows job is red, and a re-run will not make it green. Run 43915751618 (attempt 3) fails only TestWriteSession_FailedEraseKeepsNumbering (import_test.go:367: LastSeq = 0, want the 4 reserved). #1887 fixes that test. But GitHub created this run at 17:11 UTC, and #1887 merged at 17:56 UTC. A re-run uses the merge commit of the first run, so it does not include #1887. To get a new merge commit, merge main into the branch (it merges with no conflicts) or push a new commit.

Author: michaljacovi (MEMBER — maintainer)
Areas reviewed: Go (core/session/archive)
Agent/IDE config (.claude/.vscode): none
Commits: 1 commit, all signed-off: yes
CI status: all checks pass, except Go CI (Windows build, archive and ledger) (see above)
Local checks: go vet ./session/archive/... passes with GOOS windows, linux and darwin. GOOS=windows go test -c compiles. gofmt -l is clean.

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

@huang195 huang195 closed this Nov 16, 2026
@huang195 huang195 reopened this Nov 16, 2026
@huang195

Copy link
Copy Markdown
Member

Closing and reopening it to force a CI to run from main

@huang195
huang195 merged commit 76b3d40 into rossoctl:main Nov 16, 2026
107 of 110 checks passed
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

None yet

Development

Successfully merging this pull request may close these issues.

5 participants