I'm trying to solve this thermodynamics problem. There's a spring of elastic constant $k$ attached to a mass $m$ in it's equilibrium position
\begin{equation} x_{0}=\frac{mg}{k} \end{equation}
Suddenly we add a new mass $M$ in the end of the spring so the spring oscillates for a while until it settles in a new equilibrium position. This happens at a constant temperature $T$ in contact with the enviroment.
\begin{equation} x_f=\frac{(m+M)g}{k} \end{equation}
The question is: How much heat was released or absorbed by the spring during that process and how much did the entropy of the universe increase?
My problem is that I have two alternative methods for this and they give two results. Furthermore, there are certain subtleties of thermodynamics that are confusing me. Let me explain the two methods:
First Method:
The energy that the system has lost is equal to:
\begin{equation} \begin{aligned} \Delta E &= E_f-E_i \\ &= -\frac{g^2(m+M)^2}{k}+\frac{g^2m^2}{k} \end{aligned} \end{equation}
since we know that this energy was lost due to friction it had to be released in the form of heat so we get
\begin{equation} Q_{out}=-\Delta E >0 \end{equation}
If we write down the first law of thermodynamics for this system and we use the fact that the internal energy of an harmonic oscillator is $U=Nk_bT$ we get
\begin{equation} \begin{aligned} dU&=\delta Q- \delta W \\ 0 &= \delta Q - F dx \\ \rightarrow \delta Q &=kx dx \end{aligned} \end{equation}
where I'm using that the work done by the system is $\delta W = kxdx$. Integrating this we get
\begin{equation} \begin{aligned} Q&=k \int_{x_i}^{x_f}xdx \\ &=-\Delta E \end{aligned} \end{equation}
which agrees with the prediction that the heat should we equal to the change in energy.
Second Method:
Instead of using the energy of a thermal harmonic oscillator let's use the mechanical energy plus something that might depend on temperature (which is not important since the temperature remains constant):
\begin{equation} dU=kx dx+CdT \end{equation}
and let's think of the masses as external agents applying a force on the spring. Then the first law takes the form
\begin{equation} \begin{aligned} dU&=\delta Q - \delta W \\kx dx &= \delta Q + (m+M)g dx \end{aligned} \end{equation}
Here comes an important doubt: If the system and it's enviroment are doing unequal forces, which one should we take into account when we write the work? In the first method I was using the force that the spring does, here I'm using the force that the masses do. Now we can integrate the heat to get
\begin{equation} \begin{aligned} Q&=\int \Big[kx-(m+M)g\Big] dx \\ &= -\frac{g^2M^2}{2k} \end{aligned} \end{equation}
On one hand I like this equation because when we take the limit $M\rightarrow 0 $ the heat goes straight to zero. Also, I like this method because in the first law it's clear that if we do the expansion cuasistationarily (meaning that the external force is always equal to the Hooke force) then there's no heat exchange. However, I still don't see why the heat should be less than the energy lost in the expansion.
Regarding the entropy question, I'm just not sure how to calculate it.