Repository navigation
Fix stale identity overwrite with timestamp-based protection (TT-031 follow-up) - #890
Merged
Merged
Conversation
**Server:** Add identity_updated_at column to Session table. Only update user_id/user_email when incoming timestamp is newer than stored value. Protects against delayed SDK requests overwriting fresher identity data. **SDK:** Track identity timestamps in telemetry-core. When identify() is called, capture current timestamp and send as identity_updated_at. Old SDKs without this field fall back to started_at as the identity timestamp. **Tests:** Added regression tests for: - Stale request arriving after identify() (should be rejected) - Newer identity overwriting older identity (should succeed) - Backward compat: old SDK without identity_updated_at (uses started_at) **Root cause:** RN SDK 1.3.1 sends delayed session requests ~1s after identify(), carrying previous user's ID. With new non-null-wins COALESCE logic from #887, stale requests overwrote correct user. Solution: timestamp-based ordering prevents out-of-order updates. **Versions:** - @telemetry-tracker/core: 1.5.2 → 1.5.3 - @telemetry-tracker/react-native: 1.3.1 → 1.3.2 Refs #886
1. Drop started_at fallback: Only use strict-newer comparison when BOTH stored and incoming have timestamps. Requests without identity_updated_at use #887 behavior (new non-null wins). Old SDKs (1.3.1) remain affected until apps upgrade. 2. Migration: Remove backfill, leave identity_updated_at NULL for existing sessions. 3. Timestamp clamping: Clamp client timestamp to LEAST(client_ts, now()) and bound by started_at to prevent future timestamps and ensure logical ordering. 4. Core init() fix: Preserve identity only if set via identify-before-init (no active session). Clear stale identity from previous sessions. Supports identify-before-init pattern while preventing stale user carryover from re-init scenarios. 5. Tests updated: - QA sequence: stale init() first, then identify() - Old-SDK identify mid-session (uses #887 behavior) - Future timestamp clamping - SDK: identify-before-init preservation - SDK: re-init clears stale identity 6. CHANGELOG updated to reflect actual behavior and note that old SDKs stay affected. Root cause confirmed: init() calls startSession() which builds payload with module-level userId before clearing it. With new strict-newer logic and timestamp clamping, this is now properly handled. Refs #886
Use timestamps 1 minute in the past for QA sequence test to prevent clamping to server time when test runs close to 'now'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause confirmed: In core,
init()callsstartSession()and builds the session payload right away with the module-leveluserId, which still holds the previous user. That stale init request reaches the server (potentially FIRST due to network ordering), and the correctidentify()request comes after it.Fixes applied:
Old SDKs handling: Dropped the
started_atfallback. Requests withoutidentity_updated_atkeep Fix duplicate session race condition (TT-031) #887's behavior (a non-null value overwrites). Use strict-newer comparison (incoming > stored) only when BOTH the stored and incoming values have a client timestamp. SDK 1.3.1 stays affected until apps upgrade to 1.3.2 / core 1.5.3. This is documented inCHANGELOG.md.Migration: No backfill.
identity_updated_atremainsNULLfor existing sessions (will use Fix duplicate session race condition (TT-031) #887 behavior until re-identified).Timestamp clamping: Client timestamp is clamped on the server to
LEAST(client_ts, now()), and no earlier thanstarted_at(i.e.,GREATEST(started_at, LEAST(client_ts, now()))). This prevents malicious or skewed client clocks from setting infinite future timestamps.Core
init()fix: Preserve identity only if it was set viaidentify()before ANY session started (supports identify-before-init pattern). Clear stale identity from previous sessions when re-init is called. This prevents stale user carryover while keeping apps that callidentify()beforeinit()working correctly.Regression Tests:
Version bumps (DO NOT publish to npm; Sanja publishes):
@telemetry-tracker/core→ 1.5.3@telemetry-tracker/react-native→ 1.3.2All tests pass. All CI checks green ✅
Refs #886