Flagsmith / Flagsmith/flagsmith-go-client
Support `$.flags` context values in segment conditions
- Dominant language
- Go
- Stars
- 16
- Forks
- 16
- Avg merge
- 8h 32m
- Merged PRs (30d)
- 1
Description
Dependent flags let a segment condition read another flag's result via a `$.flags..` property, so that flag has to be resolved before the condition is evaluated. Behaviour is defined by the shared cases in Flagsmith/engine-test-data#59; schema in Flagsmith/flagsmith#8396; reference implementation in Flagsmith/flagsmith-engine#343.
The reference implementation resolves a flag lazily, on first read, rather than scanning every condition up front to discover dependencies. `ojg` supports this directly — `jp/get.go` dispatches on `jp.Keyed`, so a lazy `Flags` type resolves on read with no property parsing. Two things in this engine currently get in the way:
- `getContextValue` builds its getter per call, so `jp.ParseString` runs on every lookup — about 20% of a lookup and 10 of its 16 allocations.
- `client.go` keeps a single `*EngineEvaluationContext` in an `atomic.Value`, shared across goroutines. Resolved flags written onto that struct would be written concurrently by every in-flight evaluation.
For reference, pre-resolving all flags instead costs a flat ~12 µs and ~49 KB per evaluation, against ~400 ns per flag actually read; lazy resolution via `jp.Keyed` and via parsed-`Expr` inspection measure the same, so either is fine.
### Acceptance criteria
Engine:
- `engine-test-data` is bumped to the tag containing the flag dependency cases, and they pass.
- An environment with no `$.flags` conditions gains no per-evaluation cost.
- Resolved flags are held per evaluation, never written to the context shared via `atomic.Value`.
- Parsed JSONPath expressions are cached per property string.
SDK:
- `GetFlags` does not skip segments anymore.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with getContextValue and client.go, then read jp/get.go for the jp.Keyed dispatch and lazy lookup behavior. Trace how EngineEvaluationContext is shared through atomic.Value and how GetFlags handles segments. The work is done when the dependency cases from the bumped engine-test-data pass, parsed expressions are cached, evaluations remain isolated, and GetFlags evaluates all segments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100