Principal bundle (or torsor) for a diagonalizable group over a torus Let $T$ be an algebraic torus and $G$ a diagonalizable group; both are over an algebraically closed field $k$ of characteristic $0$ (take $k=\mathbb C$, if you like).
I am trying to understand principal $G$-bundles $P\to T$ over $T$, but I'm getting conflicting conclusions from two perspectives.

From what I've read (e.g. pg 11-13 here: https://arxiv.org/pdf/2009.08675.pdf), the total space $P$ is given by
$$P=\operatorname{Spec}_T\left(\bigoplus_{m\in\Gamma} \mathcal L^{\otimes m}\right)$$ where $\Gamma$ is the character group of $G$ (so $\Gamma$ is a finitely generated abelian group) and $\mathcal L$ is a product of line bundles on $T$ indexed by generators for $\Gamma$ (some possibly torsion, if $\Gamma$ has torsion).
But line bundles on $T$ are all trivial, so $\color{red}{\text{I think we just have (?)}}$

$$\begin{align}\operatorname{Spec}_T\left(\bigoplus_{m\in\Gamma} \mathcal L^{\otimes m}\right) = \operatorname{Spec}_T\left(\bigoplus_{m\in\Gamma} \mathcal O_T^{\otimes m}\right) = \operatorname{Spec}(k[T][\Gamma]) &= \operatorname{Spec}(k[T]\otimes_k k[\Gamma])\\&= T\times G.\end{align}$$

This seems to imply that every principal $G$-bundle over $T$ is trivial.

On the other hand, consider the following example. Take $G=\{1,-1\}$ (i.e. $\mu_2$) as a subgroup of $T=\mathbb G_m$ (rank $1$ torus). Then we have an exact sequence
$$1 \to G \to T \xrightarrow{t\mapsto t^2} T \to 1$$
where the map $T\to T$ via $t\mapsto t^2$ is a principal $G$-bundle over $T$. This should not be trivial, since $T\not\cong T\times G$ in this case (i.e. the exact sequence does not split).
This seems to contradict the above approach.

My question is: can anyone explain where I've gone wrong? Is one of the approaches correct and the other incorrect?
Edit: I think in the first approach the $\mathcal O_T$-algebra structure will depend on the torsion in $\Gamma$. For example, if $\Gamma=\mathbb Z/2$, then this $\mathcal O_T$-algebra structure will depend on a choice of isomorphism $\mathcal O_T^{\otimes 2}\to\mathcal O_T$. If this is right, then I guess it comes down to understanding these isomorphisms and how they give different $\mathcal O_T$-algebra structures, which is still confusing to me.
 A: Just to get this off the unanswered list, I will elaborate on my comment above.
