paperclipai/paperclip · error

Failed to generate a unique invite token

Error message

Failed to generate a unique invite token

What it means

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.

Source

Thrown at server/src/services/plugin-host-services.ts:2988

        let created: typeof invites.$inferSelect | null = null;
        for (let attempt = 0; attempt < INVITE_TOKEN_MAX_RETRIES; attempt += 1) {
          const candidateToken = createInviteToken();
          try {
            created = await db
              .insert(invites)
              .values({
                ...insertValues,
                tokenHash: hashToken(candidateToken),
              })
              .returning()
              .then((rows) => rows[0] ?? null);
            token = candidateToken;
            break;
          } catch (error) {
            if (!isInviteTokenHashCollisionError(error)) throw error;
          }
        }
        if (!token || !created) throw new Error("Failed to generate a unique invite token");
        await logPluginActivity({
          companyId,
          action: "invite.created_by_plugin",
          entityType: "invite",
          entityId: created.id,
          details: {
            allowedJoinTypes: created.allowedJoinTypes,
            expiresAt: created.expiresAt.toISOString(),
            hasAgentMessage: Boolean(normalizedAgentMessage),
          },
        });
        return { ...redactInvite(created), token };
      },
      async revokeInvite(params) {
        const companyId = ensureCompanyId(params.companyId);
        await ensurePluginAvailableForCompany(companyId);
        const invite = await db
          .select()

View on GitHub (pinned to a7e689b3c3)

Solutions

  1. Transient collision generating invite tokens; retry the invite creation. If it persists, check the randomness source/DB unique constraint health.
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at server/src/services/plugin-host-services.ts:2979 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@a7e689b3c3 (2026-08-18). Data as JSON: /api/errors/55d29603906ff8b4. Report an issue: GitHub.