I have some misgivings about "contingency tasks" - seems to undercut Earned Value Management. I'm not sure how to insert the contingency task automatically; should be possible to do it manually.
I think that Mr. Espina has described using Critical Chain Management to address the problem of managing the risk of task slippage. When I have had a need for similar buffers, I've used two techniques. First is to manually insert a milestone after the task, and move the milestone to manage the slippage. The other is to use PERT Analysis. MS Project allows you to plan the schedule based on weighted estimates. That allows you to display an optimistic/pessimistic/most likely schedule. Not precisely what you're looking for, but the technique may help.
Mechanistically, I'd create: (Here's where I'm trying to answer OP's question directly with minimal assumptions)
- A custom field for each task to track the contingency
- A custom field for each task to track the pessimistic duration (duration + contingency)
I think that will preserve the constraints imposed on the project. The question that remains in my mind is how I would use the information to convey information to my stakeholders. I could run a simplistic estimate that shows the optimistic end date, the pessimistic end date and the PERT end date. (This is what I've done most recently because my stakeholders aren't interested in any more complex analysis, and the quick experiments I've done indicate that the answers converge on the PERT answer anyway).
Because I'm a frustrated quant, I'd probably also record the actual duration for every task/work package and generate a quick distribution of variances and use that to build a monte carlo model for the rest of my project. (e.g. "In the past, 50% of work packages deliver on time, but 30% use most of the contingency, 10% use all of the contingency and 20% exceed the contingency. If I assume that pattern continues going forward, then let's simulate the project end date if future work packages follow the pattern of prior work packages.....)
I'd also look for patterns in the distribution... but I'm way beyond what OP asked at this point, I'm just thinking about how I'd use the data.