feat(routing): consolidate scheduling strategy configuration

This commit is contained in:
fawney
2026-09-03 11:05:59 +08:00
parent e8d9877b79
commit 2cb4d554aa
88 changed files with 1836 additions and 3635 deletions
+52 -2
View File
@@ -27,6 +27,47 @@ pub struct RoutingPoolPolicyOverride {
/// failing over: one retry on the same key.
pub const DEFAULT_STICKY_KEY_ATTEMPTS: u32 = 2;
/// Request-independent execution behaviours selected by a routing strategy.
///
/// These flags deliberately live beside scheduling rather than in provider
/// transport configuration. A resolved policy is snapshotted for the request
/// and can therefore be consumed by execution without rereading mutable
/// system settings.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Default)]
pub struct RoutingExecutionPolicy {
#[serde(default, skip_serializing_if = "is_false")]
pub enable_cf_heartbeat: bool,
#[serde(default, skip_serializing_if = "is_false")]
pub cyber_continue_failover: bool,
}
impl<'de> Deserialize<'de> for RoutingExecutionPolicy {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
#[derive(Deserialize, Default)]
struct LegacyCompatibleExecutionPolicy {
#[serde(default)]
enable_cf_heartbeat: bool,
#[serde(default)]
enable_openai_image_sync_heartbeat: bool,
#[serde(default)]
enable_standard_text_sync_heartbeat: bool,
#[serde(default)]
cyber_continue_failover: bool,
}
let value = LegacyCompatibleExecutionPolicy::deserialize(deserializer)?;
Ok(Self {
enable_cf_heartbeat: value.enable_cf_heartbeat
|| value.enable_openai_image_sync_heartbeat
|| value.enable_standard_text_sync_heartbeat,
cyber_continue_failover: value.cyber_continue_failover,
})
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct RoutingDefaultPolicy {
#[serde(default)]
@@ -40,6 +81,10 @@ pub struct RoutingDefaultPolicy {
/// `0` and `1` both mean no same-key retry.
#[serde(default = "default_sticky_key_attempts")]
pub sticky_key_attempts: u32,
/// Strategy-scoped execution behaviour. Flattened for a stable JSON
/// shape and backwards-compatible migration from system settings.
#[serde(flatten)]
pub execution_policy: RoutingExecutionPolicy,
}
impl Default for RoutingDefaultPolicy {
@@ -49,6 +94,7 @@ impl Default for RoutingDefaultPolicy {
scheduling_mode: RoutingSchedulingMode::default(),
keep_priority_on_conversion: false,
sticky_key_attempts: DEFAULT_STICKY_KEY_ATTEMPTS,
execution_policy: RoutingExecutionPolicy::default(),
}
}
}
@@ -57,6 +103,10 @@ fn default_sticky_key_attempts() -> u32 {
DEFAULT_STICKY_KEY_ATTEMPTS
}
fn is_false(value: &bool) -> bool {
!*value
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct RoutingModelPolicy {
pub model: String,
@@ -100,8 +150,8 @@ pub struct RoutingRule {
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct RoutingGroupConfig {
#[serde(default)]
pub allowed_models: Vec<String>,
/// The default policy is global for the selected strategy group. Model
/// differences are expressed through `model_policies` and `rules`.
#[serde(default)]
pub default_policy: RoutingDefaultPolicy,
#[serde(default)]