fix(persistence): FlushAndAck is a durability barrier that reports lost writes
The persistence actor acked FlushAndAck unconditionally after writing its pending merged notification: nothing was fsynced and every storage failure was only warn-logged, so persist_ack, the reconnect flush and history repair treated lost writes as persisted. The barrier now writes the pending notification, reports the first storage failure latched since the last barrier (every actor arm latches), and fsyncs the whole session directory tree (files, directories, deletions). Session directories are created durably (init and fork copy), and the shared summary writer syncs its staged bytes before publishing and the parent afterwards, so a concurrent /rename cannot publish unsynced bytes over a synced summary.json. FlushComplete and the persist_ack, history repair and end-of-turn callers propagate the io::Result; CopyFile fails on a sync error but keeps the latch for the barrier. Ported from upstream 1.0.1x (grok-build persistence.rs pending_write_error + durable storage helpers), reshaped without the dirty-file set. Claude-Session: https://claude.ai/code/session_01RUqV8HVGXcAETyYbZ2tPQ4
This commit is contained in:
1 parent
5f7416f3ef
commit
63d26d4a3e
11 files changed
+413
-106
No files matched your search
@@ -2794,3 +2794,24 @@ async fn graph_mode_state_round_trips_and_tombstones() {
|
||||
let after = adapter.load_session_without_updates(&info).await.unwrap();
|
||||
assert!(after.graph_mode_state.is_none(), "cleared graph must not resurrect");
|
||||
}
|
||||
|
||||
/// The barrier covers nested state files, and an unsyncable one fails it.
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn sync_session_files_reports_a_nested_file_that_cannot_be_synced() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
// Root opens anything; the permission probe is meaningless there.
|
||||
if unsafe { libc::geteuid() } == 0 {
|
||||
return;
|
||||
}
|
||||
let dir = TempDir::new().unwrap();
|
||||
let adapter = JsonlStorageAdapter::with_explicit_session_dir(dir.path().to_path_buf());
|
||||
let info = create_test_info();
|
||||
adapter.init_session(&info, default_model_id()).await.unwrap();
|
||||
let nested = adapter.goal_mode_state_file(&info);
|
||||
std::fs::create_dir_all(nested.parent().unwrap()).unwrap();
|
||||
std::fs::write(&nested, b"{}").unwrap();
|
||||
std::fs::set_permissions(&nested, std::fs::Permissions::from_mode(0o000)).unwrap();
|
||||
let error = adapter.sync_session_files(&info).await.unwrap_err();
|
||||
assert_eq!(error.kind(), io::ErrorKind::PermissionDenied, "got {error}");
|
||||
}
|
||||
Reference in new issue
Block a user