Problem
When users switch accounts in-app, previously recorded feature flag evaluations from the old user persist in the buffer and get attached to error events for the new user. There is no public API to clear or reset the feature flag buffer.
Example:
- UserA has:
experimentA=control, experimentB=experiment
- UserB has:
experimentB=experiment, experimentC=experiment
- After switching from UserA → UserB, error events report:
experimentA=control, experimentB=experiment, experimentC=experiment
- Expected: only UserB's flags (
experimentB=experiment, experimentC=experiment)
Why existing APIs don't work
Scope.clear() does not reset the featureFlags field (Scope.java#L564-L578)
pushIsolationScope() clones the existing scope (including flags) via isolationScope.clone(), so stale flags carry over
addFeatureFlag() updates existing entries by name but cannot remove flags that don't apply to the new user
FeatureFlagBuffer and IFeatureFlagBuffer have no clear() method
Proposed changes
- Add
clear() to IFeatureFlagBuffer and FeatureFlagBuffer
- Include
featureFlags in Scope.clear() (reset to a fresh buffer)
- Optionally expose
clearFeatureFlags() on IScope for targeted use
Precedent
The Python SDK already supports this — FlagBuffer.clear() exists and Scope.clear() resets flags to None (sentry-python feature_flags.py#L30, scope.py#L756).
Action taken on behalf of Michael Chai.
Problem
When users switch accounts in-app, previously recorded feature flag evaluations from the old user persist in the buffer and get attached to error events for the new user. There is no public API to clear or reset the feature flag buffer.
Example:
experimentA=control,experimentB=experimentexperimentB=experiment,experimentC=experimentexperimentA=control,experimentB=experiment,experimentC=experimentexperimentB=experiment,experimentC=experiment)Why existing APIs don't work
Scope.clear()does not reset thefeatureFlagsfield (Scope.java#L564-L578)pushIsolationScope()clones the existing scope (including flags) viaisolationScope.clone(), so stale flags carry overaddFeatureFlag()updates existing entries by name but cannot remove flags that don't apply to the new userFeatureFlagBufferandIFeatureFlagBufferhave noclear()methodProposed changes
clear()toIFeatureFlagBufferandFeatureFlagBufferfeatureFlagsinScope.clear()(reset to a fresh buffer)clearFeatureFlags()onIScopefor targeted usePrecedent
The Python SDK already supports this —
FlagBuffer.clear()exists andScope.clear()resets flags toNone(sentry-python feature_flags.py#L30, scope.py#L756).Action taken on behalf of Michael Chai.