fix: return 404 when a presence disappears during update by ChiragAgg5k · Pull Request #13792 · appwrite/appwrite · GitHub
Skip to content

fix: return 404 when a presence disappears during update - #13792

Merged
ChiragAgg5k merged 8 commits into
mainfrom
fix-presence-update-permissions
Sep 21, 2026
Merged

ChiragAgg5k merged 8 commits into
mainfrom
fix-presence-update-permissions

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

PATCH /v1/presences/:presenceId reads the presence, then writes. If the presence is deleted or expires in between, updateDocument returns an empty document, and serializing it as a presence throws $permissions must be an array of type string, a 500. Fixes Sentry CLOUD-3QWW, 509 events since 9/5. The empty result is now mapped to 404 presence_not_found, and a requested list-cache purge still runs on that path.

Test Plan

New E2E testUpdateWhilePresenceIsDeleted in PresenceBase creates a presence and fires its update and delete concurrently, twenty times per side. It forbids any 500, checks the presence_not_found shape whenever the update loses the race, and checks the presence is gone from the list afterwards. Without the guard the race reproduces the exact production 500 within the twenty attempts; with it both sides are green.

Checklist

updateDocument returns an empty document when the row was deleted or expired between the action's read and its write. Serializing that as a presence threw on $permissions and surfaced as a 500 (Sentry CLOUD-3QWW). Treat the empty result as presence not found.
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Comment thread src/Appwrite/Platform/Modules/Presences/HTTP/Update.php Outdated
Comment thread tests/unit/Platform/Modules/Presences/Http/UpdateTest.php Outdated
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-presence-update-permissions (after).

Metric Before After Change
🚀 Requests/sec 187.56 188.38 ⚪ +0.4%
⏱️ Latency P50 90.02 ms 91.57 ms ⚪ +1.7%
⏱️ Latency P95 218.39 ms 215.96 ms ⚪ -1.1%
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 91.57 215.96 11,685 188.38 -2.43
Account 175.22 346.99 615 10.19 -34.64
TablesDB 88.75 168.33 6,355 104.39 -1.45
Storage 82.73 181.77 3,075 52.44 -8.29
Functions 135.55 273.84 1,640 28.69 +11.96

Top API waits (after)

API request Max wait (ms)
account.name.update 549.93
account.prefs.update 427.4
functions.variables.update 426.29
functions.variables.create 391.76
functions.create 373.69

Comment thread tests/e2e/Services/Presences/PresenceBase.php Outdated
Comment thread tests/e2e/Services/Presences/PresenceBase.php Outdated
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptile review

Comment thread tests/e2e/Services/Presences/PresenceBase.php Outdated
@ChiragAgg5k

Copy link
Copy Markdown
Member Author

The console suite has no API key, so the test now uses each side's own headers, and the concurrent calls go through the shared e2e client inside coroutines instead of raw curl.
Other suites can race requests the same way without reimplementing the coroutine plumbing.
Enabling the coroutine curl hook leaves it on for the rest of the process, so every later test in the same suite failed on CI with 'Failed initialization'. The client now builds and parses handles through shared methods and runs the concurrent set through curl_multi.
@ChiragAgg5k
ChiragAgg5k merged commit acedb66 into main Sep 21, 2026
51 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-presence-update-permissions branch September 21, 2026 14:48
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.

3 participants