refactor: isolate dispatch scheduling core

This commit is contained in:
fawney19
2026-05-12 13:15:41 +08:00
parent 81ee27cdea
commit fa73655134
50 changed files with 4467 additions and 3202 deletions

View File

@@ -1177,12 +1177,9 @@ fn ai_serving_planner_separates_local_candidate_resolution_from_ranking() {
let ranking_call = candidate_resolution
.find("rank_eligible_local_execution_candidates(")
.expect("candidate_resolution.rs should call core-backed local candidate ranking");
let pool_scheduler_call = candidate_resolution
.find("apply_local_execution_pool_scheduler(")
.expect("candidate_resolution.rs should call pool scheduler after ranking");
assert!(
ranking_call < pool_scheduler_call,
"candidate_resolution.rs should rank eligible candidates before applying pool-internal account scheduling"
!candidate_resolution.contains("apply_local_execution_pool_scheduler("),
"candidate_resolution.rs should leave pool-internal key scheduling to dispatch cursors"
);
for pattern in [
"pub(crate) async fn resolve_and_rank_local_execution_candidates(",
@@ -1270,18 +1267,45 @@ fn ai_serving_planner_separates_local_candidate_resolution_from_ranking() {
);
}
let pool_scheduler =
let planner_pool_scheduler =
read_workspace_file("apps/aether-gateway/src/ai_serving/planner/pool_scheduler.rs");
for pattern in [
"pub(crate) use crate::dispatch::pool_scheduler::apply_local_execution_pool_scheduler;",
"pub(crate) use crate::dispatch::pool_scheduler::PoolKeyCursor;",
] {
assert!(
planner_pool_scheduler.contains(pattern),
"planner/pool_scheduler.rs should only re-export dispatch pool scheduler compatibility item {pattern}"
);
}
for forbidden in [
"pub(crate) async fn apply_local_execution_pool_scheduler(",
"run_ai_pool_scheduler(",
"fn ai_pool_candidate_facts(",
"fn ai_pool_scheduling_config(",
"fn ai_pool_runtime_state(",
] {
assert!(
!planner_pool_scheduler.contains(forbidden),
"planner/pool_scheduler.rs should not own dispatch implementation {forbidden}"
);
}
let pool_scheduler = read_workspace_file("apps/aether-gateway/src/dispatch/pool_scheduler.rs");
for pattern in [
"pub(crate) async fn apply_local_execution_pool_scheduler(",
"pub(crate) struct PoolKeyCursor",
"run_ai_pool_scheduler(",
"fn ai_pool_candidate_facts(",
"fn ai_pool_scheduling_config(",
"fn ai_pool_runtime_state(",
"DEFAULT_POOL_WINDOW_SIZE",
"DEFAULT_POOL_PAGE_SIZE",
"DEFAULT_POOL_MAX_SCAN",
] {
assert!(
pool_scheduler.contains(pattern),
"planner/pool_scheduler.rs should adapt gateway pool runtime data through serving pool scheduler helper {pattern}"
"dispatch/pool_scheduler.rs should adapt gateway pool runtime data through serving pool scheduler helper {pattern}"
);
}
for forbidden in [
@@ -1296,7 +1320,34 @@ fn ai_serving_planner_separates_local_candidate_resolution_from_ranking() {
] {
assert!(
!pool_scheduler.contains(forbidden),
"planner/pool_scheduler.rs should not own global candidate ranking or pool scheduling policy helper {forbidden}"
"dispatch/pool_scheduler.rs should not own global candidate ranking or pool scheduling policy helper {forbidden}"
);
}
let dispatch_refs = read_workspace_file("apps/aether-gateway/src/dispatch/refs.rs");
for pattern in [
"DispatchCandidateRef::SingleKey",
"DispatchCandidateRef::PoolRef",
"pub(crate) fn key_ref_for_candidate",
"pub(crate) fn pool_ref_for_candidate",
] {
assert!(
dispatch_refs.contains(pattern),
"dispatch/refs.rs should expose logical dispatch refs through {pattern}"
);
}
let dispatch_core = read_workspace_file("crates/aether-dispatch-core/src/lib.rs");
for pattern in [
"DispatchCandidateRef",
"DispatchSequence",
"PoolDispatchPort",
"PoolWindowConfig",
"DispatchEffect",
] {
assert!(
dispatch_core.contains(pattern),
"aether-dispatch-core should export pure dispatch primitive {pattern}"
);
}

View File

@@ -540,8 +540,8 @@ async fn gateway_forwards_public_request_to_remote_tunnel_owner_before_fallback_
state = state
.with_data_state_for_tests(data_state)
.with_tunnel_identity_for_tests("gateway-a", Some("http://gateway-a:8080"));
state.scheduler_affinity_cache.insert(
"scheduler_affinity:api-key-affinity-1:openai:chat:gpt-4.1".to_string(),
state.remember_scheduler_affinity_target(
"scheduler_affinity:api-key-affinity-1:openai:chat:gpt-4.1",
crate::cache::SchedulerAffinityTarget {
provider_id: "provider-owner".to_string(),
endpoint_id: "endpoint-owner".to_string(),
@@ -761,8 +761,8 @@ async fn gateway_aggregates_sync_sse_from_remote_tunnel_owner_before_returning_t
state = state
.with_data_state_for_tests(data_state)
.with_tunnel_identity_for_tests("gateway-a", Some("http://gateway-a:8080"));
state.scheduler_affinity_cache.insert(
"scheduler_affinity:api-key-affinity-cli-1:openai:responses:gpt-5.4".to_string(),
state.remember_scheduler_affinity_target(
"scheduler_affinity:api-key-affinity-cli-1:openai:responses:gpt-5.4",
crate::cache::SchedulerAffinityTarget {
provider_id: "provider-cli-owner".to_string(),
endpoint_id: "endpoint-cli-owner".to_string(),
@@ -1001,8 +1001,8 @@ async fn gateway_streamifies_sync_json_from_remote_tunnel_owner_before_returning
state = state
.with_data_state_for_tests(data_state)
.with_tunnel_identity_for_tests("gateway-a", Some("http://gateway-a:8080"));
state.scheduler_affinity_cache.insert(
"scheduler_affinity:api-key-affinity-cli-1:openai:responses:gpt-5.4".to_string(),
state.remember_scheduler_affinity_target(
"scheduler_affinity:api-key-affinity-cli-1:openai:responses:gpt-5.4",
crate::cache::SchedulerAffinityTarget {
provider_id: "provider-cli-owner".to_string(),
endpoint_id: "endpoint-cli-owner".to_string(),