So I know for a fact that free adiabatic expansion is irreversible. I thought of the following argument which shows that free adiabatic expansion is reversible and I wanted to know where's the mistake in my argument.
Assumptions:
My understanding is that a process is reversible if we can return the system to its original state without affecting its surroundings. By “without affecting its surroundings”, I mean that there's no net energy transfer between the system and the surroundings after we restored the system to its original state.
The internal energy of the system depends only on its temperature.
Argument: The system under consideration is a gas in an insulated cylinder with a clamped piston as shown in the figure. It has an initial temperature of $T_i$ with corresponding energy $E_i$. Now the gas expands adiabatically in the vacuum (see figure). There's no heat exchange with the surroundings and no work done by the gas hence it maintains its original energy and temperature. Now, we draw energy from the surroundings to do work $W$ in compressing the gas to its original volume (how/where we draw this energy from should not matter, but for example, it can be achieved by a heat engine that draws heat from a hot reservoir and outputs $W$ as work). Now, the temperature of the compressed gas increases to $T_{\text{compress}}$ with a corresponding change in internal energy equal to $E_{\text{compress}}-E_i=W$. Now we allow the hot gas to come into contact with a heat sink and extract energy from it by heat $Q$ until the gas returns to its original temperature of $T_i$, where now its internal energy changes by $E_{i}-E_{\text{compress}}=Q=-W$. That is, all the energy drawn from the surroundings to the system as work returned back again to the system as heat. All in all, the system returned to its original state and the net energy transfer between the system and the surroundings is zero; therefore the process is reversible.
Now, where exactly is the mistake in this argument (or assumptions/definitions) that led to this wrong conclusion?