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_0 (already cloned)
- Base commit: e637b214e348216d30c9af59cce85a1264badebf
- Task ID: juspay__hyperswitch-8157
- Version: v1.114.0
TASK DESCRIPTION: Bug: refactor(success_based): add support for exploration
DETAILED CONTEXT & HINTS:
Type of Change
- Bugfix
- New feature
- Enhancement
- Refactoring
- Dependency updates
- Documentation
- CI/CD
Description
This pull request introduces a new feature to support an "exploration percentage" parameter in success-based routing configurations and adds a "RoutingApproach" enum to define routing strategies. These changes span multiple files, including API specifications, Rust models, and protocol buffer definitions, ensuring end-to-end support for the new functionality.
New Feature: Exploration Percentage in Routing Configurations
- Added
exploration_percentparameter to theSuccessBasedRoutingConfigstruct in Rust models (crates/api_models/src/routing.rs) and updated its default implementation. [1] [2] - Modified the
updatemethod inSuccessBasedRoutingConfigBodyto handle updates to theexploration_percentfield. - Updated the gRPC client (
crates/external_services/src/grpc_client/dynamic_routing/success_rate_client.rs) to include theexploration_percentfield in theCalSuccessRateConfigmapping. - Enhanced the protocol buffer definition (
proto/success_rate.proto) to includeexploration_percentas an optional field in theCalSuccessRateConfigmessage.
New Enum: Routing Approach
- Introduced a
RoutingApproachenum with valuesEXPLORATIONandEXPLOITATIONin the protocol buffer definition (proto/success_rate.proto) and added it to theCalSuccessRateResponsemessage. - Updated the OpenAPI specification (
api-reference/hyperswitch_intelligent_router_open_api_spec.yml) to include theRoutingApproachtype and its usage in API responses.
API Specification Enhancements
- Added
exploration_percentto the API's routing configuration schema in the OpenAPI spec.
Additional Changes
- This PR modifies the API contract
- This PR modifies the database schema
- This PR modifies application configuration/environment variables
Motivation and Context
How did you test it?
- Toggle success based routing for a profile, Check the business profile table in DB, get the routing_algorithm_id active for that profile and check in routing_algorithm table. it should have exploration set to 20.0
curl --location --request POST 'http://localhost:8080/account/merchant_1747851996/business_profile/pro_Rbh3PEV8EITILLoKDC6N/dynamic_routing/success_based/toggle?enable=dynamic_connector_selection' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: xyz' \ --data ''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_0/'
- 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 refactoring task to add support for exploration in success-based routing. Let me first understand the current implementation by examining the relevant files mentioned in the task description.
Assistant
Let me start by examining the current SuccessBasedRoutingConfig struct in the routing.rs file to understand the existing implementation.
Assistant
Now let me examine the gRPC client implementation to understand how the success rate config is currently handled:
Assistant
Now let me examine the protocol buffer definition to understand how the exploration_percent field should be added:
Assistant
Now let me check the OpenAPI specification to see where the exploration_percent should be added:
Assistant
(no content)
Assistant
Let me search more specifically in the yaml files:
Assistant
(no content)
Assistant
(no content)
Assistant
(no content)
Assistant
Let me check what files are in the api-reference directory:
Assistant
Great! Now let me examine the OpenAPI specification file to understand how to add the exploration_percent:
Assistant
Let me continue reading the YAML file to find the schemas:
Assistant
Let me find the components/schemas section:
Assistant
(no content)
Assistant
Let me look at the schemas section around line 639:
Assistant
Let me also look for CalGlobalSuccessRateConfig to understand the complete picture:
Assistant
Now I'll start making the required changes. First, let me update the SuccessBasedRoutingConfig in the routing.rs file to add the exploration_percent field:
Assistant
Now I'll modify the protocol buffer definition to add the exploration_percent field and RoutingApproach enum:
Assistant
Let me update the todo list and then make the necessary changes to the Rust code first:
Assistant
Now let me update the SuccessBasedRoutingConfig in the routing.rs file to add the exploration_percent field:
Assistant
Let me check the exact content of that struct again:
Assistant
(no content)
Assistant
Let me also update the default implementation for SuccessBasedRoutingConfig to include exploration_percent:
Assistant
Now I'll also update the update method for SuccessBasedRoutingConfigBody to handle the exploration_percent field:
Assistant
Let me now update the OpenAPI spec file to include the exploration_percent parameter:
Assistant
Let me update the CalGlobalSuccessRateConfig as well:
Assistant
Let me update the gRPC client code to handle the exploration_percent field. First, I'll examine the current ForeignTryFrom implementations:
Assistant
Let me also update the gRPC client code to handle the exploration_percent field. First let me read the rest of the file to understand how it's structured:
Assistant
Now let me update the ForeignTryFrom implementations to handle exploration_percent:
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 →