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_6 (already cloned)
- Base commit: 99885b699d7524e87697f78608e6f2b36c9d8a8e
- Task ID: juspay__hyperswitch-8601
- Version: v1.115.0
TASK DESCRIPTION: Bug: Deleting a user role and again assigning a role to user is not updating its previous role to new role
Role id is not getting updated in the invited user account in case the role is deleted and assigned again to invited user. This is happening due to the lineage context stored in db not updating the role id in case that role id does not exist any more.
Steps to duplicate this edge case:
- Invite a user with any user role
- Accept the invitation and login to invited user account
- Delete the user role from the account who invited the user
- Assign a user role, then try to login to the invited account
- Invited account still operates on the previous user role because of the lineage context getting stored in db
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This PR fixes an issue where a stale
role_idfrom the cachedlineage_contextwas being used to generate the JWT token during sign-in, even if the actual user role was modified (e.g., role deleted and recreated with a differentrole_idbut same lineage).Previously, we only validated if a user role existed for the lineage (
user_id,tenant_id,org_id,merchant_id,profile_id), but did not verify that therole_idmatched the current assigned role. This led to JWTs being issued with outdatedrole_idvalues.Changes Made
- During sign-in, added a strict match check for
role_idin the fetched user role. - If the
role_idfrom cachedlineage_contextdoes not match the current role fetched from DB (v2 fallback to v1), we now resolve the lineage afresh from the currentuser_roleobject. - Logged errors for failed role fetch attempts for better traceability.
Additional Changes
- This PR modifies the API contract
- This PR modifies the database schema
- This PR modifies application configuration/environment variables
Motivation and Context
In systems where roles can be modified dynamically (e.g., deleted and recreated), relying on cached
lineage_context.role_idwithout validating it introduces a silent inconsistency. This can lead to:- Unexpected authorization behavior
- Hard-to-debug permission issues
- Stale tokens being issued
This fix ensures that JWTs are always generated using valid and current
role_idinformation associated with the user role.How did you test it?
Scenario: Validate fallback when
role_idhas changed-
Initial Setup
- Log in as an
org_adminof Org A. - Invite User X to Org A with the role
org_admin. - Ensure User X is also part of another organization (Org B) and has a valid user role there.
- Log in as an
-
Initial Sign-In
- Sign in as User X to Org A, selecting a specific merchant and profile.
- This populates and stores the
lineage_contextbased on the selected values.
-
Modify Role Assignment
- Log back in as the original
org_adminof Org A. - Delete the current user role (
org_admin) of User X in Org A. - Create a new role in Org A named
profile_adminusing the same merchant and profile from the storedlineage_context. - Re-invite User X to Org A with this new
profile_adminrole.
- Log back in as the original
-
Re-Sign-In Validation
- Now sign in again as User X.
- Since the original role (
org_admin) no longer exists, the cached lineage context will fail validation. - The system should fall back to the default sign-in flow and pick a valid user role for JWT construction.
-
Verify Correct Role Assignment
- If sign-in occurs into a different organization, it's acceptable.
- If signed into Org A, validate the
role_id:- Check the response from
/userAPI. - OR decode the JWT token.
- Check the response from
- The
role_idshould now correctly reflectprofile_admin.
Checklist
- I formatted the code
cargo +nightly fmt --all - I addressed lints thrown by
cargo clippy - I reviewed the submitted code
- I added unit tests for my changes where possible
CRITICAL INSTRUCTIONS - WORK FAST AND EFFICIENTLY:
-
Create DENSE, ACTION-FOCUSED todos IMMEDIATELY
- Make todos specific and actionable
- Focus on HIGH-IMPACT actions only
- 5-8 todos maximum - be surgical, not exhaustive
-
Execute aggressively:
- Use bash commands to search efficiently
- Read multiple related files in quick succession
- Make ALL related changes in one edit
- Skip unnecessary exploration
-
File operations:
- All repo files: './repos/hyperswitch_pool_6/'
- Use targeted edits over whole file rewrites
-
NO TESTING UNLESS CRITICAL:
- Focus on making the actual code changes
- Only test if explicitly required
-
Maximize information density:
- Each turn should accomplish significant work
- Batch file reads when examining related code
- Use search commands to locate code quickly
EFFICIENCY IS CRITICAL. Make substantial progress every turn.
Assistant
I'll tackle this bug where deleting and reassigning a user role doesn't properly update the lineage context in the hyperswitch repository. Let me start by exploring the codebase to understand how user roles and lineage context are handled.
First, let me create a plan for this task:
Assistant
Let me search for files related to user roles, lineage context, and sign-in functionality to understand how this is implemented:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me look for files related to user authentication and sign-in functionality:
Assistant
Now let me examine the key files that seem most relevant - the user core module and the user role implementation:
Assistant
Let me search more specifically for the JWT token generation and sign-in flow:
Assistant
Let me look at the JWT service and authentication files specifically:
Assistant
(no content)
Assistant
Let me focus on the user role and lineage context files that I found earlier:
Assistant
(no content)
Assistant
(no content)
Assistant
Now let me examine the types for the LineageContext:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me look more specifically at the user role and authentication implementation to understand the flow better:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →
claude-sonnet-4-5-20250929Compare side by side →