jackwener/OpenCLI · error · CommandExecutionError

Mode toggle did not reach requested state "${want}".

Error message

Mode toggle did not reach requested state "${want}".

What it means

After clicking the mode capsule, the command re-reads the aria-label and derives the resulting mode; if the observed mode ('after') does not equal the requested 'want', this CommandExecutionError signals the toggle did not take effect. The detail tells you whether a mode was read at all — an empty read means the capsule state couldn't be parsed post-click.

Source

Thrown at clis/trae-solo/mode.js:74

      };
      cap.dispatchEvent(new PointerEvent('pointerdown', { ...init, pointerType: 'mouse' }));
      cap.dispatchEvent(new MouseEvent('mousedown', init));
      cap.dispatchEvent(new PointerEvent('pointerup', { ...init, pointerType: 'mouse' }));
      cap.dispatchEvent(new MouseEvent('mouseup', init));
      cap.dispatchEvent(new MouseEvent('click', init));
      await wait(500);
    })()`);
        await page.wait(0.4);

        const after = await page.evaluate(`(function() {
      const cap = document.querySelector('[class*="capsule"]');
      if (!cap) return '';
      const aria = cap.getAttribute('aria-label') || '';
      const m = aria.match(/Switch to (Code|Work) mode/i);
      return m ? (m[1].toLowerCase() === 'work' ? 'code' : 'work') : '';
    })()`);
        if (after !== want) {
            throw new CommandExecutionError(
                `Mode toggle did not reach requested state "${want}".`,
                after ? `current=${after}` : 'Mode capsule state could not be read after click.',
            );
        }
        return [{ Status: 'switched', Mode: after }];
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the mode switch once the Trae SOLO window is focused, visible, and idle
  2. Read current mode first; if already in the target mode, skip the toggle
  3. If 'after' is empty (unreadable state), check whether a recent Trae SOLO update changed the capsule aria-label — update the library's regex/selectors
  4. Take a screenshot / inspect the DOM around [class*="capsule"] to confirm the element is the actual mode toggle

Example fix

// before
await traeSoloCli.mode({ target: 'work' }); // throws: did not reach state
// after
const cur = await traeSoloCli.mode({});
if (cur[0]?.Mode !== 'work') {
  await new Promise(r => setTimeout(r, 1000));
  await traeSoloCli.mode({ target: 'work' }); // one retry
}
Defensive patterns

Strategy: retry

Validate before calling

const cur = await traeSoloCli.mode({});
if (cur[0]?.Mode === want) return cur; // already in target mode, skip toggle

Try / catch

try {
  await traeSoloCli.mode({ target: want });
} catch (e) {
  if (/did not reach requested state/.test(e.message)) {
    await new Promise(r => setTimeout(r, 1000));
    await traeSoloCli.mode({ target: want }); // bounded retry after UI settles
  } else throw e;
}

Prevention

When it happens

Trigger: Clicking the Code/Work capsule but the UI didn't switch (click landed on the wrong element, an overlay intercepted it, or the app was busy), or the aria-label regex /Switch to (Code|Work) mode/i no longer matches so 'after' is ''.

Common situations: Trae SOLO UI update changed the capsule's aria-label text; a modal/dialog intercepted the click; the window was minimized or not focused so the click was dropped; the mode was already being toggled concurrently.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/a82a0fe37436e599. Report an issue: GitHub.