OP
"I should add that he has slept for 6 hours in a row on three occasions, but I honestly couldn't tell you what I did differently on those days! "
This is the key thing - the fact is that often baby's sleeping depends very little on what you do or don't do. The sad fact is that we have little control over it. Either they sleep well, or they don't.
Of course you influence things (eg its silly to give babies loads of sugary stuff just before bedtime etc) and make sure that they are comfortable, not in pain, warm enough. But beyond that there is not much you can do.
You can agonise about it but I think better is to accept that we can't control it, and to decide that you will just respond to whatever comes up sleepwise. That is actually less stressful than thinking there is some magic thing you ought to be doing - there isn't!
Children do eventually sleep better, but unless you have an exceptional child or you decide to go in for rigorous sleep training (which may not work anyway), I am afraid you have got many moons of broken nights ahead of you, given yours is only 12 weeks old.
Mine is 20 months - sometimes she sleeps through 8 to 8, sometimes like last night she is up for hours!! [grr]!
But be reassured is that the general trajectory is to better sleeping and it being easier to put them to bed. My DD now has a bedtime and actually asks to go in her cot. I sing a few songs and then off I go, and she is out for a good 6 hours at least. On good nights she goes right through, on less good nights, she wakes up but settles back quickly, on bad nights she is up for an hour in the middle of the night, and on hideous nights like two nights ago she is up from 2.30am to 5.30am (though that was DHs fault for giving her supper at 8pm , naughty man(sugary baked beans too!)).