Repository navigation
fix(realtime): cast presence ids to string in onClose cleanup - #13551
Merged
Merged
Conversation
Numeric-only presence ids are valid UIDs, but PHP coerces them to
integer keys when stored in the connection map. array_keys then yields
ints, so Query::equal('$id', ...) queries the string $id column with an
integer - rejected by the query validator and unmatched on strict
adapters, leaking presence rows. Cast the ids back to strings before the
delete query.
… ids Record user.id on the cleanup span and add userId plus the concrete presenceIds to the realtimeOnClosePresenceDeletion error tags, so a future failure carries the offending ids instead of only a count.
Publish a presence with a numeric id over realtime, close the connection, and assert the delete event fires and the row is gone (404) - guards the coerced-key $id cleanup regression.
Contributor
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Sample at most 10 ids in the error tag; the total stays available via the separate presences count, so a busy connection cannot overflow telemetry tag length limits.
Guard the publisher against a double close and tear it down even if an earlier assertion throws before the mid-body close.
abnegate
reviewed
Sep 9, 2026
abnegate
reviewed
Sep 9, 2026
abnegate
approved these changes
Sep 9, 2026
2 of 4 tasks
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.
What
Fixes an
Invalid query: Query value is invalid for attribute "$id"error thrown from the realtimeonClosepresence-cleanup path (Sentry:realtimeOnClosePresenceDeletion/realtime.close.presenceCleanup).Root cause
A presence id is a valid UID, and a UID may be purely numeric (
0-9are allowed). ThepresenceIdparam is validated only asText(36), so a client can publish a presence with an id like"12345".The realtime worker tracks live presences as a set keyed by id:
PHP coerces any canonical-integer string key to an
int. On disconnect the cleanup does:So
$id(a string column) is queried with an integer:Note:
user.id/project.idreadingn/ain the Sentry tags is a span-tagging artifact (the cleanup span only setsrealtime.projectId), not evidence the user was unauthenticated — a presence cannot be created without an authenticated user.Fix
Cast the ids back to strings right before the delete query:
Diagnostics
To make any future occurrence self-explanatory, the cleanup now records
user.idon the span and addsuserId+ the concretepresenceIdsto therealtimeOnClosePresenceDeletionerror tags (previously only a count). Ids are attached on the failure path only, to avoid span cardinality blowup.Tests
Adds
testPresenceCloseWithNumericIdEmitsDeleteEvent(e2e,PresenceRealtimeClientTest): publishes a presence with a numeric id over realtime, closes the connection, and asserts thepresences.<id>.deleteevent fires andGET /presences/<id>returns404. Without the fix the numeric id is queried as an int, the row is not deleted, and both assertions fail.app/realtime.phpis a process entrypoint with no unit-testable seam for this glue, so the regression is covered through the real realtime API per the repo's E2E conventions.Verification
🤖 Generated with Claude Code