Skip to content

Cap channel CIDs at 100 when calling getSyncHistory#6419

Open
VelikovPetar wants to merge 1 commit intov6from
bug/limit_max_cids_for_sync
Open

Cap channel CIDs at 100 when calling getSyncHistory#6419
VelikovPetar wants to merge 1 commit intov6from
bug/limit_max_cids_for_sync

Conversation

@VelikovPetar
Copy link
Copy Markdown
Contributor

@VelikovPetar VelikovPetar commented May 6, 2026

Goal

The getSyncHistory endpoint enforces a server-side limit on the number of channel_cids it 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 the cids list at 100 (SYNC_MAX_CIDS) before passing it to chatClient.getSyncHistory. Both code paths (with and without rawLastSyncAt) use the capped list.

UI Changes

No UI changes.

Testing

  • New unit test performSync caps channel_cids at 100 in SyncManagerTest verifies that when 150 cids are passed in, only the first 100 reach getSyncHistory.

Summary by CodeRabbit

  • Bug Fixes

    • Improved channel synchronization reliability by implementing a batch processing limit, preventing potential stability issues when syncing large numbers of channels in a single operation.
  • Tests

    • Added test coverage to validate the new channel synchronization batch limit behavior.

Co-Authored-By: Claude <noreply@anthropic.com>
@VelikovPetar VelikovPetar added the pr:bug Bug fix label May 6, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled (or ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.26 MB 0.00 MB 🟢
stream-chat-android-offline 5.49 MB 5.49 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.65 MB 0.00 MB 🟢
stream-chat-android-compose 12.87 MB 12.87 MB 0.00 MB 🟢

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 6, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
71.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@VelikovPetar VelikovPetar changed the title Cap channel CIDs at 100 when calling getSyncHistory Cap channel CIDs at 100 when calling getSyncHistory May 6, 2026
@VelikovPetar VelikovPetar added pr:improvement Improvement and removed pr:bug Bug fix labels May 6, 2026
@VelikovPetar VelikovPetar marked this pull request as ready for review May 6, 2026 17:24
@VelikovPetar VelikovPetar requested a review from a team as a code owner May 6, 2026 17:24
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 6, 2026

Walkthrough

This PR introduces a limit on the number of channel IDs processed during sync operations. A new constant SYNC_MAX_CIDS = 100 is added, and performSync is updated to cap the channel ID list to this maximum before calling getSyncHistory. A test verifies this capping behavior.

Changes

Sync Channel ID Capping

Layer / File(s) Summary
Constants Definition
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt
New constant SYNC_MAX_CIDS = 100 added to define the maximum number of channel IDs for history syncing.
Core Implementation
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt
performSync method updated to cap channel IDs using cids.take(SYNC_MAX_CIDS) before passing to chatClient.getSyncHistory in both conditional branches.
Test Coverage
stream-chat-android-state/src/test/java/io/getstream/chat/android/state/internal/SyncManagerTest.kt
New test performSync caps channel_cids at 100 verifies that only the first 100 channel IDs are passed to the chat client when more than 100 are provided; adds eq import for Mockito Kotlin assertion support.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐰 A hundred channels, no more, no less—
We cap the list to pass the test.
Sync flows swift with this little bound,
A fuzzy fix that keeps us sound! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: capping channel CIDs at 100 in getSyncHistory calls.
Description check ✅ Passed The description covers the required Goal, Implementation, and Testing sections; UI Changes section notes no changes are needed. Most template sections are appropriately addressed or marked as not applicable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/limit_max_cids_for_sync

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt (1)

307-312: 💤 Low value

Consider 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_CIDS would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 988fb0f and b546995.

📒 Files selected for processing (2)
  • stream-chat-android-state/src/main/java/io/getstream/chat/android/state/sync/internal/SyncManager.kt
  • stream-chat-android-state/src/test/java/io/getstream/chat/android/state/internal/SyncManagerTest.kt

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

Labels

pr:improvement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant