{"record":{"id":"214ea3bbf2a7db82","repo":"overleaf/overleaf","slug":"user-limit-cannot-be-added-to-variant-variant-n","errorCode":null,"errorMessage":"User limit cannot be added to variant '${variant.name}' after creation: user limits can only be set when the split test is created","messagePattern":"User limit cannot be added to variant '(.+?)' after creation: user limits can only be set when the split test is created","errorType":"validation","errorClass":"Errors.InvalidError","httpStatus":400,"severity":"error","filePath":"services/web/app/src/Features/SplitTests/SplitTestManager.mjs","lineNumber":483,"sourceCode":"        `Rollout percentage for variant defined in previous version as ${JSON.stringify(\n          variant\n        )} cannot be decreased: revert to a previous configuration instead`\n      )\n    }\n    if (variant.userLimit !== undefined) {\n      // Existing variant has a user limit - can only increase it\n      if (\n        newVariantConfiguration.userLimit !== undefined &&\n        newVariantConfiguration.userLimit < variant.userLimit\n      ) {\n        throw new Errors.InvalidError(\n          `User limit for variant '${variant.name}' cannot be decreased: revert to a previous configuration instead`\n        )\n      }\n    } else {\n      // Existing variant has no user limit - cannot add one\n      if (newVariantConfiguration.userLimit !== undefined) {\n        throw new Errors.InvalidError(\n          `User limit cannot be added to variant '${variant.name}' after creation: user limits can only be set when the split test is created`\n        )\n      }\n    }\n  }\n}\n\nfunction _updateVariantsWithNewConfiguration(\n  variants,\n  newVariantsConfiguration\n) {\n  let totalRolloutPercentage = _getTotalRolloutPercentage(variants)\n  const variantsCopy = _.clone(variants)\n  for (const newVariantConfig of newVariantsConfiguration) {\n    if (newVariantConfig.rolloutPercent === 0) {\n      continue\n    }\n    const variant = _.find(variantsCopy, { name: newVariantConfig.name })","sourceCodeStart":465,"sourceCodeEnd":501,"githubUrl":"https://github.com/overleaf/overleaf/blob/28ad3b03b71cb4311decdcb55c36b33ec10d72db/services/web/app/src/Features/SplitTests/SplitTestManager.mjs#L465-L501","documentation":"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.","triggerScenarios":"Calling createNewVersion where variant.userLimit === undefined in the current version but newVariantConfiguration.userLimit !== undefined — i.e. introducing a cap post-creation.","commonSituations":"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.","solutions":["Omit userLimit in the new configuration for that variant.","If a user limit is required, create a new split test with the limit set at creation time.","Strip default userLimit fields from config payloads before applying to existing tests.","Catch Errors.InvalidError (400) and indicate which variant cannot gain a limit."],"exampleFix":"// before\nawait manager.createNewVersion(name, userId, [{ name: 'variant', rolloutPercent: 50, userLimit: 100 }]) // variant had no limit\n// after\nawait manager.createNewVersion(name, userId, [{ name: 'variant', rolloutPercent: 50 }]) // no userLimit","handlingStrategy":"validation","validationCode":"const current = SplitTestUtils.getCurrentVersion(splitTest)\nfor (const v of current.variants) {\n  const nv = cfg.find(c => c.name === v.name)\n  if (v.userLimit === undefined && nv?.userLimit !== undefined) {\n    throw new Error(`cannot add userLimit to '${v.name}'; create a new split test instead`)\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await manager.createNewVersion(name, userId, cfg)\n} catch (err) {\n  if (err instanceof Errors.InvalidError && err.message.includes('User limit cannot be added')) {\n    // strip userLimit or create a new split test\n  } else throw err\n}","preventionTips":["Set user limits at split test creation time if quotas are needed","Strip default userLimit fields from config payloads for existing tests","Create a fresh split test to introduce quotas on existing variants"],"tags":["split-tests","user-limit","validation","invalid-config"],"backgroundTag":"user-limit-immutable-after-creation","analyzedSha":"28ad3b03b71cb4311decdcb55c36b33ec10d72db","analyzedAt":"2026-09-03T02:10:22.807Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}