You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: retain latest flags and segments for duplicate identifiers - #33
Duplicate feature flag keys in a data-sync payload previously caused DataModel.Data.toStorageType() to throw, failing the sync and preventing new clients from initializing. Duplicate segment IDs could cause the same failure.
Collect feature flags by key and segments by ID, retaining the entry with the greatest timestamp for each identifier, then copy the results to immutable maps.
Validation: mvn -q -Dtest=DataModelTest test — both regression tests passed. Each directly constructs two records with the same identifier, places the older record last, and verifies that the newest record is retained.
Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.
Summary
This PR lets data sync accept duplicate feature keys and segment IDs instead of failing.
Feature flags with duplicate keys and segments with duplicate IDs now retain the item with the latest timestamp. When timestamps match, the existing item is retained. Archived items are converted before selection.
DataModel.Data.toStorageType() built an ImmutableMap keyed by flag key,
so a payload with the same key twice (e.g. featbit-agent still holding
an archived copy of a flag that was deleted and re-created) threw
"Multiple entries with same key" and failed the whole sync, leaving new
clients in a reconnect loop.
Collect items into a LinkedHashMap so the last entry wins, as the Go,
Python, Rust, Ruby and Node SDKs already do.
No actionable comments were generated in the recent review.
Walkthrough
DataModel.toStorageType() stores feature flags by key and segments by ID. For duplicates, it retains the item with the later timestamp. Tests cover duplicate feature flag keys and segment IDs.
Data sync no longer fails when a payload contains duplicate feature-flag keys or segment IDs, and the newer item is kept. No actionable merge risk remains.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "fix: retain latest flags and segments for duplicate identifiers" matches the main change. DataModel.Data.toStorageType() now keeps the item with the greater timestamp when feature flags or …
Linked Issues check
[#32] requires that a payload with an archived and a live flag sharing one key no longer fails the full sync, and that the re-created flag is evaluated. At head 7e6dbe6, DataModel.Data.toStorageType()…
Out of Scope Changes check
The DataModel.java diff changes only toStorageType(), plus the LinkedHashMap import. The added segment merge uses the same duplicate-key path and the same failure mode as flags, so it is a closely rel…
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title "fix: retain latest flags and segments for duplicate identifiers" matches the main change. DataModel.Data.toStorageType() now keeps the item with the greater timestamp when feature flags or segments share a key or ID. The added DataModelTest cases check this behavior. The title is specific and describes the fix, not the implementation details.
Full details: Linked Issues check
Explanation
[#32] requires that a payload with an archived and a live flag sharing one key no longer fails the full sync, and that the re-created flag is evaluated. At head 7e6dbe6, DataModel.Data.toStorageType() replaces ImmutableMap.Builder with a LinkedHashMap for flags, keyed by flag.getKey(), using merge(). The merge keeps the item with the greater timestamp. The re-created flag is newer than the archived copy, so it is retained. DataModelTest.toStorageTypeKeepsFlagWithLatestTimestampForDuplicateKey asserts this. The issue's Proposed fix describes last-entry-wins. The implementation uses timestamp-based selection instead. On equal timestamps, the lambda returns the incoming item, so the later entry wins. This differs from the proposal but meets the stated Expected outcome. The current change also applies the same rule to segments, keyed by ID. This goes beyond the issue, but it does not block the issue's requirement.
Full details: Out of Scope Changes check
Explanation
The DataModel.java diff changes only toStorageType(), plus the LinkedHashMap import. The added segment merge uses the same duplicate-key path and the same failure mode as flags, so it is a closely related hardening within the same method. It is not an unrelated change. DataModelTest.java contains two unit tests for flag and segment duplicate handling. These tests support the changed behavior. The raw summary states that equal timestamps keep the existing item, but the code returns the incoming item on ties. The code is the authoritative behavior. No unrelated change was found.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
deleteLater
changed the title
fix: tolerate duplicate flag keys in data sync payload
fix: retain latest flags and segments for duplicate identifiers
Nov 13, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The tests cover only live records, leaving archived/live collision handling and preservation of the retained item's key, timestamp, and archived state unverified.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32
Duplicate feature flag keys in a data-sync payload previously caused
DataModel.Data.toStorageType()to throw, failing the sync and preventing new clients from initializing. Duplicate segment IDs could cause the same failure.Collect feature flags by key and segments by ID, retaining the entry with the greatest timestamp for each identifier, then copy the results to immutable maps.
Validation:
mvn -q -Dtest=DataModelTest test— both regression tests passed. Each directly constructs two records with the same identifier, places the older record last, and verifies that the newest record is retained.

Confidence Score: 5/5
The PR appears safe to merge; no actionable issues were found.Summary
This PR lets data sync accept duplicate feature keys and segment IDs instead of failing.
Reviews (3) · Last reviewed commit: "fix: retain latest segment timestamp for..." · Reviewed by Greptile
Summary by CodeRabbit