Skip to content

Prevent tracking channel states for malformed CIDs#6497

Draft
gpunto wants to merge 1 commit into
developfrom
and-1187-prevent-tracking-channelstates-by-malformed-cid
Draft

Prevent tracking channel states for malformed CIDs#6497
gpunto wants to merge 1 commit into
developfrom
and-1187-prevent-tracking-channelstates-by-malformed-cid

Conversation

@gpunto

@gpunto gpunto commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Goal

Prevent the SDK from tracking ChannelStates by a malformed cid. The original symptom is in SyncManager.updateActiveChannels: it issues a Filters.in("cid", missingCids) query on reconnect, and a single malformed entry in the list fails the whole request, blocking re-watch for every valid channel in the same batch. The underlying problem is that StateRegistry/LogicRegistry happily store state keyed by an unvalidated (channelType, channelId) pair, so malformed cids can leak in through any code path that bypasses the existing validateCidWithResult gates (sync recovery, channelFromMessage, etc.).

Closes AND-1187.

Implementation

  • New internal ChannelId value class with fromCid / fromTypeAndId factories that return null on invalid input.
  • StateRegistry and LogicRegistry re-key their channel maps on ChannelId. Their public channel(type, id) entry points validate at the boundary; malformed input returns a fresh, non-cached state/logic.
  • StateRegistry.getActiveChannelStates() now returns Map<ChannelId, ChannelState>, so SyncManager.updateActiveChannels and EventHandlerSequential iterate validated keys directly.
  • QueryChannelsStateLogic.addChannelsState filters out malformed server channels upfront so they never reach setCids / setChannels / logicRegistry.

Testing

  • New ChannelIdTest covers fromCid / fromTypeAndId.
  • StateRegistryTest and LogicRegistryTest: malformed cid returns a non-cached state/logic and the registry maps stay empty.
  • QueryChannelsStateLogicTest: getActiveChannelState returns null on malformed cid; addChannelsState drops malformed channels from setCids / setChannels / logicRegistry.

@gpunto gpunto added the pr:bug Bug fix label Jun 11, 2026
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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 the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.88 MB 5.88 MB 0.00 MB 🟢
stream-chat-android-ui-components 11.11 MB 11.11 MB 0.00 MB 🟢
stream-chat-android-compose 12.53 MB 12.53 MB 0.00 MB 🟢

@gpunto gpunto force-pushed the and-1187-prevent-tracking-channelstates-by-malformed-cid branch from c94969e to 7fd715c Compare June 11, 2026 12:35
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant