Repository navigation
fix(frontend): coordinate HTTP token refresh with a shared worker - #21622
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2cd383c77d
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8a31067202
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be81447ef1
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5f3579fe53
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30be173013
ℹ️ 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".

Summary
On plain HTTP origins,
navigator.locksis unavailable and session refresh fails. Keep the existing Web Locks/BroadcastChannel flow where supported and use a SharedWorker otherwise. The worker owns the refresh request and shares its result across tabs, avoiding concurrent use of the backend's single-use refresh token.The fallback uses a separate Connect client with cookies and no UI interceptors. Same-tab callers share one promise. The client waits for the worker readiness handshake before dispatching a refresh. Startup errors and timeouts close the unused port and retry within the same shared refresh promise, up to three attempts with 250 ms and 500 ms delays. If startup retries are exhausted, the auth interceptor returns temporary unavailability without expiring the session; later API requests can retry startup throughout a longer rollout. Failures or timeouts after readiness require reloading the page before trying the worker again. The worker refresh RPC has no client deadline: the page watchdog gives startup and the dispatched refresh separate 35-second intervals, and rejects waiting callers without aborting an in-flight token rotation. Backend token rotation is unchanged, with no grace period.
This is an independent alternative to #21616; that PR is unchanged.
Validation
pnpm --dir frontend fixandpnpm --dir frontend testpass: guards, Biome, TypeScript, production bundle, and 586 test files / 6,614 tests.Added tests for Web Locks selection, fallback selection, concurrent worker ports, rotations lasting beyond the page watchdog without starting a second request, shared failures, later refreshes, recoverable worker startup errors and timeouts, a full refresh watchdog interval after slow startup, terminal failures after readiness, stale worker errors, and unavailable SharedWorker.
Chromium verification using the built fallback on a LAN HTTP origin (
isSecureContext === false, nonavigator.locks) against a simulated single-use refresh endpoint: two tabs produce one request, both succeed, the next rotation uses the replacement HTTP-only cookie, and closing the initiating tab does not interrupt the remaining tab's refresh.No full Bytebase browser E2E run; the browser endpoint above was simulated.
Review follow-up: Chromium verification with a production-built worker and a simulated old-replica HTML response confirmed that a single refresh call survives the initial HTML response: two worker loads produce exactly one refresh request. Interceptor regression tests verify that recovery and repeated startup retry exhaustion do not set the session-expired flag or show a reauthentication notification, and that a later request recovers once the worker becomes available.
Compatibility and limits
HTTP fallback requires SharedWorker with module-worker support. Unsupported or blocked workers fail explicitly rather than issuing competing requests. HTTPS/localhost deployments retain the existing Web Locks path. Lost responses after server-side rotation can still require reauthentication, as before.