"Bring 6 eggs. If there are potatoes, bring 9."

Solution 1:

Bring is transitive (here). The wife has omitted the object in the second sentence. The husband resolved it to the object in the previous sentence (see parallelism). Omission of a required part is called ellipsis in linguistics. The husband's way of resolving it would have been valid in this kind of a scenario:

“Bring six eggs. If you're very hungry, bring nine.”

With my example, no new candidate has been provided for the object, and the object of the second "bring" resolves to "eggs".

If you are looking for papers, I'd recommend looking in ACL's anthology for "ellipsis resolution". I found many, but none addressing this topic in good detail. Not because there aren't any, but because there were too many on ellipsis resolution to sift for one that specifically addresses this kind of an ellipsis.

Coming to your second point:

Bring me one strip of my allergy meds. If you see many weeds on your way there, bring me two.

Bring me one can of bug spray. If you see many bugs on your way there, bring me two.

clearly resolve to the first object, even if the second object is possible literally. (See pragmatics.)

But,

I could use a few people to help me move. Ask my father to help me. If our friends are free, ask two.

clearly resolves to the second object. Hopefully, this programmer would not have trouble with:

Bring me 20 eggs. If they have egg beaters, bring me one.

Solution 2:

The process of interpreting the meaning of an ambiguous statement from context is what I've always called top-down processing, and is something that computers can't do in the slightest, which is the reason that computer programming is so terribly literal. Humans are constantly doing a mix of bottom-up processing ("When I put together the words in the sentence, what do they mean?") and top-down processing ("What kind of information do I expect in my current situation or context?") and conclude on a meaning that satisfies both.

Side note: When I read your phrase, I totally thought it meant "If there are potatoes, buy nine eggs along with the potatoes (because I can make some special kind of dish that requires more eggs)." I need to step away from a computer, I guess...

As to the second question, yes, this form of discussion is ambiguous and relies on context. Contrast these two sentences that have the same form:

"If you need anything, ring the bell."  (conditional)

"If you need anything, my name is Mark." (not a conditional)

In addition, contrast these that have the same if/then/else form that you're describing in your question.

"Go to the store and buy candy. If they have Snickers, buy those." (buy 1 thing)

"Go to the store and buy candy. If they have muffins, buy those." (buy 2 things)

Even though these are identical except for the noun used, they mean completely different things. Context is everything and syntax alone isn't enough.

Solution 3:

Like @Jeremy, I also read it as 'bring 9 eggs'. I'm not sure of the actual rules at work here, but 'If there are potatoes' part sounds like a self-contained conditional clause and the 'bring nine' still refers to the eggs of the first sentence. But I am a programmer so I'm probably the wrong person to comment on this with any objectivity...