Is there a known workaround for undefined behavior in theme.reset()

As I understand it, there is currently an intrinsic conflict between dynamic and non-dynamic themes which is outlined in this bug:
Define behaviour of theme.reset()
and on the Mozilla documentation here: theme.reset(). This causes a situation where:

  1. A user installs a theme
  2. A user installs a webextension which overrides the theme dynamically
  3. A user switches to a non-themed tab, extension calls browser.theme.reset()
  4. The user no longer sees their desired theme from step 1 but the default instead

I would like to alter this behavior in my extension. I think I should be able to get the whole theme with browser.theme.getCurrent() as soon as my extension starts up, and then store it somewhere, then anywhere I call browser.theme.reset() instead retrieve the stored theme and re-apply it with browser.theme.update(). However it turns out most of the ways I attempt it turn out to be brittle. The obvious flaw is that if the user closes and re-opens their browser while using an extension which has triggered a dynamic theme which is visible, the theme that gets stored is the first theme that is active, undermining the users intent and in some cases the functionality of the extension. Updating the theme for every theme event except for theme events where the theme object equals one of the theme objects from the extension works better as long as only one of your extensions is doing dynamic theming. But both approaches get close to working well. Has anybody else figured this one out yet?

This was the best thing I managed to come up with:

function unsetTheme() {
        console.log('(theme)Resetting theme window to stored theme');

        function gotAllThemes(infoArray) {
            for (const info of infoArray) {
                if (info.type === 'theme') {
                    if (info.enabled) {
                        console.log('(theme) found enabled theme in list', info.id);

                        async function resetEnabled(disabled) {
                            console.log('(theme) disabled theme temporarily', info.id);

                            function logReset(prom) {
                                console.log('(theme) re-enabled:', info.id);
                            }

                            function sleep(ms) {
                                return new Promise(resolve => setTimeout(resolve, ms));
                            }
                            var slept = await sleep(2000);

                            function sleepyTime(sleepyTimeOver) {
                                return browser.management.setEnabled(
                                    info.id,
                                    true
                                );
                            }
                            let settingEnabled = sleepyTime(slept);
                            logReset(settingEnabled);
                        }
                        let settingDisabled = browser.management.setEnabled(
                            info.id,
                            false
                        );
                        resetEnabled(settingDisabled);
                    }
                }
            }
        }
        let gettingAll = browser.management.getAll();
        gettingAll.then(gotAllThemes);
    }

It’s the only approach I tried in 2 years that worked every time.