Skip to content

Commit 19fac16

Browse files
mengqing.cao@amd.comcursoragent
andcommitted
fix(mesh): assert the prefill release on P/D cancel and error paths
- The cancel and stalled error-body P/D tests check the prefill charge is taken and released, not only the request load. - WorkerLoadGuard::with_prefill_tokens debug-asserts a fresh guard instead of releasing a charge no caller has. - The mesh_worker_prefill_tokens help names the paths that charge it. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 42d9d8c commit 19fac16

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎atom/mesh/src/core/worker.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,9 +1002,9 @@ impl WorkerLoadGuard {
10021002
}
10031003

10041004
/// Also charge `tokens` of prefill to the worker until the guard drops or
1005-
/// [`Self::release_prefill`] runs.
1005+
/// [`Self::release_prefill`] runs. Call once, on a new guard.
10061006
pub fn with_prefill_tokens(mut self, tokens: usize) -> Self {
1007-
self.release_prefill();
1007+
debug_assert_eq!(self.prefill_tokens, 0, "prefill already charged");
10081008
if tokens > 0 {
10091009
self.worker.charge_prefill_tokens(tokens);
10101010
self.prefill_tokens = tokens;

‎atom/mesh/src/observability/metrics/schema.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ pub const METRIC_INVENTORY: &[MetricSpec] = &[
432432
MetricSpec {
433433
name: names::WORKER_PREFILL_TOKENS,
434434
kind: MetricKind::Gauge,
435-
help: "Prompt tokens charged to a worker (url@rank) whose prefill has not finished",
435+
help: "Prompt tokens charged to a worker (url@rank) whose prefill has not finished; only HTTP P/D prefills and streaming HTTP requests with counted or estimated tokens are charged",
436436
status: MetricStatus::Active,
437437
},
438438
MetricSpec {

‎atom/mesh/tests/routing/http_pd_load_tests.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,10 +744,12 @@ async fn cancelling_dispatch_releases_pending_load() {
744744
let task = dispatch(kind, &p, &d, true);
745745
p.wait_entered().await;
746746
assert_eq!(p.worker.load(), 1);
747+
assert_eq!(p.worker.prefill_tokens(), 7);
747748
assert_eq!(d.worker.load(), 1);
748749
task.abort();
749750
assert!(task.await.unwrap_err().is_cancelled());
750751
assert_eq!(p.worker.load(), 0);
752+
assert_eq!(p.worker.prefill_tokens(), 0);
751753
assert_eq!(d.worker.load(), 0);
752754
}
753755
}
@@ -836,6 +838,7 @@ async fn check_stalled_dual_dispatch_error(fail_prefill: bool) {
836838
let task = dispatch(DispatchKind::Sglang, &p, &d, streaming);
837839
p.wait_entered().await;
838840
d.wait_entered().await;
841+
assert_eq!(p.worker.prefill_tokens(), 7);
839842
let (failed, peer) = if fail_prefill {
840843
(&mut p, &d)
841844
} else {
@@ -858,6 +861,7 @@ async fn check_stalled_dual_dispatch_error(fail_prefill: bool) {
858861
let bytes = response.into_body().collect().await.unwrap().to_bytes();
859862
assert!(String::from_utf8_lossy(&bytes).contains("upstream unavailable"));
860863
assert_eq!(p.worker.load(), 0);
864+
assert_eq!(p.worker.prefill_tokens(), 0);
861865
assert_eq!(d.worker.load(), 0);
862866
}
863867
}

0 commit comments

Comments
 (0)