Skip to content

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

Rust

Merge PR #640: pin the IP login window's expiry with clock-injected tests

AkitaOnRails4d6fde092626
diff --cc crates/ai-memory-mcp/src/human_auth.rs
index 0e57f788,3fd1574e..d957f192
--- a/crates/ai-memory-mcp/src/human_auth.rs
+++ b/crates/ai-memory-mcp/src/human_auth.rs
@@@ -162,7 -163,26 +162,21 @@@ impl LoginLimiter
/// True when this IP has already spent its window. Call before Argon2.
#[must_use]
pub fn ip_blocked(&self, ip: IpAddr) -> bool {
- let now = Instant::now();
+ self.ip_blocked_at(ip, Instant::now())
+ }
+
+ /// Record an IP failure.
+ pub fn record_ip_failure(&self, ip: IpAddr) {
+ self.record_ip_failure_at(ip, Instant::now());
+ }
+
- /// Record a username failure in a fixed-size, bounded key space.
- pub fn record_username_failure(&self, username: &str) {
- self.record_username_failure_at(username, Instant::now());
- }
-
+ // The `_at` forms take the reading instead of sampling it, because the
+ // window is 60s and a test that waits it out is not a test anyone runs.
+ // Without them `prune` is unobservable: delete its body and the suite
+ // stays green, while a spent window would stop reopening and one minute
+ // of failures would lock the account out until the process restarts.
+
+ fn ip_blocked_at(&self, ip: IpAddr, now: Instant) -> bool {
let mut map = self.ip.lock().unwrap_or_else(|e| e.into_inner());
let Some(q) = map.get_mut(&ip) else {
return false;