mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-21 14:22:14 +03:00
`admitChatRequest`'s structural admission gate (chatBodyAdmission.ts) is the first caller in the request path to consult pressure severity, ahead of every other code path that would otherwise call `checkResourcePressureGuard()` (handleChatCore, checkResourcePressureBeforeProviderWork, AdaptiveAdmissionRuntimeImpl.acquire). `defaultPressureSeverity()` read the resourcePressure singleton's cached `state` directly (getResourcePressureObservation) instead of driving `check()` — so once `state.severity` flipped to "critical" (from any pressure trigger: PSI, v8 heap ratio, a worker-leak spike, etc.), every subsequent request was shed at this cheap cached-read gate before it could ever reach the one function capable of drawing a fresh sample and observing recovery. The gate and the only means of clearing it were mutually exclusive once tripped: the gate's own rejection starved the sampler that would clear the gate. Only a full process restart cleared it. `defaultPressureSeverity()` now calls `checkResourcePressureGuard()` first. That call is cheap on the hot path — a synchronous `process.memoryUsage()` read plus a timestamp comparison; the actual signal sampling (`/proc/pressure/memory`, cgroup reads) stays asynchronous via `scheduleRefresh()` and throttled by `staleAfterMs`, so this adds no per-request I/O. A non-null guard is this request's authoritative "shed now" answer and maps to "critical". A null guard means this request is not shed, but the raw cached label can still briefly read "critical" until the async refresh settles (or if the last real sample simply went stale), so that case is downgraded to "high" rather than re-introducing the same problem for the queue-wait-sizing branch that also reads this value. Fixes #13821 Test: new tests/unit/resource-pressure-gate-recovery.test.ts drives the resourcePressure singleton to critical through the same sustained-sample path production uses (not the synchronous immediate-heap escape hatch), using an injected mock clock so no scheduled refresh from setup can resolve on its own. Confirmed red on the base commit — the recovery assertion fails with `actual: 'critical', expected: 'normal'`, i.e. the singleton never recovers on its own — and green with the fix.