runtime: add execution concurrency limits

This commit is contained in:
a.tolmachev
2026-05-01 12:11:53 +00:00
parent 3d2d97c1e6
commit 8ac55ebcc2
13 changed files with 448 additions and 15 deletions
+24 -1
View File
@@ -128,11 +128,12 @@ pub fn build_app(
refresh_interval: Duration,
public_base_url: Option<String>,
secret_crypto: SecretCrypto,
runtime: RuntimeExecutor,
) -> Router {
let state = Arc::new(AppState {
registry: registry.clone(),
catalog: PublishedToolCatalog::new(registry, refresh_interval),
runtime: RuntimeExecutor::new(),
runtime,
secret_crypto,
sessions: SessionStore::new(),
allowed_origins: AllowedOrigins::new(public_base_url),
@@ -2047,6 +2048,7 @@ fn runtime_error_code(error: &RuntimeError) -> &'static str {
RuntimeError::SoapAdapter(_) => "adapter_execution_error",
RuntimeError::WebsocketAdapter(_) => "adapter_execution_error",
RuntimeError::UnsupportedProtocol { .. } => "unsupported_protocol",
RuntimeError::ConcurrencyLimitExceeded { .. } => "runtime_overloaded",
RuntimeError::MissingStreamingConfig { .. } => "streaming_config_error",
RuntimeError::UnsupportedExecutionMode { .. } => "streaming_mode_error",
RuntimeError::InvalidPreparedRequest { .. } => "runtime_error",
@@ -2098,6 +2100,10 @@ fn runtime_error_context(error: &RuntimeError) -> Option<Value> {
RuntimeError::UnsupportedProtocol { protocol } => Some(json!({
"protocol": protocol,
})),
RuntimeError::ConcurrencyLimitExceeded { kind, limit } => Some(json!({
"kind": kind,
"limit": limit,
})),
_ => None,
}
}
@@ -2506,6 +2512,23 @@ mod tests {
);
}
#[test]
fn runtime_error_context_includes_runtime_overload_details() {
let context = runtime_error_context(&RuntimeError::ConcurrencyLimitExceeded {
kind: "async_job",
limit: 8,
})
.unwrap();
assert_eq!(
context,
json!({
"kind": "async_job",
"limit": 8
})
);
}
#[tokio::test]
async fn tool_error_response_includes_structured_context() {
let response = tool_error_response(