Commit Graph

13 Commits

Author SHA1 Message Date
jnjpng
35ecf2279f chore: remove dead sync model validator code (#8606)
Remove commented-out sync_value_and_value_enc model validator and
unused imports (traceback, model_validator, logger). This code was
disabled and replaced with async decryption via from_orm_async methods.
2026-01-19 15:54:37 -08:00
jnjpng
59c2b19812 fix: remove sync model validator for env var (#8518)
* base

* import
2026-01-12 10:57:49 -08:00
jnjpng
dceed06f84 fix: set value on agent environment variable as pydantic obj (#8452)
base
2026-01-12 10:57:49 -08:00
jnjpng
737d6e2550 fix: remove noisy sync log and fix timeout type (#8392)
base
2026-01-12 10:57:48 -08:00
jnjpng
4ee267a57c chore: add warning logs for sync model validate fallback for agent environment variables (#8362)
base
2026-01-12 10:57:48 -08:00
Kian Jones
bce1749408 fix: run PBKDF2 in thread pool to prevent event loop freeze (#6763)
* fix: run PBKDF2 in thread pool to prevent event loop freeze

Problem: Event loop freezes for 100-500ms during secret decryption, blocking
all HTTP requests and async operations. The diagnostic monitor detected the
main thread stuck in PBKDF2 HMAC SHA256 computation at:
  apps/core/letta/helpers/crypto_utils.py:51 (_derive_key)
  apps/core/letta/schemas/secret.py:161 (get_plaintext)

Root cause: PBKDF2 with 100k iterations is intentionally CPU-intensive for
security, but running it synchronously on the main thread blocks the event loop.

Stack trace showed:
  Thread 1 (Main): PBKDF2HMAC -> SHA256_Final -> sha256_block_data_order_avx2
  Event loop watchdog: Detected freeze at 01:11:44 (request started 01:12:03)

Solution:
1. Run PBKDF2 in ThreadPoolExecutor to avoid blocking event loop
2. Add async versions of encrypt/decrypt methods
3. Add LRU cache for derived keys (deterministic results)
4. Add async get_plaintext_async() method to Secret class

Changes:
- apps/core/letta/helpers/crypto_utils.py:
  - Added ThreadPoolExecutor for crypto operations
  - Added @lru_cache(maxsize=256) to _derive_key_cached()
  - Added _derive_key_async() using loop.run_in_executor()
  - Added encrypt_async() and decrypt_async() methods
  - Added warnings to sync methods about blocking behavior

- apps/core/letta/schemas/secret.py:
  - Added get_plaintext_async() method
  - Added warnings to get_plaintext() about blocking behavior

Benefits:
- Event loop no longer freezes during secret decryption
- HTTP requests continue processing while crypto runs in background
- Derived keys are cached, reducing CPU usage for repeated operations
- Backward compatible - sync methods still work for non-async code

Performance impact:
- Before: 100-500ms event loop block per decryption
- After: 100-500ms in thread pool (non-blocking) + LRU cache hits ~0.1ms

Next steps (follow-up PRs):
- Migrate all async callsites to use get_plaintext_async()
- Add metrics to track sync vs async usage
- Consider reducing PBKDF2 iterations if security allows

* update

* test

---------

Co-authored-by: Letta Bot <jinjpeng@gmail.com>
2025-12-15 12:03:09 -08:00
jnjpng
4be813b956 fix: migrate sandbox and agent environment variables to encrypted only (#6623)
* base

* remove unnnecessary db migration

* update

* fix

* update

* update

* comments

* fix

* revert

* anotha

---------

Co-authored-by: Letta Bot <noreply@letta.com>
2025-12-15 12:03:08 -08:00
jnjpng
e5bda413c0 fix: agent environment variables not using encrypted values (#6520)
* base

* clean up

---------

Co-authored-by: Letta Bot <noreply@letta.com>
2025-12-15 12:02:33 -08:00
jnjpng
89ca8fe8b0 feat: read from encrypted values with error on fallback [LET-4250] (#6484)
* base

* warning

---------

Co-authored-by: Letta Bot <noreply@letta.com>
2025-12-15 12:02:33 -08:00
Kian Jones
3f78c93be5 chore: add new primitive types and replace id_prefixes everywhere (#5749)
add new primitive types and replace id_prefixes everywhere
2025-11-13 15:35:41 -08:00
jnjpng
a772bedfe4 feat: add secret pydantic fields (#5291)
* add secret pydantic fields

* stage publish

---------

Co-authored-by: Letta Bot <noreply@letta.com>
2025-10-09 15:25:21 -07:00
Matthew Zhou
7aa824ea38 fix: Bug fixes (#2377)
Co-authored-by: Charles Packer <packercharles@gmail.com>
Co-authored-by: cthomas <caren@letta.com>
Co-authored-by: mlong93 <35275280+mlong93@users.noreply.github.com>
Co-authored-by: Mindy Long <mindy@letta.com>
Co-authored-by: Shubham Naik <shubham.naik10@gmail.com>
Co-authored-by: Shubham Naik <shub@memgpt.ai>
Co-authored-by: dboyliao <qmalliao@gmail.com>
Co-authored-by: Sarah Wooders <sarahwooders@gmail.com>
Co-authored-by: Nuno Rocha <nunuroxa@gmail.com>
Co-authored-by: Theo Conrads <theo.conrads@ella-lab.io>
Co-authored-by: Jyotirmaya Mahanta <jyotirmaya.mahanta@gmail.com>
Co-authored-by: Stephan Fitzpatrick <knowsuchagency@gmail.com>
Co-authored-by: Stephan Fitzpatrick <stephan@knowsuchagency.com>
Co-authored-by: Krishnakumar R (KK) <65895020+kk-src@users.noreply.github.com>
2025-01-22 17:06:31 -08:00
Matthew Zhou
5c07095d2a chore: Improved sandboxing support (#2333)
Co-authored-by: Shubham Naik <shub@memgpt.ai>
Co-authored-by: Shubham Naik <shubham.naik10@gmail.com>
Co-authored-by: Caren Thomas <caren@letta.com>
Co-authored-by: Sarah Wooders <sarahwooders@gmail.com>
Co-authored-by: cpacker <packercharles@gmail.com>
2025-01-06 11:25:50 -08:00