Hello and welcome. Wandering, up and down, in and out of house to and from the gate is something my mum has been doing for sometime now and at first it used to really annoy me, mainly because I kept thinking how dangerous this was for her but also because for at least 2 hours every day I take mum out, so was beginning to think I was not doing enough with her, not so. Now I have accepted that all I can do is make sure she cannot leave the garden-padlock on gate with a code. When it gets intense and she looks tired I lock the front door or take her for a drive to local park and a little walk. for her safety I was following her in and out!! It was hard to put up with it, but had to, I could not distract her and if I did it was only for a short time and she would return to the activity. Maybe it is time, but I have become a bit more relaxed about this activity.
If there is nothing you can do to distract, then let it happen, make sure he is safe, read your book or get online and tell us about it.