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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(sessions): prune processed claims on hot path
cyh16da4ef0dac1
diff --git a/storage/sessions_service.py b/storage/sessions_service.pyindex 3c3dc6337..2835bfafd 100644--- a/storage/sessions_service.py+++ b/storage/sessions_service.py@@ -217,6 +217,7 @@ class SQLiteSessionsService:updated_at=now,))+ _prune_processed_message_records(conn, channel_id=channel_key, thread_id=thread_key)except IntegrityError:return Falsereturn True@@ -282,6 +283,7 @@ class SQLiteSessionsService:)with self.engine.begin() as conn:_upsert_runtime_record(conn, values)+ _prune_processed_message_records(conn, channel_id=channel_key, thread_id=thread_key)def mark_thread_active(self, scope_key: str, channel_id: str, thread_ts: str, last_active_at: float) -> None:now = _utc_now_iso()@@ -513,11 +515,11 @@ class SQLiteSessionsService:)for (channel_id, thread_id), record_keys in retained_processed_records.items():- conn.execute(- runtime_records.delete()- .where(runtime_records.c.record_type == "processed_message")- .where(runtime_records.c.record_key.like(f"{channel_id}|{thread_id}|%"))- .where(runtime_records.c.record_key.not_in(record_keys))+ _prune_processed_message_records(+ conn,+ channel_id=channel_id,+ thread_id=thread_id,+ retained_record_keys=record_keys,)if state.last_activity is not None:@@ -814,6 +816,55 @@ def _processed_message_record_key(channel_id: str, thread_id: str, message_id: sreturn "|".join((str(channel_id), str(thread_id), str(message_id)))+def _processed_message_like_prefix(channel_id: str, thread_id: str) -> str:+ prefix = _processed_message_record_key(channel_id, thread_id, "")+ return f"{_escape_sql_like(prefix)}%"+++def _escape_sql_like(value: str) -> str:+ return (+ str(value)+ .replace("\\", "\\\\")+ .replace("%", "\\%")+ .replace("_", "\\_")+ )+++def _prune_processed_message_records(+ conn: Connection,+ *,+ channel_id: str,+ thread_id: str,+ retained_record_keys: set[str] | None = None,+) -> None:+ retained = set(retained_record_keys or [])+ prefix_pattern = _processed_message_like_prefix(channel_id, thread_id)+ if retained:+ conn.execute(+ runtime_records.delete()+ .where(runtime_records.c.record_type == "processed_message")+ .where(runtime_records.c.record_key.like(prefix_pattern, escape="\\"))+ .where(runtime_records.c.record_key.not_in(retained))+ )+ return++ rows = conn.execute(+ select(runtime_records.c.record_key)+ .where(runtime_records.c.record_type == "processed_message")+ .where(runtime_records.c.record_key.like(prefix_pattern, escape="\\"))+ .order_by(runtime_records.c.created_at.desc())+ .offset(200)+ ).all()+ old_record_keys = [row[0] for row in rows]+ if not old_record_keys:+ return+ conn.execute(+ runtime_records.delete()+ .where(runtime_records.c.record_type == "processed_message")+ .where(runtime_records.c.record_key.in_(old_record_keys))+ )++def _upsert_runtime_record(conn: Connection, values: dict[str, Any], *, update_created_at: bool = False) -> None:stmt = sqlite_insert(runtime_records).values(**values)set_values = {diff --git a/tests/test_sqlite_sessions_store.py b/tests/test_sqlite_sessions_store.pyindex 04d4d464f..8c7bd3337 100644--- a/tests/test_sqlite_sessions_store.py+++ b/tests/test_sqlite_sessions_store.py@@ -396,6 +396,46 @@ def test_sessions_store_save_prunes_stale_processed_claim_rows(tmp_path: Path) -service.close()+def test_sessions_store_hot_path_prunes_processed_claim_rows(tmp_path: Path) -> None:+ db_path = tmp_path / "vibe.sqlite"+ service = SQLiteSessionsService(db_path)+ try:+ for index in range(205):+ assert service.try_record_processed_message("C123", "171717.123", f"msg-{index:03d}") is True++ engine = create_sqlite_engine(db_path)+ try:+ with engine.connect() as conn:+ runtime_count = conn.exec_driver_sql(+ "select count(*) from runtime_records where record_type = 'processed_message'"+ ).scalar_one()+ finally:+ engine.dispose()++ assert runtime_count == 200+ processed = service.load_state().processed_message_ts["C123"]["171717.123"]+ assert processed[0] == "msg-005"+ assert processed[-1] == "msg-204"+ finally:+ service.close()+++def test_sessions_store_prunes_processed_claims_with_escaped_like_prefix(tmp_path: Path) -> None:+ db_path = tmp_path / "vibe.sqlite"+ service = SQLiteSessionsService(db_path)+ try:+ for index in range(205):+ assert service.try_record_processed_message("C_1", "thread%1", f"msg-{index:03d}") is True+ assert service.try_record_processed_message("CA1", "threadX1", "other-thread-message") is True++ processed = service.load_state().processed_message_ts+ assert processed["C_1"]["thread%1"][0] == "msg-005"+ assert processed["C_1"]["thread%1"][-1] == "msg-204"+ assert processed["CA1"]["threadX1"] == ["other-thread-message"]+ finally:+ service.close()++def test_sessions_store_runtime_updates_do_not_flush_stale_snapshots(tmp_path: Path) -> None:sessions_path = tmp_path / "sessions.json"stale = SessionsStore(sessions_path)