Skip to content

The agent that grows with you

fix(memory): key the stuck-call registries by the home providers were bound to

kshitijk4poor9f0c6824bcd7
diff --git a/agent/memory_manager.py b/agent/memory_manager.py
index d5a788914ed..72810d02697 100644
--- a/agent/memory_manager.py
+++ b/agent/memory_manager.py
@@ -332,7 +332,7 @@ class MemoryManager:
result_box: dict[str, Any] = {}
- key = (self._home_key, provider.name)
+ key = self._registry_key(provider)
def _run() -> None:
try:
@@ -493,7 +493,7 @@ class MemoryManager:
if provider.name == "builtin":
call()
return
- key = (self._home_key, provider.name)
+ key = self._registry_key(provider)
token = object()
now = time.monotonic()
with self._BACKGROUND_CALLS_LOCK:
@@ -515,6 +515,11 @@ class MemoryManager:
if _forget_inflight(self._BACKGROUND_CALLS, key, token):
self._BACKGROUND_SKIPS.pop(key, None)
+ def _registry_key(self, provider: MemoryProvider) -> tuple[str, str]:
+ """Process-wide registry key: the home the providers were bound to (``initialize_all``, which may
+ name another profile than the one this manager was built in), else the build-time home."""
+ return ((self._bound_scope or {}).get("home_key") or self._home_key, provider.name)
+
def _forget_background_future(self, future: Future) -> None:
with self._sync_executor_lock:
self._background_futures.pop(future, None)
diff --git a/tests/agent/test_memory_provider.py b/tests/agent/test_memory_provider.py
index 58f87ddca31..7160bd77a4e 100644
--- a/tests/agent/test_memory_provider.py
+++ b/tests/agent/test_memory_provider.py
@@ -560,6 +560,26 @@ class TestMemoryManager:
finally:
orphan.release.set()
+ def test_registry_is_keyed_by_the_home_providers_were_bound_to(self, tmp_path, monkeypatch):
+ """Two managers built in one ambient home but initialized for profiles A and B: A's stuck
+ prefetch must not gate B, whose providers belong to another profile."""
+ import agent.memory_manager as mm
+
+ monkeypatch.setattr(mm, "_MAX_STUCK_CALLS", 1)
+ stuck, other = BlockingPrefetchProvider("bound-home"), FakeMemoryProvider("bound-home")
+ other._prefetch_result = "profile b memory"
+ mgr_a = MemoryManager(external_prefetch_timeout=0.01)
+ mgr_b = MemoryManager(external_prefetch_timeout=5.0)
+ for mgr, provider, home in ((mgr_a, stuck, "a"), (mgr_b, other, "b")):
+ mgr.add_provider(provider)
+ mgr.initialize_all(session_id=home, hermes_home=str(tmp_path / home))
+ try:
+ mgr_a._prefetch_provider(stuck, "q", session_id="a")
+ assert stuck.started.wait(timeout=2.0)
+ assert mgr_b._prefetch_provider(other, "q", session_id="b") == "profile b memory"
+ finally:
+ stuck.release.set()
+
def test_healthy_concurrent_prefetches_from_two_sessions_both_recall(self):
"""Only a TIMED-OUT call gates other managers: a slow-but-healthy prefetch in one session
must not blank the recall of another session that prefetches meanwhile."""
diff --git a/tests/agent/test_memory_stalled_background_call.py b/tests/agent/test_memory_stalled_background_call.py
index 4b3fd7692aa..04af0d5498b 100644
--- a/tests/agent/test_memory_stalled_background_call.py
+++ b/tests/agent/test_memory_stalled_background_call.py
@@ -93,7 +93,7 @@ def test_sustained_wedge_pins_at_most_max_stuck_threads():
assert fresh.flush_pending(timeout=5) # returns: nothing blocked behind the hung calls
fresh.shutdown_all()
- key = (hung[0][0]._home_key, hung[0][1].name)
+ key = hung[0][0]._registry_key(hung[0][1])
assert MemoryManager._BACKGROUND_SKIPS[key] == 10
assert len(MemoryManager._BACKGROUND_CALLS[key]) == mm._MAX_STUCK_CALLS
# Idle workers of shut-down executors exit asynchronously.