{"record":{"id":"55d29603906ff8b4","repo":"paperclipai/paperclip","slug":"failed-to-generate-a-unique-invite-token","errorCode":null,"errorMessage":"Failed to generate a unique invite token","messagePattern":"Failed to generate a unique invite token","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-host-services.ts","lineNumber":2988,"sourceCode":"        let created: typeof invites.$inferSelect | null = null;\n        for (let attempt = 0; attempt < INVITE_TOKEN_MAX_RETRIES; attempt += 1) {\n          const candidateToken = createInviteToken();\n          try {\n            created = await db\n              .insert(invites)\n              .values({\n                ...insertValues,\n                tokenHash: hashToken(candidateToken),\n              })\n              .returning()\n              .then((rows) => rows[0] ?? null);\n            token = candidateToken;\n            break;\n          } catch (error) {\n            if (!isInviteTokenHashCollisionError(error)) throw error;\n          }\n        }\n        if (!token || !created) throw new Error(\"Failed to generate a unique invite token\");\n        await logPluginActivity({\n          companyId,\n          action: \"invite.created_by_plugin\",\n          entityType: \"invite\",\n          entityId: created.id,\n          details: {\n            allowedJoinTypes: created.allowedJoinTypes,\n            expiresAt: created.expiresAt.toISOString(),\n            hasAgentMessage: Boolean(normalizedAgentMessage),\n          },\n        });\n        return { ...redactInvite(created), token };\n      },\n      async revokeInvite(params) {\n        const companyId = ensureCompanyId(params.companyId);\n        await ensurePluginAvailableForCompany(companyId);\n        const invite = await db\n          .select()","sourceCodeStart":2970,"sourceCodeEnd":3006,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/plugin-host-services.ts#L2970-L3006","documentation":"Invite creation retried INVITE_TOKEN_MAX_RETRIES times and every insert collided on the token hash uniqueness constraint. Extremely unlikely, but the loop gives up rather than spin forever; the invite was not created.","triggerScenarios":"Thrown at server/src/services/plugin-host-services.ts:2979 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Transient collision generating invite tokens; retry the invite creation. If it persists, check the randomness source/DB unique constraint health."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}