fix(agent): reserve shared runtime atomically

This commit is contained in:
zipg authored and GitHub committed 2026-07-15 13:20:16 +08:00
1 parent 55f15c8e4b
commit ebebc4fccd
2 files changed
+166 -14

No files matched your search

+3 -1
View File
@@ -203,11 +203,12 @@ impl AgentRuntimeClient {
self.active_sessions.fetch_add(1, Ordering::AcqRel);
}
pub fn decrement_session_count(runtime: &Arc<Self>) {
pub fn decrement_session_count(runtime: &Arc<Self>) -> u64 {
let previous = runtime
.active_sessions
.fetch_update(Ordering::AcqRel, Ordering::Acquire, |value| Some(value.saturating_sub(1)))
.unwrap_or_default();
let remaining = previous.saturating_sub(1);
if previous <= 1 {
let runtime = runtime.clone();
tokio::spawn(async move {
@@ -217,6 +218,7 @@ impl AgentRuntimeClient {
}
});
}
remaining
}
pub fn kill(&self) {