Your mistake was in the understanding of the total space of a $\mu_{n,X}$-torsor as $\underline{\mathrm{Spec}}\left(\bigoplus_{i=0}^{n-1}\mathscr{L}^{\otimes i}\right)\to X$ where $\mathscr{L}$ is an $n$-torsion element of $\mathrm{Pic
}(X)$. Namely, how are you thinking of a $\bigoplus_{i=0}^{n-1}\mathscr{L}^{\otimes i}$ as a quasi-coherent $\mathscr{O}_X$-algebra? Namely, the multiplication here should be obtained via the natural maps
$$\mathscr{L}^{\otimes a}\otimes \mathscr{L}^{\otimes b}\to \mathscr{L}^{\otimes(a+b)},$$
but, of course, as we only consider $\mathscr{L}^{\otimes i}$ for $i=0,\ldots,n-1$ what you really need is a map like
$$\mathscr{L}^{\otimes a}\otimes \mathscr{L}^{\otimes b}\to \mathscr{L}^{\otimes(a+b\mod n)}.$$
This is doable as $\mathscr{L}^{\otimes n}\cong \mathscr{O}_X$, but not canonically so. In fact, you need to fix an isomorphism $\iota\colon \mathscr{L}^{\otimes n}\xrightarrow{\approx}\mathscr{O}_X$ and then from this structure one can actually give $\bigoplus_{i=0}^{n-1}\mathscr{L}^{\otimes i}$ the structure of a quasi-coherent $\mathscr{O}_X$-algebra.
Let us call this algebra structure $\mathscr{A}(\mathscr{L},\iota)$. Then, one can check that the isomorphism class of $\mathscr{A}(\mathscr{L},\iota)$ only depends on the following equivalence relation on the pair $(\mathscr{L},\iota)$: $(\mathscr{L}_1,\iota_1)\sim (\mathscr{L}_2,\iota_2)$ is there exists an isomorphism $f\colon \mathscr{L}_1\xrightarrow{\approx}\mathscr{L}_2$ such that $\iota_2\circ f^{\otimes n}=\iota_1$. In this way, using $H^1(X,\mu_{n,X})$ to denote the isomorphism classes of $\mu_{n,X}$-torsors, one gets a map
$$\{(\mathscr{L},\iota)\}/\sim\, \longrightarrow\, H^1(X,\mu_{n,X}).$$
This is actually an isomorphism of groups where one defines a group structure on the source in the obvious way: $(\mathscr{L}_1,\iota_1)\otimes (\mathscr{L}_2,\iota_2)=(\mathscr{L}_3,\iota_3)$ where $\mathscr{L}_3=\mathscr{L}_1\otimes\mathscr{L}_2$, and $\iota_3$ is the composition of
$$(\mathscr{L}_1\otimes\mathscr{L}_2)^{\otimes n}\xrightarrow{\text{natural}}\mathscr{L}_1^{\otimes n}\otimes \mathscr{L}_2^{\otimes n}\xrightarrow{\iota_1\otimes\iota_2}\mathscr{O}_X\otimes\mathscr{O}_X\xrightarrow{\text{natural}}\mathscr{O}_X.$$
There are several ways to prove this assertion, let me list two here.

*

*You can first prove that the association of $\mathscr{L}$ of the sheaf $\underline{\mathrm{Isom}}(\mathscr{O}_X,\mathscr{L})$ (which associates to an $X$-scheme $T$ the isomorphisms $\mathscr{O}_T\to \mathscr{L}_T$) is actually an isomorphism $\mathrm{Pic}(X)\to H^1(X,\mathbf{G}_{m,X})$ -- this is classical, for instance see here. One can then deduce the result for $\mu_{n,X}$ by tracing through the long exact sequence in cohomology obtained from the Kummer sequence $1\to \mu_{n,X}\to\mathbf{G}_{m,X}\to\mathbf{G}_{m,X}\to 1$.

*A more conceptual reason (which also handles the case of $\mathbf{G}_{m,X}$-torsors) is to see that $\mathscr{A}(\mathscr{L},\iota)$ represents the scheme $\underline{\mathrm{Isom}}((\mathscr{O}_X,\iota_0),(\mathscr{L},\iota))$ where $\iota_0\colon \mathscr{O}_X^{\otimes n}\xrightarrow{\approx}\mathscr{O}_X$ is the obvious map. One then wins from the general yoga that if $\mathcal{S}$ is any stack over a site $\mathcal{X}$, and any $x$ is any object of $\mathcal{C}_T$ (for $T$ an object of $\mathcal{X}$) then the association $y\mapsto \underline{\mathrm{Isom}}(x,y)$ is an isomorphism $\mathrm{Tw}(x)\to H^1(T,\underline{\mathrm{Aut}}(x))$. Here $\mathrm{Tw}(x)$ is the (isomorphism classe) of objects of $\mathcal{C}_T$ which are locally isomorphic to $x$ (i.e. the 'twists'). Why is this relevant here? Well, line bundlesform a stack, and therefore so do pairs
$(\mathscr{L},j)$ where $j\colon \mathscr{L}^{\otimes m}\to \mathscr{O}_X$. Note then that $\{(\mathscr{L},\iota)\}/\sim$ is precisely $\mathrm{Tw}((\mathscr{O}_X,\iota_0))$. But, what is $\underline{\mathrm{Aut}}(\mathscr{O}_X,\iota)$? It's precisely $\mu_{n,X}$!

