There's no specific cut-off point. But it is beyond dispute that ageism is very real (if perhaps overstated as a career obstacle).

The thing is, it's a nuanced issue (and rather different from other discriminatory -isms). What it comes down to is the fact that most mid- or senior-level SWE work (in the usual sense of "senior" these days) is pretty menial -- in that your day-to-day existence usually boils down to "Go do this feature here, clean up that mess there, maybe architect a little box there, please, while the adults chart the company's direction and make the big bucks, or at least enjoy an uptick in status."

One way or another you will definitely want to "graduate" from this box, ideally around age 40 or so. This doesn't mean you'll have to stop coding. But you should ask yourself, intently, where you want to be in 10-15 years time[1]. This might be Staff or Principal Engineer (at a company where this title actually means something), which is definitely different from the mid-career role. Or analogously, becoming a consultant (with public presence, articles published and so forth). Or becoming a founder or starting a company. Or moving to a totally different profession you've always loved (teaching or running a restaurant say... or running off and joining a band).

Or... telling the world to fuck itself, and more specifically, the perceived imperative to shape our lives around the meritocratic ideal. And just stay in the mid-career SWE role for as long as you want to keep working. Which in my view is perfectly fine - provided you're willing to accept the ceiling in terms of salary level (and status) that comes with it. You'll still be doing better financially (and with far less stress) than most academics, public school teachers, and a whole lot of other valuable and socially useful people.

But to get back to the original subject: this is exactly where (a good chunk of) the "ageism" in the industry comes from. It's not that they see 40+ types as out of date, too slow, or too inflexible, or just too uncool to "have a beer with" (though some of course do). But rather it's an unspoken feeling they have (perhaps not even consciously recognized) that says: "Shouldn't this person have moved on to something bigger and better by now? Do I want to be doing this stuff for another 20 years? Hell no!"

So yeah, one way or another, ageism is definitely a thing. It's not a hard cliff though, by any stretch. And at the end of the day it all depends on how you play it. If you play it right, your age can even work to your advantage.

Many people have told me "do what your heart wants" but they don't wake up with my debt.

I agree that "do what your love" is mostly crap. A better question to ask yourself is: What kind of work can I see myself living with / not burning out on beyond age X (assuming I'm not fully independent financially by then)? Which is of course adjacent to the question of work that "love" but is really more one of work you at least like and which is sustainable for you in terms of overall working conditions.

[1] Yes, exactly like the BS interview question (expressed usually in terms of 5 years of course). Which is actually a really good question to be asking one's self, now and then. The reason it becomes BS in the interviewing context is that you're never allowed to give an honest answer.