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(channels): debounce after persistence

cyh4ec896874fb8
diff --git a/core/chat_discovery.py b/core/chat_discovery.py
index 26bd85bf3..1ee9502cc 100644
--- a/core/chat_discovery.py
+++ b/core/chat_discovery.py
@@ -293,7 +293,6 @@ def remember_chat(
cached = _debounce_cache.get(debounce_key)
if cached is not None and monotonic_now - cached[0] < _DEBOUNCE_SECONDS and cached[1] == debounce_payload:
return
- _debounce_cache[debounce_key] = (monotonic_now, debounce_payload)
now = _utc_now_iso()
engine = _engine(db_path)
@@ -320,6 +319,8 @@ def remember_chat(
and _seconds_since(row["last_seen_at"]) < _DEBOUNCE_SECONDS
)
if unchanged:
+ with _debounce_lock:
+ _debounce_cache[debounce_key] = (monotonic_now, debounce_payload)
return
is_private = final_is_private
supports_threads = final_supports_threads
@@ -339,6 +340,8 @@ def remember_chat(
)
finally:
engine.dispose()
+ with _debounce_lock:
+ _debounce_cache[debounce_key] = (monotonic_now, debounce_payload)
def list_chats(
diff --git a/tests/test_chat_discovery.py b/tests/test_chat_discovery.py
index ce8628036..21533a4bd 100644
--- a/tests/test_chat_discovery.py
+++ b/tests/test_chat_discovery.py
@@ -69,6 +69,34 @@ def test_remember_chat_lists_inventory_with_configured_state(tmp_path: Path) ->
assert chats[0].visibility_status == chat_discovery.VISIBILITY_VISIBLE
+def test_remember_chat_debounce_does_not_suppress_retry_after_persist_failure(tmp_path: Path, monkeypatch) -> None:
+ db_path = tmp_path / "vibe.sqlite"
+ run_migrations(db_path)
+ original_upsert_scope = chat_discovery.upsert_scope
+ calls = 0
+
+ def flaky_upsert_scope(*args, **kwargs):
+ nonlocal calls
+ calls += 1
+ if calls == 1:
+ raise RuntimeError("database is locked")
+ return original_upsert_scope(*args, **kwargs)
+
+ monkeypatch.setattr(chat_discovery, "upsert_scope", flaky_upsert_scope)
+
+ try:
+ chat_discovery.remember_chat("telegram", "retry", name="Retry", db_path=db_path)
+ except RuntimeError as exc:
+ assert str(exc) == "database is locked"
+
+ chat_discovery.remember_chat("telegram", "retry", name="Retry", db_path=db_path)
+
+ chats = chat_discovery.list_chats("telegram", db_path=db_path)
+
+ assert calls == 2
+ assert [chat.chat_id for chat in chats] == ["retry"]
+
+
def test_legacy_discovered_chats_migration_is_idempotent(tmp_path: Path) -> None:
db_path = tmp_path / "vibe.sqlite"
run_migrations(db_path)