Skip to main content

Module tenant_config

Module tenant_config 

Source
Expand description

Per-tenant resource limits for multi-tenant A2A servers.

PerTenantConfig is a default TenantLimits plus per-tenant overrides; get resolves the effective limits for a tenant id. Hand it to RequestHandlerBuilder::with_tenant_config and every limit below is enforced.

§Where each limit is applied

LimitEnforcedOn exceeding
max_concurrent_tasksper-tenant semaphore, permit taken before any side effectServerError::Overloaded
executor_timeoutresolved before the executor is spawnedthe task fails, as with the handler-wide timeout
event_queue_capacityat queue creationthe stream buffer is that deep
rate_limit_rpsRateLimitInterceptor, opt-inthe request is refused

Three of the four the handler applies by itself. rate_limit_rps is the exception and needs wiring, because the request is counted in an interceptor rather than in the handler:

let limiter = RateLimitInterceptor::new(RateLimitConfig::default())?
    .with_tenant_config(config);

Without that call the other three limits still apply and rate_limit_rps does nothing — the one place in this design where a field can be set and not take effect, and it is named here rather than left to be discovered.

§Tenant identity has to come from somewhere trustworthy

Every limit is keyed on the tenant the handler resolved, so a caller who can choose their own tenant id can choose their own limits. Pair this with a TenantResolver that reads an authenticated claim, and see that module’s security section.

§The limit that is not here

A per-tenant cap on stored tasks lives on the store, as TenantAwareInMemoryTaskStore::with_tenant_override, because only the store can enforce it — a store is constructed independently and handed to the builder, and never sees a PerTenantConfig. TenantLimits::max_stored_tasks, which tried to be it from this side and that nothing could read, was removed in 0.15.0.

§Example

use std::time::Duration;
use a2a_protocol_server::tenant_config::{PerTenantConfig, TenantLimits};

let config = PerTenantConfig::builder()
    .default_limits(TenantLimits::builder()
        .with_max_concurrent_tasks(100)
        .with_rate_limit_rps(50)
        .build())
    .with_override("premium-corp", TenantLimits::builder()
        .with_max_concurrent_tasks(1000)
        .with_executor_timeout(Duration::from_secs(120))
        .with_rate_limit_rps(500)
        .build())
    .build();

assert_eq!(config.get("premium-corp").max_concurrent_tasks, Some(1000));
assert_eq!(config.get("unknown").max_concurrent_tasks, Some(100));

§Fairness under shared process-wide caps

Per-tenant limits bound what each tenant may use; they do not reserve capacity. Process-wide resources — the event-queue manager’s max_concurrent_queues, handler sweep thresholds, and the tenant-partition cap of the tenant store wrappers — are shared pools, so a tenant running inside its own limit can still exhaust one and cause another tenant’s requests to be rejected as overloaded. Size the per-tenant max_concurrent_tasks so the sum across active tenants stays within the process-wide caps.

Data isolation is separate and does not depend on any of this: the tenant-aware stores partition by tenant, so one tenant cannot read another’s tasks whether or not a limit is set.

Structs§

PerTenantConfig
Per-tenant configuration for timeouts, capacity limits, and executor selection.
PerTenantConfigBuilder
Builder for PerTenantConfig.
TenantLimits
Resource limits declared for a single tenant.
TenantLimitsBuilder
Builder for TenantLimits.