Skip to content

feat(multi-objective-routing): add support for Economic Value calculation and Autopilot mode#300

Merged
jagan-jaya merged 10 commits into
mainfrom
feat/automatic-band-EV-calculation
Jul 1, 2026
Merged

feat(multi-objective-routing): add support for Economic Value calculation and Autopilot mode#300
jagan-jaya merged 10 commits into
mainfrom
feat/automatic-band-EV-calculation

Conversation

@jagan-jaya

@jagan-jaya jagan-jaya commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator
  1. Introduced an economic value-based winner prediction so that we optimize for Auth always and cost if possible for a transaction.

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:

Economic value (EV) = auth rate × settlement value*
EV_PSP_A: 91.0% × ($20.00 − $2.00) = 91.0% × $18.00 = $16.38 ← Best auth rate PSP
EV_PSP_B: 90.2% × ($20.00 − $1.50) = 90.2% × $18.50 = $16.69 ← Winner PSP 
EV_PSP_C: 88.5% × ($20.00 − $1.20) = 88.5% × $18.80 = $16.64 ← Cheapest PSP

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.

  1. Added support for autopilot mode so that merchants need not configure the bucket size and hedging percentage for each payment cluster in a moving traffic. Our self-tuning mechanism works based on the concepts clarified in this paper.

@jagan-jaya jagan-jaya self-assigned this Jul 1, 2026
@jagan-jaya jagan-jaya marked this pull request as ready for review July 1, 2026 21:09
Copilot AI review requested due to automatic review settings July 1, 2026 21:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread website/src/components/pages/SRRoutingPage.tsx Outdated
Comment thread src/types/routing_configuration.rs Outdated
Comment thread src/decider/gatewaydecider/flow_new.rs Outdated
Comment thread src/decider/gatewaydecider/multi_objective/algorithm.rs Outdated
Comment thread src/decider/gatewaydecider/flow_new.rs Outdated
Comment thread src/sr_auto_calibration.rs Outdated
@jagan-jaya jagan-jaya merged commit fc57477 into main Jul 1, 2026
16 checks passed
@jagan-jaya jagan-jaya deleted the feat/automatic-band-EV-calculation branch July 1, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants