Its quite simple... you trade 30 turns worth of marbles for 200 gold, but the goods are all shipped upon reciept of cash. In order for your civ to once again have enough marbles to keep people happy every turn, it will take you 30 turns to make up the loss in your inventories. Meanwhile, the civ who sent you their gold has the shipment of marbles, an inventory that will suffice to satisfy their people for 30 turns.
Contracts in real life can be made to work this way.
In game terms, you simply do not cancel the deal until it expries in 30 turns, even if either party is eliminated. A small tweak to create balance and prevent abuse.
Yes, this would help to that "exploit", but it's quite counter-intuitive and cumbersome ad hoc-solution. It's hard to believe in that kind of "inventory" when there isn't one. I'm not sure if that exploit is so bad after all. The AI could use it too, and it already uses very similar exploit of making research agreement just before declaring war.