Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
chore: add warning logs for sync model validate fallback for agent environment variables (#8362)
jnjpng4ee267a57c6c
diff --git a/letta/schemas/environment_variables.py b/letta/schemas/environment_variables.pyindex 81abfa357..5db1c28ad 100644--- a/letta/schemas/environment_variables.py+++ b/letta/schemas/environment_variables.py@@ -1,11 +1,15 @@+import tracebackfrom typing import Optionalfrom pydantic import Field, model_validator+from letta.log import get_loggerfrom letta.schemas.enums import PrimitiveTypefrom letta.schemas.letta_base import LettaBase, OrmMetadataBasefrom letta.schemas.secret import Secret+logger = get_logger(__name__)+# Base Environment Variableclass EnvironmentVariableBase(OrmMetadataBase):@@ -28,11 +32,23 @@ class EnvironmentVariableBase(OrmMetadataBase):def sync_value_and_value_enc(self):"""Sync deprecated `value` field with `value_enc` for backward compatibility."""if self.value_enc and not self.value:+ # ERROR: This should not happen - all code paths should populate value via async decryption+ # Log error with stack trace to identify the caller that bypassed async decryption+ logger.warning(+ f"Sync decryption fallback triggered for env var key={self.key}. "+ f"This indicates a code path that bypassed async decryption. Stack trace:\n{''.join(traceback.format_stack())}"+ )# Decrypt value_enc -> value (for API responses)plaintext = self.value_enc.get_plaintext()if plaintext:self.value = plaintextelif self.value and not self.value_enc:+ # WARNING: This triggers sync encryption - should use async encryption where possible+ # Log warning with stack trace to identify the caller+ logger.warning(+ f"Sync encryption fallback triggered for env var key={self.key}. "+ f"This indicates a code path that bypassed async encryption. Stack trace:\n{''.join(traceback.format_stack())}"+ )# Encrypt value -> value_enc (for backward compat when value is provided directly)self.value_enc = Secret.from_plaintext(self.value)return self