In general, I prefer to stay in a job a long time, 5+ years. We (my employer and I) chose to contract for risk management. I demanded a generous salary, and they wanted to test drive me. I was also very nervous about situations that lead to poor working conditions.
Specifically, what kept me in my old job so long was that, when there was a problem with working conditions, we usually resolved it. It wasn't perfect, but it was "good enough." When we had a tech stack that was difficult to work with, we refactored. Troublesome co-workers were given severance. Poor managers were shuffled out. Pay eventually got high. Poor processes were improved. (See last paragraph.) When my manager tried to push me to become a manager, we realized that I was better as a lead engineer.
In my current job, I was afraid that I'd show up and the stack would be impossible to work with. (Turns out that is true, the stack is impossible to work with.) But what's going to make me stay is that I'm allowed to refactor the stack to make it workable. (I also have the freedom to fix the 4000 compiler warnings.) I'll probably convert to a permanent employee.
(Note regarding processes:) Good processes are what make or break a company. When people complain about process; either they are unable to fix their processes, or they just don't want to do their job. The biggest factor in my eventual success in my old job was, ironically, getting a manager who backed good process. Initially, we had a lot of problems with poorly-written bugs and support tickets. It required a good manager to push back on the organization to make sure that, once bugs and support escalations made it to me, the tickets were in a state where I could take them. (IE, we didn't tolerate the "duuuhhh, there's a bug" tickets without steps to reproduce, or the "duuuuh, the customer has a problem, what do I do" tickets without preliminary research.)