feat(multi-objective-routing): add support for Economic Value calculation and Autopilot mode#300
Merged
Merged
Conversation
…h PSP SR and calculate EV to decide the best PSP at the moment
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the decision-engine’s multi-objective routing and dashboard to support expected economic value (EV)–based selection (auth × net value) and introduces an “Autopilot” mode that auto-calibrates SRv3 bucket size and hedging based on observed traffic, surfacing those retunes as routing events in the UI.
Changes:
- Reworks multi-objective routing from tolerance-band terminology to EV-based ranking, adding margin/EV diagnostics and simulator-friendly deterministic cost seeding.
- Adds SRv3 auto-calibration background job + ClickHouse support for segment traffic inputs and calibration event replay in routing events.
- Updates the dashboard SR Routing page to add Autopilot UX, SR dimension configuration, and calibration event display.
Reviewed changes
Copilot reviewed 49 out of 63 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| website/src/types/api.ts | Updates dashboard API types for margin/EV fields and calibration event payload fields. |
| website/src/hooks/useRoutingEvents.ts | Adds human-readable description for calibration_applied events. |
| website/src/hooks/useMerchantFeatures.ts | Adds new feature slugs: elimination, auto-calibration, autopilot. |
| website/src/components/pages/SRRoutingPage.tsx | Major SR Routing UI restructure: Autopilot tab, manual sub-tabs, SR dimensions config, and sub-level dimension fields. |
| website/src/components/pages/RoutingHubPage.tsx | Displays SR margin instead of the removed tolerance band. |
| website/src/components/pages/RoutingEventsPage.tsx | Adds UI metadata (badge/icon) for calibration events. |
| website/src/components/pages/DecisionExplorerPage.tsx | Updates multi-objective panel labels/wording to EV terminology. |
| website/src/components/pages/BucketHedgingTuner.tsx | New explainer component illustrating static vs auto tuning from volume profiles and PAR uploads. |
| website/src/components/pages/AnalyticsPage.tsx | Updates copy to reflect EV-derived auth band terminology. |
| website/src/components/layout/Sidebar.tsx | Hides Decision Explorer link in the sidebar. |
| website/src/components/layout/NotificationBell.tsx | Adds icon/color for calibration_applied notifications. |
| website/dist/index.html | Updates built asset references. |
| website/dist/decision-engine/logo/decision-engine-light.svg | Adds/updates built dashboard branding asset. |
| website/dist/decision-engine/logo/decision-engine-dark.svg | Adds/updates built dashboard branding asset. |
| website/dist/decision-engine/index.html | Adds built dashboard entrypoint under /decision-engine/. |
| website/dist/decision-engine/images/auth_bg.svg | Adds built background asset. |
| website/dist/decision-engine/favicon.svg | Adds built favicon asset. |
| src/types/routing_configuration.rs | Replaces tolerance field with margin; extends SR sub-level config to round-trip optional dimensions and source provenance. |
| src/types/card/txn_card_info.rs | Adds card_issuer_country to txn card info (and safe form) for cost clustering. |
| src/sr_auto_calibration.rs | New periodic job: derives bucket/hedge per cluster from analytics and writes autopilot-managed sub-level overrides. |
| src/routes/merchant_account_config.rs | Adds feature wiring for elimination/auto-calibration/autopilot with stable slugs. |
| src/routes/gateway_score.rs | New authenticated endpoint to hard-reset SR gateway scores and drop autopilot overrides. |
| src/routes/decide_gateway.rs | Emits additional analytics dimensions (network/currency/country). |
| src/routes/analytics.rs | Switches routing-events detector to use AuthBandSpec (currently forced Off). |
| src/routes.rs | Exposes new gateway_score route module. |
| src/redis/commands.rs | Adds delete_keys_by_pattern via cursor-based SCAN for safe admin deletes. |
| src/lib.rs | Exports the new sr_auto_calibration module. |
| src/feedback/utils.rs | Updates SR queue update to trim via LTRIM using current bucket size; changes signatures accordingly. |
| src/feedback/gateway_selection_scoring_v3/flow.rs | Threads bucket size through key creation and moving-window update; stops maintaining cached score key incrementally. |
| src/euclid/handlers/routing_rules.rs | Adds GET endpoint for SR dimension config so dashboard can render a selector. |
| src/decider/gatewaydecider/validators.rs | Initializes new card issuer country field when parsing API payloads. |
| src/decider/gatewaydecider/utils.rs | Fixes SRv3 sub-level override selection to prefer most-specific matches; adds regression tests. |
| src/decider/gatewaydecider/types.rs | Adds card network/currency/country helpers and card issuer country field plumbing. |
| src/decider/gatewaydecider/multi_objective/seed_costs.rs | New deterministic seed-cost resolution for simulator/offline EV demos. |
| src/decider/gatewaydecider/multi_objective/mod.rs | Replaces tolerance band with DEFAULT_MARGIN and adds EV gap diagnostics to response payload. |
| src/decider/gatewaydecider/multi_objective/hypersense_client.rs | Hardens live cost model fitting (≥3 observations, fit tolerance, fixed-fee sanity cap) and adds seed-cost mode. |
| src/decider/gatewaydecider/multi_objective/cluster_key.rs | Adds issuer-region normalization and cross-border flag derivation for pricing tiers. |
| src/decider/gatewaydecider/multi_objective/algorithm.rs | Changes multi-objective selection to pure EV ranking (no auth band gate) and updates fallback ordering. |
| src/decider/gatewaydecider/gw_scoring.rs | Stops deleting/refilling score keys on bucket-size change (resize-in-place model). |
| src/decider/gatewaydecider/flow_new.rs | Loads margin, changes MO gating (request opt-in AND flag), and threads margin into MO algorithm. |
| src/decider/gatewaydecider/ab_test/outcome.rs | Extends emitted outcome analytics with new optional dimensions (as None). |
| src/config.rs | Adds SR auto-calibration config block and Hypersense seed-cost configuration types. |
| src/app.rs | Spawns calibration job at startup and wires new routes (/config-sr-dimension/:merchant_id, /gateway-score/reset). |
| src/analytics/store.rs | Adds SegmentTraffic and a read-store method for calibrator inputs. |
| src/analytics/service.rs | Adds a typed autopilot calibration domain event emitter. |
| src/analytics/models.rs | Adds CalibrationApplied routing event type, calibration event payload fields, and AuthBandSpec. |
| src/analytics/flow.rs | Adds analytics FlowType::AutopilotCalibration. |
| src/analytics/events.rs | Defines the autopilot calibration domain event row packing. |
| src/analytics/clickhouse/mod.rs | Implements ClickHouse read-store support for segment traffic. |
| src/analytics/clickhouse/metrics/mod.rs | Registers calibration events metric loader. |
| src/analytics/clickhouse/metrics/calibration_events.rs | New loader to fetch autopilot calibration domain events for routing-events replay. |
| src/analytics/clickhouse/endpoints/segment_traffic.rs | New ClickHouse endpoint to compute per-cluster volume + PSP count for calibration. |
| src/analytics/clickhouse/endpoints/routing_events.rs | Merges calibration domain events into routing events feed; updates auth-band detection to use AuthBandSpec. |
| src/analytics/clickhouse/endpoints/mod.rs | Exposes the new segment-traffic endpoint module. |
| config/development.toml | Adds demo-tuned SR auto-calibration config and simulator seed-cost models. |
| .gitignore | Ignores **/scratch. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
How does Economic Value-based routing work?
The auth rate-based routing shortlists PSPs - A, B, and C. To trade-off between these 3 PSPs, we calculate the true Economic Value (EV) with the observed PSP success rates and expected transaction cost calculated:
settlement value = txn amount - cost of payment processing (acquirer, issuer & network fee)
PSP B wins - not because it's cheapest (PSP C is cheaper) but because its combination of auth rate and cost produces the highest expected economic value.
Cost-based PSP will be chosen only when the real economic value is higher. The calculation accounts for the recently observed auth rate, amount, and the cost. Even if the payment fails during cost-based routing, smart retry will act as a fallback to recover the transaction using the available alternative PSP.