diff --git a/gui/tests/codex-account-pool-target-switch.test.tsx b/gui/tests/codex-account-pool-target-switch.test.tsx
index c0f34182ab0..f1f8761009f 100644
--- a/gui/tests/codex-account-pool-target-switch.test.tsx
+++ b/gui/tests/codex-account-pool-target-switch.test.tsx
@@ -143,8 +143,21 @@ async function switchTarget(targetKey: string, releasePrevious: () => void) {
configureApiTargets(relay("/same", targetKey));
actEnvironment(false);
try {
- root!.render();
- await new Promise(resolve => setTimeout(resolve, 0));
+ // A timer scheduled before React commits can win the race on a loaded runner.
+ // Observe the layout commit itself; release the old read in that same phase so
+ // the regression still exercises the interval before passive effects run.
+ await new Promise(resolve => {
+ root!.render( { releasePrevious(); resolve(); }} />);
+ });
+ // The new target's first read is kicked from a passive effect plus a queued
+ // microtask, so the layout commit alone cannot prove it started. Wait until the
+ // in-flight state is painted: `refreshing` turns true only after the read's
+ // fetch was issued and React committed the new counter. The timer is the yield
+ // between observations, not an assumption that effects have completed.
+ for (let spins = 0; seen?.refreshing !== true; spins += 1) {
+ if (spins >= 1000) throw new Error("the new target's read never reached in-flight state");
+ await new Promise(resolve => setTimeout(resolve, 0));
+ }
} finally {
actEnvironment(true);
}