There is a well-known, long standing, and highly annoying bug with most (or maybe all?) OnePlus phones where the battery optimization setting gets automatically and frequently reenabled by the phone for no good reason. This is well documented in the OnePlus forums, and is a likely explanation for the behaviour you’re seeing. So I suggest checking the battery optimization setting again, to see whether it got reset by the phone.
Unfortunately OnePlus have not done anything about this bug for a very long time, despite hundreds of complaints. Please complain to OnePlus about this - the more of us complain, hopefully the more likely they are to fix it!