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(sentry): guard rate caches with lock
cyh7376d7a69c55
diff --git a/tests/test_sentry_integration.py b/tests/test_sentry_integration.pyindex 106420730..a21d80a6c 100644--- a/tests/test_sentry_integration.py+++ b/tests/test_sentry_integration.py@@ -4,6 +4,7 @@ import sysimport typesimport importlibimport ast+from concurrent.futures import ThreadPoolExecutorfrom pathlib import Pathsys.path.insert(0, str(Path(__file__).resolve().parents[1]))@@ -336,3 +337,21 @@ def test_event_rate_state_enforces_cache_limit(monkeypatch):assert sentry_integration.before_send(event, {}) is not Noneassert len(sentry_integration._EVENT_RATE_STATE) == 2+++def test_before_send_rate_state_is_thread_safe(monkeypatch):+ monkeypatch.setattr(sentry_integration, "_EVENT_RATE_CACHE_LIMIT", 8)+ sentry_integration._EVENT_RATE_STATE.clear()++ def send_event(index: int) -> bool:+ event = {+ "logger": "core.message_dispatcher",+ "logentry": {"formatted": f"concurrent application bug {index}"},+ }+ return sentry_integration.before_send(event, {}) is not None++ with ThreadPoolExecutor(max_workers=8) as executor:+ results = list(executor.map(send_event, range(64)))++ assert all(results)+ assert len(sentry_integration._EVENT_RATE_STATE) <= 8diff --git a/vibe/sentry_integration.py b/vibe/sentry_integration.pyindex 51e2d17ff..bbc55607c 100644--- a/vibe/sentry_integration.py+++ b/vibe/sentry_integration.py@@ -6,6 +6,7 @@ import platformimport reimport socketimport sys+import threadingimport timefrom pathlib import Pathfrom typing import Any, Optional@@ -48,6 +49,7 @@ _ONE_DAY_SECONDS = 60 * 60 * 24_NOISY_EVENT_TTL_SECONDS = _ONE_DAY_SECONDS_NOISY_EVENT_CACHE_LIMIT = 128_NOISY_EVENT_LAST_SEEN: dict[str, float] = {}+_SENTRY_EVENT_CACHE_LOCK = threading.RLock()_EVENT_RATE_WINDOW_SECONDS = _ONE_DAY_SECONDS * 2_EVENT_RATE_LIMIT_PER_WINDOW = 1_EVENT_RATE_CACHE_LIMIT = 2048@@ -302,14 +304,15 @@ def _should_drop_noisy_event(event: dict[str, Any]) -> bool:return Falsenow = time.monotonic()- last_seen = _NOISY_EVENT_LAST_SEEN.get(fingerprint)- _NOISY_EVENT_LAST_SEEN[fingerprint] = now+ with _SENTRY_EVENT_CACHE_LOCK:+ last_seen = _NOISY_EVENT_LAST_SEEN.get(fingerprint)+ _NOISY_EVENT_LAST_SEEN[fingerprint] = now- if len(_NOISY_EVENT_LAST_SEEN) > _NOISY_EVENT_CACHE_LIMIT:- expired_before = now - ttl_seconds- for key, timestamp in list(_NOISY_EVENT_LAST_SEEN.items()):- if timestamp < expired_before:- _NOISY_EVENT_LAST_SEEN.pop(key, None)+ if len(_NOISY_EVENT_LAST_SEEN) > _NOISY_EVENT_CACHE_LIMIT:+ expired_before = now - ttl_seconds+ for key, timestamp in list(_NOISY_EVENT_LAST_SEEN.items()):+ if timestamp < expired_before:+ _NOISY_EVENT_LAST_SEEN.pop(key, None)return last_seen is not None and now - last_seen < ttl_seconds@@ -361,7 +364,9 @@ def _prune_event_rate_state(now: float, window_seconds: float) -> None:overflow = len(_EVENT_RATE_STATE) - _EVENT_RATE_CACHE_LIMITif overflow <= 0:return- oldest_keys = sorted(_EVENT_RATE_STATE, key=lambda key: _EVENT_RATE_STATE[key][0])[:overflow]+ oldest_keys = [+ key for key, _timestamp in sorted((key, value[0]) for key, value in _EVENT_RATE_STATE.items())[:overflow]+ ]for key in oldest_keys:_EVENT_RATE_STATE.pop(key, None)@@ -377,14 +382,15 @@ def _should_drop_repeated_event(event: dict[str, Any]) -> bool:now = time.monotonic()fingerprint = _event_rate_fingerprint(event)- window_started_at, count = _EVENT_RATE_STATE.get(fingerprint, (now, 0))- if now - window_started_at >= window_seconds:- window_started_at = now- count = 0-- count += 1- _EVENT_RATE_STATE[fingerprint] = (window_started_at, count)- _prune_event_rate_state(now, window_seconds)+ with _SENTRY_EVENT_CACHE_LOCK:+ window_started_at, count = _EVENT_RATE_STATE.get(fingerprint, (now, 0))+ if now - window_started_at >= window_seconds:+ window_started_at = now+ count = 0++ count += 1+ _EVENT_RATE_STATE[fingerprint] = (window_started_at, count)+ _prune_event_rate_state(now, window_seconds)return count > limit