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(sentry): evict oldest rate entries

cyh6c66bf56310a
diff --git a/tests/test_sentry_integration.py b/tests/test_sentry_integration.py
index a21d80a6c..44d1c8e93 100644
--- a/tests/test_sentry_integration.py
+++ b/tests/test_sentry_integration.py
@@ -339,6 +339,23 @@ def test_event_rate_state_enforces_cache_limit(monkeypatch):
assert len(sentry_integration._EVENT_RATE_STATE) == 2
+def test_event_rate_state_evicts_oldest_entries(monkeypatch):
+ monkeypatch.setattr(sentry_integration, "_EVENT_RATE_CACHE_LIMIT", 2)
+ sentry_integration._EVENT_RATE_STATE.clear()
+ sentry_integration._EVENT_RATE_STATE.update(
+ {
+ "z-oldest": (1.0, 1),
+ "a-middle": (2.0, 1),
+ "m-newest": (3.0, 1),
+ }
+ )
+
+ sentry_integration._prune_event_rate_state(now=3.0, window_seconds=10.0)
+
+ assert "z-oldest" not in sentry_integration._EVENT_RATE_STATE
+ assert set(sentry_integration._EVENT_RATE_STATE) == {"a-middle", "m-newest"}
+
+
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()
diff --git a/vibe/sentry_integration.py b/vibe/sentry_integration.py
index bbc55607c..a33658d03 100644
--- a/vibe/sentry_integration.py
+++ b/vibe/sentry_integration.py
@@ -365,7 +365,11 @@ def _prune_event_rate_state(now: float, window_seconds: float) -> None:
if overflow <= 0:
return
oldest_keys = [
- key for key, _timestamp in sorted((key, value[0]) for key, value in _EVENT_RATE_STATE.items())[:overflow]
+ key
+ for key, _timestamp in sorted(
+ ((key, value[0]) for key, value in _EVENT_RATE_STATE.items()),
+ key=lambda item: item[1],
+ )[:overflow]
]
for key in oldest_keys:
_EVENT_RATE_STATE.pop(key, None)