LibreChat/packages/api/src/stream/implementations
Danny Avila 81275ff0e0
⏱️ refactor: User Job Tracking TTL and Proactive Cleanup to Redis Job Store (#12595)
* refactor: Add user job tracking TTL to RedisJobStore

- Introduced a new TTL for per-user job tracking sets, set to 24 hours, to enhance job management.
- Updated RedisJobStoreOptions interface to include userJobsSetTtl for configuration.
- Modified job creation and deletion methods to manage user job sets effectively, ensuring proper expiration and cleanup.
- Enhanced comments for clarity on the new TTL functionality and its implications for user job tracking.

* fix: Address review findings for user job tracking TTL

- Remove redundant `del(userJobsKey)` in `getActiveJobIdsByUser` that
  raced with concurrent `createJob` on other replicas (Redis auto-deletes
  empty Sets after SREM)
- Guard `userJobsSetTtl: 0` from silently destroying tracking sets
  (`EXPIRE key 0` deletes the key on Redis 7.0+)
- Extract `deleteJobInternal` so `cleanup()` reuses the already-fetched
  userId instead of issuing a redundant HGETALL per stale job
- Add integration tests for TTL behavior, proactive SREM, configurable
  userJobsSetTtl, and TTL refresh on repeated createJob

* fix: Address follow-up review findings for RedisJobStore

- Use deleteJobInternal in cleanup() terminal-but-in-running-set path
  to ensure userJobsKey SREM is not skipped
- Clear local caches in deleteJob before the fallible getJob call so
  they are cleaned even on transient Redis errors
- Add proactive SREM tests for aborted and error terminal statuses
- Add test for tenant-qualified user tracking key format

* fix: Preserve completedTtl for non-running jobs in cleanup()

The cleanup() terminal-status branch should only remove tracking set
membership, not delete the job hash. deleteJobInternal bypasses the
completedTtl window that updateJob already applied, causing clients
polling for final status to lose the job data early.
2026-04-09 17:42:54 -04:00
..
index.ts 🌊 feat: Resumable LLM Streams with Horizontal Scaling (#10926) 2025-12-19 12:14:19 -05:00
InMemoryEventTransport.ts 🔗 fix: Preserve Stream State Across Reconnects to Prevent Reorder Buffer Desync (#11842) 2026-02-18 01:57:34 -05:00
InMemoryJobStore.ts 🏗️ feat: bulkWrite isolation, pre-auth context, strict-mode fixes (#12445) 2026-03-28 16:43:50 -04:00
RedisEventTransport.ts 🧮 fix: Atomize Redis Event Sequence Counters for Multi-Replica Deployments (#12578) 2026-04-09 09:57:54 -04:00
RedisJobStore.ts ⏱️ refactor: User Job Tracking TTL and Proactive Cleanup to Redis Job Store (#12595) 2026-04-09 17:42:54 -04:00