Rename ranked minimal candidate reads

This commit is contained in:
fawney19
2026-04-27 15:28:20 +08:00
parent 44930532dc
commit dda6f34a07
4 changed files with 36 additions and 33 deletions

View File

@@ -51,14 +51,14 @@ pub(crate) async fn read_requested_model_rows(
Ok(Some((resolved_global_model_name, rows))) Ok(Some((resolved_global_model_name, rows)))
} }
pub(crate) async fn read_minimal_candidate_selection( pub(crate) async fn read_ranked_minimal_candidate_selection(
state: &(impl MinimalCandidateSelectionRowSource + Sync), state: &(impl MinimalCandidateSelectionRowSource + Sync),
api_format: &str, api_format: &str,
requested_model_name: &str, requested_model_name: &str,
require_streaming: bool, require_streaming: bool,
auth_snapshot: Option<&GatewayAuthApiKeySnapshot>, auth_snapshot: Option<&GatewayAuthApiKeySnapshot>,
) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> { ) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> {
read_minimal_candidate_selection_with_priority_mode( read_ranked_minimal_candidate_selection_with_priority_mode(
state, state,
api_format, api_format,
requested_model_name, requested_model_name,
@@ -69,7 +69,7 @@ pub(crate) async fn read_minimal_candidate_selection(
.await .await
} }
pub(crate) async fn read_minimal_candidate_selection_with_priority_mode( pub(crate) async fn read_ranked_minimal_candidate_selection_with_priority_mode(
state: &(impl MinimalCandidateSelectionRowSource + Sync), state: &(impl MinimalCandidateSelectionRowSource + Sync),
api_format: &str, api_format: &str,
requested_model_name: &str, requested_model_name: &str,
@@ -77,7 +77,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode(
auth_snapshot: Option<&GatewayAuthApiKeySnapshot>, auth_snapshot: Option<&GatewayAuthApiKeySnapshot>,
priority_mode: SchedulerPriorityMode, priority_mode: SchedulerPriorityMode,
) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> { ) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> {
read_minimal_candidate_selection_with_priority_mode_and_affinity_key( read_ranked_minimal_candidate_selection_with_priority_mode_and_affinity_key(
state, state,
api_format, api_format,
requested_model_name, requested_model_name,
@@ -89,7 +89,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode(
.await .await
} }
pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_required_capabilities( pub(crate) async fn read_ranked_minimal_candidate_selection_with_priority_mode_and_required_capabilities(
state: &(impl MinimalCandidateSelectionRowSource + Sync), state: &(impl MinimalCandidateSelectionRowSource + Sync),
api_format: &str, api_format: &str,
requested_model_name: &str, requested_model_name: &str,
@@ -98,7 +98,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_requ
priority_mode: SchedulerPriorityMode, priority_mode: SchedulerPriorityMode,
required_capabilities: Option<&serde_json::Value>, required_capabilities: Option<&serde_json::Value>,
) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> { ) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> {
read_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities( read_ranked_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities(
state, state,
api_format, api_format,
requested_model_name, requested_model_name,
@@ -111,7 +111,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_requ
.await .await
} }
pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_affinity_key( pub(crate) async fn read_ranked_minimal_candidate_selection_with_priority_mode_and_affinity_key(
state: &(impl MinimalCandidateSelectionRowSource + Sync), state: &(impl MinimalCandidateSelectionRowSource + Sync),
api_format: &str, api_format: &str,
requested_model_name: &str, requested_model_name: &str,
@@ -120,7 +120,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_affi
priority_mode: SchedulerPriorityMode, priority_mode: SchedulerPriorityMode,
affinity_key: Option<&str>, affinity_key: Option<&str>,
) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> { ) -> Result<Vec<SchedulerMinimalCandidateSelectionCandidate>, DataLayerError> {
read_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities( read_ranked_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities(
state, state,
api_format, api_format,
requested_model_name, requested_model_name,
@@ -133,7 +133,7 @@ pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_affi
.await .await
} }
pub(crate) async fn read_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities( pub(crate) async fn read_ranked_minimal_candidate_selection_with_priority_mode_and_affinity_key_and_required_capabilities(
state: &(impl MinimalCandidateSelectionRowSource + Sync), state: &(impl MinimalCandidateSelectionRowSource + Sync),
api_format: &str, api_format: &str,
requested_model_name: &str, requested_model_name: &str,

View File

@@ -14,7 +14,7 @@ use aether_scheduler_core::SchedulerMinimalCandidateSelectionCandidate;
use crate::cache::SchedulerAffinityTarget; use crate::cache::SchedulerAffinityTarget;
use crate::data::auth::GatewayAuthApiKeySnapshot; use crate::data::auth::GatewayAuthApiKeySnapshot;
use crate::data::candidate_selection::{ use crate::data::candidate_selection::{
read_minimal_candidate_selection, MinimalCandidateSelectionRowSource, read_ranked_minimal_candidate_selection, MinimalCandidateSelectionRowSource,
}; };
use crate::data::GatewayDataState; use crate::data::GatewayDataState;
use crate::{AppState, GatewayError}; use crate::{AppState, GatewayError};
@@ -86,7 +86,7 @@ async fn same_priority_candidates_are_distributed_by_affinity_key() {
let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas); let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas);
let auth_snapshot = sample_auth_snapshot("affinity-key-1"); let auth_snapshot = sample_auth_snapshot("affinity-key-1");
let selection = read_minimal_candidate_selection( let selection = read_ranked_minimal_candidate_selection(
&state, &state,
"openai:chat", "openai:chat",
"gpt-4.1", "gpt-4.1",

View File

@@ -7,7 +7,7 @@ use aether_scheduler_core::{
resolve_requested_global_model_name, SchedulerMinimalCandidateSelectionCandidate, resolve_requested_global_model_name, SchedulerMinimalCandidateSelectionCandidate,
}; };
use crate::data::candidate_selection::read_minimal_candidate_selection; use crate::data::candidate_selection::read_ranked_minimal_candidate_selection;
use crate::data::GatewayDataState; use crate::data::GatewayDataState;
use super::super::{ use super::super::{
@@ -119,7 +119,7 @@ fn scheduler_candidate_is_serializable() {
} }
#[tokio::test] #[tokio::test]
async fn read_minimal_candidate_selection_resolves_provider_model_alias() { async fn read_ranked_minimal_candidate_selection_resolves_provider_model_alias() {
let mut row = sample_row(); let mut row = sample_row();
row.global_model_name = "gpt-5".to_string(); row.global_model_name = "gpt-5".to_string();
row.model_provider_model_name = "gpt-5.2".to_string(); row.model_provider_model_name = "gpt-5.2".to_string();
@@ -135,7 +135,8 @@ async fn read_minimal_candidate_selection_resolves_provider_model_alias() {
let quotas = Arc::new(InMemoryProviderQuotaRepository::seed(vec![])); let quotas = Arc::new(InMemoryProviderQuotaRepository::seed(vec![]));
let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas); let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas);
let selection = read_minimal_candidate_selection(&state, "openai:chat", "gpt-5.2", false, None) let selection =
read_ranked_minimal_candidate_selection(&state, "openai:chat", "gpt-5.2", false, None)
.await .await
.expect("selection should succeed"); .expect("selection should succeed");
@@ -145,7 +146,7 @@ async fn read_minimal_candidate_selection_resolves_provider_model_alias() {
} }
#[tokio::test] #[tokio::test]
async fn read_minimal_candidate_selection_keeps_all_rows_supporting_requested_model() { async fn read_ranked_minimal_candidate_selection_keeps_all_rows_supporting_requested_model() {
let mut exact = sample_row(); let mut exact = sample_row();
exact.provider_id = "provider-exact".to_string(); exact.provider_id = "provider-exact".to_string();
exact.endpoint_id = "endpoint-exact".to_string(); exact.endpoint_id = "endpoint-exact".to_string();
@@ -177,7 +178,8 @@ async fn read_minimal_candidate_selection_keeps_all_rows_supporting_requested_mo
let quotas = Arc::new(InMemoryProviderQuotaRepository::seed(vec![])); let quotas = Arc::new(InMemoryProviderQuotaRepository::seed(vec![]));
let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas); let state = GatewayDataState::with_candidate_selection_and_quota_for_tests(candidates, quotas);
let selection = read_minimal_candidate_selection(&state, "openai:chat", "gpt-5", false, None) let selection =
read_ranked_minimal_candidate_selection(&state, "openai:chat", "gpt-5", false, None)
.await .await
.expect("selection should succeed"); .expect("selection should succeed");
@@ -193,7 +195,7 @@ async fn read_minimal_candidate_selection_keeps_all_rows_supporting_requested_mo
} }
#[tokio::test] #[tokio::test]
async fn read_minimal_candidate_selection_allows_resolved_global_model_in_auth_snapshot() { async fn read_ranked_minimal_candidate_selection_allows_resolved_global_model_in_auth_snapshot() {
let mut row = sample_row(); let mut row = sample_row();
row.global_model_name = "gpt-5".to_string(); row.global_model_name = "gpt-5".to_string();
row.global_model_mappings = Some(vec!["gpt-5(?:\\.\\d+)?".to_string()]); row.global_model_mappings = Some(vec!["gpt-5(?:\\.\\d+)?".to_string()]);
@@ -213,7 +215,7 @@ async fn read_minimal_candidate_selection_allows_resolved_global_model_in_auth_s
auth_snapshot.user_allowed_models = Some(vec!["gpt-5".to_string()]); auth_snapshot.user_allowed_models = Some(vec!["gpt-5".to_string()]);
auth_snapshot.api_key_allowed_models = Some(vec!["gpt-5".to_string()]); auth_snapshot.api_key_allowed_models = Some(vec!["gpt-5".to_string()]);
let selection = read_minimal_candidate_selection( let selection = read_ranked_minimal_candidate_selection(
&state, &state,
"openai:chat", "openai:chat",
"gpt-5.2", "gpt-5.2",

View File

@@ -169,7 +169,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
"provider_key_rpm_allows_request_since", "provider_key_rpm_allows_request_since",
"PROVIDER_KEY_RPM_WINDOW_SECS", "PROVIDER_KEY_RPM_WINDOW_SECS",
"SchedulerMinimalCandidateSelectionCandidate", "SchedulerMinimalCandidateSelectionCandidate",
"read_minimal_candidate_selection", "read_ranked_minimal_candidate_selection",
"read_cached_scheduler_affinity_target", "read_cached_scheduler_affinity_target",
"list_selectable_candidates", "list_selectable_candidates",
"list_selectable_candidates_for_required_capability_without_requested_model", "list_selectable_candidates_for_required_capability_without_requested_model",
@@ -187,7 +187,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
); );
assert!( assert!(
!candidate_mod.contains("build_ranked_minimal_candidate_selection"), !candidate_mod.contains("build_ranked_minimal_candidate_selection"),
"candidate/mod.rs should not own the core minimal candidate builder anymore" "candidate/mod.rs should not own the core ranked minimal candidate builder anymore"
); );
assert!( assert!(
!candidate_mod.contains("collect_global_model_names_for_required_capability"), !candidate_mod.contains("collect_global_model_names_for_required_capability"),
@@ -206,7 +206,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
"candidate/mod.rs should not own the minimal candidate DTO" "candidate/mod.rs should not own the minimal candidate DTO"
); );
for pattern in [ for pattern in [
"pub(crate) async fn read_minimal_candidate_selection(", "pub(crate) async fn read_ranked_minimal_candidate_selection(",
"pub(crate) async fn select_minimal_candidate(", "pub(crate) async fn select_minimal_candidate(",
"pub(crate) fn read_cached_scheduler_affinity_target(", "pub(crate) fn read_cached_scheduler_affinity_target(",
"async fn collect_selectable_candidates(", "async fn collect_selectable_candidates(",
@@ -539,7 +539,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
"impl MinimalCandidateSelectionRowSource for GatewayDataState", "impl MinimalCandidateSelectionRowSource for GatewayDataState",
"impl MinimalCandidateSelectionRowSource for AppState", "impl MinimalCandidateSelectionRowSource for AppState",
"impl SchedulerRuntimeState for AppState", "impl SchedulerRuntimeState for AppState",
"async fn read_minimal_candidate_selection(", "async fn read_ranked_minimal_candidate_selection(",
] { ] {
assert!( assert!(
!candidate_state.contains(pattern), !candidate_state.contains(pattern),
@@ -558,8 +558,9 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
"data/candidate_selection.rs should host requested-model row lookup" "data/candidate_selection.rs should host requested-model row lookup"
); );
assert!( assert!(
candidate_selection.contains("pub(crate) async fn read_minimal_candidate_selection("), candidate_selection
"data/candidate_selection.rs should host minimal candidate selection builder" .contains("pub(crate) async fn read_ranked_minimal_candidate_selection("),
"data/candidate_selection.rs should host ranked minimal candidate selection builder"
); );
assert!( assert!(
candidate_selection candidate_selection
@@ -572,7 +573,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
); );
assert!( assert!(
candidate_selection.contains("build_ranked_minimal_candidate_selection"), candidate_selection.contains("build_ranked_minimal_candidate_selection"),
"data/candidate_selection.rs should depend on core minimal candidate builder" "data/candidate_selection.rs should depend on core ranked minimal candidate builder"
); );
assert!( assert!(
candidate_selection.contains("collect_global_model_names_for_required_capability"), candidate_selection.contains("collect_global_model_names_for_required_capability"),
@@ -653,7 +654,7 @@ fn scheduler_candidate_runtime_paths_depend_on_scheduler_core_and_state_trait()
"state/integrations.rs should host SchedulerRuntimeState for AppState" "state/integrations.rs should host SchedulerRuntimeState for AppState"
); );
assert!( assert!(
!state_integrations.contains("async fn read_minimal_candidate_selection("), !state_integrations.contains("async fn read_ranked_minimal_candidate_selection("),
"state/integrations.rs should not re-host scheduler minimal candidate bridge anymore" "state/integrations.rs should not re-host scheduler minimal candidate bridge anymore"
); );
@@ -806,15 +807,15 @@ fn gateway_data_state_does_not_depend_on_scheduler_candidate_selection() {
read_workspace_file("apps/aether-gateway/src/state/runtime/auth/api_keys.rs"); read_workspace_file("apps/aether-gateway/src/state/runtime/auth/api_keys.rs");
assert!( assert!(
!state_mod.contains("read_minimal_candidate_selection"), !state_mod.contains("read_ranked_minimal_candidate_selection"),
"data/state/mod.rs should not import scheduler candidate selection entrypoints" "data/state/mod.rs should not import scheduler candidate selection entrypoints"
); );
assert!( assert!(
!state_runtime.contains("pub(crate) async fn read_minimal_candidate_selection("), !state_runtime.contains("pub(crate) async fn read_ranked_minimal_candidate_selection("),
"data/state/runtime.rs should not own scheduler minimal candidate derived read" "data/state/runtime.rs should not own scheduler minimal candidate derived read"
); );
assert!( assert!(
!auth_api_keys.contains("read_minimal_candidate_selection("), !auth_api_keys.contains("read_ranked_minimal_candidate_selection("),
"state/runtime/auth/api_keys.rs should not keep scheduler minimal candidate wrapper anymore" "state/runtime/auth/api_keys.rs should not keep scheduler minimal candidate wrapper anymore"
); );
for pattern in [ for pattern in [