(The book implies that the force must be applied to keep the velocity at v which is wrong)

It is right, from the formula, you need a force to keep it at constant velocity when the mass is changing(note that this is not the case for a constant rest mass at relativistic velocities, because mass is a function of velocity). there's only the second term.
Force is change in momentum, not only velocity

The reason that a force must be supplied to keep the truck moving at a constant speed, is because the incoming sand has a speed 0 and must be accelerated to a speed of v.
If the truck loses sand through a hole in the bottom the outgoing sand will have the same speed as the truck and this will not accellerate the truck.

I think in the second case, where we have a loss of mass from the hole, we should use dm/dt=x either, because the sands which are leaving already have velocity and don't need to be accelerated, so the answer is the same i think!

The reason that a force must be supplied to keep the truck moving at a constant speed, is because the incoming sand has a speed 0 and must be accelerated to a speed of v.
If the truck loses sand through a hole in the bottom the outgoing sand will have the same speed as the truck and this will not accellerate the truck.

I think the point of the thought experiment was that the sand was supplied by a second co-moving truck travelling at v

Thus for the truck, although it's mass is changing, there is no change of velocity.

What happens if the truck is moving up a slope of [itex]\theta[/itex] degrees? Does the truck gain or lose momentum if the truck is gaining mass? What if its losing mass?

I tried to simplify this thought experiment with one of a body moving in space in the x direction. It has mass being added to it equally from both sides on the perpendicular axis: y and -y direction (so as not to complicate things with an acceleration on the y axis). This mass being added is comoving in the x direction.

Does the resulting body increase or decrease its speed in the x direction? I think it does neither. Since the mass that was added to it was comoving at the same velocity on the x axis, all its interactions with the original moving body would be in the y direction.

I think the reverse situation is even clearer. If a mass moving on the x axis started expelling mass in the y and -y direction, we should not expect to see the original mass accelerate in the x direction.

By the way, I think something that can make the case even more strongly is imagining the two preceeding examples were being viewed from a frame of reference co moving with the bodies. In that case how could you expect a body expelling or receiving matter entirely on the y axis accelerate on the x axis?

Although this seems intuitionally strong to me, I could still be wrong. Anyone disagree?

As a consequence, I think that original truck example moving on the frictionless railway having mass added to it from the top by a comoving railtruck would not change its velocity in the "forward" direction. And that energy is conserved, since whichever kinetic energy the sand had from its up/down direction upon dropping onto the truck could be converted to internal energy, with its forward kinetic energy contribution left unchanged.

However keep in mind that if a force was being applied to the truck in the "forward" direction to maintain some constant acceleration in that direction, then that force would need to vary so as to make up for the varying amount of mass being accelerated.