overleaf/overleaf · error · Errors.InvalidError

User limit cannot be added to variant '${variant.name}' afte

Error message

User limit cannot be added to variant '${variant.name}' after creation: user limits can only be set when the split test is created

What it means

Thrown by _checkNewVariantsConfiguration when attempting to add a userLimit to a variant that was created without one. User limits are treated as fixed at split test creation: existing limit-less variants can never gain a limit in later versions, so the only option is a new split test.

Source

Thrown at services/web/app/src/Features/SplitTests/SplitTestManager.mjs:483

        `Rollout percentage for variant defined in previous version as ${JSON.stringify(
          variant
        )} cannot be decreased: revert to a previous configuration instead`
      )
    }
    if (variant.userLimit !== undefined) {
      // Existing variant has a user limit - can only increase it
      if (
        newVariantConfiguration.userLimit !== undefined &&
        newVariantConfiguration.userLimit < variant.userLimit
      ) {
        throw new Errors.InvalidError(
          `User limit for variant '${variant.name}' cannot be decreased: revert to a previous configuration instead`
        )
      }
    } else {
      // Existing variant has no user limit - cannot add one
      if (newVariantConfiguration.userLimit !== undefined) {
        throw new Errors.InvalidError(
          `User limit cannot be added to variant '${variant.name}' after creation: user limits can only be set when the split test is created`
        )
      }
    }
  }
}

function _updateVariantsWithNewConfiguration(
  variants,
  newVariantsConfiguration
) {
  let totalRolloutPercentage = _getTotalRolloutPercentage(variants)
  const variantsCopy = _.clone(variants)
  for (const newVariantConfig of newVariantsConfiguration) {
    if (newVariantConfig.rolloutPercent === 0) {
      continue
    }
    const variant = _.find(variantsCopy, { name: newVariantConfig.name })

View on GitHub (pinned to 28ad3b03b7)

Solutions

  1. Omit userLimit in the new configuration for that variant.
  2. If a user limit is required, create a new split test with the limit set at creation time.
  3. Strip default userLimit fields from config payloads before applying to existing tests.
  4. Catch Errors.InvalidError (400) and indicate which variant cannot gain a limit.

Example fix

// before
await manager.createNewVersion(name, userId, [{ name: 'variant', rolloutPercent: 50, userLimit: 100 }]) // variant had no limit
// after
await manager.createNewVersion(name, userId, [{ name: 'variant', rolloutPercent: 50 }]) // no userLimit
Defensive patterns

Strategy: validation

Validate before calling

const current = SplitTestUtils.getCurrentVersion(splitTest)
for (const v of current.variants) {
  const nv = cfg.find(c => c.name === v.name)
  if (v.userLimit === undefined && nv?.userLimit !== undefined) {
    throw new Error(`cannot add userLimit to '${v.name}'; create a new split test instead`)
  }
}

Try / catch

try {
  await manager.createNewVersion(name, userId, cfg)
} catch (err) {
  if (err instanceof Errors.InvalidError && err.message.includes('User limit cannot be added')) {
    // strip userLimit or create a new split test
  } else throw err
}

Prevention

When it happens

Trigger: Calling createNewVersion where variant.userLimit === undefined in the current version but newVariantConfiguration.userLimit !== undefined — i.e. introducing a cap post-creation.

Common situations: Deciding later to quota-limit a variant that launched unlimited; copying a config with limits onto a test originally created without them; automation that always sets userLimit fields regardless of history.

Related errors


AI-assisted analysis of overleaf/overleaf@28ad3b03b7 (2026-09-03). Data as JSON: /api/errors/214ea3bbf2a7db82. Report an issue: GitHub.