Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(sessions): persist cross-scope aliases after reload

cyh608c51f261f0
diff --git a/modules/sessions_facade.py b/modules/sessions_facade.py
index 12969b287..8afd34070 100644
--- a/modules/sessions_facade.py
+++ b/modules/sessions_facade.py
@@ -183,7 +183,7 @@ class SessionsFacade:
self.sessions_store._ensure_user_namespace(target_key)
source_agent_maps = self.sessions_store.state.session_mappings.get(source_key, {})
- target_agent_maps = self.sessions_store.state.session_mappings.get(target_key, {})
+ aliases_to_bind: List[tuple[str, str, Any]] = []
changed = False
for agent_name, source_agent_map in source_agent_maps.items():
@@ -199,6 +199,10 @@ class SessionsFacade:
additions[alias_key] = native_session_id
if additions:
target_agent_map.update(additions)
+ aliases_to_bind.extend(
+ (agent_name, alias_key, native_session_id)
+ for alias_key, native_session_id in additions.items()
+ )
changed = True
logger.info(
"Aliased %s session base across scopes: %s/%s -> %s/%s (%s keys)",
@@ -211,10 +215,8 @@ class SessionsFacade:
)
if changed:
- for agent_name, target_agent_map in target_agent_maps.items():
- for mapping_key, native_session_id in target_agent_map.items():
- if self._matches_base_prefix(mapping_key, alias_base_session_id):
- self.sessions_store.bind_agent_session(target_key, agent_name, mapping_key, native_session_id)
+ for agent_name, mapping_key, native_session_id in aliases_to_bind:
+ self.sessions_store.bind_agent_session(target_key, agent_name, mapping_key, native_session_id)
return changed
def clear_session_base(self, user_id: Union[int, str], base_session_id: str) -> int:
diff --git a/tests/test_sqlite_sessions_store.py b/tests/test_sqlite_sessions_store.py
index 02b2c6f80..dfb01ce8d 100644
--- a/tests/test_sqlite_sessions_store.py
+++ b/tests/test_sqlite_sessions_store.py
@@ -7,6 +7,7 @@ from sqlalchemy import select
from config import paths
from config.v2_sessions import ActivePollInfo, SessionState, SessionsStore
+from modules.sessions_facade import SessionsFacade
from storage.db import create_sqlite_engine
from storage.models import agent_sessions
from storage.sessions_service import SQLiteSessionsService
@@ -315,6 +316,37 @@ def test_sessions_store_lifecycle_survives_followup_save(tmp_path: Path) -> None
reloaded.close()
+def test_sessions_facade_cross_scope_alias_persists_after_reload_during_target_map_read(tmp_path: Path) -> None:
+ sessions_path = tmp_path / "sessions.json"
+ store = SessionsStore(sessions_path)
+ facade = SessionsFacade(store)
+ try:
+ store.bind_agent_session("slack::C123", "codex", "slack_source-1", "native-base")
+ store.bind_agent_session("slack::C123", "codex", "slack_source-1:/repo", "native-workdir")
+ external = SQLiteSessionsService(tmp_path / "vibe.sqlite")
+ try:
+ external.try_record_runtime_event("test_external_write", "reload-marker")
+ finally:
+ external.close()
+
+ assert facade.alias_session_base_across_scopes(
+ "slack::C123",
+ "slack::C999",
+ "slack_source-1",
+ "slack_target-1",
+ )
+
+ reloaded = SessionsStore(sessions_path)
+ try:
+ target_map = reloaded.state.session_mappings["slack::C999"]["codex"]
+ assert target_map["slack_target-1"] == "native-base"
+ assert target_map["slack_target-1:/repo"] == "native-workdir"
+ finally:
+ reloaded.close()
+ finally:
+ store.close()
+
+
def test_sessions_store_atomically_claims_processed_messages_across_instances(tmp_path: Path) -> None:
sessions_path = tmp_path / "sessions.json"
first = SessionsStore(sessions_path)