Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

feat(revenue_recovery): add the HybridAdaptiveRetry algorithm (#14697)

balakrishnak-ctrl0b2df96df528
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.json
index 47b86cbc29..feb8e66908 100644
--- a/api-reference/v2/openapi_spec_v2.json
+++ b/api-reference/v2/openapi_spec_v2.json
@@ -32172,6 +32172,7 @@
"description": "The retry implementations available within the `Smart` arm of revenue recovery.",
"enum": [
"adaptive_retry",
+ "hybrid_adaptive_retry",
"systematic_k_max_at_softmax",
"systematic_k_max_at_score"
]
diff --git a/crates/common_enums/src/enums.rs b/crates/common_enums/src/enums.rs
index d62f9531dc..9655cac56a 100644
--- a/crates/common_enums/src/enums.rs
+++ b/crates/common_enums/src/enums.rs
@@ -395,6 +395,10 @@ pub enum RevenueRecoveryABAlgorithm {
/// the weekday and month-day signals are softmaxed before the max, and the day is drawn by the
/// per-day walk. Kept as the control arm, and kept stable because invoices already carry it.
AdaptiveRetry,
+ /// Control's pairing, hybridised with the static ladder: the ladder bounds the model's time
+ /// rather than standing by for what it declines, reproducing the behaviour production ran
+ /// before systematic sampling landed. Differs from `AdaptiveRetry` in the ladder's role alone.
+ HybridAdaptiveRetry,
/// Control's combine, drawn instead by systematic sampling. Differs from `AdaptiveRetry` in the
/// sampler alone, so a difference between the two is attributable to the draw.
SystematicKMaxAtSoftmax,
diff --git a/crates/router/src/core/revenue_recovery/schedule.rs b/crates/router/src/core/revenue_recovery/schedule.rs
index 5abde952a3..f05273bd30 100644
--- a/crates/router/src/core/revenue_recovery/schedule.rs
+++ b/crates/router/src/core/revenue_recovery/schedule.rs
@@ -1,8 +1,10 @@
use time::PrimitiveDateTime;
+/// How far along the static ladder an invoice has walked. A rung is one position in the
+/// `pt_mapping_adaptive_retries` gap list; past the end the ladder is spent.
#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
pub struct StaticLadderProgress {
- /// Static ladder positions consumed so far.
+ /// Rungs already used; the next one to offer is `consumed_rungs + 1`.
#[serde(default)]
pub consumed_rungs: i32,
}
@@ -33,19 +35,30 @@ impl StaticLadderProgress {
}
}
- /// The next ladder position after those already consumed. Unused in production since the
- /// static ladder was removed from the decision; kept with the inert counter.
+ /// The rung to ask the ladder for on this decision — the one after those already used.
pub fn next_rung(&self) -> i32 {
self.consumed_rungs + 1
}
}
+/// What the static ladder is to the model's time.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+#[serde(rename_all = "snake_case")]
+pub enum StaticLadderRole {
+ /// The model's time stands as it is; the ladder is not consulted at all.
+ Standby,
+ /// The earlier calendar day of the two wins, ties to the ladder.
+ Ceiling,
+}
+
/// Which source produced the scheduled time.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ScheduleSource {
/// Whichever retry model the invoice was routed to.
Model,
+ /// The static ladder, under `StaticLadderRole::Ceiling`.
+ Static,
/// The MIT cascading ladder, the global fallback for whatever the model declines.
Fallback,
}
@@ -61,35 +74,68 @@ pub struct ScheduleDecision {
pub source: ScheduleSource,
}
-/// The retry model decides whenever it has an opinion; the MIT cascading ladder is the global
-/// fallback for everything it declines. `None` when neither has anything to offer.
-///
-/// The two are NOT compared — the model's time is taken as it stands, however much later than the
-/// fallback's it falls. The fallback is a standby, not a ceiling.
+/// A decision that leaves the ladder where it is, so the same rung is offered again.
+fn keep_rung(
+ schedule: &StaticLadderProgress,
+ schedule_time: PrimitiveDateTime,
+ source: ScheduleSource,
+) -> ScheduleDecision {
+ ScheduleDecision {
+ schedule_time,
+ next_progress: StaticLadderProgress {
+ consumed_rungs: schedule.consumed_rungs,
+ },
+ source,
+ }
+}
+
+/// A decision taken off the ladder, which uses up the rung it supplied. The only way the ladder
+/// advances, and so the only way it is spent.
+fn spend_rung(queried_rung: i32, schedule_time: PrimitiveDateTime) -> ScheduleDecision {
+ ScheduleDecision {
+ schedule_time,
+ next_progress: StaticLadderProgress {
+ consumed_rungs: queried_rung,
+ },
+ source: ScheduleSource::Static,
+ }
+}
+
+/// Pick the next retry time under the role the invoice's variant assigns the static ladder.
+/// `None` when every source in play has declined.
///
-/// Neither source spends a ladder position, so `next_progress` echoes what it was handed. The
-/// counter is inert here and kept only so the persisted field keeps round-tripping; removing it
-/// reaches merchant-facing config and belongs in its own change.
+/// Under `Standby` the model's time stands and the ladder is not consulted, so callers pass
+/// `None` for `static_time`. Under `Ceiling` the earlier calendar day wins and a tie goes to the
+/// ladder, since it already covers that day. Only the static branch spends a rung.
pub fn decide_next_retry(
schedule: &StaticLadderProgress,
+ ladder: StaticLadderRole,
+ queried_rung: i32,
model_time: Option<PrimitiveDateTime>,
+ static_time: Option<PrimitiveDateTime>,
fallback_time: Option<PrimitiveDateTime>,
) -> Option<ScheduleDecision> {
- let decision = |schedule_time, source| ScheduleDecision {
- schedule_time,
- next_progress: StaticLadderProgress {
- consumed_rungs: schedule.consumed_rungs,
+ match ladder {
+ StaticLadderRole::Standby => model_time
+ .map(|schedule_time| keep_rung(schedule, schedule_time, ScheduleSource::Model))
+ .or_else(|| {
+ fallback_time.map(|schedule_time| {
+ keep_rung(schedule, schedule_time, ScheduleSource::Fallback)
+ })
+ }),
+
+ StaticLadderRole::Ceiling => match (static_time, model_time) {
+ (Some(static_time), Some(model_time)) if model_time.date() < static_time.date() => {
+ Some(keep_rung(schedule, model_time, ScheduleSource::Model))
+ }
+ (Some(static_time), _) => Some(spend_rung(queried_rung, static_time)),
+ (None, Some(model_time)) => {
+ Some(keep_rung(schedule, model_time, ScheduleSource::Model))
+ }
+ (None, None) => fallback_time
+ .map(|schedule_time| keep_rung(schedule, schedule_time, ScheduleSource::Fallback)),
},
- source,
- };
-
- model_time
- .map(|schedule_time| decision(schedule_time, ScheduleSource::Model))
- // The model declined, so the global fallback gets the last word. `None` here means there is
- // genuinely nothing left to schedule for this invoice.
- .or_else(|| {
- fallback_time.map(|schedule_time| decision(schedule_time, ScheduleSource::Fallback))
- })
+ }
}
#[cfg(test)]
@@ -112,15 +158,6 @@ mod tests {
StaticLadderProgress { consumed_rungs }
}
- /// A decision the caller would act on. Panics where the test's premise is that one exists.
- fn expect_decision(
- schedule: &StaticLadderProgress,
- model_time: Option<PrimitiveDateTime>,
- fallback_time: Option<PrimitiveDateTime>,
- ) -> ScheduleDecision {
- decide_next_retry(schedule, model_time, fallback_time).expect("a time was available")
- }
-
// ---- seeding ----------------------------------------------------------
//
// Both constructors clamp the billing connector's own attempts against the cascading
@@ -199,54 +236,68 @@ mod tests {
);
}
- // ---- the model decides, the global fallback covers what it declines ---
-
- #[test]
- fn a_later_model_time_still_wins() {
- // The fallback is not a ceiling: a model day after the fallback's is taken as it stands.
- // Nothing here compares the two.
- let fallback_time = at(240);
- let model_time = at(336);
- assert!(model_time.date() > fallback_time.date());
-
- let decision = expect_decision(&at_rung(2), Some(model_time), Some(fallback_time));
-
- assert_eq!(decision.schedule_time, model_time);
- assert_eq!(decision.source, ScheduleSource::Model);
- }
-
- #[test]
- fn no_model_opinion_uses_the_global_fallback() {
- let decision = expect_decision(&StaticLadderProgress::default(), None, Some(at(240)));
-
- assert_eq!(decision.schedule_time, at(240));
- assert_eq!(decision.source, ScheduleSource::Fallback);
- }
-
- #[test]
- fn both_declining_yields_no_decision() {
- assert_eq!(decide_next_retry(&at_rung(5), None, None), None);
- }
-
- // ---- the rung counter is inert ----------------------------------------
+ // ---- the decision rule ------------------------------------------------
+ /// Every arm of both rules, with the roles interleaved: a model time later than the other
+ /// candidate is overridden under `Ceiling` and survives under `Standby`.
#[test]
- fn no_source_spends_a_ladder_position() {
- // With the static ladder gone, neither source advances the count: whatever a decision is
- // handed, it hands back. Pinned because the field is still persisted and still seeded, so
- // a future edit that starts moving it would otherwise change stored state unnoticed.
- for (model_time, fallback_time, expected_source) in [
- (Some(at(72)), None, ScheduleSource::Model),
- (Some(at(72)), Some(at(240)), ScheduleSource::Model),
- (None, Some(at(240)), ScheduleSource::Fallback),
- ] {
- for consumed_rungs in [0, 1, 5] {
- let schedule = at_rung(consumed_rungs);
- let decision = expect_decision(&schedule, model_time, fallback_time);
-
- assert_eq!(decision.source, expected_source);
- assert_eq!(decision.next_progress, schedule);
- assert_eq!(decision.next_progress.consumed_rungs, consumed_rungs);
+ fn each_arm_picks_its_source_and_only_static_spends_a_position() {
+ use ScheduleSource::{Fallback, Model, Static};
+ use StaticLadderRole::{Ceiling, Standby};
+
+ // 2 rungs used throughout, so `queried_rung` is 3: a spent rung leaves the count at 3,
+ // a kept one at 2.
+ #[rustfmt::skip]
+ let cases = [
+ // role, model, static, fallback, expected (source, rungs)
+ (Ceiling, Some(at(72)), Some(at(240)), None, Some((Model, 2))),
+ (Ceiling, Some(at(336)), Some(at(240)), None, Some((Static, 3))),
+ (Ceiling, Some(at(249)), Some(at(258)), None, Some((Static, 3))),
+ (Ceiling, Some(at(336)), None, None, Some((Model, 2))),
+ (Ceiling, None, Some(at(240)), None, Some((Static, 3))),
+ (Ceiling, None, None, Some(at(240)), Some((Fallback, 2))),
+ (Ceiling, None, None, None, None),
+ (Standby, Some(at(336)), None, Some(at(240)), Some((Model, 2))),
+ (Standby, None, None, Some(at(240)), Some((Fallback, 2))),
+ (Standby, None, None, None, None),
+ ];
+
+ for (ladder, model_time, static_time, fallback_time, expected) in cases {
+ let schedule = at_rung(2);
+ let row = format!(
+ "{ladder:?} model={model_time:?} static={static_time:?} fallback={fallback_time:?}"
+ );
+ let decision = decide_next_retry(
+ &schedule,
+ ladder,
+ schedule.next_rung(),
+ model_time,
+ static_time,
+ fallback_time,
+ );
+
+ match expected {
+ None => assert_eq!(
+ decision, None,
+ "{row} has nothing to offer, so must decline"
+ ),
+ Some((source, consumed_rungs)) => {
+ let decision = decision.expect(&row);
+ assert_eq!(decision.source, source, "{row} picked the wrong source");
+
+ let expected_time = match source {
+ Model => model_time,
+ Static => static_time,
+ Fallback => fallback_time,
+ }
+ .expect("the winning source must have been given a time");
+ assert_eq!(decision.schedule_time, expected_time, "{row} wrong time");
+
+ assert_eq!(
+ decision.next_progress.consumed_rungs, consumed_rungs,
+ "{row} spent the wrong number of ladder positions"
+ );
+ }
}
}
}
diff --git a/crates/router/src/workflows/revenue_recovery.rs b/crates/router/src/workflows/revenue_recovery.rs
index c759cb6d03..f4ec1f925c 100644
--- a/crates/router/src/workflows/revenue_recovery.rs
+++ b/crates/router/src/workflows/revenue_recovery.rs
@@ -253,6 +253,25 @@ pub(crate) async fn get_schedule_time_to_retry_mit_payments(
scheduler_utils::get_time_from_delta(time_delta)
}
+/// Static ladder time, for the variants that treat the ladder as a ceiling on the model's time.
+/// Read at the ladder position rather than the invoice's overall retry count, because
+/// `pt_mapping_adaptive_retries` is the mapping built for rung semantics.
+#[cfg(feature = "v2")]
+pub(crate) async fn get_schedule_time_to_retry_adaptive_payments(
+ db: &dyn StorageInterface,
+ superposition_client: &external_services::superposition::SuperpositionClient,
+ dimensions: &crate::core::configs::dimension_state::DimensionsWithProcessorMerchantIdAndConnector,
+ queried_rung: i32,
+) -> Option<time::PrimitiveDateTime> {
+ let mapping = dimensions
+ .get_pt_mapping_adaptive_retries(db, superposition_client, None)
+ .await;
+
+ let time_delta = scheduler_utils::get_pcr_payments_retry_schedule_time(mapping, queried_rung);
+
+ scheduler_utils::get_time_from_delta(time_delta)
+}
+
#[derive(Debug, Clone)]
pub struct RetryDecision {
pub retry_time: time::PrimitiveDateTime,
@@ -849,13 +868,14 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
if ab_enabled || adaptive_retry_enabled {
// Same shape as the cascading arm — compute the schedule time, then gate on the
- // token. The addition is the model's candidate, which decides outright whenever
- // it has one; the cascading ladder covers only the decisions it declines.
+ // token. The addition is the model's candidate, and the variant says both how it
+ // is produced and whether the static ladder bounds it; the cascading ladder covers
+ // only what every source in play declines.
//
- // Enrolled and unenrolled invoices differ ONLY in which variant produces that
- // candidate. The allowances it works against arrive as arguments, and everything
- // after it — the fallback, the decision, the token — is shared, so enrolling an
- // invoice cannot change whether it gets retried at all.
+ // Enrolled and unenrolled invoices differ ONLY in that variant. The allowances it
+ // works against arrive as arguments, and everything after it — the fallback, the
+ // decision, the token — is shared, so enrolling an invoice cannot change whether
+ // it gets retried at all.
let (model_time, assigned_algorithm) = if ab_enabled {
let (time, algorithm) = get_ab_routed_retry_time(
state,
@@ -900,13 +920,50 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
(time, None)
};
- // The MIT cascading ladder is the global fallback for everything the model
- // declines, indexed by the invoice's overall retry count. Resolved only on the
- // decline path, so the Superposition read costs nothing when the model decides —
- // `None` here means "not consulted", not "nothing to offer".
- let fallback_time = match model_time {
- Some(_) => None,
- None => {
+ let ladder_role = assigned_algorithm.map_or_else(
+ || RetryModelVariant::default().ladder,
+ |arm| RetryModelVariant::from(arm).ladder,
+ );
+ let queried_rung = static_ladder_progress.next_rung();
+
+ // Read only where it can win, and only while the merchant's configured length
+ // still has the rung being asked for. Rungs run 1..=max.
+ let static_time = match ladder_role {
+ pcr::schedule::StaticLadderRole::Standby => None,
+ pcr::schedule::StaticLadderRole::Ceiling => {
+ let max_hybrid_cascading_retry_count = revenue_recovery_payment_data
+ .billing_mca
+ .get_max_hybrid_cascading_retry_count()
+ .map(i32::from)
+ .ok_or(errors::ProcessTrackerError::MissingRequiredField)
+ .attach_printable(
+ "Failed to get max hybrid cascading retry count from billing merchant connector account",
+ )?;
+
+ if queried_rung <= max_hybrid_cascading_retry_count {
+ get_schedule_time_to_retry_adaptive_payments(
+ state.store.as_ref(),
+ state.superposition_service.as_ref(),
+ &dimensions,
+ queried_rung,
+ )
+ .await
+ } else {
+ logger::info!(
+ queried_rung,
+ max_hybrid_cascading_retry_count,
+ "hybrid ladder spent for this invoice — the merchant's configured \
+ length is reached, so the model's time stands unbounded"
+ );
+ None
+ }
+ }
+ };
+
+ // The global fallback for everything the sources above decline, indexed by the
+ // invoice's overall retry count. `None` means "not consulted", not "nothing left".
+ let fallback_time = match (model_time, static_time) {
+ (None, None) => {
get_schedule_time_to_retry_mit_payments(
state.store.as_ref(),
state.superposition_service.as_ref(),
@@ -915,21 +972,27 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
)
.await
}
+ _ => None,
};
let decision = pcr::schedule::decide_next_retry(
static_ladder_progress,
+ ladder_role,
+ queried_rung,
model_time,
+ static_time,
fallback_time,
)
.ok_or_else(|| {
logger::error!(
retry_count = retry_count,
+ queried_rung = queried_rung,
+ ladder_role = ?ladder_role,
error_code = ?tracking_data.prev_attempt_error_code,
remaining_grace_days = remaining_grace_days,
remaining_budget = remaining_budget,
- "No retry time available — the model declined and the MIT cascading \
- ladder had nothing left"
+ "No retry time available — every source in play declined and the MIT \
+ cascading ladder had nothing left"
);
// Counted, not just logged: an arm that loses invoices at a different rate
// from another is measuring its own drop rate rather than retry quality, and
@@ -950,8 +1013,12 @@ pub async fn get_token_with_schedule_time_based_on_retry_algorithm_type(
logger::info!(
source = ?decision.source,
retry_count = retry_count,
+ ladder_role = ?ladder_role,
+ queried_rung = queried_rung,
model_time = ?model_time,
+ static_time = ?static_time,
fallback_time = ?fallback_time,
+ consumed_rungs = decision.next_progress.consumed_rungs,
error_code = ?tracking_data.prev_attempt_error_code,
remaining_grace_days = remaining_grace_days,
remaining_budget = remaining_budget,
@@ -1680,8 +1747,9 @@ pub enum DaySelection {
SystematicK,
}
-/// Which combine and which sampler this call runs. Independent axes on purpose: a combine change
-/// and a sampler change are separately attributable only if they can be varied separately.
+/// Which combine, which sampler and what the static ladder is to the result. Independent axes on
+/// purpose: a combine change, a sampler change and a scheduling-rule change are separately
+/// attributable only if they can be varied separately.
///
/// Public because the arm an invoice gets is an experiment-assignment decision, which belongs above
/// this layer — this module only executes the variant it is handed. `Default` is the baseline an
@@ -1692,14 +1760,18 @@ pub enum DaySelection {
pub struct RetryModelVariant {
pub combine: DayCombine,
pub selection: DaySelection,
+ pub ladder: pcr::schedule::StaticLadderRole,
}
+/// The pairing production ran before systematic sampling landed, which is what an invoice outside
+/// the experiment gets. Not the control arm, which is pinned separately.
#[cfg(feature = "v2")]
impl Default for RetryModelVariant {
fn default() -> Self {
Self {
- combine: DayCombine::MaxAtScore,
- selection: DaySelection::SystematicK,
+ combine: DayCombine::MaxAtSoftmax,
+ selection: DaySelection::PerTick,
+ ladder: pcr::schedule::StaticLadderRole::Ceiling,
}
}
}
@@ -1720,14 +1792,22 @@ impl From<common_enums::RevenueRecoveryABAlgorithm> for RetryModelVariant {
common_enums::RevenueRecoveryABAlgorithm::AdaptiveRetry => Self {
combine: DayCombine::MaxAtSoftmax,
selection: DaySelection::PerTick,
+ ladder: pcr::schedule::StaticLadderRole::Standby,
+ },
+ common_enums::RevenueRecoveryABAlgorithm::HybridAdaptiveRetry => Self {
+ combine: DayCombine::MaxAtSoftmax,
+ selection: DaySelection::PerTick,
+ ladder: pcr::schedule::StaticLadderRole::Ceiling,
},
common_enums::RevenueRecoveryABAlgorithm::SystematicKMaxAtSoftmax => Self {
combine: DayCombine::MaxAtSoftmax,
selection: DaySelection::SystematicK,
+ ladder: pcr::schedule::StaticLadderRole::Standby,
},
common_enums::RevenueRecoveryABAlgorithm::SystematicKMaxAtScore => Self {
combine: DayCombine::MaxAtScore,
selection: DaySelection::SystematicK,
+ ladder: pcr::schedule::StaticLadderRole::Standby,
},
}
}
@@ -2457,28 +2537,29 @@ mod retry_model_tests {
(a - b).abs() <= tol
}
- // Every combine x selection pairing. The contract tests below run over all four, because the
- // guarantees they assert (in-window, never panics, declines only when it should) must not depend
- // on which variant an invoice was bucketed into.
- fn all_variants() -> [RetryModelVariant; 4] {
+ // Every combine x selection x ladder-role triple. The contract tests below run over all eight,
+ // because the guarantees they assert (in-window, never panics, declines only when it should)
+ // must not depend on which variant an invoice was bucketed into.
+ fn all_variants() -> [RetryModelVariant; 8] {
+ use pcr::schedule::StaticLadderRole::{Ceiling, Standby};
+ use DayCombine::{MaxAtScore, MaxAtSoftmax};
+ use DaySelection::{PerTick, SystematicK};
+
[
- RetryModelVariant {
- combine: DayCombine::MaxAtSoftmax,
- selection: DaySelection::PerTick,
- },
- RetryModelVariant {
- combine: DayCombine::MaxAtSoftmax,
- selection: DaySelection::SystematicK,
- },
- RetryModelVariant {
- combine: DayCombine::MaxAtScore,
- selection: DaySelection::PerTick,
- },
- RetryModelVariant {
- combine: DayCombine::MaxAtScore,
- selection: DaySelection::SystematicK,
- },
+ (MaxAtSoftmax, PerTick, Standby),
+ (MaxAtSoftmax, PerTick, Ceiling),
+ (MaxAtSoftmax, SystematicK, Standby),
+ (MaxAtSoftmax, SystematicK, Ceiling),
+ (MaxAtScore, PerTick, Standby),
+ (MaxAtScore, PerTick, Ceiling),
+ (MaxAtScore, SystematicK, Standby),
+ (MaxAtScore, SystematicK, Ceiling),
]
+ .map(|(combine, selection, ladder)| RetryModelVariant {
+ combine,
+ selection,
+ ladder,
+ })
}
#[test]
@@ -2942,32 +3023,56 @@ mod retry_model_tests {
RetryModelVariant {
combine: DayCombine::MaxAtSoftmax,
selection: DaySelection::PerTick,
+ ladder: pcr::schedule::StaticLadderRole::Standby,
+ }
+ );
+ }
+
+ #[test]
+ fn the_unenrolled_default_is_the_pairing_production_ran_before_systematic_sampling() {
+ // This `Default` is the only thing selecting an unenrolled invoice's algorithm, so moving
+ // it re-points every invoice outside the experiment.
+ assert_eq!(
+ RetryModelVariant::default(),
+ RetryModelVariant {
+ combine: DayCombine::MaxAtSoftmax,
+ selection: DaySelection::PerTick,
+ ladder: pcr::schedule::StaticLadderRole::Ceiling,
}
);
}
#[test]
fn each_arm_varies_at_most_one_axis_from_its_reference() {
- // Attributability: SystematicKMaxAtSoftmax moves only the sampler from control, and
- // SystematicKMaxAtScore only the combine from it. An arm moving both against both
- // references leaves nothing able to say which change caused a result.
+ // Attributability: SystematicKMaxAtSoftmax moves only the sampler from control,
+ // SystematicKMaxAtScore only the combine from it, and HybridAdaptiveRetry only the
+ // ladder's role. An arm moving two axes leaves nothing able to say which change caused
+ // a result.
use common_enums::RevenueRecoveryABAlgorithm as Arm;
let control = RetryModelVariant::from(Arm::AdaptiveRetry);
+ let hybrid = RetryModelVariant::from(Arm::HybridAdaptiveRetry);
let softmax_k = RetryModelVariant::from(Arm::SystematicKMaxAtSoftmax);
let score_k = RetryModelVariant::from(Arm::SystematicKMaxAtScore);
let axes_differing = |a: RetryModelVariant, b: RetryModelVariant| {
- usize::from(a.combine != b.combine) + usize::from(a.selection != b.selection)
+ usize::from(a.combine != b.combine)
+ + usize::from(a.selection != b.selection)
+ + usize::from(a.ladder != b.ladder)
};
assert_eq!(
axes_differing(control, softmax_k),
1,
- "sampler comparison must hold the combine fixed"
+ "sampler comparison must hold the combine and the ladder fixed"
);
assert_eq!(
axes_differing(softmax_k, score_k),
1,
- "combine comparison must hold the sampler fixed"
+ "combine comparison must hold the sampler and the ladder fixed"
+ );
+ assert_eq!(
+ axes_differing(control, hybrid),
+ 1,
+ "ladder comparison must hold the combine and the sampler fixed"
);
}
@@ -2993,6 +3098,7 @@ mod retry_model_tests {
use common_enums::RevenueRecoveryABAlgorithm as Arm;
for (arm, expected) in [
(Arm::AdaptiveRetry, "adaptive_retry"),
+ (Arm::HybridAdaptiveRetry, "hybrid_adaptive_retry"),
(Arm::SystematicKMaxAtSoftmax, "systematic_k_max_at_softmax"),
(Arm::SystematicKMaxAtScore, "systematic_k_max_at_score"),
] {