fix: return 409 when a token request reuses an existing user ID by ChiragAgg5k · Pull Request #13790 · appwrite/appwrite · GitHub
Skip to content

fix: return 409 when a token request reuses an existing user ID - #13790

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix-phone-token-duplicate-user
Sep 21, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix-phone-token-duplicate-user

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

What does this PR do?

POST /v1/account/tokens/phone, /tokens/email and /tokens/magic-url create a user when no user matches the given identifier. When the caller supplies a userId that already belongs to a different user, the insert hits the unique index and the request 500s instead of returning 409 user_already_exists. Fixes Sentry CLOUD-3QYD, 5.7k events since 9/6.

Test Plan

testCreatePhone gains a case that reuses the created user ID with a different phone and asserts 409. New testCreateEmailTokenWithExistingUserId covers the email and magic URL endpoints the same way. Verified red (500) with the controller hunk reverted and green with it applied.

Related PRs and Issues

Same shape as #13789, which fixed the push target update path.

Checklist

The phone, email and magic URL token endpoints create a user when no user matches the identifier, but never caught the unique-index failure when the caller supplied a userId that already belongs to another user. That surfaced as an unhandled 500 (Sentry CLOUD-3QYD, 5.7k events). Map it to USER_ALREADY_EXISTS like the other user-creating endpoints.
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-phone-token-duplicate-user (after).

Metric Before After Change
🚀 Requests/sec 169.91 187.02 🟢 +10.1%
⏱️ Latency P50 99.87 ms 92.94 ms 🟢 -6.9%
⏱️ Latency P95 244.47 ms 217.16 ms 🟢 -11.2%
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 92.94 217.16 11,514 187.02 -27.31
Account 181.27 338.83 606 10.03 -51.48
TablesDB 89.51 168.64 6,262 103.24 -6.58
Storage 85.13 183.14 3,030 52.41 -28.24
Functions 135.95 268.77 1,616 28.8 -55.1

Top API waits (after)

API request Max wait (ms)
account.prefs.update 527.32
account.name.update 527.27
functions.variables.create 471.76
functions.create 433.17
functions.delete 428.66

@ChiragAgg5k
ChiragAgg5k merged commit 8e16702 into main Sep 21, 2026
50 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix-phone-token-duplicate-user branch September 21, 2026 10:32
abnegate added a commit that referenced this pull request Sep 22, 2026
Drop the account.php and AccountCustomClientTest changes: the phone token
and push target duplicate handling landed on main via #13789 and #13790
with 409 semantics. Keep only the teams membership Duplicate mapping and
its concurrent E2E coverage.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

2 participants