Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat(helm): M3 multi-signal HPA external metrics + behavior (dev shadow, prod disabled) (#9833)
Kian Jones500293703a1a
diff --git a/fern/openapi.json b/fern/openapi.jsonindex 7e5c36067..245ed7a5b 100644--- a/fern/openapi.json+++ b/fern/openapi.json@@ -38703,6 +38703,7 @@"deepseek","xai","zai",+ "baseten","fireworks","openrouter","chatgpt_oauth"@@ -43105,6 +43106,7 @@"enum": ["anthropic","azure",+ "baseten","bedrock","cerebras","chatgpt_oauth",diff --git a/letta/monitoring/event_loop_watchdog.py b/letta/monitoring/event_loop_watchdog.pyindex a1dfd1c1c..61c5845cc 100644--- a/letta/monitoring/event_loop_watchdog.py+++ b/letta/monitoring/event_loop_watchdog.py@@ -39,8 +39,10 @@ class EventLoopWatchdog:self.timeout_threshold = timeout_thresholdself._thread: Optional[threading.Thread] = Noneself._stop_event = threading.Event()- self._last_heartbeat = time.time()- self._heartbeat_scheduled_at = time.time()+ # Use monotonic time for watchdog timing to avoid wall-clock jumps (e.g. NTP)+ # producing negative lag samples.+ self._last_heartbeat = time.monotonic()+ self._heartbeat_scheduled_at = time.monotonic()self._heartbeat_lock = threading.Lock()self._loop: Optional[asyncio.AbstractEventLoop] = Noneself._monitoring = False@@ -57,7 +59,7 @@ class EventLoopWatchdog:self._loop = loopself._monitoring = Trueself._stop_event.clear()- now = time.time()+ now = time.monotonic()self._last_heartbeat = nowself._heartbeat_scheduled_at = now@@ -85,10 +87,10 @@ class EventLoopWatchdog:if not self._monitoring:return- now = time.time()+ now = time.monotonic()with self._heartbeat_lock:# Calculate event loop lag: time between when we scheduled this callback and when it ran- lag = now - self._heartbeat_scheduled_at+ lag = max(0.0, now - self._heartbeat_scheduled_at)self._last_heartbeat = nowself._heartbeat_scheduled_at = now + 1.0@@ -118,10 +120,10 @@ class EventLoopWatchdog:last_beat = self._last_heartbeatscheduled_at = self._heartbeat_scheduled_at- now = time.time()+ now = time.monotonic()time_since_heartbeat = now - last_beat# Calculate current lag: how far behind schedule is the heartbeat?- current_lag = now - scheduled_at+ current_lag = max(0.0, now - scheduled_at)max_lag_seen = max(max_lag_seen, current_lag)# Try to estimate event loop load (safe from separate thread)diff --git a/letta/otel/db_pool_monitoring.py b/letta/otel/db_pool_monitoring.pyindex b80cdb1f0..bdcb13586 100644--- a/letta/otel/db_pool_monitoring.py+++ b/letta/otel/db_pool_monitoring.py@@ -105,12 +105,15 @@ class DatabasePoolMonitor:MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs)MetricRegistry().db_pool_connections_total_gauge.set(pool_stats["total"], attributes=attrs)MetricRegistry().db_pool_in_use_gauge.set(pool_stats["checked_out"], attributes=attrs)+ utilization_ratio = (pool_stats["checked_out"] / pool_stats["total"]) if pool_stats["total"] > 0 else 0.0+ MetricRegistry().db_pool_utilization_ratio_gauge.set(utilization_ratio, attributes=attrs)waiters = self._get_pool_waiters(pool)MetricRegistry().db_pool_waiters_gauge.set(waiters, attributes=attrs)if pool_stats["overflow"] is not None:MetricRegistry().db_pool_connections_overflow_gauge.set(pool_stats["overflow"], attributes=attrs)else:MetricRegistry().db_pool_in_use_gauge.set(0, attributes=attrs)+ MetricRegistry().db_pool_utilization_ratio_gauge.set(0.0, attributes=attrs)MetricRegistry().db_pool_waiters_gauge.set(0, attributes=attrs)# Record checkout event@@ -160,6 +163,9 @@ class DatabasePoolMonitor:pool_stats = self._get_pool_stats(pool)MetricRegistry().db_pool_connections_checked_out_gauge.set(pool_stats["checked_out"], attributes=attrs)MetricRegistry().db_pool_connections_available_gauge.set(pool_stats["available"], attributes=attrs)+ MetricRegistry().db_pool_in_use_gauge.set(pool_stats["checked_out"], attributes=attrs)+ utilization_ratio = (pool_stats["checked_out"] / pool_stats["total"]) if pool_stats["total"] > 0 else 0.0+ MetricRegistry().db_pool_utilization_ratio_gauge.set(utilization_ratio, attributes=attrs)# Record checkin eventattrs["event"] = "checkin"diff --git a/letta/otel/metric_registry.py b/letta/otel/metric_registry.pyindex 44d825663..09dd2db48 100644--- a/letta/otel/metric_registry.py+++ b/letta/otel/metric_registry.py@@ -332,6 +332,7 @@ class MetricRegistry:unit="1",),)+# Database connection pool metrics# (includes engine_name, pool_mode)@property@@ -359,6 +360,19 @@ class MetricRegistry:),)+ # (includes engine_name, pool_mode)+ @property+ def db_pool_utilization_ratio_gauge(self) -> Gauge:+ return self._get_or_create_metric(+ "db_pool_utilization_ratio",+ partial(+ self._meter.create_gauge,+ name="db_pool_utilization_ratio",+ description="Ratio of checked-out base pool connections to configured pool size (excludes overflow).",+ unit="1",+ ),+ )+# (includes engine_name, pool_mode)@propertydef db_pool_checkout_timeout_counter(self) -> Counter: