This is just a restatement of David Balažic's answer.
We agree, right at the outset, that this perpetual-energy-source machine won't work, and are only trying to narrow down where exactly it fails. But, neglecting all dissipative forces like friction and viscosity, the machine may very well work as a perpetual motion machine - when you attach a dynamo the whole thing will have to come to a halt.
First thing to do is to simplify the system so as to avoid misleading explanations, though they may contribute partially to the overall failure. So, we'll remove the air and water portions (or make the thickness of those 0) - just two layers left and right. Also, we'll not worry about the gases mixing at the common surfaces. We'll leave the (impossible) construction of this oversimplified setup to engineering.
Also let's restrict our discussion to a single container. The perpetual motion argument presented in the question will go through for this case also, without the added complication of containers driving one another.
What happens here is similar to leaving a hollow plastic ball at the bottom of a tube of water. There is a net flow of mass downward (Gas B downward, container upward). The loss of PE is converted into KE of the container. No problems here.
Ordinarily to restore the system to the initial condition, we'll have to push the container through Gas B (against the increasing pressure gradient). But instead, we've decided to cheat by dropping the container through Gas A (against a much more slowly increasing pressure gradient - one overcome by the weight of the container itself) and then relying on the speed developed while travelling upward through Gas B and downward through Gas A to take the ball back into the Gas B (across the pressure barrier).
Claim is that the work required to overcome this barrier is the energy gain achieved elsewhere. An clean way of seeing this is the following:
Work done to break the potential barrier $W$ is given by
$$W = (\rho_B-\rho_A)ghV$$
where $V$ is the volume of the container.
KE gained when moving through Gas B $KE_2$ is given by
$$KE_B = (\rho_B-\rho)ghV$$
where $\rho$ is the density of the container.
$$KE_A = (\rho-\rho_A)ghV$$
$$KE_A + KE_B = W$$
In other words, in the absence of all dissipative forces, the container will barely make it back into Gas 2 (unless the container had a non-zero initial velocity in the right side to begin with). Add a dynamo, and the machine will stop immediately (or after the initial KE has all been lost in the dynamo).
I say clean, because of some of the oversimplifications involved. The work done in breaking the pressure barrier is actually work done to lift volume $V$ of Gas B by height $h$ minus energy gained by the drop of volume $V$ of Gas A by height $h$. But our oversimplified system has no room for change in heights of the gas columns. I've ignored this and conveniently used the formula for pressure at the bottom of a fluid column open at the top (which is not applicable here) so as to not muck up the discussion. But this where some of the other answers come into the picture.
This is kind of interesting. It seems that our little trick of dropping the container through Gas A has accomplished perpetual motion at least, if not perpetual energy generation. But I claim that nothing has been accomplished and perpetual motion has always been there to begin with. Can you see why? What happens to a hollow plastic ball placed at the bottom of a tube of water in the absence of dissipative forces?