Skip to content

fix(jsonl): make write_private_atomic work on Windows - #8

Open
enricodetoma wants to merge 1 commit into
xhluca:mainfrom
enricodetoma:main
Open

enricodetoma wants to merge 1 commit into
xhluca:mainfrom
enricodetoma:main

Conversation

@enricodetoma

Copy link
Copy Markdown

On Windows every write failed. os.fchmod() is Unix-only, so on Python <= 3.12 it raised AttributeError just after mkstemp() left the descriptor open; the cleanup unlink() then hit WinError 32 ("the file is being used by another process") and that secondary error replaced the real one, so users saw "cannot write target session ...: <winerror 32>" pointing at a target file that never existed. On Python 3.13, where os.fchmod exists, writes instead died in _fsync_directory(): Windows cannot os.open() a directory.

  • skip os.fchmod() where it is unavailable; Windows keeps the creating user's ACLs
  • skip the directory fsync on Windows; NTFS journaling keeps directory entries durable without it
  • make the temporary-file unlink in the error path best-effort so a cleanup failure cannot mask the original error being reported

Add regression tests for both failure modes. Verified on Windows with Python 3.11 and 3.13: a 371-record Codex-to-Claude transfer now completes, and write, collision refusal, and rollback behave as on POSIX.

Note: some existing tests remain POSIX-specific (permission-bit assertions, pty imports, CRLF-sensitive fixture bytes) and cannot pass on Windows regardless of this change; the Ubuntu CI matrix is unaffected.

On Windows every write failed. os.fchmod() is Unix-only, so on Python
<= 3.12 it raised AttributeError just after mkstemp() left the
descriptor open; the cleanup unlink() then hit WinError 32 ("the file
is being used by another process") and that secondary error replaced
the real one, so users saw "cannot write target session ...: <winerror
32>" pointing at a target file that never existed. On Python 3.13,
where os.fchmod exists, writes instead died in _fsync_directory():
Windows cannot os.open() a directory.

- skip os.fchmod() where it is unavailable; Windows keeps the creating
  user's ACLs
- skip the directory fsync on Windows; NTFS journaling keeps directory
  entries durable without it
- make the temporary-file unlink in the error path best-effort so a
  cleanup failure cannot mask the original error being reported

Add regression tests for both failure modes. Verified on Windows with
Python 3.11 and 3.13: a 371-record Codex-to-Claude transfer now
completes, and write, collision refusal, and rollback behave as on
POSIX.

Note: some existing tests remain POSIX-specific (permission-bit
assertions, pty imports, CRLF-sensitive fixture bytes) and cannot pass
on Windows regardless of this change; the Ubuntu CI matrix is
unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant