Skip to content

fix: honor date and treat tolerance as a refresh margin in hasValidToken - #1055

Open
davidliu wants to merge 1 commit into
mainfrom
dl/token_payload_date_fix
Open

davidliu wants to merge 1 commit into
mainfrom
dl/token_payload_date_fix

Conversation

@davidliu

Copy link
Copy Markdown
Contributor

Summary

TokenSourceResponse.hasValidToken(tolerance, date) had two problems:

  • date was never read. A fresh Date() was used for every comparison.
  • tolerance was applied past exp, so a cached token stayed valid for 60 seconds after it expired and was handed to Room.connect, which the server rejects.

The tolerance is now a refresh margin: a token within tolerance of exp is reported invalid so the caching source fetches a fresh one. This matches isResponseTokenValid in client-sdk-js and hasValidToken(withTolerance:) in client-sdk-swift, both of which have always subtracted the margin.

Tests

  • tokenBeforeNbfIsInvalid and tokenAfterExpIsInvalid asserted true and only passed because date was ignored. They now assert false.
  • Two new tests pin the window against the default tolerance: 30 seconds before exp is invalid, 90 seconds before is valid.

CachingTokenSourceTest passes (9 tests), spotlessCheck passes.

Behaviour change

The default validator used by cached() now refetches tokens with under 60 seconds left instead of serving them from cache. Apps that passed their own date will now see it honoured.

🤖 Generated with Claude Code

The `date` parameter was never read; the wall clock was used instead. The
tolerance was applied past `exp`, keeping a token valid for 60 seconds
after it expired. It now marks a token invalid once it is within the
tolerance of `exp`, matching the JavaScript and Swift SDKs.

The two tests named "IsInvalid" asserted true and only passed because
`date` was ignored. They now assert false, and two new tests pin the
tolerance window at 30 and 90 seconds before `exp`.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5b78c5e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
client-sdk-android Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@github-actions

Copy link
Copy Markdown
Contributor

Diffuse output:

OLD: diffuse-source-file
NEW: livekit-android-sdk-release.aar

 AAR      │ old      │ new      │ diff  
──────────┼──────────┼──────────┼───────
      jar │  3.1 MiB │  3.1 MiB │ -48 B 
 manifest │  1.5 KiB │  1.5 KiB │   0 B 
 lint-jar │ 12.7 KiB │ 12.7 KiB │   0 B 
    other │  2.4 KiB │  2.4 KiB │   0 B 
──────────┼──────────┼──────────┼───────
    total │  3.1 MiB │  3.1 MiB │ -48 B 

 JAR     │ old   │ new   │ diff       
─────────┼───────┼───────┼────────────
 classes │  1771 │  1771 │  0 (+0 -0) 
 methods │ 22472 │ 22470 │ -2 (+0 -2) 
  fields │  5910 │  5910 │  0 (+0 -0)
AAR
 size    │ diff  │ path          
─────────┼───────┼───────────────
 3.1 MiB │ -48 B │ ∆ classes.jar 
─────────┼───────┼───────────────
 3.1 MiB │ -48 B │ (total)
JAR
METHODS:

   old   │ new   │ diff       
  ───────┼───────┼────────────
   22472 │ 22470 │ -2 (+0 -2) 
  
  - java.util.Date <init>(long)
  - java.util.Date after(Date) → boolean

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant