Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(ragfs): stabilize s3fs directory mod times (#1603)

Jiahui Zhou419e27de6294
diff --git a/crates/ragfs/src/plugins/s3fs/mod.rs b/crates/ragfs/src/plugins/s3fs/mod.rs
index cff095919..000076f79 100644
--- a/crates/ragfs/src/plugins/s3fs/mod.rs
+++ b/crates/ragfs/src/plugins/s3fs/mod.rs
@@ -18,7 +18,7 @@ pub mod client;
use async_trait::async_trait;
use std::sync::Arc;
-use std::time::SystemTime;
+use std::time::{SystemTime, UNIX_EPOCH};
use cache::{S3ListDirCache, S3StatCache};
use client::S3Client;
@@ -112,6 +112,13 @@ impl S3FileSystem {
.unwrap_or("")
.to_string()
}
+
+ /// Prefer the directory marker's timestamp when available.
+ /// Pure prefix-based directories in S3 have no real mtime, so fall back
+ /// to a stable sentinel instead of returning a fresh timestamp on each call.
+ fn directory_mod_time(marker: Option<SystemTime>) -> SystemTime {
+ marker.unwrap_or(UNIX_EPOCH)
+ }
}
#[async_trait]
@@ -306,11 +313,17 @@ impl FileSystem for S3FileSystem {
continue;
}
+ let marker_time = self
+ .client
+ .head_object(&format!("{}/", dir_key))
+ .await?
+ .map(|meta| meta.last_modified);
+
files.push(FileInfo {
name: name.to_string(),
size: 0,
mode: 0o755,
- mod_time: SystemTime::now(),
+ mod_time: Self::directory_mod_time(marker_time),
is_dir: true,
});
}
@@ -366,11 +379,17 @@ impl FileSystem for S3FileSystem {
// Check if it's a directory
if self.client.directory_exists(&normalized).await? {
+ let dir_key = format!("{}/", self.client.build_key(&normalized));
+ let marker_time = self
+ .client
+ .head_object(&dir_key)
+ .await?
+ .map(|meta| meta.last_modified);
let info = FileInfo {
name: Self::file_name(&normalized),
size: 0,
mode: 0o755,
- mod_time: SystemTime::now(),
+ mod_time: Self::directory_mod_time(marker_time),
is_dir: true,
};
self.stat_cache
@@ -728,6 +747,17 @@ mod tests {
assert_eq!(S3FileSystem::file_name("/dir/file.txt"), "file.txt");
}
+ #[test]
+ fn test_directory_mod_time_prefers_marker_time() {
+ let marker_time = UNIX_EPOCH + std::time::Duration::from_secs(123);
+ assert_eq!(S3FileSystem::directory_mod_time(Some(marker_time)), marker_time);
+ }
+
+ #[test]
+ fn test_directory_mod_time_is_stable_without_marker() {
+ assert_eq!(S3FileSystem::directory_mod_time(None), UNIX_EPOCH);
+ }
+
#[tokio::test]
async fn test_plugin_validate() {
let plugin = S3FSPlugin::new();