Skip to content

fix(realtime): re-authorize console tails on project transfer and re-authentication - #14989

Merged
abnegate merged 5 commits into
mainfrom
fix-realtime-tail-reauthorization
Oct 27, 2026
Merged

abnegate merged 5 commits into
mainfrom
fix-realtime-tail-reauthorization

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

A console tail (console.tail.<projectId>) keeps the project's read roles from the moment it was subscribed. Until now it was revalidated only against the viewer's roles, and only when a permissions-changed event about that viewer arrived. That left two gaps:

  • Transfers: PATCH /v1/projects/:projectId/team emitted no realtime event and changed only the project's roles, so tails held by members of the previous team kept streaming.
  • In-band authentication: authenticating as another user rebuilt the connection's subscriptions but left its tails in place.

This PR:

  • Transfer event: the transfer publishes projects.{projectId}.update.team. Realtime::fromPayload marks it as a permissions change.
  • Worker: on that event, the realtime worker calls the new EventTailRegistry::reauthorizeProject(). It checks every tail of the project against the project's current read roles and the connection's roles, drops the tails that no longer qualify, and stores the new read roles on the ones that remain so later revalidation uses them.
  • In-band authentication: the handler revalidates the connection's tails against the new user's roles.

Test Plan

  • Unit tests in EventTailRegistryTest:

    • testReauthorizeProjectDropsTailsOfViewersWhoCanNoLongerReadIt
    • testReauthorizeProjectKeepsTheNewRolesForRevalidation

    Both pass.

  • E2E tests in RealtimeConsoleTailTest:

    • testTailEndsWhenProjectIsTransferred
    • testTailEndsWhenConnectionAuthenticatesAsAnotherUser

    These rely on CI. The local Docker stack was unavailable, so neither the passing run nor the run with the source change reverted (to show they fail without the fix) could be done locally.

  • Lint: Pint, PHPStan and the Rector dry run pass on the changed files.

Related PRs and Issues

🤖 Generated with Claude Code

…authentication

A console tail keeps the project's read roles from the moment it started
and was only revalidated against the viewer's roles. Transferring a
project emitted no realtime event and changed only the project's roles, so
tails held by the previous team kept streaming. Authenticating in-band as
another user rebuilt the subscriptions but left the tails untouched.

The transfer now publishes `projects.{projectId}.update.team`, which the
realtime worker handles as a permissions change: every tail of the project
is checked against its current read roles, and the roles it keeps are
replaced so later revalidation uses them. In-band authentication
revalidates the connection's tails against the new user's roles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (1)

  • 🟡 Publish tail reauthorization before sub-resource propagation — Update.php:110
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Team deletion never revokes project tails · Realtime.php:936 · unchanged line

// src/Appwrite/Messaging/Adapter/Realtime.php
936	                    $permissionsChanged = $parts[2] === 'create';

Tail revocation on permission change is keyed to projects.{id}.update.team and per-user permissionsChanged events (src/Appwrite/Messaging/Adapter/Realtime.php:936). Deleting a team removes team:{teamId} read roles from every project that referenced it, but produces only a teams.{teamId}.delete event with permissionsChanged = false; the Deletes worker's deleteMemberships bulk-deletes membership rows without emitting per-membership realtime events (src/Appwrite/Platform/Workers/Deletes.php:821-832), so no per-user revalidation fires either. Connected former members keep their stale roles and stale tail authorizations and continue streaming project tails until their next re-authentication.


The PR wires a revocation path for realtime tail streams: Team/Update.php emits a projects.[projectId].update.team event after an ownership transfer, the realtime worker maps it to EventTailRegistry::reauthorizeProject() with the project's fresh read roles, and the Authentication handler revalidates a connection's tails on re-authentication.

Files Change
src/Appwrite/Realtime/EventTailRegistry.php, app/realtime.php New registry plus worker wiring that reauthorizes or detaches tail entries when a project's read roles change or a connection re-authenticates.
src/Appwrite/Messaging/Adapter/Realtime.php, src/Appwrite/Realtime/Message/Handlers/Authentication.php Flags the team-transfer event as a permission change and injects the registry into the authentication handler for per-connection revalidation.
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Publishes the update.team realtime event after rewriting permissions across the project's sub-resources.
tests/unit/Realtime/EventTailRegistryTest.php, tests/e2e/Services/Realtime/RealtimeConsoleTailTest.php Unit coverage of registry reauthorization semantics and an e2e suite covering tail revocation across team transfer and re-authentication.

Reviewed commit: 310d9aa

@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Both transfer and in-band authentication update tail authorization, with unit and end-to-end coverage for the changed behavior.

Project transfers now emit a realtime permissions-change event that refreshes project-tail authorization. In-band authentication also revalidates existing tails against the newly authenticated user's roles, with registry and websocket coverage for both flows.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 7
File Change
app/realtime.php Re-authorizes project tails when a project-scoped permissions-change event arrives.
src/Appwrite/Messaging/Adapter/Realtime.php Marks project team updates as permission changes for realtime processing.
src/Appwrite/Platform/Modules/Projects/Http/Projects/Team/Update.php Publishes a realtime event after updating the project's team and permissions.
src/Appwrite/Realtime/EventTailRegistry.php Adds project-wide tail reauthorization and refreshes the stored read roles.
src/Appwrite/Realtime/Message/Handlers/Authentication.php Revalidates tails after a connection authenticates as a different user.
tests/e2e/Services/Realtime/RealtimeConsoleTailTest.php Covers tails ending after project transfer and in-band reauthentication.
tests/unit/Realtime/EventTailRegistryTest.php Covers dropping unauthorized tails and updating roles for later revalidation.

Reviewed 6600664 · 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 S · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot 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.

Adds realtime tail re-authorization: on project team transfer the realtime worker revokes or refreshes connected clients console.tail subscriptions via a new EventTailRegistry, with unit and e2e test coverage.

Key findings

  • 🟡 Publish tail reauthorization before sub-resource propagation — Update.php:110
  • 🟡 Team deletion never revokes project tails — Realtime.php:936

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-realtime-tail-reauthorization (after).

Metric Before After Change
🚀 Requests/sec 170.12 174.76 ⚪ +2.7%
⏱️ Latency P50 99.46 ms 98.75 ms ⚪ -0.7%
⏱️ Latency P95 240.22 ms 232.96 ms ⚪ -3%
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 98.75 232.96 11,343 174.76 -7.25
Account 181.88 345.21 597 9.89 +13.02
TablesDB 95.13 176.89 6,169 97.98 -26.94
Storage 92.53 216.92 2,985 48.9 -3.43
Functions 139.64 274.97 1,592 26.77 +5.53

Top API waits (after)

API request Max wait (ms)
account.name.update 554.43
functions.create 443.2
functions.delete 411.63
account.prefs.update 409.11
tablesdb.rows.create 388.93

abnegate and others added 3 commits October 27, 2026 19:40
The event that re-authorizes a project's tails was published after the
installation, repository and VCS comment permissions were rewritten. If
that propagation failed, the project already belonged to the new team but
the previous team's tails were never re-authorized. Publish it as soon as
the project document and its cache are updated.

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

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

@abnegate
abnegate merged commit c7476c1 into main Oct 27, 2026
38 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