Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(wiki): skip transient sharing violations in confinement walks (#1107)
AkitaOnRailsd0f555038b97
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b74f5839..c19436c1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0provider. (#1026)### Fixed+- Fixed wiki confinement walks failing on Windows with `PermissionDenied`+ (sharing violation) or `ERROR_DELETE_PENDING` when a concurrent commit or+ the atomic writer held or rename-replaced a file mid-walk; per-entry walk+ probes now skip those as transient churn exactly like the NotFound vanish+ race, while every entry that does stat is still refused when link-like and+ root-level probes keep their strict semantics. (#1107)- Fixed generic OpenCode commands selecting integration contracts from commandspelling instead of the executable's major version. `run opencode` now probesthe exact executable once and carries the resolved V1/V2 dialect throughdiff --git a/crates/ai-memory-wiki/src/confinement.rs b/crates/ai-memory-wiki/src/confinement.rsindex 6970c1d4..004ffbac 100644--- a/crates/ai-memory-wiki/src/confinement.rs+++ b/crates/ai-memory-wiki/src/confinement.rs@@ -209,18 +209,22 @@ pub(crate) fn inspect_tree_except(root: &Path, excluded_roots: &[&Path]) -> Wikilet entry = match entry {Ok(entry) => entry,// The directory went away mid-listing; the rest of it is- // as unobserved as the part already read.- Err(error) if error.kind() == std::io::ErrorKind::NotFound => break,+ // as unobserved as the part already read. On Windows the+ // same churn surfaces as sharing violations or+ // delete-pending handles instead of NotFound.+ Err(error) if is_transient_churn(&error) => break,Err(error) => return Err(error.into()),};let path = entry.path();- // Vanish-tolerant, never link-tolerant: an entry gone by the- // time it is statted was not observed, so there is nothing to- // refuse; every entry that IS stat-able must pass the- // link-like check below.+ // Vanish-tolerant, never link-tolerant: an entry unstatable by+ // the time it is probed — deleted outright, or held and+ // rename-replaced by a concurrent commit under Windows sharing+ // semantics — was not observed, so there is nothing to refuse;+ // every entry that IS stat-able must pass the link-like check+ // below.let metadata = match std::fs::symlink_metadata(&path) {Ok(metadata) => metadata,- Err(error) if error.kind() == std::io::ErrorKind::NotFound => continue,+ Err(error) if is_transient_churn(&error) => continue,Err(error) => return Err(error.into()),};if is_link_like(&metadata) {@@ -252,6 +256,26 @@ pub(crate) fn is_link_like(metadata: &std::fs::Metadata) -> bool {}}+/// Whether a walk-probe error is concurrent-writer churn rather than a+/// verdict about the tree.+///+/// Windows rename semantics give the vanish race a second shape: the+/// atomic writer rename-replaces files and a concurrent commit holds+/// `.git` lock and temp files, so a stat on an already-listed entry can+/// fail with a sharing violation (`PermissionDenied`) or+/// `ERROR_DELETE_PENDING` for a path that exists again — or does not —+/// an instant later. Like NotFound, neither says anything stable enough+/// to act on, so the walk skips the entry; any entry that does stat+/// still faces the link-like refusal.+fn is_transient_churn(error: &std::io::Error) -> bool {+ // ERROR_DELETE_PENDING: std maps sharing violations to+ // PermissionDenied but leaves this one an unmapped raw code.+ const ERROR_DELETE_PENDING: i32 = 303;+ error.kind() == std::io::ErrorKind::NotFound+ || error.kind() == std::io::ErrorKind::PermissionDenied+ || error.raw_os_error() == Some(ERROR_DELETE_PENDING)+}+fn inspect_root(root: &Path) -> WikiResult<()> {let metadata = std::fs::symlink_metadata(root)?;require_directory(root, &metadata)@@ -348,7 +372,8 @@ mod tests {/// A walk beside create/delete churn (a concurrent commit's `.git`/// lock and temp files, an atomic writer's temp renames) must not/// fail on an entry that vanishes between read_dir and stat — while- /// a link the walk does observe is still refused.+ /// a link the walk does observe is still refused, and the walk runs+ /// clean once the churn stops.#[test]fn tree_walks_skip_entries_that_vanish_but_still_refuse_observed_links() {use std::sync::Arc;@@ -377,6 +402,11 @@ mod tests {racer.join().unwrap();let _ = std::fs::remove_file(&scratch);+ // Churn settled: a plain walk over the now-stable tree must+ // succeed, proving the skip tolerance above leaves no lingering+ // failure behind on the next walk.+ inspect_tree_except(&root, &[]).unwrap();+#[cfg(any(unix, windows))]{let outside = temp.path().join("outside");