Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix(billing): match identity meter to the shared seat pool
Tre Dubrava5a58d28e0c96
diff --git a/backend/src/ee/services/license-v2/license-v2-service.ts b/backend/src/ee/services/license-v2/license-v2-service.tsindex 3bc9f6d4e0..d402a287e2 100644--- a/backend/src/ee/services/license-v2/license-v2-service.ts+++ b/backend/src/ee/services/license-v2/license-v2-service.ts@@ -343,14 +343,17 @@ export const licenseV2ServiceFactory = ({const counterByFeatureKey = new Map(meteredFeatures.map((metered) => [metered.feature.key, metered.count]));- // Live per-org usage for the subscription's non-metered dimensions, keyed by feature key. Only the- // feature keys that have a counter and appear as a non-metered dimension are counted, once each,- // in parallel. A count failure is logged and dropped so the overview still renders.+ // Live per-org usage for the subscription's non-metered dimensions, keyed by feature key. Seeded+ // values (e.g. the shared member+identity pool, computed once for the Usage card) win, so a+ // dimension that also has its own count elsewhere on the page reads the same number. The rest are+ // counted once each, in parallel, via the same counters the usage meter uses. A count failure is+ // logged and dropped so the overview still renders.const resolveLiveUsage = async (orgId: string,- subscription: TSubscriptionResponse | null+ subscription: TSubscriptionResponse | null,+ seed: Map<string, number>): Promise<Map<string, number>> => {- const usage = new Map<string, number>();+ const usage = new Map<string, number>(seed);if (!subscription) {return usage;}@@ -358,7 +361,12 @@ export const licenseV2ServiceFactory = ({const featureKeys = new Set<string>();subscription.items.forEach((item) => {item.dimensions.forEach((dimension) => {- if (!dimension.metered && dimension.featureKey && counterByFeatureKey.has(dimension.featureKey)) {+ if (+ !dimension.metered &&+ dimension.featureKey &&+ !usage.has(dimension.featureKey) &&+ counterByFeatureKey.has(dimension.featureKey)+ ) {featureKeys.add(dimension.featureKey);}});@@ -383,7 +391,11 @@ export const licenseV2ServiceFactory = ({// Fold the subscription items and the entitlement features sourced from a product into a single// per-product entitlement map, keyed by the server's product ids.- const buildEntitlements = async (org: TEntitlementOrg, subscription: TSubscriptionResponse | null) => {+ const buildEntitlements = async (+ org: TEntitlementOrg,+ subscription: TSubscriptionResponse | null,+ liveUsageSeed: Map<string, number>+ ) => {const entitlements: Record<string, BillingV2Entitlement> = {};const labelByDimension = new Map<string, string>();@@ -408,10 +420,9 @@ export const licenseV2ServiceFactory = ({}// The license server only tracks usage for metered dimensions, so per-unit ones come back with- // used=0. Overlay live counts from the same feature-keyed counters the usage meter uses, matched- // on the stable feature key (dimension keys drift). Metered dimensions keep the server's period- // peak, which is the billed figure. Counts are fetched once per distinct feature key.- const liveUsageByFeatureKey = await resolveLiveUsage(org.id, subscription);+ // used=0. Overlay live counts, matched on the stable feature key (dimension keys drift). Metered+ // dimensions keep the server's period peak, which is the billed figure.+ const liveUsageByFeatureKey = await resolveLiveUsage(org.id, subscription, liveUsageSeed);if (subscription) {subscription.items.forEach((item) => {@@ -631,9 +642,12 @@ export const licenseV2ServiceFactory = ({logger.error(error, `billing-v2: failed to read billing profile [orgId=${orgId}]`);}+ // The identity dimension caps against the same shared member+identity pool the Usage card shows,+ // so seed its usage from that one figure instead of a separate count that could diverge from it.const entitlements = await buildEntitlements({ id: orgId, name: organization.name, slug: organization.slug },- subscription+ subscription,+ new Map([[IDENTITY_LIMIT_FEATURE_KEY, members + identities]]));// Org-wide projected metered usage (dollars): the summary adds this to recurringAmount for the// next-month total, so every product's estimate is summed once here.