fix(pre-init): stop processPreloadedItem mutating the shared ready-queue item#1292
Open
darrenli-rokt wants to merge 1 commit into
Open
fix(pre-init): stop processPreloadedItem mutating the shared ready-queue item#1292darrenli-rokt wants to merge 1 commit into
darrenli-rokt wants to merge 1 commit into
Conversation
…eue item
processPreloadedItem spliced the queued item array in place. Because the
ready queue can be drained more than once (e.g. a synchronous cache-hit
identify re-enters processReadyQueue before the outer drain resets the
queue), a second pass over an already-consumed item saw a stripped array:
["Identity.login", opts] had become [opts], so `method` was an object (or
`undefined` for a single-element item) and the unguarded `method.split('.')`
threw a TypeError. That TypeError surfaces from within sendIdentityRequest's
try/catch and gets reported with code IDENTITY_REQUEST ("Error sending
identity request to servers - e.split is not a function" / "...reading
'split'"), even though the identity request itself succeeded.
Fix:
- operate on a copy of the queued item so repeat drains cannot corrupt it
- skip malformed entries (empty array / non-string method) instead of
throwing an uncaught TypeError
Existing behaviour is otherwise unchanged. Adds regression tests: item is
not mutated, the same queue can be drained twice without throwing, and
malformed items are skipped.
Note: this stops the crash and the mislabelled IDENTITY_REQUEST errors; a
complementary follow-up is to make the ready-queue drain itself
re-entrancy-safe (reset before draining) so a method is not run twice.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
darrenli-rokt
marked this pull request as ready for review
July 23, 2026 13:57
PR SummaryCursor Bugbot is generating a summary for commit 57972d0. Configure here. |
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.



Problem
processPreloadedItem(src/pre-init-utils.ts) splices the queued item array in place:The ready queue can be drained more than once (e.g. a synchronous cache-hit
identifyre-entersprocessReadyQueueviaparseIdentityResponsebefore the outer drain resets the queue). On a second pass over an already-consumed item, the array has already been stripped:["Identity.login", opts]→[opts]→methodis an object →method.split('.')throws"e.split is not a function"["logEvent"]→[]→methodisundefined→"Cannot read properties of undefined (reading 'split')"method.split('.')is outside the localtry/catch, so the TypeError propagates up throughsendIdentityRequestand is reported with codeIDENTITY_REQUEST("Error sending identity request to servers - ...") — even though the identity request itself succeeded. This surfaces as a high volume of misleadingIDENTITY_REQUESTclient-error reports.Fix
readyQueueItem.slice()) so a repeat drain cannot corrupt the shared array.Existing behaviour is otherwise unchanged (all pre-existing tests pass untouched).
Tests
Full jest suite green. Added regression tests in
test/jest/pre-init-utils.spec.ts:Follow-up (not in this PR)
This stops the crash and the mislabelled
IDENTITY_REQUESTerrors. A complementary hardening is to make the ready-queue drain itself re-entrancy-safe (reset the queue before draining) so a queued method is not executed twice under re-entrancy. There is also a separate latent issue at thewindow.mParticle[args[0]]membership check (it should key offmethod), left untouched here to keep the diff surgical.