imho referencing your initial request won’t help. The implementation shown in the docs works pretty well,
So it looks like your use case is different from our common sense. And you should explain it in more detail.
if you play with the built-in Hugo theme, you can see that it has a menu of top level sections and classes are assigned to the pages:
on a main section or home page: the top level menu gets the class “active”
on a single page in a section (posts) : the section menu gets class “ancestor”
other entries get no class.
play with it - maybe that will help to provide details we are missing.
hugo new theme --themesDir menu-test
cd menu-test
hugo server
p.s. the tags pages are not handled. it may display pages from different top level sections. maybe that’s your case? I’m pretty sure this could be addressed.