Redouble AI Nucleo documentation
Part 13 · Inside the runtime

Inside admission

ai.redouble.nucleo.harness.admission · nucleo-core

This page is for people working on the runtime itself. It is the package's statement of record: every rule a caller or an implementor of an account can rely on is stated here, and the tests named beside each section hold it. How a job uses admission is in Admission, and why admission has this shape is in Why admission has this shape.

What is here

TypeRole
AdmissionThe monitor, one per dispatcher. start once, admit, release, rollback, stop, queueSize.
DemandA job's whole need: entries in the order their first amount was added, normalized by account key.
GrantA demand after admission took it, settled once, with the wait attribution.
RateLimiterThe account contract every gate and limiter implements.
LimiterIdentityWhat an account is called in every event, health row and wait attribution.
AbstractRateLimiterThe base for accounts that are their own identity.
CountingGateEvery unit-permit gate held for the work; DatabaseGate is one, named db:<datasource>.
ModelGateThe account of a model entry bounded by how many requests its server takes at once (max_concurrent) rather than by a quota window: one permit per request in flight, named after the entry, RELEASE replenishment. Built by the factory for such an entry in place of a token bucket.
MemoryPressureGateThe heap account: latch, drain, growth penalty, floor. Its javadoc is the full statement of that rule.
TokenBucketRateLimiterThe per-model TIME account: requests and tokens per minute, clocked, with the adaptive throttle.
ElasticWindowRateLimiterThe per-service TIME account: a sliding window, an elastic throttle, a circuit breaker.
RateLimiterFactory, RateLimiterRegistryEvery limiter instance in the process, and the per-model facade over it.
LimiterEventsThe one place a LimiterEvent is built and published.
RateLimiterStatus and its recordsTokenBucketStatus, ElasticWindowStatus, SemaphoreLimiterStatus, MemoryPressureStatus.
RateLimitInfo, RateLimitTypeWhat a provider's response headers said about its limits, as the clients capture it.
SpendGateThe money wall, consulted after pricing and before admission; implemented by the cost ledger.
DBResourceProvider, DBManagedResourceThe contract a database stack implements to be managed by Nucleo.
DBResourceProvidersThe process's database providers by name, for jobs built by reflection.
CountingDBResourceProviderThe default database provider: a DatabaseGate counting declared use, holding nothing.
DatabaseSettingsThe default provider's knobs: name and maxConcurrent, bound from nucleo.database.*.

The monitor

AdmissionTest, AdmissionEventTest, MemoryGateDrainTest hold this section.

Events

Admission emits every LimiterEvent; no account emits for itself. The vocabulary: a fast path emits GRANTED_IMMEDIATE and nothing else; a slow path emits HELD once per account the waiter was short on, then GRANTED_FROM_HOLD with the wait and the post-transition waiter count; REJECTED carries a reason, cancelled for an interrupt or a context cancellation, circuit_blocked for an account's LLM-readable refusal, aborted for an account's bug, and shutdown for stop; release and rollback emit RELEASED. Every event carries the waiting job's snapshot. N slow-path waiters on one account produce exactly 2N transitions with balanced counts.

Demand and Grant

GrantAndDemandTest holds this section.

The account contract

AccountContractTest, ReplenishmentTest, DatabaseGateTest hold this section.

An account answers about amounts and moves counters; it never parks anyone. fits(mine, reservedAhead) is whether the asking job's amounts fit now with the head's amounts set aside; it throws UncorrectableRuntimeLLMException when mine can never fit the configuration or the account is refusing everyone, and answers false, never throws, when mine fits alone but not together with the reservation. tryTake is the same check and the debit in one step under the account's own lock. give credits back: at close for RELEASE accounts, at rollback and as compensation inside a failed grant for every account. earliestFit is the System.nanoTime() instant at which fits would become true from the clock alone, null when only an event can change the answer, and a past instant means now.

replenishment() has no default on the interface. AbstractRateLimiter answers RELEASE, which is what a permit means for the capacity gates built on it; the two clocked families override with TIME, and ElasticWindowRateLimiter's override is final. A TIME window still binds after the work that took a slot has finished; give remains the rollback path.

AbstractRateLimiter is its own accountFor, reports a nominal (null) statusIndicator, and holds the one wake slot: onCapacityChange installs it, capacityChanged() runs it, installing null clears it. On the interface, onSuccess(input) and onRateLimitError(failure, input) delegate to the plain calls, requiresHttpConnection is false, and observeHeld is a no-op that never consults the supplier it is handed.

limiterCategory is one of memory, token_bucket, elastic_window, semaphore. statusIndicator is null when nominal, else blocked, probing, throttle:<n>x or pace:<n>ms.

A CountingGate needs a positive capacity, else IllegalArgumentException; refuses a demand larger than its capacity on the check and on the take; answers null to earliestFit; stamps lastActivity on every take and give; and reports maxConcurrent, availablePermits, activeCount and the stamp in its SemaphoreLimiterStatus.

The memory gate

MemoryPressureGateTest and MemoryGateDrainTest hold the gate's javadoc, which is its full rule: the latch at 95 clearing only below 90, the two-second re-check while anything is pending, the drain one at a time by a completion or the delay for the heap as it reads now, the cubic curve from 50 ms at 80 to 30 s at 95, the growth penalty over the floor, the closed delay reported as its instant. A lone arrival is never spaced, in any zone below the latch. A line held on some other account is that account's to release, not memory's, whatever the heap reads. Its status names a zone: CRITICAL while latched, DRAINING while memory's line is non-empty, GREEN otherwise; its category is memory. It logs the latch setting at warn and clearing at info with the same summary. Once stopped it answers true to everyone. Under random heap readings and completions every job is granted and no permit leaks.

The token bucket

TokenBucketAccountTest and TokenBucketRateLimiterTest hold this section; the weighted backpressure rows are held in harness.errors.retry's UpstreamRetrySignalTest.

The elastic window

ElasticWindowRateLimiterTest, ElasticWindowStatusIndicatorTest, ReplenishmentTest hold this section.

The factory

RateLimiterFactoryTest holds this section.

Events and statuses

AccountContractTest holds this section.

Header information

RateLimitInfoTest holds this section.

RateLimitInfo.rateLimited(model) is the record for a limit that was hit and nothing more: no limits known, nothing remaining, a sixty-second retry-after, kind UNKNOWN. fromHeaders is a CAPACITY reading that was not rate limited, with no retry-after and no request limits. The per-minute fields mirror the limits and read zero when a limit is absent; a null kind reads as UNKNOWN; parseIntOrNull trims and answers null for a missing or non-numeric header.

The database contract

A provider exposes its bound as an account through admission(); Admission takes one permit on it as part of the job's whole demand, and only then does Nucleo call acquire, which materializes the handle under that permit and never gates. The permit is admission's, held in the grant and returned at release; the handle holds the session, the commit latches and the transaction state, never the permit. The lifecycle methods are the provider's own contract.

CountingDBResourceProvider carries nothing on its handle, its transaction verbs do nothing, and it depends on no database API (CountingDBResourceProviderTest, which measures on a real pool that jobs sharing a bound never have more connections out than the bound).

JdbcResourceProvider, HibernateResourceProvider and SpringTransactionResourceProvider each hold one connection per permit from acquire to close and never touch the host's pool. DBResourceProviderContract, in this package's tests and shipped in the test-jar, is the contract they all pass: a real in-process database behind a real Hikari pool, whose live active count is what "one permit is one held connection" is measured by, down to a fan-out through the dispatcher that never holds more connections than the bound.

DBResourceProviders registers each provider once; a second provider under a registered name is refused, and a miss names what is registered (DBResourceProvidersTest). DBResourceProviders.registerDefault() registers a CountingDBResourceProvider of maxConcurrent permits under name (default unless set); with maxConcurrent unset it registers nothing and answers null; the pool's size is the host's, and no bound is inferred from it (DBResourceProvidersTest).

^