Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.
Python agent-contextagent-memoryagent-pluginsagentic-ragcontext-databasedsh-pluginknowledge-basememorymemory-managementself-evolvingvector-database
feat(lock): add force parameter to remove_token method (#4575)
baojun-zhang0821c9b87802
diff --git a/crates/ragfs/src/lock/manager.rs b/crates/ragfs/src/lock/manager.rsindex 98bd9fb9a..5ed5b4cdb 100644--- a/crates/ragfs/src/lock/manager.rs+++ b/crates/ragfs/src/lock/manager.rs@@ -614,7 +614,7 @@ impl PathLockManager {lock_path: &str,owner_id: &str,) -> PathLockResult<bool> {- match provider.remove_token(lock_path, owner_id).await {+ match provider.remove_token(lock_path, owner_id, false).await {Ok(true) => Ok(true),Ok(false) => match provider.read_token(lock_path).await? {None => Ok(true),@@ -916,7 +916,7 @@ impl PathLockManager {}let removed = match self.provider- .remove_token(lock_path, &token.owner_id)+ .remove_token(lock_path, &token.owner_id, true).await{Ok(removed) => removed,@@ -1178,7 +1178,7 @@ impl PathLockManager {}// Stale — remove it before attempting to create our own token.self.provider- .remove_token(lock_path, &existing.owner_id)+ .remove_token(lock_path, &existing.owner_id, true).await?;}@@ -2227,7 +2227,12 @@ mod tests {self.inner.refresh_token(lock_path, owner_id, time_ns).await}- async fn remove_token(&self, lock_path: &str, owner_id: &str) -> PathLockResult<bool> {+ async fn remove_token(+ &self,+ lock_path: &str,+ owner_id: &str,+ force: bool,+ ) -> PathLockResult<bool> {if self.busy_next_remove.swap(false, Ordering::SeqCst) {self.busy_remove_count.fetch_add(1, Ordering::SeqCst);return Err(PathLockError::Busy {@@ -2241,7 +2246,7 @@ mod tests {if self.fail_next_remove.swap(false, Ordering::SeqCst) {return Err(PathLockError::Io("injected remove failure".to_string()));}- self.inner.remove_token(lock_path, owner_id).await+ self.inner.remove_token(lock_path, owner_id, force).await}async fn scan_descendant_locks(&self, root: &str) -> PathLockResult<Vec<String>> {@@ -2331,8 +2336,13 @@ mod tests {self.inner.refresh_token(lock_path, owner_id, time_ns).await}- async fn remove_token(&self, lock_path: &str, owner_id: &str) -> PathLockResult<bool> {- self.inner.remove_token(lock_path, owner_id).await+ async fn remove_token(+ &self,+ lock_path: &str,+ owner_id: &str,+ force: bool,+ ) -> PathLockResult<bool> {+ self.inner.remove_token(lock_path, owner_id, force).await}async fn scan_descendant_locks(&self, root: &str) -> PathLockResult<Vec<String>> {diff --git a/crates/ragfs/src/lock/provider.rs b/crates/ragfs/src/lock/provider.rsindex 3c00eaac3..a3d92a9f4 100644--- a/crates/ragfs/src/lock/provider.rs+++ b/crates/ragfs/src/lock/provider.rs@@ -47,8 +47,14 @@ pub trait PathLockProvider: Send + Sync {) -> PathLockResult<bool>;/// Remove the token at `lock_path` if owned by `owner_id`.+ /// `force` bypasses storage CAS after the ownership check./// Returns `true` if removed, `false` if not found or wrong owner.- async fn remove_token(&self, lock_path: &str, owner_id: &str) -> PathLockResult<bool>;+ async fn remove_token(+ &self,+ lock_path: &str,+ owner_id: &str,+ force: bool,+ ) -> PathLockResult<bool>;/// Scan all descendant lock paths under `root`.async fn scan_descendant_locks(&self, root: &str) -> PathLockResult<Vec<String>>;@@ -131,7 +137,12 @@ impl PathLockProvider for MemoryPathLockProvider {}}- async fn remove_token(&self, lock_path: &str, owner_id: &str) -> PathLockResult<bool> {+ async fn remove_token(+ &self,+ lock_path: &str,+ owner_id: &str,+ _force: bool,+ ) -> PathLockResult<bool> {let mut tokens = self.tokens.write().await;match tokens.get(lock_path) {Some(token) if token.owner_id == owner_id => {@@ -438,7 +449,12 @@ impl PathLockProvider for FilesystemPathLockProvider {.map_err(|e| Self::map_cas_error("refresh", lock_path, e))}- async fn remove_token(&self, lock_path: &str, owner_id: &str) -> PathLockResult<bool> {+ async fn remove_token(+ &self,+ lock_path: &str,+ owner_id: &str,+ force: bool,+ ) -> PathLockResult<bool> {let Some(raw) = self.read_token_raw(lock_path).await? else {return Ok(false);};@@ -446,6 +462,17 @@ impl PathLockProvider for FilesystemPathLockProvider {if token.owner_id != owner_id {return Ok(false);}+ if force {+ return match self.fs.remove(lock_path).await {+ Ok(()) => Ok(true),+ Err(+ crate::core::Error::NotFound(_) | crate::core::Error::MountPointNotFound(_),+ ) => Ok(false),+ Err(error) => Err(PathLockError::Io(format!(+ "failed to force remove lock token at '{lock_path}': {error}"+ ))),+ };+ }self.fs.compare_and_remove(lock_path, &raw).await