AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Clerk-Js: SessionTokenCache Serves Server-Expired Session Tokens When The Device Clock Runs Behind (Regression Of #672)

SessionTokenCache.get() compares the server-issued JWT expiry (exp) directly against the device clock when computing remaining TTL. If the device clock is behind the server, the cache keeps returning the token after it has expired, causing the backend to reject requests with 401. This is a regression introduced by #7317 and maintained by #9030.

highConfidence 75%Clerk-JscurrentUser()OrganizationsAffected V6.33.0

Origin Analysis

In tokenCache.ts, the cache entry's 'createdAt' is set to the JWT 'iat' (issued-at, server time) instead of the device clock time at caching. The get() method then computes elapsed as deviceNow - createdAt, effectively mixing server and device clocks. When the device clock is behind by S seconds, the remaining TTL is overestimated by S seconds, so the token is served until S seconds after its real server-side expiry.
1. Server issues a token at time T with a 60-second lifetime. 2. Device clock reads T-40 when the token is cached. 3. Advance 50 seconds: get() returns the token (expected, since 10 seconds remain by server time). 4. Advance 20 more seconds: by server time the token expired 10 seconds ago. 5. Expected: get() returns undefined. 6. Actual: get() still returns the token.

Fixing Code Block

Edge Case Audit

This hotfix assumes tokens are fresh at caching time. If a token is already partway through its lifetime when it reaches the cache (e.g., restored from storage), it may be considered valid for its full nominal lifetime after caching, potentially serving an expired token. The existing test 'broadcast resilience > a failing postMessage does not evict the freshly cached token' uses a fixture with iat > exp and will need its fixture corrected to iat <= exp. Rollback: revert the cache entry to store only createdAt = issuedAt and use the original calculation if this change causes regressions. A more robust fix would require measuring the server-device clock offset with a fresh token minting.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state