AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
status: accepted
Pending invitations reserve seats, enforced at invite creation under a platform_plan row lock
Context
usersLimit was enforced counting active Users only, at invite-creation time. Because a PENDING
invitation consumes no seat until accepted, several invites sent while under the limit could all be
accepted past it — the limit was not a real ceiling (the "accept-time gap"). We want the seat limit to
hold, and we want the "out of seats" error to land on the admin (proactive), not the invitee.
Decision
Adopt the GitHub model: a pending invitation reserves a seat as soon as it is created, and enforce proactively at invite time.
usedSeats = activeUsers + reservedInvites.reservedInvites=COUNT(DISTINCT lower(email))of non-expireduser_invitationrows withstatus IN (PENDING, ACCEPTED)whose email does not already resolve to a platform user of any status (predicate identical towouldAddNewUser). Both PLATFORM and PROJECT invites count (both create a platform User on accept).ACCEPTEDrows are counted because an accepted invitation reserves a seat until the User is provisioned (and the row deleted) — this covers both the invitee-has-no-identity-yet case and the auto-accept path (see the API-key bypass consequence below). Expiry uses the singleINVITATION_EXPIRY_SECONDSconstant that also signs the invitation link, so link-expiry and count-expiry cannot drift; expired rows are excluded byupdated > cutoff(they are never deleted).- The expiry filter is
updated, notcreated. A resend goes throughcreateInvitationRecord's upsert, which reissues the link with a fresh 7-day JWT but leavescreatedon the original date. Filtering oncreatedlet the reservation lapse while the emailed link still worked — the exact drift this decision forbids — so a resend at the seat boundary passed its check, immediately stopped reserving, let another invite take the last seat, and still provisioned an ACTIVE user. TypeORM appends"updated" = DEFAULTto theON CONFLICT DO UPDATE SETforisUpdateDatecolumns, so the resend already movesupdatedwith no extra write.updatedtherefore means "when was the currently-valid link issued", which is what the reservation window is actually about. - Enforced at invite creation and at reactivation (INACTIVE→ACTIVE).
entitled_seatsis read from the projectedplatform_plan.usersLimit— never a live Autumn call (the billing projection is pull-based). - A seat-neutral operation skips the cap check entirely —
checkUsersExceededLimitreturns early onadditionalSeatsNeeded === 0rather than evaluatingusedSeats + 0 > usersLimit.countAdditionalSeatsNeededreturns 0 in exactly two cases, and in both the seat is already insideusedSeats: (1) the email resolves to an existing platform user (wouldAddNewUserfalse) — e.g. adding a current member to a second project; (2) a non-expiredPENDING/ACCEPTEDinvitation for that email already holds the seat — i.e. a resend. Comparing instead of skipping made both operations fail with 402 wheneverusedSeats >= usersLimit, even though neither adds a person. Being at or over cap is a legitimate steady state (decision 000017: a scheduled downgrade caps seats immediately while existing users stay), so an admin could not re-send an invitation email for a seat they were already paying for. Only the invite endpoint passes a computed value; the reactivation path uses the default of 1 and is unaffected. - Concurrency: a Postgres row lock. The seat check + the write run in one transaction that takes
SELECT … FOR UPDATE(.setLock('pessimistic_write')) on the platform'splatform_planrow, so all seat-consuming writes for a platform serialize. Accepted alternatives were rejected: reject-at-accept (bounces the invitee instead of warning the admin); RedLock (adds a Redis dependency and a 200ms retry-poll latency under batch contention); a bulk invite endpoint (only justified as a RedLock workaround). The row lock blocks-and-wakes with no polling, needs no new dependency, and matches the in-repo precedent (waitpoint-service.ts). - The seat-lowering floor (
assertSeatsNotBelowActiveUsers, used on plan downgrade / cancel-to-Free / seat decrease) compares the target againstusedSeats(active + reserved), not active alone. The deactivate-users dialog lets the admin free seats by deactivating users and/or revoking pending invites. Unlike the invite/reactivation paths, the floor is an intentional lock-free read — it takes noFOR UPDATE. These flows call Autumn'sattachover the network, and holding theplatform_planrow lock across that round-trip would serialize/block every invite for the platform until Autumn responds. A bounded transient overshoot (an invite landing between the floor read and the limit change) is acceptable: the invite path is the only hard ceiling and over-cap-after-downgrade is out of scope.
Consequences
- The limit is a real ceiling for the invite and reactivation paths, including API-key / auto-accept
invites: those write the row as
ACCEPTEDinside the locked transaction, and becauseACCEPTEDrows count as reserved, a concurrent second invite acquiring the lock sees the first and is blocked — closing the TOCTOU window where two simultaneous API-key invites at the seat boundary could both provision and overshoot. Normal invite-accept cannot overshoot either: the seat was already reserved at invite creation, and accept only materializes it. It is not a global invariant, though: SCIM and managed-authn (embedding) create Users with no seat check at all, sousedSeats ≤ usersLimitcan still be exceeded through those paths — deliberately out of scope (separate ticket). countActiveByPlatformIdis read outside the locked transaction'sentityManager(only the invite-count half participates); safe under READ COMMITTED + the row lock for invite-vs-invite and invite-vs-reactivation, which is all the guard claims.- A rare concurrent duplicate-email invite may be over-conservatively rejected (never over-permitted) —
additionalSeatsNeededis computed just before the lock;DISTINCT+ the exclude-existing-user predicate make the 0-cases genuinely seat-neutral, so no overshoot is possible. - Billing is never overcharged by an overshoot: Autumn is metered on active Users via a separate
ACTIVE-only query (
license-key-usage-report-service.ts), independent ofusedSeats. - Stale (expired, never-accepted)
PENDINGrows linger (not deleted) and appear in the now seat-relevant invitations list; they stop counting after expiry via theupdated > cutofffilter. - Accepting an invitation extends its reservation window —
accept()writesstatus = ACCEPTED, which bumpsupdated, so the seat is held for anotherINVITATION_EXPIRY_SECONDSfrom the accept without a new link being issued. This drifts the other way (reservation outlives the JWT), which is the safe direction: it over-reserves (blocks an invite) rather than over-provisioning past a paid cap, and holding a seat for someone who has accepted is the intended behaviour anyway. - Tests that age an invitation must backdate
updated, not justcreated. A rawUPDATE user_invitation SET created = …bumpsupdatedto now as a side effect, so it makes the row look fresh to the reservation queries.seedInvitationinseat-reservation.test.tssets both. - Still open: provisioning an accepted invitation performs no seat check of its own, so an accept followed by a much later signup can still land past the cap once the window lapses. The reservation and provisioning predicates disagree; tracked separately.