For a general ensemble, we define the entropy $S = k_B\left\langle -\ln p_i\right\rangle = -k_B \sum_i p_i \ln p_i$ and the internal energy $U = \left\langle \varepsilon_i \right\rangle = \sum_i p_i \varepsilon_i$, where $p_i$ is the probability of state $i$ and $\varepsilon_i$ is the energy of state $i$.
We may split the differential of the internal energy and identify the different terms as heat and work (see the answers to this question, and a more thorough discussion in a previous question of mine): $$ dU = d\big(\sum_i p_i \varepsilon_i\big) = \underbrace{\sum_i \varepsilon_i dp_i}_{\delta Q} + \underbrace{\sum_i p_i d\varepsilon_i}_{-\delta W}. \tag{1}\label{1} $$ Thus, we have the first law $dU = \delta Q - \delta W$, and microscopic definitions of work and heat.
In the canonical ensemble, we have $p_i = \frac{1}{Z} e^{-\beta \varepsilon_i}$ where $Z = \sum_i e^{-\beta \varepsilon_i}$. We may show using some manipulations that $\delta Q = T\,dS$.
Now, this doesn't work in the grand canonical ensemble. Here, $p_i = \frac{1}{\mathcal{Z}} e^{-\beta(\varepsilon_i - \mu n_i)}$ where $n_i$ is the number of particles in state $i$ and $\mathcal{Z} = \sum_i e^{-\beta(\varepsilon_i - \mu n_i)}$. I find $$ \begin{align} \frac{dS}{k_B} &= -\sum_i dp_i \ln p_i - \sum_i p_i d\ln p_i \\ &= -\sum_i dp_i \ln p_i - \underbrace{\sum_i dp_i}_{d(\sum_i p_i) = d(1) = 0} \\ &= -\sum_i dp_i \ln p_i \\ &= \overbrace{\sum_i dp_i (\ln\mathcal{Z}}^0 + \beta \varepsilon_i - \beta\mu n_i) \\ &= \beta \sum_i \varepsilon_i dp_i - \beta\mu\sum_i n_i dp_i \\ &= \beta \delta Q - \beta\mu\sum_i n_i dp_i, \end{align} $$ that is, $$ T\,dS = \delta Q - \mu \sum_i n_i dp_i. \tag{2}\label{2} $$ Does this mean that $\delta Q = T\,dS$ does not hold in the grand canonical ensemble? Or does one usually modify the definitions of $\delta Q$ and $\delta W$ in \eqref{1}?