Skip to content

refactor: client core - #298

Open
vazarkevych wants to merge 15 commits into
refactor/repository-corefrom
refactor/client-core
Open

vazarkevych wants to merge 15 commits into
refactor/repository-corefrom
refactor/client-core

Conversation

@vazarkevych

@vazarkevych vazarkevych commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Base: refactor/repository-core · stacked on #296; review after it, this diff only shows the client stage.

What

Both clients built their own plugins, exposure tracker, subscriptions, evaluation calls and teardown. They also read typed values through ten broad catch (Exception) blocks. They are now facades over multiusermode/internal:

  • ClientCore handles:
    • plugins;
    • the exposure tracker (GrowthBookClient passes one sized for multi-user traffic, 10 000 entries);
    • experiment subscriptions;
    • feature and experiment evaluation;
    • an ordered teardown.
  • FeatureValues reads an evaluated value as the caller's type. It falls back to the caller's default for a missing value or another type, without broad catches.

Also:

  • fix(sticky): InMemoryStickyBucketServiceImpl.saveAssignments merges the saved document into the stored one, atomically on a ConcurrentMap. Before, two concurrent saves for the same user, both built from the same stale document, lost one assignment. The Redis services already merged with compare-and-set.
  • TransformationUtil uses Gson's TypeToken instead of Guava's.

The async sticky-bucket wiring from #235 is kept and runs through ClientCore:

The CompletableFuture API from #236 runs through ClientCore as well:

  • evalFeatureAsync, isOnAsync, isOffAsync, getFeatureValueAsync and runAsync evaluate through the core, so async runs notify experiment subscribers and read typed values through FeatureValues, like their sync twins;
  • shutdown() resolves every async operation still pending once the async executor has stopped, so no caller is left waiting on a discarded task.

Public API

No signature is removed. New deprecations:

  • EvaluationContext.StackContext and the constructor that takes it, replaced by EvaluationContext(GlobalContext, UserContext, Options);
  • the public GrowthBook.evaluationContext field;
  • GrowthBookUtils.fireSubscriptions, which is no longer used.

Behaviour changes

  • shutdown() / destroy() close plugins first, so buffered events are flushed while everything else still works. A failing teardown step no longer skips the rest. GrowthBookClient then drains sticky-bucket saves and stops its executor, resolves pending async operations, then shuts down remote eval, the repository and the listener executor.
  • Plugins are initialized as the last step of construction, as on main, so a constructor that throws (for example remote evaluation without a client key) never leaves started plugins behind.
  • getFeatureValue and getFeatureValueAsync still return the caller's default when evaluation fails, as documented and as on main; only the type conversion moved to FeatureValues.
  • GrowthBookClient no longer merges the subscription state of an experiment without a key with one whose key is "".
  • InMemoryStickyBucketServiceImpl merges concurrent saves instead of replacing them (see above).

Why

The two entry points duplicated plugin lifecycle, de-duplication and teardown, so a fix in one regularly missed the other. Running both through one core keeps them in step, as AGENTS.md requires for evaluation and refresh changes.

Verification

./gradlew build javadoc on JDK 17, merged with current main:

Module Tests Failures Skipped
lib 1935 0 4
growthbook-cache-caffeine 12 0 0
growthbook-cache-jcache 6 0 0
growthbook-cache-redis 89 0 0

Guava is still a dependency of lib. RemoteEvalCache exposes a Guava Ticker in a public constructor, and #235's StickyBucketManager uses a Guava cache. Removing it needs a deprecation cycle and is not part of this stack.

Checklist

  • PR title and commits follow Conventional Commits (feat:/fix: drive the release version)
  • Tests cover both valid and invalid cases (see the test style section in AGENTS.md)
  • No Java 9+ APIs (compiled with --release 8 on JDK 9+; the Java 8 matrix job is the backstop)
  • Release-please-owned files untouched (CHANGELOG.md, versions.txt, Version.java, gradle.properties version)
  • Public API of lib unchanged — or the change is deliberate and marked feat!: / BREAKING CHANGE:
  • New dependencies: none in lib (or explicitly approved); cache providers stay compileOnly

