Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(wiki): skip a reported staging file in a path-scoped commit

AkitaOnRailse5fafea1cfbd
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f263e9a2..cd929e2f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -223,13 +223,6 @@ version in [`docs/changelog/`](docs/changelog/):
relay and wiki sync companions take the same `rustls-webpki` bump.
### Fixed
-- Wiki commits no longer stage a write that is still in flight. A batch write
- keeps one `.ai-memory-tmp.` staging file per page on disk across an await,
- and auto-commit does not hold the mutation lock, so a checkpoint landing in
- that window committed page bodies that were never installed — and a batch
- that then failed left the rolled-back content in wiki history.
- ([#1524](https://github.com/akitaonrails/ai-memory/pull/1524))
-
- Reserved local-embedding capacity for interactive search queries instead of
allowing concurrent page writes and backfill work to occupy every inference
slot. Excess queries fall back immediately to non-vector retrieval, and a
@@ -243,7 +236,14 @@ version in [`docs/changelog/`](docs/changelog/):
session-start fetch whenever any handoff was open, so the session started
with no profile digest, brief or inbox notice at all. The refusal now costs
only the claim, and the handoff stays open.
-
+- Wiki commits no longer stage a write that is still in flight. A batch write
+ keeps one `.ai-memory-tmp.` staging file per page on disk across an await,
+ and auto-commit does not hold the mutation lock, so a checkpoint landing in
+ that window committed page bodies that were never installed, and a batch
+ that then failed left the rolled-back content in wiki history. A page parked
+ under `.ai-memory-delete.` during a delete, or under
+ `.ai-memory-tmp.move-session.` during a session move, is left out the same
+ way. ([#1524](https://github.com/akitaonrails/ai-memory/pull/1524))
- `mcp-bridge` and the `setup` self-check no longer send requests to the
server through `HTTP_PROXY`, `HTTPS_PROXY` or `ALL_PROXY`, as the hooks
already did. A sandbox such as ai-jail exports a proxy with an empty
diff --git a/crates/ai-memory-wiki/src/git.rs b/crates/ai-memory-wiki/src/git.rs
index 2dd4b308..01dbd20e 100644
--- a/crates/ai-memory-wiki/src/git.rs
+++ b/crates/ai-memory-wiki/src/git.rs
@@ -939,8 +939,11 @@ fn stage_working_tree(root: &Path, index: &mut git2::Index) -> Result<Vec<PathBu
/// records a page body that may never be installed. `Wiki::apply_batch` holds
/// one staging file per page across an `await`, and `commit_all` takes only the
/// commit lock, never the mutation lock, so a checkpoint can land in that
-/// window. The watcher already ignores the same prefix
-/// ([`crate::watcher`]'s `is_tempfile`).
+/// window. A parked page is also reported by name: `rename_checked` marks the
+/// `.ai-memory-delete.` quarantine and the `.ai-memory-tmp.move-session.` name
+/// written, so the reported-file branch of [`stage_paths`] checks this too.
+/// The watcher drops both for its own reasons: `is_tempfile` matches the
+/// `.ai-memory-tmp.` prefix, and a quarantine name carries no `.md` suffix.
fn is_in_flight_write(rel: &Path) -> bool {
rel.file_name()
.and_then(|name| name.to_str())
@@ -1036,7 +1039,7 @@ fn stage_paths(
if index.get_path(rel, 0).is_some() {
index.remove_path(rel)?;
}
- } else {
+ } else if !is_in_flight_write(rel) {
index.add_path(rel)?;
}
} else if index.get_path(rel, 0).is_some() {
@@ -2014,6 +2017,31 @@ mod tests {
assert_eq!(head_blob(&adapter, "ws/proj/.ai-memory-tmp.cD4y0R"), None);
}
+ /// `quarantine_file` and `move_session_page` park a page under a staging
+ /// name with `rename_checked`, which reports that exact path, so the
+ /// reported-file branch of `stage_paths` must skip it as well.
+ #[test]
+ fn a_reported_staging_file_is_never_staged() {
+ let (_tmp, root, adapter) = committed(&[("ws/proj/a.md", "a")]);
+ let parked = [
+ "ws/proj/.ai-memory-delete.Xy12Ab",
+ "ws/proj/.ai-memory-tmp.move-session.s1.md",
+ ];
+ for rel in parked {
+ write(&root, rel, "a page between two renames");
+ adapter.mark_written(&root.join(rel));
+ }
+ write(&root, "ws/proj/c.md", "c");
+ adapter.mark_written(&root.join("ws/proj/c.md"));
+
+ adapter.commit_all("scoped with pages parked").unwrap();
+
+ assert_eq!(head_blob(&adapter, "ws/proj/c.md").as_deref(), Some("c"));
+ for rel in parked {
+ assert_eq!(head_blob(&adapter, rel), None, "{rel} was committed");
+ }
+ }
+
#[test]
fn a_commit_stages_the_reported_paths_only() {
let (_tmp, root, adapter) = committed(&[("page-7.md", "page 7"), ("page-8.md", "page 8")]);
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 838b8675..9117b8a6 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -537,7 +537,9 @@ prunable rather than only after it ages in place.
* `<data_dir>/wiki/`: markdown source of truth. Owned by a `git2`
repo so every consolidation pass + every session-end produces a
durable commit. Editable by hand in Obsidian / vim; the watcher
- reconciles outside edits.
+ reconciles outside edits. A checkpoint never stages a hook event ledger or
+ a write still in flight (an `.ai-memory-tmp.` staging file or an
+ `.ai-memory-delete.` parked page).
* `<data_dir>/db/memory.sqlite`: derived index. WAL mode. One
writer actor owns the writer `Connection`; reads go through a
cloneable read-only pool.