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_4 (already cloned)
- Base commit: 07a6271b76f6986f30064d51113838d486f0f2c6
- Task ID: juspay__hyperswitch-8906
- Version: v1.116.0
TASK DESCRIPTION: Bug: Improve UCS connector configuration format for better type safety and usability
Problem Statement
The current unified connector service (UCS) configuration uses an array format for specifying connectors that should use UCS only. This approach has several limitations:
Current Issues
- Type Safety: The current
Vec<String>approach allows invalid connector names to be specified without compile-time validation - Configuration Verbosity: Array format in TOML files is more verbose and harder to read/maintain
- Runtime Validation: Invalid connector names are only caught at runtime when the configuration is parsed
- Inconsistent Format: Different from other comma-separated configuration patterns used elsewhere in the codebase
Current Configuration Format
[grpc_client.unified_connector_service] ucs_only_connectors = [ "razorpay", "phonepe", "paytm", "cashfree", ]Proposed Solution
Refactor the configuration to use a comma-separated string format with type-safe parsing:
Benefits
- Type Safety: Use
HashSet<Connector>with enum validation to prevent invalid connector names - Cleaner Configuration: More concise and readable comma-separated format
- Better Error Handling: Custom deserializer with detailed error messages for invalid configurations
- Consistency: Aligns with other comma-separated configuration patterns in the codebase
- Performance: HashSet provides O(1) lookup time for connector validation
Proposed Configuration Format
[grpc_client.unified_connector_service] ucs_only_connectors = "paytm, phonepe, razorpay, cashfree"Implementation Requirements
- Custom Deserializer: Implement a generic deserializer for comma-separated strings to typed HashSets
- Type Safety: Use
Connectorenum instead of raw strings - Backward Compatibility: Ensure existing connector validation logic continues to work
- Configuration Updates: Update all config files to use the new format
- Comprehensive Testing: Add unit tests for the deserializer and configuration parsing
Acceptance Criteria
- Configuration uses comma-separated string format
- Type-safe parsing with
Connectorenum validation - Custom deserializer handles edge cases (whitespace, duplicates, empty strings)
- All configuration files updated consistently
- Comprehensive unit tests for the deserializer
- Existing connector validation logic works with new format
- Detailed error messages for invalid configurations
Labels
- Enhancement
- Configuration
- Type Safety
- Refactoring
DETAILED CONTEXT & HINTS:
Refactor: Change UCS connector configuration from array to comma-separated string
Summary
This PR refactors the unified connector service (UCS) configuration to use a comma-separated string format instead of an array for specifying connectors that should use UCS only. This change improves configuration management and parsing efficiency while maintaining type safety through a custom deserializer.
Changes
- Configuration Format Change: Modified
ucs_only_connectorsfromVec<String>toHashSet<Connector>with comma-separated string input - Custom Deserializer Implementation: Added a new
utils.rsmodule inexternal_serviceswithdeserialize_hashsetfunction for parsing comma-separated values into typed HashSets - Type Safety Enhancement: Updated connector validation to use
Connectorenum instead of raw strings, preventing invalid connector names - Configuration Updates: Updated all config files (
development.toml,config.example.toml,deployments/env_specific.toml) to use the new comma-separated format - Dependencies: Added
common_enumsdependency toexternal_servicescrate for proper connector enum handling
Related Issues
Closes #8906 - Improve UCS connector configuration format for better type safety and usability
Type of Change
- Refactoring
- Bug fix
- New feature
- Breaking change
- Documentation update
Testing
- Configuration Parsing: Tested comma-separated string parsing with various inputs including whitespace handling
- Type Validation: Verified that invalid connector names are properly rejected during deserialization
- Backward Compatibility: Ensured existing connector validation logic works with the new enum-based approach
- Unit Tests: Added comprehensive test suite for the new deserializer functionality covering:
- Valid comma-separated inputs
- Whitespace handling
- Error handling for invalid values
- Empty string and single value scenarios
- Duplicate value handling
Implementation Details
Key Files Modified
crates/external_services/src/grpc_client/unified_connector_service.rs:119- Configuration struct updatecrates/external_services/src/utils.rs- New deserializer implementationcrates/router/src/core/unified_connector_service.rs:57- Connector validation logic update- Configuration files in
config/directory
New Functionality
The custom deserializer provides:
- Type-safe parsing of comma-separated strings into HashSets
- Comprehensive error handling with detailed error messages
- Generic implementation supporting any type that implements
FromStr + Eq + Hash - Proper handling of edge cases (empty strings, whitespace, duplicates)
Checklist
- Code follows project style guidelines
- Self-review completed
- Configuration changes tested locally
- Unit tests added for new deserializer functionality
- Type safety improvements verified
- All config files updated consistently
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_4/'
- 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 help you refactor the UCS connector configuration to use a comma-separated string format for better type safety and usability. Let me start by exploring the codebase to understand the current implementation and identify the files that need to be modified.
First, let me examine the current configuration structure and locate the relevant files.
Assistant
(no content)
Assistant
Let me examine the specific files that need to be modified to implement this refactoring. I'll start by reading the configuration struct and connector enums.
Assistant
Now let me look at the connector enum definitions to understand what connectors are available:
Assistant
Now let me check the current configuration files to see how they're currently set up:
Assistant
(no content)
Assistant
(no content)
Assistant
Let me check the config.example.toml file to see how it's set up:
Assistant
Let me also look at the deployment config files:
Assistant
Let me also check for any existing utils.rs files that might contain helper functions:
Assistant
Let me check the router code to understand how the UCS connectors are used:
Assistant
Now I have a good understanding of the current implementation. Let me check if there are any existing tests for this functionality to understand how to approach testing:
Assistant
Let me now plan the implementation with clear todos:
Assistant
I'll now implement the changes to refactor the UCS connector configuration from array format to comma-separated string format with type safety.
First, let me create the utility module with the custom deserializer:
Assistant
Let me check the Cargo.toml files to make sure the dependency is correct:
Assistant
I see that
common_enumsis already a dependency. Now let me make the required changes to the unified connector service configuration:Assistant
I need to be more careful about permissions. Let me first create the utils.rs file manually, then modify the configuration struct:
Assistant
(no content)
Assistant
Let me check the current directory structure to make sure I'm in the right place:
Assistant
(no content)
Assistant
I'll work with the file content directly and create the utils.rs file in the appropriate location. Let me approach this more carefully by reading and editing existing files directly:
Assistant
Let me first create the utils.rs file with the custom deserializer. Since I cannot directly write the file, I'll need to make the change using the Edit tool. Let me create a placeholder for now and make the changes step by step:
Assistant
Now let me create the custom deserializer by editing the file. I'll update the imports and the configuration struct. Let me first make a plan to update the imports:
Assistant
Let me approach this differently by focusing on modifying just the necessary parts in a more targeted way. I'll focus on updating the struct definition first to see what we're working with:
Assistant
Let me approach this differently by creating a new file to represent the utility functions and make a plan to implement all the necessary changes. Let's continue with implementing the changes step by step:
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 →