[Rust Frontend] Add external→internal request-id map for abort() (#45137)

Signed-off-by: Sahil Singh <sahiilsiingh37@gmail.com>
This commit is contained in:
Sahil Singh
2026-06-15 06:51:24 +00:00
committed by GitHub
parent ddad5dbda2
commit 64833f8158
13 changed files with 447 additions and 27 deletions
@@ -490,6 +490,10 @@ impl EngineCoreClient {
return Ok(());
}
// Finalize the consumer streams first, before the engine round-trip.
let all_request_ids: Vec<String> = abortable.values().flatten().cloned().collect();
self.inner.abort_requests_locally(&all_request_ids);
for (engine_id, request_ids) in abortable {
self.inner.do_abort_requests(&engine_id, &request_ids).await?;
}
@@ -1,5 +1,6 @@
use std::collections::{BTreeMap, BTreeSet};
use std::sync::Arc;
use std::time::{SystemTime, UNIX_EPOCH};
use arc_swap::ArcSwapOption;
use parking_lot::Mutex;
@@ -126,6 +127,20 @@ impl ClientInner {
self.request_reg.lock().finish_many(request_ids)
}
/// Finalize client-initiated aborts by pushing a terminal `Abort` output
/// down each request's stream and removing it from the registry. Returns
/// the request ids that were still active. See [`RequestRegistry::abort_many`].
pub fn abort_requests_locally<'a>(
&self,
request_ids: impl IntoIterator<Item = &'a String>,
) -> Vec<String> {
let timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_secs_f64())
.unwrap_or(0.0);
self.request_reg.lock().abort_many(request_ids, timestamp)
}
/// Apply one scheduler stats update for the given engine to the local
/// routing state. Returns `false` if the engine is unknown to the
/// client.
@@ -9,7 +9,7 @@ use crate::client::stream::EngineCoreStreamOutput;
use crate::error::{Error, Result};
use crate::protocol::stats::SchedulerStats;
use crate::protocol::utility::UtilityOutput;
use crate::protocol::{EngineCoreEventType, EngineCoreOutput};
use crate::protocol::{EngineCoreEventType, EngineCoreFinishReason, EngineCoreOutput};
use crate::transport::ConnectedEngine;
pub type OutputSender = mpsc::UnboundedSender<Result<EngineCoreStreamOutput>>;
@@ -289,6 +289,34 @@ impl RequestRegistry {
.collect()
}
/// Finalize client-initiated aborts: remove each request and push a
/// terminal output with `finish_reason = Abort` down its stream before the
/// sender drops. Returns the request ids that were still active.
pub fn abort_many<'a>(
&mut self,
request_ids: impl IntoIterator<Item = &'a String>,
timestamp: f64,
) -> Vec<String> {
let mut aborted = Vec::new();
for request_id in request_ids {
let Some((sender, engine_id)) = self.remove(request_id) else {
continue;
};
let output = EngineCoreStreamOutput {
engine_index: engine_id.engine_index().unwrap_or(0),
timestamp,
output: EngineCoreOutput {
request_id: request_id.clone(),
finish_reason: Some(EngineCoreFinishReason::Abort),
..EngineCoreOutput::default()
},
};
let _ = sender.send(Ok(output));
aborted.push(request_id.clone());
}
aborted
}
/// Remove one request from the local registry. Returns the tracked entry if
/// it exists.
#[must_use]
@@ -1939,7 +1939,7 @@ async fn multi_engine_abort_is_grouped_and_utility_fans_out_to_all_engines() {
let (shutdown_tx_0, engine_task_0) = spawn_mock_engine_task(
handshake_address.clone(),
b"engine-0".to_vec(),
EngineId::from_engine_index(0).into_frame().to_vec(),
|dealer, push| {
Box::pin(async move {
let utility = recv_engine_message(dealer).await;
@@ -1993,7 +1993,7 @@ async fn multi_engine_abort_is_grouped_and_utility_fans_out_to_all_engines() {
tokio::time::sleep(Duration::from_millis(50)).await;
let (shutdown_tx_1, engine_task_1) = spawn_mock_engine_task(
handshake_address.clone(),
b"engine-1".to_vec(),
EngineId::from_engine_index(1).into_frame().to_vec(),
|dealer, push| {
Box::pin(async move {
let utility = recv_engine_message(dealer).await;