Skip to content

♻️ replace custom cookie lock with native Web Locks API#4294

Open
thomas-lebeau wants to merge 3 commits intov7from
thomas.lebeau/v7-webLocks
Open

♻️ replace custom cookie lock with native Web Locks API#4294
thomas-lebeau wants to merge 3 commits intov7from
thomas.lebeau/v7-webLocks

Conversation

@thomas-lebeau
Copy link
Collaborator

Motivation

The old session concurrency mechanism was a custom cookie-based spin-lock — polling for a lock= cookie entry with retries and delays. It was complex (~136 lines in sessionStoreOperations.ts), only enabled in Chromium (isLockEnabled: isChromium()), and left Firefox/Safari without any cross-tab session protection.

Changes

  • Remove sessionStoreOperations.ts and its cookie-based lock mechanism
  • Introduce sessionLock.ts using navigator.locks for concurrency — available in all modern browsers (Chrome 69+, Firefox 96+, Safari 15.4+), so this also extends cross-tab session consistency to non-Chromium browsers
  • Simplify sessionStore.ts by inlining retrieve/persist logic directly within the lock callback
  • Remove isLockEnabled from SessionStoreStrategy interface
  • Clean up related tests and fake session store strategy

Net: ~554 lines removed, ~137 added.

Test instructions

Unit tests cover the async initialization scenarios:

  • Session manager initialization is delayed until the lock is released
  • onReady callback is deferred until after the lock is released
  • Session is expired when tracking consent is withdrawn while waiting for the lock

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/v7-webLocks branch 2 times, most recently from ffe2ea5 to 8a8065a Compare March 9, 2026 13:22
@cit-pr-commenter-54b7da
Copy link

cit-pr-commenter-54b7da bot commented Mar 9, 2026

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 170.70 KiB 169.79 KiB -932 B -0.53%
Rum Profiler 6.18 KiB 6.18 KiB -1 B -0.02%
Rum Recorder 25.26 KiB 25.48 KiB +226 B +0.87%
Logs 56.94 KiB 56.17 KiB -787 B -1.35%
Flagging 944 B 944 B 0 B 0.00%
Rum Slim 127.92 KiB 127.17 KiB -769 B -0.59%
Worker 23.63 KiB 23.63 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base CPU Time (ms) Local CPU Time (ms) 𝚫%
RUM - add global context 0.0047 0.0045 -4.26%
RUM - add action 0.0136 0.0145 +6.62%
RUM - add error 0.0141 0.0154 +9.22%
RUM - add timing 0.003 0.0039 +30.00%
RUM - start view 0.0144 0.0127 -11.81%
RUM - start/stop session replay recording 0.0007 0.0007 0.00%
Logs - log message 0.0161 0.0171 +6.21%
🧠 Memory Performance
Action Name Base Memory Consumption Local Memory Consumption 𝚫
RUM - add global context 26.87 KiB 31.31 KiB +4.44 KiB
RUM - add action 49.71 KiB 222.03 KiB +172.32 KiB
RUM - add timing 26.39 KiB 34.25 KiB +7.87 KiB
RUM - add error 56.25 KiB 245.16 KiB +188.90 KiB
RUM - start/stop session replay recording 25.90 KiB 33.96 KiB +8.06 KiB
RUM - start view 451.66 KiB 574.31 KiB +122.65 KiB
Logs - log message 45.22 KiB 223.29 KiB +178.06 KiB

🔗 RealWorld

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/v7-webLocks branch from 8a8065a to cd03262 Compare March 9, 2026 13:24
@datadog-official
Copy link

datadog-official bot commented Mar 9, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 75.51%
Overall Coverage: 76.72% (+0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 2ee6b36 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback!

@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/v7-webLocks branch 3 times, most recently from a94a0dd to bd49ace Compare March 9, 2026 14:57
- Remove sessionStoreOperations and its cookie-based lock mechanism
- Introduce sessionLock module using navigator.locks for concurrency
- Simplify sessionStore by inlining retrieve/persist logic within lock
- Remove isLockEnabled from SessionStoreStrategy interface
- Clean up related tests and fake session store strategy
@thomas-lebeau thomas-lebeau force-pushed the thomas.lebeau/v7-webLocks branch from bd49ace to e7defdc Compare March 10, 2026 09:19
@thomas-lebeau thomas-lebeau marked this pull request as ready for review March 11, 2026 08:04
@thomas-lebeau thomas-lebeau requested a review from a team as a code owner March 11, 2026 08:04
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e7defdcc66

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Add catch handler to navigator.locks.request() to capture unexpected failures
- Send telemetry debug event with error details for 6-month monitoring period
- Restructure expand/renew callback to skip cache assignment when
  session is in not-started state, preventing stale cache entries
- Ensure callback is always invoked regardless of session state
Copy link
Contributor

@mormubis mormubis left a comment

Choose a reason for hiding this comment

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

All unit tests replace withNativeSessionLock with a synchronous stub — is the real navigator.locks async path only exercised in E2E? If so, a timing bug there would not be caught by unit tests.

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.

2 participants