Volodymyr Nazarkevych added 4 commits October 31, 2026 18:58
…entCore

Both clients built their own plugins, exposure tracker, subscriptions,
evaluation calls and teardown, and read typed values with ten broad
catch (Exception) blocks. They are now facades over
multiusermode/internal:

- ClientCore: plugins, the exposure tracker, experiment subscriptions,
  feature and experiment evaluation, and an ordered teardown
- FeatureValues: typed reads of an evaluated value, falling back to the
  caller's default for a missing value or another type, without broad
  catches

Public APIs are unchanged. GrowthBook no longer resets a per-call stack
on its shared context; that stack, StackContext and the constructor
taking it are deprecated in favour of a new EvaluationContext
constructor, and the public GrowthBook.evaluationContext field is
deprecated. GrowthBookUtils.fireSubscriptions, no longer used, is
deprecated. AGENTS.md records that GrowthBook uses
multiusermode/internal.

Behaviour changes:
- shutdown() and destroy() close plugins first, so buffered events
  are flushed while everything else still works, and a failing step no
  longer skips the rest of the teardown
- GrowthBookClient no longer merges the subscription state of an
  experiment without a key with one whose key is ""
saveAssignments replaced the stored document, so when two evaluations
of the same user saved concurrently, each built from the same stale
document, one assignment was lost. The saved document is now merged
into the stored one, the saved assignments winning on conflict, which
is atomic on a ConcurrentMap. The Redis services already merge with a
compare-and-set.
Gson already provides TypeToken, so feature parsing no longer needs
Guava's. Guava stays a dependency: RemoteEvalCache exposes a Guava
Ticker in a public constructor.
# Conflicts:
#	lib/src/main/java/growthbook/sdk/java/GrowthBook.java
#	lib/src/main/java/growthbook/sdk/java/multiusermode/GrowthBookClient.java
#	lib/src/main/java/growthbook/sdk/java/multiusermode/configurations/EvaluationContext.java
@vazarkevych
vazarkevych changed the base branch from main to refactor/repository-core November 19, 2026 16:04
@vazarkevych
vazarkevych added this pull request to stack #297 November 19, 2026 16:04
@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[High impact] The reviewed changes appear safe to merge; both prior findings are fixed.

Reviews (7) · Last reviewed commit: "fix(client): let running async evaluatio..." · Reviewed by Greptile

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Comments Outside Diff

These findings could not be posted inline.

  • P1 Direct evaluations repeat exposure events lib/src/main/java/growthbook/sdk/java/evaluators/internal/EvaluationEvents.java:95 ▶

    Direct evaluations repeat exposure events. A caller using ExperimentEvaluator with a directly constructed EvaluationContext now reaches this code without a tracker. Every repeated evaluation sends the exposure again. Previously, the evaluator supplied its own tracker when the context had none. Preserve that default for existing callers rather than requiring a new setter call to avoid duplicate events.

Volodymyr Nazarkevych added 2 commits November 20, 2026 09:44
# Conflicts:
#	lib/src/main/java/growthbook/sdk/java/multiusermode/configurations/EvaluationContext.java
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych vazarkevych mentioned this pull request Nov 25, 2026
6 tasks done
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych vazarkevych mentioned this pull request Nov 25, 2026
6 tasks done
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

…ture values

Converting through a JSON tree truncated 2.75 to 2 and overflowed
2147483648 to -2147483648 instead of returning the caller's default, as
main did. Convert through JSON text again, whose reader rejects them.
…own closes them

shutdown() closed plugins first, so an evaluation that finished its
tracking callback during the executor's grace period notified an
already-closed plugin, and the tracking plugin dropped the exposure.
Sticky bucket draining, the executor grace period and pending-future
resolution now run before the plugins close; the repository still
outlives the plugin flush.
@vazarkevych

Copy link
Copy Markdown
Collaborator Author

@greptile review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant