Skip to content

Fix file handling on Windows for session registry#228

Merged
subsy merged 4 commits intomainfrom
claude/investigate-gh-issue-221-7CZlY
Jan 26, 2026
Merged

Fix file handling on Windows for session registry#228
subsy merged 4 commits intomainfrom
claude/investigate-gh-issue-221-7CZlY

Conversation

@subsy
Copy link
Copy Markdown
Owner

@subsy subsy commented Jan 26, 2026

Summary

Add platform-specific file handling to support Windows in the session registry module. Windows doesn't support Unix-style numeric file flags combined with permission modes, so this change uses string-based flags on Windows and numeric flags on Unix-like systems.

Changes

  • Add IS_WINDOWS platform detection constant to identify Windows systems
  • Update acquireLock() to use 'wx' flag on Windows instead of O_CREAT | O_EXCL | O_WRONLY with FILE_MODE
  • Update saveRegistryInternal() to use 'w' flag on Windows instead of O_CREAT | O_WRONLY | O_TRUNC with FILE_MODE
  • Add clarifying comments explaining the Windows compatibility issue

Implementation Details

The changes maintain the same semantic behavior across platforms:

  • Lock file creation uses exclusive write mode ('wx' on Windows, O_CREAT | O_EXCL | O_WRONLY on Unix)
  • Registry file writing uses truncate mode ('w' on Windows, O_CREAT | O_WRONLY | O_TRUNC on Unix)
  • Unix systems continue to use restrictive file permissions (0o600) via numeric flags
  • Windows uses its default file permissions since the platform doesn't support the Unix permission model in this API

Summary by CodeRabbit

  • Bug Fixes

    • Improved cross-platform file operation compatibility with better handling for Windows-exclusive file locking and atomic temporary-file writes while preserving Unix-like behaviour.
  • Tests

    • Added Windows-compatible tests covering exclusive write locks, atomic temporary-file writes/renames and cleanup to validate cross-platform reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

Windows doesn't properly support Unix-style numeric file flags (O_CREAT,
O_EXCL, etc.) combined with Unix permission modes (0o600). This caused
EINVAL and ENOENT errors when users tried to launch ralph-tui on Windows.

The fix detects Windows via process.platform and uses string-based flags
('wx' for exclusive write, 'w' for write/truncate) instead of numeric
constants. Unix systems continue to use numeric flags with permissions.

Fixes #221
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
ralph-tui Ignored Ignored Preview Jan 26, 2026 9:23pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 26, 2026

Walkthrough

Platform-specific file I/O handling was added to the session registry: Windows detection (IS_WINDOWS) drives use of 'wx' for lock acquisition and 'w' for temporary file writes; non-Windows paths keep the original numeric flags and FILE_MODE semantics.

Changes

Cohort / File(s) Summary
Platform-specific registry I/O
src/session/registry.ts
Added IS_WINDOWS detection and conditional flag handling: lock acquisition uses 'wx' on Windows vs `O_CREAT
Windows-compatible tests
src/session/registry.test.ts
New/extended tests exercising Windows-compatible file flags (wx, w), checking exclusive-open (EEXIST), atomic write via temp file and rename, content integrity and cleanup of created files.

Sequence Diagram(s)

(omitted — changes do not introduce a multi-component sequential flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰
I nibble through the file and sing,
Where 'wx' gives locks a wing,
And 'w' lays temp files neat and clean,
Cross-platform carrots in a gleam,
Hooray — the registry hops between! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: adding Windows-specific file handling to the session registry module.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.93%. Comparing base (07d8bc8) to head (2b6d8d9).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/session/registry.ts 77.77% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #228   +/-   ##
=======================================
  Coverage   44.93%   44.93%           
=======================================
  Files          84       84           
  Lines       24479    24486    +7     
=======================================
+ Hits        10999    11004    +5     
- Misses      13480    13482    +2     
Files with missing lines Coverage Δ
src/session/registry.ts 72.83% <77.77%> (-0.04%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/session/registry.ts`:
- Around line 225-229: The Windows branch that opens the temp file omits the
FILE_MODE argument, so when IS_WINDOWS is true the call to open(tempPath, 'w')
should pass the same FILE_MODE used on Unix to ensure restrictive permissions;
update the code path that assigns tempHandle (the open call guarded by
IS_WINDOWS) to call open(tempPath, 'w', FILE_MODE) instead of open(tempPath,
'w'), keeping the existing Unix branch using constants.O_CREAT |
constants.O_WRONLY | constants.O_TRUNC and FILE_MODE unchanged.

claude and others added 3 commits January 26, 2026 17:17
Add tests that verify the string-based file flags ('wx', 'w') used on
Windows work correctly for lock acquisition and atomic write patterns.
These tests ensure >50% coverage on the new Windows-compatible code paths.
Add FILE_MODE parameter to the Windows branch of open() calls to maintain
consistent permission handling across platforms, even though Windows
ignores Unix-style permissions.
@subsy subsy merged commit 6f92991 into main Jan 26, 2026
9 checks passed
@subsy subsy deleted the claude/investigate-gh-issue-221-7CZlY branch January 26, 2026 21:24
sakaman pushed a commit to sakaman/ralph-tui that referenced this pull request Feb 15, 2026
…21-7CZlY

Fix file handling on Windows for session registry
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.

2 participants