A few years ago, the PBS series Frontline did a TV show on the criminal plea process. Here's one part of the show's website. It confirms the usual rule, which allows a judge to ignore a sentencing recommendation tied to a plea. Dave O's experience in this regard is right on, and his comment here was 100% accurate as to the general rule.
I'm a lawyer myself (though not a criminal lawyer) and this is also my understanding. Lots of things can alter a specific situation, so we should be cautious of all the "legal absolutes" that are bandied about here. But speaking generally (the best we Mudcatters can do), there is always some risk that a judge will sentence as he or she wishes. I suspect that Polanski's undoubtedly expensive lawyers explained this to him before he pled guilty.
A judge should not engage in sentencing discussions with one party, alone. However, I would caution against accepting the claims of a documentary as the gospel truth in this regard, as to all pertinent matters. In any event, if these discussions occurred after the plea, the assignment of a new sentencing judge would probably serve as sufficient remedy for any harm.
Here's a pertinent quote from the website. Note the final sentence:
"What is a judge's role in a plea bargain?
There are a variety of different forms of plea bargaining and there are versions in which the judge has a relatively passive role, and in which most of the pressures are brought by the prosecutor.
. . .
In other forms of plea bargaining, typically called "sentence bargaining," the judge may have a larger role and can be the real driving force. The standards of judicial ethics vary from jurisdiction to jurisdiction and so judges are more involved in some places than in others. In many jurisdictions, the judge may bring everybody back into his office and sit them down and pressure them until the cases get worked out -- particularly judges who want to get cases off their trial calendar.
The judge always has the power to reject the plea offer negotiated between the prosecutor and the accused, and many judges will, if they don't think the sentence is severe enough, or for other reasons."