feat: add feature data change notifications - #33
Conversation
- expose IFbClientDataChangeNotifier through the server SDK - notify subscribers after full and effective patch synchronizations - identify whether feature flags or segments were changed - register the notifier as the same singleton instance as IFbClient - isolate subscriber exceptions and stop forwarding events after shutdown - document the subscribe-then-refresh pattern for initial state - add coverage for full, patch, segment, DI, and client lifecycle behavior
📝 WalkthroughWalkthroughThe SDK adds feature-data change contracts and notifications. Synchronizers report full and effective patch updates. ChangesFeature data change notifications
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant WebSocketDataSynchronizer
participant FbClient
participant DataChangedSubscriber
WebSocketDataSynchronizer->>FbClient: raise DataChanged
FbClient->>DataChangedSubscriber: invoke handler with change metadata
DataChangedSubscriber-->>FbClient: complete or throw
FbClient->>FbClient: log exceptions and continue
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Warning |
f47959f to
0a88c0c
Compare
|
related to featbit/featbit#672 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@tests/FeatBit.ServerSdk.Tests/DataSynchronizer/WebSocketDataSynchronizerTests.cs`:
- Around line 187-194: Update the test around
WebSocketDataSynchronizer.StartAsync to track DataChanged with a
TaskCompletionSource, then await a bounded post-processing interval before
asserting the source remains incomplete. Ensure the test observes notifications
raised after initialization and fails when DataChanged is incorrectly triggered,
while preserving the existing startup wait.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 99c7f19b-e3dd-402f-9ba4-73ac60c6be65
📒 Files selected for processing (13)
src/FeatBit.ServerSdk/DataSynchronizer/IDataChangeNotifier.cssrc/FeatBit.ServerSdk/DataSynchronizer/NullDataSynchronizer.cssrc/FeatBit.ServerSdk/DataSynchronizer/WebSocketDataSynchronizer.cssrc/FeatBit.ServerSdk/DependencyInjection/ServiceCollectionExtensions.cssrc/FeatBit.ServerSdk/FbClient.cssrc/FeatBit.ServerSdk/FeatureDataChangeKind.cssrc/FeatBit.ServerSdk/FeatureDataChangedEventArgs.cssrc/FeatBit.ServerSdk/IFbClientDataChangeNotifier.cstests/FeatBit.ServerSdk.Tests/DataSynchronizer/WebSocketDataSynchronizerTests.cstests/FeatBit.ServerSdk.Tests/DependencyInjection/ServiceCollectionExtensionsTests.cstests/FeatBit.ServerSdk.Tests/FbClientTests.cstests/FeatBit.ServerSdk.Tests/TestData.cstests/FeatBit.ServerSdk.Tests/TestStartup.cs
| var synchronizer = new WebSocketDataSynchronizer(options, store, op => _app.CreateFbWebSocket(op)); | ||
| var notified = false; | ||
| synchronizer.DataChanged += (_, _) => notified = true; | ||
|
|
||
| await synchronizer.StartAsync().WaitAsync(options.StartWaitTime); | ||
|
|
||
| Assert.False(notified); | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Wait for message processing before asserting notification absence.
StartAsync() completes when initialization completes. The synchronizer calls OnDataChanged after that completion point. Therefore, Line 193 can pass before an incorrect notification runs.
Use a TaskCompletionSource for the event and wait for a bounded post-processing interval before asserting that it did not complete. This test must fail if an ineffective patch raises DataChanged.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@tests/FeatBit.ServerSdk.Tests/DataSynchronizer/WebSocketDataSynchronizerTests.cs`
around lines 187 - 194, Update the test around
WebSocketDataSynchronizer.StartAsync to track DataChanged with a
TaskCompletionSource, then await a bounded post-processing interval before
asserting the source remains incomplete. Ensure the test observes notifications
raised after initialization and fails when DataChanged is incorrectly triggered,
while preserving the existing startup wait.
Summary
IFbClientand documents safe subscription and disposal.Validation
dotnet test tests/FeatBit.ServerSdk.Tests/FeatBit.ServerSdk.Tests.csproj --no-restore -f net6.0netstandard2.0,netstandard2.1,netcoreapp3.1, andnet6.0.Post-Deploy Monitoring & Validation
No additional production monitoring is required before adoption because this is an opt-in SDK event and does not change feature evaluation behavior for existing consumers.
For adopters, verify that subscribers receive a notification after a full synchronization or an effective patch, and that a failing subscriber does not prevent the client or other subscribers from continuing. Roll back by removing the subscriber or retaining the previous SDK version if an integration misuses the event.
Greptile Summary
The PR adds opt-in feature-data change notifications and forwards effective full-sync and patch changes through
FbClient.IFbClient.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Important Files Changed
Sequence Diagram
sequenceDiagram participant WS as WebSocket participant Sync as WebSocketDataSynchronizer participant Store as MemoryStore participant Client as FbClient participant Subscriber WS->>Sync: data-sync message Sync->>Store: Populate or Upsert Store-->>Sync: update applied Sync->>Client: DataChanged Client->>Subscriber: DataChanged Note over Client,Subscriber: Subscriber exceptions are isolatedReviews (3): Last reviewed commit: "fix: invalidate full feature data synchr..." | Re-trigger Greptile
Summary by CodeRabbit
New Features
Bug Fixes
Tests