Unleash client "not ready" / synchronized flapping in CI
The Unleash client fetches toggles asynchronously and emits a "ready" (or "synchronized") event once the first fetch completes. Code that calls isEnabled before that event runs against an empty repository, so every toggle returns its fallback. In CI this shows as tests that pass locally but flap when evaluation races the fetch.
What this error means
Toggles all evaluate to their default value in CI, then behave correctly on a re-run. There is no error; the client simply had not synchronized when the first evaluation ran.
// isEnabled called before the client is ready:
unleash.isEnabled('new-feature'); // -> false (fallback), repository not yet synchronizedCommon causes
Evaluation runs before the first fetch completes
isEnabled is called synchronously at start-up, before the client has downloaded any toggles, so it returns the fallback.
The process exits before synchronization
A short-lived CI script finishes before the client emits "synchronized", so toggles never load in time.
How to fix it
Await the ready or synchronized event
Wait for the client to signal readiness before evaluating any toggle.
await new Promise((resolve) => unleash.on('synchronized', resolve));
const on = unleash.isEnabled('new-feature');Bootstrap toggles for deterministic tests
Supply a bootstrap payload so evaluations are correct immediately, without depending on the timing of the first fetch.
const unleash = initialize({
url: 'http://unleash:4242/api/',
appName: 'ci',
bootstrap: { data: require('./unleash-bootstrap.json') },
});How to prevent it
- Wait for the "ready" or "synchronized" event before evaluating toggles.
- Bootstrap the client in tests so results do not depend on fetch timing.
- Avoid evaluating flags in module top-level code that runs before sync.