You are responsible for your future. Maintain your own vision/mission, project backlog and roadmap. Always be brainstorming new ideas. Managers want autonomous people they can trust and let run. If you're sitting around waiting to be told what to do, you will be RIF'ed. As a manager, I can tell you that those people are a serious drain on a manager's time and energy (ie. always trying to figure out how to make them productive and independent).
If you are not that person (and most are not), then you need to be the highest performer on the team and don't be seen as the complainer. There's still bad luck so maintain your resume (eg. org change, boss doesn't like you, etc), but another manager will see that value and hire you.
Finally, you can mitigate the risk further by always moving forward in your career (ie. look for laterals and promotions every 3-5 years). If you're not having any luck, you can either look externally or double down on my previous advice.