That's a great question!
I used to work in-office either as an employee or as a contractor, and I would regularly sit for 4 hours at a time bashing away at the keyboard, with small moments where I get up to get a drink or go to the bathroom, but I'd consider my 'session' length as half a day, split by lunch.
Then when I began freelancing I think It would get even longer. Sometimes I would work through the night, sometimes I could challenge myself and take a 12-hour block and see how much I could get done, so I know sometimes I was sitting doing the same thing for 4+ hours, maybe even double that regularly. But that's not healthy or sustainable.
I think now I spend a lot more time working, but I have much shorter sessions - 15 minutes, 30 minutes, 40 minutes, and hour or two. But rarely do I have a 'session' of work longer than 3 hours without being split up either by travelling, doing chores or running errands, meals, etc. And I feel more productive (overall) than when I used to sit and work for longer sessions.
My personal theory is that creativity is like a well full of water, and it replenishes slowly when you are inspired. So if you're building and creating things that takes energy out of you, and it takes time for you to recover before you can do that again. When I was doing those long sessions it felt like I was super productive, but I wasn't super productive like that every day, especially not after a big day.
Get up, move around every now and then, and try to let your work sessions be punctuated by little breaks so you can keep agood momentum overall :D