Cap channel CIDs at 100 when calling getSyncHistory#6419
Cap channel CIDs at 100 when calling getSyncHistory#6419VelikovPetar wants to merge 1 commit intov6from
getSyncHistory#6419Conversation
Co-Authored-By: Claude <noreply@anthropic.com>
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
SDK Size Comparison 📏
|
|
getSyncHistory
WalkthroughThis PR introduces a limit on the number of channel IDs processed during sync operations. A new constant ChangesSync Channel ID Capping
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt (1)
307-312: 💤 Low valueConsider logging when CIDs are truncated.
Silently dropping CIDs beyond the cap means that users with more than 100 active channels will not receive sync history events for the truncated channels, and there is no signal in the logs to help diagnose missing-event reports. A single warning log when
cids.size > SYNC_MAX_CIDSwould make this trivial to spot in support cases without changing behavior.📝 Proposed log addition
- val cappedCids = cids.take(SYNC_MAX_CIDS) + val cappedCids = cids.take(SYNC_MAX_CIDS) + if (cids.size > SYNC_MAX_CIDS) { + logger.w { + "[performSync] cids capped from ${cids.size} to $SYNC_MAX_CIDS (server limit)" + } + }🤖 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 `@stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt` around lines 307 - 312, Add a warning log when the incoming cids list is truncated so truncation is observable; in SyncManager.kt, before computing val cappedCids = cids.take(SYNC_MAX_CIDS), check if cids.size > SYNC_MAX_CIDS and call the logger (e.g., processLogger / logger used in this class) to warn that only the first SYNC_MAX_CIDS CIDs will be used and include counts (cids.size and SYNC_MAX_CIDS) and optionally a sample of truncated CIDs; leave the rest of the logic (rawLastSyncAt branch and chatClient.getSyncHistory calls) unchanged.
🤖 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.
Nitpick comments:
In
`@stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt`:
- Around line 307-312: Add a warning log when the incoming cids list is
truncated so truncation is observable; in SyncManager.kt, before computing val
cappedCids = cids.take(SYNC_MAX_CIDS), check if cids.size > SYNC_MAX_CIDS and
call the logger (e.g., processLogger / logger used in this class) to warn that
only the first SYNC_MAX_CIDS CIDs will be used and include counts (cids.size and
SYNC_MAX_CIDS) and optionally a sample of truncated CIDs; leave the rest of the
logic (rawLastSyncAt branch and chatClient.getSyncHistory calls) unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a36d74b6-8211-4620-9723-eab385426e58
📒 Files selected for processing (2)
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.ktstream-chat-android-state/src/test/java/io/getstream/chat/android/state/internal/SyncManagerTest.kt


Goal
The
getSyncHistoryendpoint enforces a server-side limit on the number ofchannel_cidsit accepts. When users have a large number of active channels, the SDK was forwarding the full list, which could lead to failed sync requests.Note: Aligns with the iOS limit set in: GetStream/stream-chat-swift#3863
Implementation
In
SyncManager.performSync, cap thecidslist at 100 (SYNC_MAX_CIDS) before passing it tochatClient.getSyncHistory. Both code paths (with and withoutrawLastSyncAt) use the capped list.UI Changes
No UI changes.
Testing
performSync caps channel_cids at 100inSyncManagerTestverifies that when 150 cids are passed in, only the first 100 reachgetSyncHistory.Summary by CodeRabbit
Bug Fixes
Tests