Skip to content

fix(realtime): end impersonated connections when the impersonator flag is removed - #14041

Merged
ArnabChatterjee20k merged 2 commits into
fix/realtime-session-expiryfrom
fix/realtime-impersonator-revoked
Oct 1, 2026
Merged

ArnabChatterjee20k merged 2 commits into
fix/realtime-session-expiryfrom
fix/realtime-impersonator-revoked

Conversation

@ArnabChatterjee20k

@ArnabChatterjee20k ArnabChatterjee20k commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Stacked on #14039 (→ #14038 → #14040 → #14024 → #14021).

Why

Two gaps in how impersonated connections follow the impersonator, from #14024 combined with #14039:

  1. Impersonator flag removed. The HTTP API re-checks impersonator on every request (app/init/resources/request.php), so turning it off stops impersonation immediately. An impersonated realtime socket only closed when the impersonator was deleted/blocked or their session ended, so it kept the target's roles after the flag was removed.
  2. Impersonator's session extended. fix(realtime): close connections when their session or JWT expires #14039 gives an impersonated connection the impersonator's session expiry, but nothing refreshed it, so extending that session didn't extend the connection; it was closed at the old expiry.

What

In the impersonating loop (connections a user opened while impersonating, re-checked on that user's users.* events):

Tests

E2E: testConnectionEndsWithImpersonatorSession gains a step that turns the actor's impersonator flag off and asserts a 401 and close, then turns it back on for the following "actor is blocked" step. Not run locally (no Docker); relying on CI. Lint, PHPStan and Rector pass.

testImpersonatedConnectionFollowsSessionExtension covers the session extension: on its own project with the 60s minimum duration, it extends the actor's session, polls until an unextended session created at the same time is refused, then checks the impersonated socket still receives the target's events. It takes about a minute because of that minimum.

🤖 Generated with Claude Code

…g is removed

The HTTP API re-checks the impersonator flag on every request, but an
impersonated socket kept the target's roles until the impersonator's
session ended. users.*.update.impersonator now closes the connections
that user opened while impersonating.

The impersonator's events also refresh the expiry of those connections,
so extending the impersonator's session extends them instead of closing
them at the expiry they were opened with.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@ghost

ghost commented Oct 1, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new regression test exercises the previously uncovered expiry-refresh behavior, and no defects were found in the incremental changes.

The pull request closes impersonated realtime connections when the actor loses the impersonator flag and refreshes connection expiry when the actor's session is extended. E2E coverage now checks both flag removal and delivery of target events after the original session expiry.

Latest changes: The newest commit adds an isolated-project E2E test that extends the actor's session, polls until an unextended reference session expires, and verifies the impersonated socket still receives target events and responds to ping.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 2
File Change
app/realtime.php Re-check the actor's impersonator flag and refresh impersonated connection expiry from the actor's session.
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php Cover socket closure after flag removal and continued event delivery after actor session extension.
✅ Fixed since the last review · 1
  • Cover impersonator session extension with a regression test · app/realtime.php:681

Reviewed the commits since c65e21e · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Comment thread app/realtime.php Resolved
…once extended

Runs on its own project with the 60s minimum session duration, extends
the impersonator's session, waits until an unextended session from the
same moment is refused, then checks the impersonated socket still gets
the target's events.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your trial has ended. Reactivate Greptile to resume code reviews.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing fix/realtime-session-expiry (before) → fix/realtime-impersonator-revoked (after).

Metric Before After Change
🚀 Requests/sec 204.98 203.64 ⚪ -0.7%
⏱️ Latency P50 84.5 ms 85.39 ms ⚪ +1.1%
⏱️ Latency P95 201.74 ms 196.4 ms ⚪ -2.6%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 85.39 196.4 12,597 203.64 -5.34
Account 157.58 303.17 663 11.1 -2.38
TablesDB 82.79 163.8 6,851 112.22 +16.98
Storage 77.71 164.25 3,315 56.24 -3.8
Functions 117.59 231.42 1,768 30.66 -29.81

Top API waits (after)

API request Max wait (ms)
account.name.update 487.24
tablesdb.rows.increment 438.1
account.prefs.update 430
functions.create 390.49
tablesdb.rows.update 381.91

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@ArnabChatterjee20k
ArnabChatterjee20k merged commit a1eb2d7 into fix/realtime-session-expiry Oct 1, 2026
55 checks passed
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.

1 participant