Skip to content

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

Rust

fix(audit-P2): deflake drain-lock release assertion under parallel tests

AkitaOnRails94c34ef57d66
diff --git a/crates/ai-memory-cli/src/commands/hook_spool.rs b/crates/ai-memory-cli/src/commands/hook_spool.rs
index 598ef8c5..e9e04a9e 100644
--- a/crates/ai-memory-cli/src/commands/hook_spool.rs
+++ b/crates/ai-memory-cli/src/commands/hook_spool.rs
@@ -932,8 +932,15 @@ mod tests {
);
drop(first);
+ // Bounded wait instead of NoWait: a child process fork+exec'd by a
+ // concurrently running test briefly inherits this flock's fd between
+ // fork and exec (the lock lives until the duplicated descriptor is
+ // closed by exec's CLOEXEC), so an instantaneous re-acquire can
+ // spuriously see the lock still held. The bounded window still
+ // proves release-on-drop; only a leaked/undropped lock would hold
+ // for a full five seconds.
assert!(
- acquire_drain_lock(&spool, DrainLockWait::NoWait)
+ acquire_drain_lock(&spool, DrainLockWait::Bounded(Duration::from_secs(5)))
.unwrap()
.is_some(),
"lock should release on drop"