A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
sync rows with plain fsync and take one full sync at turn settle (#3388)
Sebastian Müller79a270af8ed4
diff --git a/crates/pa-core/src/platform/fs.rs b/crates/pa-core/src/platform/fs.rsnew file mode 100644index 0000000000..9ee89da818--- /dev/null+++ b/crates/pa-core/src/platform/fs.rs@@ -0,0 +1,24 @@+//! Plain-fsync durability for append-only row writes.++use std::fs::File;+use std::io;++/// Flush one file's written bytes with a plain `fsync(2)`; std's+/// `sync_data`/`sync_all` take the `F_FULLFSYNC` barrier on Apple.+///+/// # Errors+///+/// Returns the OS error when the sync fails.+#[cfg(unix)]+pub fn fsync(file: &File) -> io::Result<()> {+ use std::os::fd::AsRawFd;+ nix::unistd::fsync(file.as_raw_fd()).map_err(io::Error::from)+}++/// # Errors+///+/// Returns the underlying I/O error when the sync fails.+#[cfg(not(unix))]+pub fn fsync(file: &File) -> io::Result<()> {+ file.sync_data()+}diff --git a/crates/pa-core/src/platform/mod.rs b/crates/pa-core/src/platform/mod.rsindex d4978f859b..4cecd29760 100644--- a/crates/pa-core/src/platform/mod.rs+++ b/crates/pa-core/src/platform/mod.rs@@ -3,11 +3,13 @@//! signatures; session-engine call sites never branch on `cfg` themselves.pub mod browser;+pub mod fs;pub mod lock_dir;pub mod perms;pub mod process;pub mod shell;+pub use fs::fsync;pub use lock_dir::LockDir;pub use perms::{file_mode, is_executable, is_readable_writable, restrict_dir, restrict_file, set_private_mode,diff --git a/crates/pa-core/src/session/window_cache.rs b/crates/pa-core/src/session/window_cache.rsindex 1f1f681fad..8d3930f671 100644--- a/crates/pa-core/src/session/window_cache.rs+++ b/crates/pa-core/src/session/window_cache.rs@@ -191,7 +191,7 @@ pub fn append_cached(path: &Path, bytes: &[u8], ownership: AppendOwnership) -> ilet mut file = std::fs::OpenOptions::new().append(true).open(path)?;file.write_all(bytes)?;file.flush()?;- file.sync_data()?;+ crate::platform::fsync(&file)?;if ownership != AppendOwnership::SessionLeaseHeld || !bytes.ends_with(b"\n") {if let Ok(mut snapshots) = live_snapshots().lock() {snapshots.remove(path);diff --git a/crates/pa-daemon/src/journal.rs b/crates/pa-daemon/src/journal.rsindex c28069314a..a1a04a9d75 100644--- a/crates/pa-daemon/src/journal.rs+++ b/crates/pa-daemon/src/journal.rs@@ -25,7 +25,7 @@ pub(crate) fn append_record(path: &Path, record: &Value) -> Result<()> {let mut line = serde_json::to_string(record)?;line.push('\n');file.write_all(line.as_bytes())?;- file.sync_all()?;+ pa_core::platform::fsync(&file)?;Ok(())}@@ -51,7 +51,7 @@ pub(crate) fn append_records(path: &Path, records: &[Value]) -> Result<()> {lines.push(b'\n');}file.write_all(&lines)?;- file.sync_all()?;+ pa_core::platform::fsync(&file)?;Ok(())}diff --git a/crates/pa-daemon/src/worker/turn.rs b/crates/pa-daemon/src/worker/turn.rsindex 16db27612b..622e8a0960 100644--- a/crates/pa-daemon/src/worker/turn.rs+++ b/crates/pa-daemon/src/worker/turn.rs@@ -1074,6 +1074,14 @@ impl TurnRunner {operation: "turn_end",},);+ let session_path = {+ let core = self.core.lock().unwrap();+ core.store.as_ref().map(|store| store.path.clone())+ };+ if let Some(path) = session_path {+ let _ =+ tokio::task::spawn_blocking(move || std::fs::File::open(&path)?.sync_all()).await;+ }let _ = self.emit_action_update(&snapshot);self.idle_notify.notify_waiters();for admission_id in settled_admissions {