I'm sure a lot of people would agree but it doesn't really explain how you keep players on an adventure path if you're running one
Well, part of the problem answering the question is that it is very broad because you don't seem to have any experience with adventure paths, and you seem to have a very wrong idea in your head about how they actually play out in play. You seem to think that an adventure path goes off the rails the minute anyone does something not anticipated by the adventure, or indeed that an adventure path only anticipates one sort of solution and novelty inherently messes everything up. You don't seem to be very familiar with the real choke points in an adventure path, so you are proposing problems that usually don't really represent problems, and not asking good questions about the things that provoke the real problems. For insight into what causes real problems, you need to read essays like "The Three Clue Rule" as very direct attempts to answer the question, "How do you keep players on an adventure path?"
For me, if I'm running a published adventure path, the first thing I do is read the module and look for places where things can go badly wrong. A good adventure will have rather few of these, make few assumptions about player behavior, make no assumptions that players will behave illogically, and will have comments on how you might handle or how things might change for most of the obvious things players might do. I think the key thing to realize about any published adventure is that it's greatly constrained by its page count, which is merely an artifact of publishing the adventure. The published adventure needs to tell a novice GM how to run the adventure, but can generally afford to only cover the basics. It leaves it up to the GM to deal with unexpected changes in the adventure, while still using the content of the adventure as the basis of setting.
The second thing I tend to do is expand the content in areas that I feel are truncated or weak. If a town or haven is mentioned, I take some time to pre-create additional NPC's and detail important locations (see B2: Keep on the Borderlands and I6: Ravenloft). If a wilderness journey seems to play an important context in creating atmosphere, but the described wilderness is too small to create the impression desired (see I5: Pyramid, S2: White Plume Mountain, and I6: Ravenloft), then I expand the wilderness around the dungeon. Often this amounts to making the adventure effectively more Sandbox-y, even if in truth it's still a Small World with a central attraction.
I then tend to go over the details and make fine adjustments to correct for the overall atmosphere I want - making comic elements less unnatural, making horror elements more frightening, making the setting more medieval or at least grittier (Dickensian, for example) where the magical elements are too cartoony, removing treasure I consider excessive, and balancing content for my PC's.
Occasionally, the author will base the story on illogical behavior or specific behavior by the PC's. In this case, I will need to do some revision (perhaps adding an event/hook) or apply some railroading technique (often Schrodinger's Map) to subtly steer the players through the rocky narrows in the story.
At that point, I'm usually satisfied I can run the adventure without mishap. But the central thing to remember is that generally players have a 'buy in'. They want to investigate the adventure in the same way that a reader wants to read a novel. Inventing new solutions probably isn't going to disrupt a well thought out AP, though it may require a bit of improvisation to rule on the player's proposition (whatever it is, big or small).
The real issues are things like:
"How do I get the train back on the rails?" It's always possible. It just requires a bit of theater. Even if the death of the BBEG in scene 1 is not a very large derailment.
"Should I get the train back on the rails?" Sometimes the train goes off the rails because the players aren't enjoying the story. In which case, should I just go with their new idea and see where that takes me? At some level, an AP is often just a slice of a setting. So that content still stays viable if the game suddenly veers into territory you didn't foresee. Sometimes the train went off the rails because the players bit red herring and are now desperately searching for the rails again. In that case, you want to gracefully help them back on.