Skip to content

Distinguish empty token from user_id mismatch at connect - #6624

Merged
aleksandar-apostolov merged 1 commit into
v6from
port/v6/distinguish-empty-token
Aug 7, 2026
Merged

Distinguish empty token from user_id mismatch at connect#6624
aleksandar-apostolov merged 1 commit into
v6from
port/v6/distinguish-empty-token

Conversation

@aleksandar-apostolov

@aleksandar-apostolov aleksandar-apostolov commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Goal

Closes AND-1374

Backport of #6622 to v6. When the TokenProvider returns a blank token (e.g. offline), setUser() returned the same Error.GenericError and message as a genuine user_id mismatch — indistinguishable. Callers can now branch on error.code. Merge after the primary #6622 lands (full review happens there).

Implementation

  • Straight re-apply of Distinguish empty token from user_id mismatch at connect #6622 to v6: in ChatClient.setUser(), check token.isBlank() before the user_id comparison and tag each failure with a stable code from the existing ChatErrorCode — both stay Error.GenericError with the message unchanged (no break for message-matchers); the code is the discriminator:
    • blank/empty token → UNDEFINED_TOKEN (1007)
    • non-empty token whose decoded user_id != user.idINVALID_TOKEN (1006)
  • Requires GenericError.code from stream-result 1.4.1 (additive slot, JVM 11); streamResult bumped 1.3.2 → 1.4.1 on v6.

Testing

  • ChatClientConnectionTests: 27 tests, 0 failures (extended mismatch test asserts INVALID_TOKEN; new blank-token test asserts UNDEFINED_TOKEN + unchanged message).
  • ./gradlew :stream-chat-android-client:spotlessCheck passes.

Summary by CodeRabbit

  • Bug Fixes

    • Improved authentication error handling during connection setup.
    • Blank tokens now return a clear undefined-token error.
    • Tokens associated with a different user now return a specific invalid-token error.
    • Preserved existing error messages for compatibility while providing more accurate error codes.
  • Maintenance

    • Updated the underlying streaming component to improve reliability and compatibility.

Backport of #6622 to v6.

Split the check in setUser() on token.isBlank() and tag each branch with a
stable code from the existing ChatErrorCode. Both stay GenericError and the
returned message is unchanged from the previous behaviour, so callers that
match on it are not broken; the code is the discriminator:
- blank token   -> code UNDEFINED_TOKEN (1007)
- user_id != id -> code INVALID_TOKEN (1006)

Requires stream-result 1.4.1 (adds GenericError.code, JVM 11); streamResult
bumped 1.3.2 -> 1.4.1.
@github-actions

github-actions Bot commented Aug 7, 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 ignored for dependabot PRs).

🎉 Great job! This PR is ready for review.

@aleksandar-apostolov
aleksandar-apostolov marked this pull request as ready for review August 7, 2026 11:17
@aleksandar-apostolov
aleksandar-apostolov requested a review from a team as a code owner August 7, 2026 11:17
@aleksandar-apostolov
aleksandar-apostolov enabled auto-merge (squash) August 7, 2026 11:20
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3816f52d-7d3b-4273-851f-fccff9e785c9

📥 Commits

Reviewing files that changed from the base of the PR and between 85adcb6 and 266ffd2.

📒 Files selected for processing (3)
  • gradle/libs.versions.toml
  • stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt
  • stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientConnectionTests.kt

Walkthrough

The PR updates streamResult to version 1.4.1. It also classifies blank tokens as UNDEFINED_TOKEN and JWT user-ID mismatches as INVALID_TOKEN, with expanded connection tests.

Changes

Token Error Classification

Layer / File(s) Summary
Token validation and error-code coverage
stream-chat-android-client/src/main/java/io/getstream/chat/android/client/ChatClient.kt, stream-chat-android-client/src/test/java/io/getstream/chat/android/client/ChatClientConnectionTests.kt
setUser loads the token once and assigns specific error codes for blank tokens and user-ID mismatches. Tests verify both codes and the existing error message.

streamResult Dependency Update

Layer / File(s) Summary
Version catalog update
gradle/libs.versions.toml
The streamResult version changes from 1.3.2 to 1.4.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: velikovpetar

Poem

A rabbit checked the token gate,
And marked each error code straight.
Blank ones hop to undefined,
Mismatched ones are invalidly penned.
The streamResult seed grew new—
Tests sprang up to prove it true.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: distinguishing blank tokens from user ID mismatches during connection.
Description check ✅ Passed The description explains the goal, implementation, dependency update, test coverage, and validation results; omitted UI and checklist sections are not critical for this change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ 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 port/v6/distinguish-empty-token

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.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.32 MB 0.05 MB 🟢
stream-chat-android-offline 5.49 MB 5.53 MB 0.04 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.75 MB 0.11 MB 🟢
stream-chat-android-compose 12.87 MB 12.96 MB 0.09 MB 🟢

@sonarqubecloud

sonarqubecloud Bot commented Aug 7, 2026

Copy link
Copy Markdown

@aleksandar-apostolov
aleksandar-apostolov merged commit 27abded into v6 Aug 7, 2026
24 of 26 checks passed
@aleksandar-apostolov
aleksandar-apostolov deleted the port/v6/distinguish-empty-token branch August 7, 2026 13:06
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.

2 participants