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(ragfs): add structured lock tracing logs (#3693)
baojun-zhangdf1557901e07
diff --git a/Cargo.lock b/Cargo.lockindex b1f5ee370..cab94ddf1 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -3271,6 +3271,15 @@ version = "0.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0676bb32a98c1a483ce53e500a81ad9c3d5b3f7c920c28c24e9cb0980d0b5bc8"+[[package]]+name = "nu-ansi-term"+version = "0.50.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"+dependencies = [+ "windows-sys 0.61.2",+]+[[package]]name = "num-bigint"version = "0.4.6"@@ -3953,6 +3962,9 @@ dependencies = ["similar","tokio","toml",+ "tracing",+ "tracing-appender",+ "tracing-subscriber",][[package]]@@ -4628,6 +4640,15 @@ dependencies = ["digest",]+[[package]]+name = "sharded-slab"+version = "0.1.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"+dependencies = [+ "lazy_static",+]+[[package]]name = "shlex"version = "1.3.0"@@ -5024,6 +5045,12 @@ version = "2.6.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"+[[package]]+name = "symlink"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a"+[[package]]name = "syn"version = "2.0.117"@@ -5139,6 +5166,15 @@ dependencies = ["syn",]+[[package]]+name = "thread_local"+version = "1.1.10"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1ad99c4c6d32803332c548b1af0540b357b3f5fc0be8f6c6bfe8b2e6ae784070"+dependencies = [+ "cfg-if",+]+[[package]]name = "tiff"version = "0.11.3"@@ -5396,6 +5432,19 @@ dependencies = ["tracing-core",]+[[package]]+name = "tracing-appender"+version = "0.2.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c"+dependencies = [+ "crossbeam-channel",+ "symlink",+ "thiserror 2.0.18",+ "time",+ "tracing-subscriber",+]+[[package]]name = "tracing-attributes"version = "0.1.31"@@ -5414,6 +5463,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"dependencies = ["once_cell",+ "valuable",+]++[[package]]+name = "tracing-log"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"+dependencies = [+ "log",+ "once_cell",+ "tracing-core",+]++[[package]]+name = "tracing-subscriber"+version = "0.3.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319"+dependencies = [+ "nu-ansi-term",+ "sharded-slab",+ "smallvec",+ "thread_local",+ "tracing-core",+ "tracing-log",][[package]]@@ -5583,6 +5658,12 @@ dependencies = ["wasm-bindgen",]+[[package]]+name = "valuable"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65"+[[package]]name = "vcpkg"version = "0.2.15"diff --git a/crates/ragfs-python/Cargo.toml b/crates/ragfs-python/Cargo.tomlindex d466c5a11..95d866844 100644--- a/crates/ragfs-python/Cargo.toml+++ b/crates/ragfs-python/Cargo.toml@@ -23,6 +23,9 @@ ragfs = { path = "../ragfs", features = ["cache"] }ragfs-cache-redis = { path = "../ragfs-cache-redis", optional = true }pyo3 = { version = "0.27", features = ["abi3", "abi3-py310"] }tokio = { version = "1", features = ["full"] }+tracing = "0.1"+tracing-appender = "0.2"+tracing-subscriber = { version = "0.3", features = ["fmt"] }serde_json = "1.0"serde = { version = "1", features = ["derive"] }toml = "0.8"diff --git a/crates/ragfs-python/src/lib.rs b/crates/ragfs-python/src/lib.rsindex 00b0265d1..2e44b318e 100644--- a/crates/ragfs-python/src/lib.rs+++ b/crates/ragfs-python/src/lib.rs@@ -7,12 +7,156 @@use pyo3::exceptions::{PyRuntimeError, PyValueError};use pyo3::prelude::*;use pyo3::types::{PyBytes, PyDict, PyList, PyType};+use pyo3::wrap_pyfunction;use std::collections::HashMap;-use std::sync::OnceLock;+use std::fs::OpenOptions;+use std::io::{self, Write};+use std::path::{Path, PathBuf};+use std::sync::{Arc, Mutex, OnceLock};+use tracing::Level;+use tracing_subscriber::fmt::writer::BoxMakeWriter;+use tracing_appender::non_blocking::WorkerGuard;/// Cached reference to the Python `openviking.storage.errors.LockAcquisitionError` class,/// imported at module init so that native and Python code share the same exception type.static LOCK_ACQUISITION_ERROR_TYPE: OnceLock<Py<PyType>> = OnceLock::new();+static RUST_TRACING_INIT_RESULT: OnceLock<Result<(), String>> = OnceLock::new();+static RUST_TRACING_GUARD: OnceLock<WorkerGuard> = OnceLock::new();+static RUST_TRACING_FILE_STATE: OnceLock<TracingFileState> = OnceLock::new();++#[derive(Clone)]+struct SharedFileWriter {+ file: Arc<Mutex<std::fs::File>>,+}++impl Write for SharedFileWriter {+ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {+ let mut file = self+ .file+ .lock()+ .map_err(|_| io::Error::other("shared tracing log file lock poisoned"))?;+ file.write(buf)+ }++ fn flush(&mut self) -> io::Result<()> {+ let mut file = self+ .file+ .lock()+ .map_err(|_| io::Error::other("shared tracing log file lock poisoned"))?;+ file.flush()+ }+}++struct TracingFileState {+ path: PathBuf,+ file: Arc<Mutex<std::fs::File>>,+}++/// Open the configured Rust tracing log file.+fn open_tracing_log_file(path: &Path) -> Result<std::fs::File, String> {+ if let Some(parent) = path.parent() {+ std::fs::create_dir_all(parent)+ .map_err(|e| format!("failed to create Rust tracing log dir: {e}"))?;+ }+ OpenOptions::new()+ .create(true)+ .append(true)+ .open(path)+ .map_err(|e| format!("failed to open Rust tracing log file: {e}"))+}++/// Swap the shared Rust tracing file handle to the current active log file.+fn replace_tracing_log_file(+ shared: &Arc<Mutex<std::fs::File>>,+ path: &Path,+) -> Result<(), String> {+ let new_file = open_tracing_log_file(path)?;+ let mut file = shared+ .lock()+ .map_err(|_| "shared tracing log file lock poisoned".to_string())?;+ *file = new_file;+ Ok(())+}++/// Parse the configured OpenViking log level into a Rust tracing level.+fn parse_tracing_level(log_level: &str) -> Result<Level, String> {+ match log_level.to_ascii_uppercase().as_str() {+ "TRACE" => Ok(Level::TRACE),+ "DEBUG" => Ok(Level::DEBUG),+ "INFO" => Ok(Level::INFO),+ "WARN" | "WARNING" => Ok(Level::WARN),+ "CRITICAL" => Ok(Level::ERROR),+ "ERROR" => Ok(Level::ERROR),+ other => Err(format!("unsupported Rust tracing level: {other}")),+ }+}++/// Build the tracing writer from the configured OpenViking log output target.+fn build_tracing_writer(log_output: &str) -> Result<(BoxMakeWriter, WorkerGuard), String> {+ match log_output {+ "stdout" => {+ let (writer, guard) = tracing_appender::non_blocking(std::io::stdout());+ Ok((BoxMakeWriter::new(writer), guard))+ }+ "stderr" => {+ let (writer, guard) = tracing_appender::non_blocking(std::io::stderr());+ Ok((BoxMakeWriter::new(writer), guard))+ }+ path => {+ let path = Path::new(path);+ let shared = Arc::new(Mutex::new(open_tracing_log_file(path)?));+ let state = TracingFileState {+ path: path.to_path_buf(),+ file: shared.clone(),+ };+ RUST_TRACING_FILE_STATE+ .set(state)+ .map_err(|_| "Rust tracing file state already initialized".to_string())?;+ let (writer, guard) = tracing_appender::non_blocking(SharedFileWriter { file: shared });+ Ok((BoxMakeWriter::new(writer), guard))+ }+ }+}++/// Reopen the Rust tracing file writer after Python log rotation.+fn reopen_tracing_file_impl() -> Result<(), String> {+ let Some(state) = RUST_TRACING_FILE_STATE.get() else {+ return Ok(());+ };+ replace_tracing_log_file(&state.file, &state.path)+}++/// Reopen the Rust tracing log file after Python rotates the active log file.+#[pyfunction]+fn reopen_tracing_file() -> PyResult<()> {+ reopen_tracing_file_impl().map_err(PyRuntimeError::new_err)+}++/// Initialize Rust tracing once for the embedded ragfs binding process.+fn init_tracing(log_level: &str, log_output: &str) -> PyResult<()> {+ let result = RUST_TRACING_INIT_RESULT.get_or_init(|| {+ let max_level = parse_tracing_level(log_level)?;+ let (writer, guard) = build_tracing_writer(log_output)?;+ let subscriber = tracing_subscriber::fmt()+ .with_max_level(max_level)+ .with_target(true)+ .with_file(true)+ .with_line_number(true)+ .with_ansi(false)+ .with_writer(writer)+ .finish();+ tracing::subscriber::set_global_default(subscriber)+ .map_err(|e| format!("failed to install Rust tracing subscriber: {e}"))?;+ RUST_TRACING_GUARD+ .set(guard)+ .map_err(|_| "failed to retain Rust tracing worker guard".to_string())?;+ Ok(())+ });+ result+ .as_ref()+ .map(|_| ())+ .map_err(|err| PyRuntimeError::new_err(err.clone()))+}/// Map a PathLockError to the appropriate Python exception.fn pathlock_err_to_py(err: PathLockError) -> PyErr {@@ -37,7 +181,6 @@ fn pathlock_err_to_py(err: PathLockError) -> PyErr {}use std::fs;use std::future::Future;-use std::sync::Arc;use std::time::{Duration, UNIX_EPOCH};/// Validate and convert a wait timeout from Python.@@ -1123,6 +1266,20 @@ impl RAGFSBindingClient {let mut runtime_cache_config = None;let mut inline_git_cfg: Option<ragfs::git::GitConfig> = None;if let Some(cfg) = config {+ if let Some(log_obj) = cfg.get("log") {+ let log_cfg: HashMap<String, Py<PyAny>> = log_obj.extract(py)?;+ let log_level = log_cfg+ .get("level")+ .map(|value| value.extract::<String>(py))+ .transpose()?+ .unwrap_or_else(|| "INFO".to_string());+ let log_output = log_cfg+ .get("output")+ .map(|value| value.extract::<String>(py))+ .transpose()?+ .unwrap_or_else(|| "stderr".to_string());+ init_tracing(&log_level, &log_output)?;+ }if let Some(enc_obj) = cfg.get("encryption") {let enc: HashMap<String, Py<PyAny>> = enc_obj.extract(py)?;let rk: Vec<u8> = enc@@ -2580,6 +2737,7 @@ impl RAGFSBindingClient {#[pymodule]fn ragfs_python(m: &Bound<'_, PyModule>) -> PyResult<()> {m.add_class::<RAGFSBindingClient>()?;+ m.add_function(wrap_pyfunction!(reopen_tracing_file, m)?)?;// Import the Python business exception so native code raises the same type// that `openviking.storage.errors` defines, enabling `except LockAcquisitionError`.@@ -2668,6 +2826,42 @@ mod tests {fs::remove_file(path).unwrap();}+ #[test]+ fn parse_tracing_level_accepts_critical_as_error() {+ assert_eq!(parse_tracing_level("CRITICAL").unwrap(), Level::ERROR);+ }++ #[test]+ fn replace_tracing_log_file_switches_shared_writer_to_new_active_file() {+ let active = std::env::temp_dir().join(format!(+ "openviking-rust-tracing-active-{}.log",+ std::process::id()+ ));+ let rotated = std::env::temp_dir().join(format!(+ "openviking-rust-tracing-rotated-{}.log",+ std::process::id()+ ));+ let _ = fs::remove_file(&active);+ let _ = fs::remove_file(&rotated);++ let shared = Arc::new(Mutex::new(open_tracing_log_file(&active).unwrap()));+ let mut writer = SharedFileWriter { file: shared.clone() };+ writer.write_all(b"before-rotate\n").unwrap();+ writer.flush().unwrap();++ fs::rename(&active, &rotated).unwrap();+ replace_tracing_log_file(&shared, &active).unwrap();++ writer.write_all(b"after-rotate\n").unwrap();+ writer.flush().unwrap();++ assert!(fs::read_to_string(&rotated).unwrap().contains("before-rotate"));+ assert!(fs::read_to_string(&active).unwrap().contains("after-rotate"));++ let _ = fs::remove_file(&active);+ let _ = fs::remove_file(&rotated);+ }+#[tokio::test]async fn cache_provider_factory_creates_memory_provider_from_ov_conf() {let path = std::env::temp_dir().join(format!(diff --git a/crates/ragfs/src/core/encryption_wrapper.rs b/crates/ragfs/src/core/encryption_wrapper.rsindex 542e4dec9..6d014749d 100644--- a/crates/ragfs/src/core/encryption_wrapper.rs+++ b/crates/ragfs/src/core/encryption_wrapper.rs@@ -14,7 +14,7 @@ use std::time::{Duration, Instant};use async_trait::async_trait;use sha2::{Digest, Sha256};-use tracing::warn;+use tracing::{debug, warn};use crate::crypto;use crate::core::internal_names::is_hidden_runtime_lock_name;@@ -389,6 +389,8 @@ impl FileSystem for EncryptionWrappedFS {.map_err(|error| {Error::internal(format!("encrypted write lock context error: {error}"))})?;+ let action_name = match &action { AutoPathLockAction::Disabled => "disabled", AutoPathLockAction::Covered(_) => "covered", AutoPathLockAction::Acquire => "acquire" };+ debug!(path = %path, temp_path = %temp_path, final_lock_path = %requests[1].path, temp_lock_path = %requests[0].path, action = %action_name, "encrypted write resolved dual-path pathlock action");let lock_guard = match action {AutoPathLockAction::Disabled => None,AutoPathLockAction::Covered(outer) => {diff --git a/crates/ragfs/src/lock/manager.rs b/crates/ragfs/src/lock/manager.rsindex ce3aa711a..ef57fef1c 100644--- a/crates/ragfs/src/lock/manager.rs+++ b/crates/ragfs/src/lock/manager.rs@@ -8,7 +8,7 @@ use std::sync::Arc;use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};use tokio::sync::RwLock;-use tracing::error;+use tracing::{debug, error, info};use uuid::Uuid;use crate::core::internal_names::{EXACT_LOCK_FILE_PREFIX, PATH_LOCK_FILE};@@ -343,6 +343,7 @@ impl PathLockManager {}}let active_count = refresh_registry.read().await.entries.len();+ if removed > 0 { info!(removed_count = removed, active_count = active_count, expire_secs = refresh_config.lock_expire_secs, "released stale pathlock leases in background refresh"); }let mut m = refresh_metrics.write().await;m.active_lock_count = active_count;m.stale_leases_released += removed;@@ -567,6 +568,7 @@ impl PathLockManager {let sorted = Self::normalize_requests(requests);let owner_id = self.resolve_owner_id(owner_capability).await?;+ debug!(owner_id = %owner_id, requests = ?requests, normalized_requests = ?sorted, timeout_ms = timeout.as_millis() as u64, "pathlock acquire batch start");let start = Instant::now();let mut acquired_lock_paths: Vec<(String, AcquisitionChange)> = Vec::new();@@ -678,6 +680,7 @@ impl PathLockManager {{let mut metrics = self.metrics.write().await;if !is_waiting {+ info!(owner_id = %owner_id, requests = ?sorted, timeout_ms = timeout.as_millis() as u64, error = %err, "pathlock acquire batch entered wait state");is_waiting = true;metrics.waiting_lock_count += 1;}@@ -716,6 +719,7 @@ impl PathLockManager {.remove_token(lock_path, &token.owner_id).await?{+ info!(lock_path = %lock_path, stale_owner = %token.owner_id, token_kind = ?token.lock_type, age_ms = ((now_ns.saturating_sub(token.time_ns)) / 1_000_000) as u64, "removed stale pathlock token during acquire retry");self.metrics.write().await.stale_tokens_removed += 1;}}@@ -851,6 +855,7 @@ impl PathLockManager {if is_waiting {metrics.waiting_lock_count = metrics.waiting_lock_count.saturating_sub(1);}+ if is_waiting { info!(lease_ref = %lease.lease_ref, owner_id = %lease.owner_id, lock_paths = ?lease.lock_paths, covered_paths = ?lease.covered_paths, wait_ms = start.elapsed().as_millis() as u64, "pathlock acquire batch succeeded after waiting"); }return Ok(OwnedPathLockLease {lease,@@ -913,6 +918,7 @@ impl PathLockManager {.compare_and_write_token(lock_path, &existing, &token).await?{+ debug!(lock_path = %lock_path, owner_id = %owner_id, from = ?existing.lock_type, to = ?kind, "upgraded pathlock token for existing owner");return Ok(AcquisitionChange::Upgraded {previous: existing,replacement: token,@@ -924,6 +930,7 @@ impl PathLockManager {kind: existing.lock_type,});}+ debug!(lock_path = %lock_path, owner_id = %owner_id, kind = ?existing.lock_type, "reused existing pathlock token for same owner");return Ok(AcquisitionChange::Reentrant);}if !self.is_stale(&existing, now_ns) {@@ -938,6 +945,7 @@ impl PathLockManager {}self.provider.try_create_token(lock_path, &token).await?;+ debug!(lock_path = %lock_path, owner_id = %owner_id, kind = ?kind, "created new pathlock token");Ok(AcquisitionChange::Created)}@@ -1017,6 +1025,7 @@ impl PathLockManager {metrics.descendant_scan_count += 1;metrics.descendant_scan_duration_ms += scan_start.elapsed().as_millis() as u64;drop(metrics);+ debug!(path = %path, descendant_count = descendants.len(), scan_ms = scan_start.elapsed().as_millis() as u64, "scanned descendant pathlock tokens");for lp in descendants {if let Some(token) = self.provider.read_token(&lp).await? {@@ -1054,6 +1063,7 @@ impl PathLockManager {}}}+ let mut created_dirs = Vec::new();for dir in missing.into_iter().rev() {if let Err(mkdir_error) = self.resolver.fs.mkdir(&dir, 0o755).await {match self.resolver.fs.stat(&dir).await {@@ -1065,7 +1075,9 @@ impl PathLockManager {}}}+ created_dirs.push(dir);}+ if !created_dirs.is_empty() { debug!(lock_path = %lock_path, created_dirs = ?created_dirs, "ensured pathlock parent directories"); }}Ok(())}@@ -1095,13 +1107,9 @@ impl PathLockManager {.touch(&lease.lease.lease_ref);}- if all_ok && any_ok {- Ok("refreshed".to_string())- } else if any_ok {- Ok("lost".to_string())- } else {- Ok("failed".to_string())- }+ let result = if all_ok && any_ok { "refreshed" } else if any_ok { "lost" } else { "failed" };+ debug!(lease_ref = %lease.lease.lease_ref, owner_id = %lease.lease.owner_id, lock_paths = ?lease.lease.lock_paths, result = %result, "pathlock refresh completed");+ Ok(result.to_string())}/// Release an owned lease.@@ -1164,6 +1172,7 @@ impl PathLockManager {let active_count = self.lease_registry.read().await.entries.len();let mut metrics = self.metrics.write().await;metrics.active_lock_count = active_count;+ debug!(lease_ref = %lease.lease.lease_ref, owner_id = %lease.lease.owner_id, lock_paths = ?lease.lease.lock_paths, active_count = active_count, "released pathlock lease");Ok(())}@@ -1223,6 +1232,7 @@ impl PathLockManager {}let active_count = self.lease_registry.read().await.entries.len();self.metrics.write().await.active_lock_count = active_count;+ debug!(lease_ref = %lease.lease.lease_ref, owner_id = %lease.lease.owner_id, requested_lock_paths = ?lock_paths, active_count = active_count, "released selected pathlock lease paths");Ok(())}@@ -1285,6 +1295,7 @@ impl PathLockManager {.remove(&lease.lease.lease_ref);let active_count = self.lease_registry.read().await.entries.len();self.metrics.write().await.active_lock_count = active_count;+ info!(lease_ref = %lease.lease.lease_ref, owner_id = %lease.lease.owner_id, lock_paths = ?lease.lease.lock_paths, active_count = active_count, "handed off pathlock lease");Ok(())}@@ -1382,6 +1393,7 @@ impl PathLockManager {let active_count = self.lease_registry.read().await.entries.len();self.metrics.write().await.active_lock_count = active_count;+ info!(lease_ref = %lease.lease_ref, owner_id = %lease.owner_id, lock_paths = ?lease.lock_paths, legacy_handoff = legacy_handoff, active_count = active_count, "adopted pathlock lease");Ok(OwnedPathLockLease {lease,@@ -1509,9 +1521,11 @@ impl PathLockManager {) -> PathLockResult<AutoPathLockAction> {let view = FsContextView::current();if view.disable_auto_pathlock() {+ debug!(requests = ?requests, "pathlock auto action resolved to disabled");return Ok(AutoPathLockAction::Disabled);}let Some(lease_ref) = view.pathlock_lease_ref() else {+ debug!(requests = ?requests, "pathlock auto action resolved to acquire");return Ok(AutoPathLockAction::Acquire);};let lease = self@@ -1523,6 +1537,7 @@ impl PathLockManager {))})?;if requests.iter().all(|request| lease.lease.covers(request)) {+ debug!(lease_ref = %lease.lease.lease_ref, requests = ?requests, "pathlock auto action resolved to covered");Ok(AutoPathLockAction::Covered(lease))} else {Err(PathLockError::InvalidRequest(format!(diff --git a/crates/ragfs/src/lock/wrapper.rs b/crates/ragfs/src/lock/wrapper.rsindex 0258203b0..89da83064 100644--- a/crates/ragfs/src/lock/wrapper.rs+++ b/crates/ragfs/src/lock/wrapper.rs@@ -9,6 +9,7 @@use std::sync::Arc;use async_trait::async_trait;+use tracing::debug;use crate::core::filesystem::FileSystem;use crate::core::internal_names::is_hidden_runtime_lock_name;@@ -57,8 +58,9 @@ impl PathLockWrappedFS {requests: &[PathLockRequest],) -> crate::core::Result<bool> {match self.manager.resolve_auto_pathlock_action(requests).await {- Ok(AutoPathLockAction::Disabled | AutoPathLockAction::Covered(_)) => Ok(true),- Ok(AutoPathLockAction::Acquire) => Ok(false),+ Ok(AutoPathLockAction::Disabled) => { debug!(requests = ?requests, "pathlock wrapper skipped auto-lock because context disabled it"); Ok(true) }+ Ok(AutoPathLockAction::Covered(lease)) => { debug!(lease_ref = %lease.lease.lease_ref, requests = ?requests, "pathlock wrapper skipped auto-lock because active lease already covers request"); Ok(true) }+ Ok(AutoPathLockAction::Acquire) => { debug!(requests = ?requests, "pathlock wrapper will auto-acquire lease for request"); Ok(false) }Err(error) => Err(crate::core::Error::internal(format!("lock lease error: {error}"))),diff --git a/openviking/pyagfs/__init__.py b/openviking/pyagfs/__init__.pyindex bf99e99b5..ba3905975 100644--- a/openviking/pyagfs/__init__.py+++ b/openviking/pyagfs/__init__.py@@ -117,6 +117,8 @@ def _load_rust_binding():so_path = _find_ragfs_so()if so_path:spec = importlib.util.spec_from_file_location("ragfs_python", so_path)+ if spec is None or spec.loader is None:+ raise ImportError(f"Unable to load Rust binding spec from {so_path}")mod = importlib.util.module_from_spec(spec)spec.loader.exec_module(mod)return mod.RAGFSBindingClient, None@@ -140,6 +142,25 @@ def get_binding_client():raise ImportError("ragfs_python native library is not available: " + str(exc)) from exc+def reopen_rust_tracing_file() -> None:+ """Reopen the Rust tracing log file after Python rotates the active file."""+ try:+ import ragfs_python as rust_module+ except ImportError:+ so_path = _find_ragfs_so()+ if not so_path:+ return+ spec = importlib.util.spec_from_file_location("ragfs_python", so_path)+ if spec is None or spec.loader is None:+ return+ rust_module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(rust_module)++ reopen_hook = getattr(rust_module, "reopen_tracing_file", None)+ if callable(reopen_hook):+ reopen_hook()++# Module-level defaults# Ensure module import never fails, even if bindings are unavailabletry:diff --git a/openviking/utils/agfs_utils.py b/openviking/utils/agfs_utils.pyindex 7e36d243c..55a9612b2 100644--- a/openviking/utils/agfs_utils.py+++ b/openviking/utils/agfs_utils.py@@ -26,6 +26,7 @@ class RagfsBindingConfig:agfs: Anyroot_key: bytes | None = Noneprovider_type: int | None = None+ log: Dict[str, Any] | None = Nonedef encryption_enabled(self) -> bool:"""Return whether the binding stack should include the encryption layer."""@@ -38,6 +39,9 @@ class RagfsBindingConfig:"pathlock": self.agfs.pathlock.model_dump(mode="json"),}+ if self.log is not None:+ binding_config["log"] = self.log+if self.root_key is not None:if len(self.root_key) != 32:raise ValueError("root_key must be exactly 32 bytes")@@ -99,9 +103,23 @@ def build_runtime_ragfs_binding_config(config: Any) -> tuple[RagfsBindingConfig,if agfs_config is None:raise ValueError("OpenViking config storage.agfs is required")+ log_config = _get_config_value(config, "log")+ log_level = _get_config_value(log_config, "level", "INFO")+ log_level = log_level.upper() if isinstance(log_level, str) else "INFO"+ log_output = _get_config_value(log_config, "output", "stdout")+ if log_output == "file":+ workspace = _get_config_value(storage, "workspace")+ log_dir = Path(workspace).resolve() / "log"+ log_dir.mkdir(parents=True, exist_ok=True)+ log_output = str(log_dir / "openviking.log")+ binding_log = {+ "level": log_level,+ "output": log_output,+ }+encryptor = _run_coro_blocking(bootstrap_encryption(_dump_openviking_config(config)))if encryptor is None:- return RagfsBindingConfig(agfs=agfs_config), None+ return RagfsBindingConfig(agfs=agfs_config, log=binding_log), Noneroot_key = _run_coro_blocking(encryptor.provider.get_root_key())if not isinstance(root_key, (bytes, bytearray)) or len(root_key) != 32:@@ -112,6 +130,7 @@ def build_runtime_ragfs_binding_config(config: Any) -> tuple[RagfsBindingConfig,agfs=agfs_config,root_key=bytes(root_key),provider_type=encryptor.provider_type,+ log=binding_log,),encryptor,)diff --git a/openviking_cli/utils/logger.py b/openviking_cli/utils/logger.pyindex 43ce71d7a..908a43e96 100644--- a/openviking_cli/utils/logger.py+++ b/openviking_cli/utils/logger.py@@ -79,6 +79,28 @@ _request_id_context: contextvars.ContextVar[str] = contextvars.ContextVar()+def _reopen_rust_tracing_file() -> None:+ """Ask the embedded Rust tracing writer to reopen the active log file."""+ try:+ from openviking.pyagfs import reopen_rust_tracing_file+ except ImportError:+ return++ try:+ reopen_rust_tracing_file()+ except Exception as exc:+ sys.stderr.write(f"Warning: Failed to reopen Rust tracing log file: {exc}\n")+++class _RustAwareTimedRotatingFileHandler(TimedRotatingFileHandler):+ """Timed rotating file handler that refreshes the Rust tracing file handle."""++ def doRollover(self) -> None:+ """Rotate the active Python log file and then refresh the Rust writer."""+ super().doRollover()+ _reopen_rust_tracing_file()++@contextmanagerdef bind_log_request_id(request_id: str) -> Iterator[None]:"""Bind a request ID to logs emitted in the current execution context."""@@ -746,7 +768,7 @@ def _create_log_handler(log_output: str, config: Optional[Any]) -> logging.Handlwhen = log_rotation_intervalinterval = 1- return TimedRotatingFileHandler(+ return _RustAwareTimedRotatingFileHandler(log_output,when=when,interval=interval,