BTW your links to your transactions are broken...
The refund should not take priority, in fact, it should be the other way around. A contract should override the refund, provided the contract was submitted in the appropriate timeframe (before the refund locktime). This is to protect users from holding a contract that has been signed by everyone but him until after the external event is known (or significant information changes), then deciding to discard it or not. Once the contract has been signed and relayed, it should take priority, unless a refund already occurred. Submitting the refund is an "escape" so you don't have money locked up at a multisig output that the other party might not ever free up.
Right, so make the fees paid by the refund transaction to be less than the fees paid by the contract. It's actually perfectly safe to make the refund tx pay zero fees as in the long run child transactions will be able to pay fees for their parents - at worst you'd create a second fee paying tx to get the refund mined, or just wait until you need to spend the money. (the tx can't be double-spend after all without the consent of both parties)
This is worth considering as a future optimization. I'll need to look into this a bit more, and as long as what I have mostly works, I'm ready to try to fill in the major holes rather than optimize. Unless you see some reason what I'm doing is problematic.
Malicious users can submit a refund now before the timelock and mess things up on testnet, but that's not a big concern, because it doesn't really cause much harm for users and can be avoided in most cases. On the main network it should be fine. The design for this is contracts that are much longer term, so they will be stored in the blockchain and prevent double spends that way, and users will know if they need to refund or the contract went through fairly easily.
I noticed there were two transactions paying into the contract - you actually can have both parties create a single transaction with inputs from both and a single multisig output.
I'm trying to think why I didn't go that way. I really wanted to. I think there were two main reasons I didn't do this. Constructing the contract was the first problem from what I remember, mainly it would have taken a major effort to refactor the bitcionJ code to be able to only partially fund a transaction. I hadn't looked at the code that closely, so I could have missed an easier way to do this, and I certainly understand it better now, so it might be worth revisiting. But the second reason is that I couldn't find a way so that one party had a signed copy without the other party having it. With the refund transactions idea, it might be possible to use doublespend to prevent this from happening. This again could be a shortfall of me being creative enough to come up with a good handshaking scheme. I tried quite a lot of different schemes with anyone-can-pay signing, SIGHASH_SINGLE, etc... but always fell short.
The basic scenario is this:
Party A constructs the TX with his input and an output and funds it (but doesn't sign it). Party B needs to add his input, sign it, send it back to A to sign, then relay it. Party B does this, then A doesn't sign until the event occurs, then he decides to discard or not. In this case, Party B could just double-spend the input to get his money back since A didn't publish fast enough. So I think the double-spend solution is the way out of it, which is pretty similar to above, so that means I must have chosen to do it this way since it was hard to work with the wallet to figure out what outputs to use, and to only fund to a certain amount. That probably is the way to go in the future, I just need to refactor some of the bitcoinJ code to handle this use case. If there is a way to do this that I couldn't find, I'd love to know about it. Otherwise, it's at least functional as a proof of concept while I go work on other parts of this (network protocol and wallet extensions to save these transactions and relay after lock time is the next biggest chunk). I can always revisit these areas once I have something functional. My goal is to have a sample app ready within a month or two that I can have a way for peers to interact and lock up transactions this way.