From bef1bfbb337faf911e2795c6263e38d02cd6bdf1 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 7 Apr 2026 19:27:36 -0400 Subject: [PATCH] Fix deadlock: lock subconscious before store (store is bottom-most) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit subconscious_snapshots() was acquiring store→subconscious while collect_results() holds subconscious→store — classic ABBA deadlock. Fix: always acquire subconscious first, store second. Store is the bottom-most lock in the ordering. Co-Authored-By: Proof of Concept --- src/mind/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mind/mod.rs b/src/mind/mod.rs index 50d1bf0..4d2a223 100644 --- a/src/mind/mod.rs +++ b/src/mind/mod.rs @@ -249,12 +249,14 @@ impl Mind { /// Initialize — restore log, start daemons and background agents. pub async fn subconscious_snapshots(&self) -> Vec { + // Lock ordering: subconscious → store (store is bottom-most). + let sub = self.subconscious.lock().await; let store = crate::store::Store::cached().await.ok(); let store_guard = match &store { Some(s) => Some(s.lock().await), None => None, }; - self.subconscious.lock().await.snapshots(store_guard.as_deref()) + sub.snapshots(store_guard.as_deref()) } pub async fn subconscious_walked(&self) -> Vec {