Flagsmith / Flagsmith/flagsmith-nodejs-client

[sdk/local-evaluation] Multivariate flag with overrides crashes on BigInt serialization (8.1.0) / resolves to a null variant (7.0.3)

Ouverte
#273 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
TypeScript
Étoiles
30
Forks
26
Merge moyen
11 min
PR mergées (30 j)
5

Description

**Summary**

Under local evaluation `(enableLocalEvaluation: true)`, evaluating a multivariate flag fails.
We observe two different behaviours depending on the SDK version, against the same environment:

| `flagsmith-nodejs` | Result |
|---|---|
| **8.1.0** (latest) | `getIdentityFlags()` throws `TypeError: Do not know how to serialize a BigInt` |
| **7.0.3** | No throw, but the flag resolves to a `null` value instead of one of the multivariate variant values — even though `enabled` is `true` and the segment matches |

Remote evaluation (`enableLocalEvaluation: false`) resolves the variant correctly in both versions, so this is specific to the local-evaluation engine.

This may be related to #267 (same `mapIdentityOverridesToSegments` / local-evaluation path), but the trigger and symptom are different, so we're reporting it separately.

### Environment

- `flagsmith-nodejs` `8.1.0` and `7.0.3`
- Node.js v22.13.1
- Server-side SDK key, Edge API (`https://edge.api.flagsmith.com/api/v1/`)
- `enableLocalEvaluation: true`, `environmentRefreshIntervalSeconds: 60`

### Steps to reproduce

1. Create a **MULTIVARIATE** flag with a weighted split (e.g. 33/34/33 across three options).
2. Add a **segment override** for that flag.
3. Ensure the environment also contains at least one **identity override** entry.
4. With `enableLocalEvaluation: true`, call:
```ts
await flagsmith.getIdentityFlags(identifier, { currency: 'EUR', domain: 'https://www.example.com' });
```

The environment additionally contains several `identity_overrides` entries (5 in our case, identifiers redacted).

### Actual behaviour

**8.1.0 — stack trace:**
```
TypeError: Do not know how to serialize a BigInt
at JSON.stringify ()
at mapIdentityOverridesToSegments (flagsmith-engine/evaluation/evaluationContext/mappers.js:130:81)
at mapEnvironmentModelToEvaluationContext (flagsmith-engine/evaluation/evaluationContext/mappers.js:69:36)
at getEvaluationContext (flagsmith-engine/evaluation/evaluationContext/mappers.js:9:32)
at Flagsmith.getIdentityFlagsFromDocument (sdk/index.js:385:63)
at async Flagsmith.getIdentityFlags (sdk/index.js:192:24)
```
The error is thrown while building the evaluation context, before any specific flag is read, so
it fails `getIdentityFlags()` for every flag in the environment — not only the multivariate one.

**7.0.3:** no error, but the value of the multivariate flag comes back as `null` (the override's
base `feature_state_value`) instead of one of the configured variant values.

### Expected behaviour

`getIdentityFlags()` should resolve the multivariate flag to one of its variant values (the deterministic percentage split), matching what remote evaluation returns, without throwing.

Thank you in advance for your help

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Start with flagsmith-engine/evaluation/evaluationContext/mappers.js, especially mapIdentityOverridesToSegments and mapEnvironmentModelToEvaluationContext, then trace how sdk/index.js calls getIdentityFlagsFromDocument. Reproduce with local evaluation, a multivariate flag, segment and identity overrides, and compare versions 8.1.0 and 7.0.3. Done means getIdentityFlags() does not throw and returns a configured variant value consistently with remote evaluation.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
nodejs, typescript
Domaine
api, backend
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
Calme
Clarté
Plutôt claire
Accessibilité débutants
55/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.