Repository navigation
fix(identity): resolve + reconcile duplicate Users rows — cat-game counter/leaderboard desync (#2651) - #2661
Merged
Merged
Conversation
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.
Summary
Fixes #2651 — the Devtoberfest cat-game (Kasimir) counter and leaderboard desync, root-caused to duplicate
Usersrows for the same human.Root cause: After the IAS migration, SAP ID Service issues IAS tokens that carry the user's email in
xs.user.attributes(surfaced asuser.attr.email) rather than the JWT rootpayload.emailclaim.tokenEmail()only readpayload.email, so Tier-3 email matching inresolveUserwas skipped for IAS logins →resolveUserreturned null →provisionDbUserminted a secondUsersrow for the same human. Cat-game points earned on a forked row have noEventRegistration, so theGAMEBOARD_PARTICIPANT_V1inner join hides them from the leaderboard while the in-game counter still counts them. ~349 duplicate-email clusters in PROD.This is why forks continued at ~4–8%/day even after the #2552 identity-linkage layer shipped.
Two logical halves (reviewed together)
Prevention (stops new forks):
tokenEmail()falls back touser.attr?.emailfor IAS tokens — the root-cause fix (XSUAApayload.emailstill wins; no regression)pickCanonicalRow()— deterministic canonical-row pick; exported from the package barrel so the CF bundle includes itprovisionDbUserreturn block hardened against concurrent-insert races__hasRegistrationso the resolver and the reconciliation job pick the same canonical rowReconciliation (fixes the 349 existing forks):
mergeAccountsextended to repointUserIdentities(dedupe issuer+subject),EventRegistrations(dedupe event, keep earliest joinedAt), andCatGameAwards(sum per-day to the 5-cap, trim per-event to the 100-cap — matches the live game's hard caps)srv/jobs/identity-dedup-job.js—reconcileDuplicateEmails({dryRun}), dry-run by default, computes real point deltas. Deliberately NOT registered inJOB_REGISTRY(registry jobs get a one-click admin button + cron; a mutating 349-cluster reconciliation must stay operator-invoked). Operator runbook in the SDD workspace.Test plan
reconcileDuplicateEmails({dryRun:true})against DEV data, review cluster/point counts before any executeNotes
revertpair in history (a5966cbf+d6e1f0925) is the honest trail of an abandoned eager-merge approach — the real fix is thetokenEmailchange.