The tricky thing here is (assuming you have open rolls) that the player know he/she failed the roll, so giving them false information isn't going to lead to a bad result, and therefore isn't really a penalty for failure. (Caveat: if your table enforces the sort of roleplaying where it is expected that the player will act on the knowledge anyway, because to do otherwise would be "metagaming", then this might work for you.)
I suppose...hearking back to
@Charlaquin's comment about stealth...you make them roll
at the critical moment. That is, when the character actually attempts to shut down the portal, and commits to it, that's when the roll is made.
And maybe that's the general case answer to these scenarios? (Not that you handle ALL knowledge tasks this way, but when the stars align and inspiration strikes.)
Let's try it out with monster abilities/features. As long as the DM is willing to be flexible, I could see something like this:
Player: "Thinking back to my course in Elemental Combat Fundamentals in Wizard School, I try to recall if these things have any special vulnerabilities."
DM: "Well, what do you remember?"
Player: "That they are especially vulnerable to sonic damage!"
DM: "Cool, try it out."
(Player casts Shatter)
DM: "Let's see an Intelligence check."
Player (using
@iserith's method): "I'm going to apply Arcana, since this was something I learned in Wizard school....oh, sheet, I rolled a 2. So 7 total."
DM: "Well, lucky for you it wasn't a total fail* and you managed to not heal the thing, but you can tell that not only did it not do as much damage as you were expecting, but it barely seemed to affect it."
Two things about this scenario:
1) Whatever the stat block said, the DM was willing to switch it up on the fly. (Although from now on these creatures
probably have resistance to sonic damage.)
2) The penalty for failure came in the form of an underutilized spell slot, and turn. (EDIT: In my book this qualifies for Ovinomancer's criterion, as the odds have just shifted in the monster's favor.)
And I'll point out that the above scenario, with higher stakes and more dramatic effect, could very well turn into the sort of story that gets told around that table for years to come. "Remember the time...?" Which is in some ways my ultimate test.
*By the way, I don't intend to keep promoting gradations of success. I tossed that one idea out there a while ago, and that seemed to have gotten interpreted as "Elfcrusher is arguing for degrees of success."
So the above conversation could have had this inserted:
"Sure. Tell me what you remember, and when you act on it you can roll Int with a DC of X. If you fail it will produce the opposite intended effect."