You are working on the hyperswitch repository (Rust payment processing system).…
- User
You are working on the hyperswitch repository (Rust payment processing system).
REPOSITORY SETUP:
- Repository: juspay/hyperswitch
- Working directory: ./repos/hyperswitch_pool_8 (already cloned)
- Base commit: 839eb2e8fb436ec0a79fe0073923fcb060b42cfc
- Task ID: juspay__hyperswitch-7933
- Version: v1.114.0
TASK DESCRIPTION: Bug: Persist Last Used Lineage Context in Database Instead of Redis
Currently, the last used lineage context (org_id, merchant_id, profile_id, role_id, tenant_id) is cached temporarily in Redis with a 7-day TTL. While this improves user experience across sessions, it introduces problems like:
- Redis is volatile — lineage context is lost if redis crashes
- Users switching between v1/v2 deployments have inconsistent Redis prefixes, leading to stale context (this has been fixed)
- Adds unnecessary dependency on Redis for critical authentication flow.
Objectives:
- Move the lineage context storage from Redis to the database (preferably to the users table as a new column).
- Ensure lineage context is persistently stored and updated in DB.
Tasks:
-
Add a new nullable last_used_lineage_context (JSON/JSONB) column to the users table.
-
Modify lineage context get and set helpers to use the DB instead of Redis.
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
Previously, the user's
lineage_context(userid, org_id, merchant_id, profile_id, role_id, tenant_id) was cached in Redis. This PR moves the storage and retrieval oflineage_contextto the PostgreSQLuserstable instead of Redis.This ensures permanent persistence of lineage_context in DB, as opposed to the 7 days TTL when stored in Redis.
Assistant
I'll help you implement the feature to persist the last used lineage context in the database instead of Redis. Let me start by understanding the current implementation and identifying the key files that need to be modified.
Assistant
Let me first explore the codebase to understand the current lineage context implementation and locate the relevant files.
Assistant
(no content)
Assistant
Now let me look more specifically for files related to user management and lineage context handling to understand where to add the database column and modify the logic.
Assistant
Let me examine the user-related files that mention lineage_context to understand the current implementation:
Assistant
Now let me look at the user domain model to understand the current structure:
Assistant
Now let me look at the core user module to understand how the authentication and lineage context flows work:
Assistant
(no content)
Assistant
Let me look at the constants to understand the lineage context prefix:
Assistant
Let me check the diesel models to understand the user table structure:
Assistant
Let me search for user table structures in diesel models:
Assistant
(no content)
Assistant
(no content)
Assistant
(no content)
Assistant
Now I'll look at the core user authentication code to understand how the lineage context is used:
Assistant
Let me get a broader view of the authentication flow to understand where the lineage context is actually used:
Assistant
Let me search for specific functions that handle lineage context usage in the user core module:
Assistant
Let me find the actual functions where the lineage context is handled and look for the authentication flow functions:
Assistant
Let me look for where the authentication is happening, especially around the login functions:
Assistant
Let me get the entire file content to understand better:
Assistant
Now let me look at the beginning of the file to find the authentication function:
Assistant
Let me get a bit more context around where the login function starts:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.