mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 10:57:03 +08:00
feat(codex): add optional minimum quota reserve for pool scheduling
This commit is contained in:
@@ -411,6 +411,7 @@ pub(crate) fn admin_provider_pool_config_from_config_value(
|
||||
unschedulable_rules: Vec::new(),
|
||||
lru_enabled: false,
|
||||
skip_exhausted_accounts: false,
|
||||
reserve_minimum_quota: false,
|
||||
sticky_session_ttl_seconds: 3600,
|
||||
latency_window_seconds: 3600,
|
||||
latency_sample_limit: 50,
|
||||
@@ -446,6 +447,10 @@ pub(crate) fn admin_provider_pool_config_from_config_value(
|
||||
.get("skip_exhausted_accounts")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false),
|
||||
reserve_minimum_quota: pool_advanced
|
||||
.get("reserve_minimum_quota")
|
||||
.and_then(Value::as_bool)
|
||||
.unwrap_or(false),
|
||||
sticky_session_ttl_seconds: pool_advanced
|
||||
.get("sticky_session_ttl_seconds")
|
||||
.and_then(json_u64)
|
||||
@@ -574,6 +579,22 @@ mod tests {
|
||||
let config = admin_provider_pool_config(&provider).expect("pool config should exist");
|
||||
|
||||
assert!(!config.skip_exhausted_accounts);
|
||||
assert!(!config.reserve_minimum_quota);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_reserve_minimum_quota_independently_of_skip_exhausted_accounts() {
|
||||
for enabled in [false, true] {
|
||||
let provider = sample_provider(json!({
|
||||
"pool_advanced": {
|
||||
"reserve_minimum_quota": enabled,
|
||||
"skip_exhausted_accounts": false
|
||||
}
|
||||
}));
|
||||
let config = admin_provider_pool_config(&provider).expect("pool config should exist");
|
||||
assert_eq!(config.reserve_minimum_quota, enabled);
|
||||
assert!(!config.skip_exhausted_accounts);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -651,6 +651,7 @@ mod tests {
|
||||
unschedulable_rules: Vec::new(),
|
||||
lru_enabled: true,
|
||||
skip_exhausted_accounts: false,
|
||||
reserve_minimum_quota: false,
|
||||
sticky_session_ttl_seconds: 120,
|
||||
latency_window_seconds: 600,
|
||||
latency_sample_limit: 10,
|
||||
|
||||
@@ -1117,10 +1117,16 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
let health_score = admin_pool_health_score(key);
|
||||
let circuit_breaker_open = false;
|
||||
let auth_semantics = provider_key_auth_semantics(key, provider_type);
|
||||
let account_quota_exhausted = pool_config
|
||||
.as_ref()
|
||||
.is_some_and(|config| config.skip_exhausted_accounts)
|
||||
&& admin_provider_pool_pure::admin_pool_key_account_quota_exhausted(key, provider_type);
|
||||
let account_quota_exhausted = pool_config.as_ref().is_some_and(|config| {
|
||||
(config.skip_exhausted_accounts
|
||||
&& admin_provider_pool_pure::admin_pool_key_account_quota_exhausted(key, provider_type))
|
||||
|| (config.reserve_minimum_quota
|
||||
&& admin_provider_pool_pure::admin_pool_key_minimum_quota_reached(
|
||||
key,
|
||||
provider_type,
|
||||
None,
|
||||
))
|
||||
});
|
||||
let auth_config = state.parse_catalog_auth_config_json(key);
|
||||
let oauth_expires_at =
|
||||
admin_pool_derive_oauth_expires_at(provider_type, key, auth_config.as_ref());
|
||||
|
||||
@@ -488,9 +488,16 @@ pub(super) fn admin_pool_key_visible_status_filter(
|
||||
) {
|
||||
return status;
|
||||
}
|
||||
if pool_config.is_some_and(|config| config.skip_exhausted_accounts)
|
||||
&& admin_provider_pool_pure::admin_pool_key_account_quota_exhausted(key, provider_type)
|
||||
{
|
||||
if pool_config.is_some_and(|config| {
|
||||
(config.skip_exhausted_accounts
|
||||
&& admin_provider_pool_pure::admin_pool_key_account_quota_exhausted(key, provider_type))
|
||||
|| (config.reserve_minimum_quota
|
||||
&& admin_provider_pool_pure::admin_pool_key_minimum_quota_reached(
|
||||
key,
|
||||
provider_type,
|
||||
None,
|
||||
))
|
||||
}) {
|
||||
return "quota_exhausted";
|
||||
}
|
||||
if !key.is_active {
|
||||
|
||||
@@ -1340,6 +1340,7 @@ async fn provider_query_apply_pool_scheduler_to_test_candidates(
|
||||
provider.id.clone(),
|
||||
provider_query_ai_pool_runtime_state(&runtime),
|
||||
);
|
||||
let reserve_minimum_quota = pool_config.reserve_minimum_quota;
|
||||
let pool_config =
|
||||
provider_query_ai_pool_scheduling_config(pool_config, provider.provider_type.as_str());
|
||||
let inputs = keys
|
||||
@@ -1351,6 +1352,14 @@ async fn provider_query_apply_pool_scheduler_to_test_candidates(
|
||||
effective_model: effective_model.to_string(),
|
||||
scheduler_skip_reason: None,
|
||||
};
|
||||
let mut key_context =
|
||||
provider_query_pool_catalog_key_context(state, &key, &provider.provider_type);
|
||||
key_context.quota_exhausted |= reserve_minimum_quota
|
||||
&& admin_provider_pool_pure::admin_pool_key_minimum_quota_reached(
|
||||
&key,
|
||||
&provider.provider_type,
|
||||
Some(effective_model),
|
||||
);
|
||||
AiPoolCandidateInput {
|
||||
facts: AiPoolCandidateFacts {
|
||||
provider_id: provider.id.clone(),
|
||||
@@ -1362,11 +1371,7 @@ async fn provider_query_apply_pool_scheduler_to_test_candidates(
|
||||
key_internal_priority: key.internal_priority,
|
||||
},
|
||||
pool_config: Some(pool_config.clone()),
|
||||
key_context: provider_query_pool_catalog_key_context(
|
||||
state,
|
||||
&key,
|
||||
&provider.provider_type,
|
||||
),
|
||||
key_context,
|
||||
candidate,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -65,6 +65,7 @@ pub(crate) struct AdminProviderPoolConfig {
|
||||
pub(crate) unschedulable_rules: Vec<AdminProviderPoolUnschedulableRule>,
|
||||
pub(crate) lru_enabled: bool,
|
||||
pub(crate) skip_exhausted_accounts: bool,
|
||||
pub(crate) reserve_minimum_quota: bool,
|
||||
pub(crate) sticky_session_ttl_seconds: u64,
|
||||
pub(crate) latency_window_seconds: u64,
|
||||
pub(crate) latency_sample_limit: u64,
|
||||
|
||||
Reference in New Issue
Block a user