Enforcing a shared access limit
UltraNow now checks organization capacity before activation and rechecks after reserving a session to handle competing requests.
Check before and after the reservation
The implementation first counts non-stopped, non-expired sessions for the organization. It checks that count against policy before reserving a new session, then counts again after the reservation to detect competition that occurred between those operations.
When the second check finds that capacity has been exceeded, it attempts to abort the new activation and returns a capacity error. The expiry cleanup path remains relevant if that compensating action fails.
Be precise about the concurrency model
This is a pre-check and compensating recheck design, not a single lock-protected reservation transaction. That distinction shapes the tests we need: simultaneous requests, cleanup failures, and the state left behind after an activation is refused.
The release moves the limit into the server’s decision path and provides a defined response to a detected race. The next task is to measure and tighten that behavior under contention while keeping the employee’s access state understandable.