Onan 4000 Intermittent Generation
This is one of those cases where a multimeter is key. Set it to AC, test to see if itís providing power to the wires leaving the generator, and follow the wires/test at each junction until it reaches your breaker panel. It may be possible that thereís a wire nut in one of those junctions that wasnít assembled properly and it has worked loose enough so itís only intermittently making contact.
I think we can rule out the wires between your transfer switch and breaker panel, though, since you donít report any issues when on shore power.
The point about fire above is important. If it is only intermittently making contact somewhere, itís probably not making GOOD contact when it does, which means itís generating excess heat which could catch something else on fire.
Itís also possible that the contractors within your transfer switch scored and not reliably making contact, possibly from regularly transferring between AC and generator with a high load applied (e.g., air conditioner running). If this is the case, search on YouTube for a channel called ĎMy RV Worksí. Heís an RV tech in Washington state and I recall he did a pretty in-depth troubleshooting video on a transfer switch at some point.