I think for castles and towns there should be internal gardens and well settlement upgrades. These reduce the amount of food the defenders use up and with clean drinking water reduces the morale decay of the defenders. How long sieges and how they end also depend what time of year the attacker attacks. The most successful sieges occurred just prior to the harvesting seasons, as the defenders are unlikely have stocked up enough food to last long in a siege, and the attackers would have easily accessible food. If the attacker times poorly and arrives just after the harvest seasons then the attacker is forced to send out logistic trains to provide food for the attacking army, while the defender is well stocked and can easily hold out.
The problem with the notion that you could simply dig a single well and solve all your water supply problems forever or that you could just have a farm inside the castle walls ignores some serious problems with the realities of medieval life.
First, they did dig wells, of course, but a well is A) exhaustable, and B) only capable of handling so many people. Further, many cities were simply not sitting on a large aquifer, or at least one large enough to sustain the city, and underground tunnels dug to reach water supplies were also weaknesses in the defense of the city.
Second, there's a big, obvious reason you don't wall in the farms when you make a walled city - towering stone walls cost a lot of money
. Most often, much of the city wasn't even walled in at all, and refugees would come streaming into the city when a siege came, making the city even more packed and crowded with people than it would normally sustain.
Further, Medieval cities simply lacked anything like urban planning or even fire codes, and people simply built their houses however they wanted, wherever they wanted. Any sort of garden you did build would simply be built over in most cases, and although people did have small pasturelands for livestock in cities, they would also, again, be nowhere near sufficient for the number of people that would be living in a walled section of a walled city during a siege.