I’m not sure if you’re (both?) referring to general periods of boredom that might last a while, like days or weeks, or ‘drifting out’ of being fully present for short periods, like moments or hours, which either does or might annoy or upset your partner.
With the second type, I don’t have much advice as I am basically lucky enough for it to a) not happen too often and b) get away with it, either because I can usually force myself to ask a question and drag my brain back to what they were saying or because my partner doesn’t get easily annoyed about this.
With the first type, we realised at some point that if we don’t plan stuff it doesn’t happen. So now we go through schedules of what’s on (concerts etc) and actually book several events at the same time, put the dates in our diaries and print the tickets and keep them in the same place every time.
This really helps us to make sure we keep doing new fun stuff together. The other thing we recently started doing is kind of the opposite of guarding against boredom: we go through put diaries together every Sunday, telling each other where we will be every day/if we have stuff planned that means we will be home late or whatever. This is actually so we can specifically take action if it seems we’re hardly going to see each other. I like doingthe diary check-in, but would not remember to actually do this if my partner didn’t actually visibly wave the diary in front of me and say ‘shall we look at the diaries then?’.
Not sure if any of this is the kind of thing you meant though.