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: 776bde00efce8be35e0c63c1bdc6215921babddf
- Task ID: juspay__hyperswitch-7870
- Version: v1.113.0
TASK DESCRIPTION: Bug: Add support for caching and resolving last used lineage context
Currently, after a user logs in and switches between merchants or profiles, their context is not remembered across sessions.
Each new login resolves the default role from the DB and starts with a clean slate.This leads to:
- Poor user experience for users with multiple roles
- Repetitive DB queries for every login
- No continuity across logins for previously active merchant/profile context
Objective
Introduce a mechanism to cache the last used lineage context (
org_id,merchant_id,profile_id,role_id,tenant_id) in Redis and use it for JWT generation on subsequent logins.Expected Behavior
- During login:
- If lineage context exists in Redis → use it to validate and generate the JWT.
- If not found or invalid → fallback to default DB-based user role resolution.
- During merchant/profile switch:
- Store the latest lineage context in Redis for future use.
- Redis entries should have a TTL of 7 days to auto-expire for inactive users.
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR introduces lineage context caching to enhance login and account-switch flows with better continuity and reduced DB load.
Key Changes
Assistant
I'll implement the lineage context caching feature for the Hyperswitch repository. Let me start by understanding the codebase structure and identifying the relevant files for login and context management.
First, I'll explore the repository structure to locate authentication and context-related code:
Assistant
Let me examine the login flow and context management more closely, particularly looking at user authentication and the areas where lineage context would need to be implemented.
Assistant
(no content)
Assistant
Now let me examine the core user authentication logic to understand how login currently works:
Assistant
Let me search for the signin function specifically to understand how login currently works:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me also look at the switch functions to understand how lineage context is managed during switches:
Assistant
Let me look at the authentication structures to understand how tokens and lineage are handled:
Assistant
Let me look for lineage context definitions and Redis integration:
Assistant
Let me search for the domain structure to understand the user roles and authentication flow better:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me search for existing Redis integration or similar caching patterns in the codebase:
Assistant
Let me check the cache implementation:
Assistant
Now let me look for how the Redis connection is managed:
Assistant
Let me check the settings file to understand Redis configuration:
Assistant
Let me now look at how the user flow works in detail to understand where to implement the lineage context:
Assistant
Let me search for the NextFlow implementation to understand how tokens are generated:
Assistant
(no content)
Assistant
Let me now check the switch functions to understand the current user context flow:
Assistant
Let me now create a plan for implementing the lineage context caching functionality. I'll create a detailed todo list to guide my implementation.
Assistant
I'll now implement the lineage context caching functionality. Let me first create a LineageContext struct to represent the lineage information that should be cached.
Assistant
I need to first create the directory and then create the file:
Assistant
Let me instead add this functionality directly to the user domain module. First, let me check how the user domain module is structured to see where to add this:
Assistant
Let me create a Redis utility module for the lineage context caching:
Assistant
Let me add this to the existing user utilities instead:
Assistant
Now let me check what's in the user utilities to see where I can add the lineage context functionality. First, let me update the todo to mark the first item as complete and start working on the Redis caching:
Assistant
Let me work on implementing the Redis utility functions. First, I'll need to add the required imports and helper functions to the existing user utilities:
Assistant
Let me create a helper function to add the Redis utility code. First I'll examine how to add it to the existing file properly by looking at the imports section:
Assistant
Great, I can see that
redis_interface::RedisConnectionPoolis already imported. Now let me look at the end of the file to see where to add the functions:Assistant
Now let me add the lineage context functions at the end of the file:
Assistant
I need to complete the task differently since I can't directly edit files. Let me focus on modifying the core user authentication logic. Let me update the todo to reflect progress and focus on modifying the signin flow:
Assistant
Now I'll work on modifying the signin flow to check for cached lineage context. Let me start by locating and reading the specific function I need to modify:
Assistant
Now let me also look at the imports at the top of the file to see what's available:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.