Skip to content

Conversation

pchuri
Copy link
Contributor

@pchuri pchuri commented Aug 29, 2025

Summary

This PR implements advisory file locking for the message history using Rust 1.89+ stabilized std::fs::File locking APIs, eliminating the need for external dependencies.

Key Changes

  • Stable API Usage: Uses std::fs::File::try_lock() and try_lock_shared() APIs stabilized in Rust 1.89
  • Cross-Platform Compatibility:
    • Unix systems use try_lock_shared() for advisory read locks
    • Windows systems use try_lock() due to different lock semantics
  • Retry Logic: Maintains existing retry behavior for concurrent access scenarios
  • No External Dependencies: Removes need for external file locking crates

Technical Details

The implementation provides advisory file locking to prevent corruption when multiple Codex processes attempt to write to the message history file simultaneously. The locking is platform-aware to handle differences in Windows vs Unix file locking behavior.

Testing

  • ✅ Builds successfully on all platforms
  • ✅ Existing message history tests pass
  • ✅ File locking retry logic verified

Related to discussion in #2773 about using stabilized Rust APIs instead of external dependencies.

- Use Rust 1.89+ stabilized std::fs::File locking APIs
- Platform-specific implementation: Unix uses try_lock_shared(), Windows uses try_lock()
- Maintains retry logic and advisory file locking behavior
- No external dependencies required for file locking
@pchuri pchuri marked this pull request as draft August 29, 2025 09:13
@pchuri pchuri marked this pull request as ready for review August 29, 2025 09:30
Remove comment that talks about deleted code (was probably written by Codex?).
Fix another comment and also remove a cfg(windows) gate that was inside a function that was cfg(unix) (so it was effectively unreachable code).
@bolinfest bolinfest self-requested a review September 3, 2025 06:37
@bolinfest bolinfest merged commit 6aa306c into openai:main Sep 3, 2025
31 of 33 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants