I believe that when you fly multi-segment fares, for it to be the cheapest it has to be available on every single let. (ie. SFO-DEN-MIA-DEN-SFO)
For your example, SFO-BOS, If T is available going, but T is sold out on the way back I think SFO-BOS will still book into T, but BOS-SFO will book into a higher fare class and you pay a bit more.
If you search by price on .bomb, you should be fine to find the cheapest routings. If you need extra help, consult farecompare.com (which is not always reliable btw) or 3rd party booking sites like Expedia, TL, Orbitz, etc.