Skip to main content

agentmux_srv/server/app_api/
fleet_check_limits.rs

1// Copyright 2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! `fleet.check-limits`: look again, now, at agents marked out of quota (task #2648). The Swarm's
5//! "Check now" calls it. Open to an agent as well as the window: it sends nothing in anyone's name, it
6//! starts a small turn on each limited agent (`limit_probe::check_limited`).
7
8use std::sync::Arc;
9
10use crate::backend::rpc::engine::WshRpcEngine;
11use crate::backend::rpc_types::*;
12
13use super::AppState;
14
15pub(super) fn register(engine: &Arc<WshRpcEngine>, state: &AppState) {
16    let state = state.clone();
17    engine.register_typed(COMMAND_FLEET_CHECK_LIMITS, move |cmd: CommandFleetCheckLimitsData, _ctx| {
18        let state = state.clone();
19        async move { Ok(check_limits_impl(&state, cmd.targets).await) }
20    });
21}
22
23/// Starts a check on each of `targets` (block ids) that is out of quota; `succeeded` where one started or
24/// runs, `failed` with why not.
25pub(crate) async fn check_limits_impl(state: &AppState, targets: Vec<String>) -> FleetActionResult {
26    let mstore = state.mstore.clone();
27    let answers = tokio::task::spawn_blocking(move || crate::server::limit_probe::check_limited(&mstore, &targets)).await.unwrap_or_default();
28    let mut result = FleetActionResult::default();
29    for (id, answer) in answers {
30        match answer {
31            Ok(()) => result.succeeded.push(id),
32            Err(error) => result.failed.push(FleetActionFailure { id, error }),
33        }
34    }
35    result
36}