LibreChat/packages/api/src/cache
Danny Avila 446b73bb6b
🧯 fix: Harden Principals Cache Invalidation and Lock-Wait Paths (#14120)
* 🧯 fix: Harden Principals Cache Invalidation and Lock-Wait Paths

Follow-up hardening for the group-membership principals cache:

- Coalesce deferred transactional invalidations into one session `ended`
  listener so many membership writes in a transaction cannot trip the
  emitter's max-listeners warning
- Re-attempt the build lock inside the lock-wait poll so readers take over
  when the holder skips its write (invalidated away, failed, or crashed)
  instead of stalling for the full wait budget
- Read cache builds from the primary so secondaryPreferred deployments
  cannot pin a lagging secondary's pre-mutation memberships for the TTL
- Decouple the delayed stale-rewrite eviction pass from build locking via a
  crossProcess store marker, so USER_PRINCIPALS_LOCK_TTL_MS=0 disables
  locking only
- Treat aggregation-pipeline bulk updates touching memberIds as
  indeterminate (namespace clear) instead of silently skipping invalidation

* ⏲️ fix: Floor the Stale-Eviction Delay for Lockless Cache Builds

The second invalidation pass ran at only 500ms when build locking is
disabled (USER_PRINCIPALS_LOCK_TTL_MS=0), so a cross-container build slower
than that could still re-cache revoked memberships until the TTL. The store
now supplies an explicit staleEvictionDelayMs (lock wait plus one build
round-trip, floored at 3s), keeping the default locked budget unchanged.
2026-07-05 11:31:06 -04:00
..
__tests__ 🚰 ci: Close Leaked Redis Clients in Cache Integration Tests (#13649) 2026-06-10 08:59:13 -04:00
cacheConfig.ts ⚡️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
cacheFactory.ts
index.ts 🗃️ perf: Cache Group Memberships for ACL Principal Resolution (#14075) 2026-07-05 08:40:14 -04:00
keyvFiles.ts ⚡️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
keyvMongo.ts ⚡️ refactor: Migrate @librechat/api build to tsdown (#13595) 2026-06-08 10:54:48 -04:00
principals.ts 🧯 fix: Harden Principals Cache Invalidation and Lock-Wait Paths (#14120) 2026-07-05 11:31:06 -04:00
redisClients.ts 🚰 ci: Close Leaked Redis Clients in Cache Integration Tests (#13649) 2026-06-10 08:59:13 -04:00
redisUtils.ts 🧩 fix: Add REDIS_CLUSTER_SAFE_DELETE Flag for ElastiCache Serverless CROSSSLOT Errors (#13275) 2026-05-24 14:49:40 -04:00