LibreChat/packages/api
Danny Avila f556fc0b5d
🚪 fix: Let Concurrent First OpenID Logins Continue as the New User (#16778)
* 🚪 fix: Let Concurrent First OpenID Logins Continue as the New User

Two requests for the same not-yet-created OpenID identity both missed
findOpenIDUser and both called createUser; the unique email and OpenID
indexes rejected the second insert, and that login failed with E11000.

createUserIfAbsent (data-schemas) inserts a first-login user and reports
a lost race as { ok: false, error: { code: 'user_exists' } }. It
initializes the start balance under the new user's id before inserting
the user, so the account is never visible without it, and removes that
balance when the write fails or a unique index rejects the insert.
createUser shares the insert-only credit (creditStartBalance).

createOpenIDUser (packages/api) creates through it and, on user_exists,
repeats findOpenIDUser with its provider and issuer checks and continues
as the account that won, admitted and refreshed exactly as if the first
lookup had found it: the account's own config (tenant config for a
tenant account) and its email-domain policy apply, and applyOpenIDProfile
writes this callback's claims. It continues only once the winner
finished provisioning the account: when that config sets a start
balance, the balance must exist, which a previous-release creator
credits only after its insert. UserRecord and NewUserData are the plain,
storage-neutral contracts.

Related to #16766

* ↩️ fix: Hold a Recovered Login on the Creation Config's Start Balance

The provisioning barrier read the recovered account's tenant config.
With a tenant start balance the base config does not set, every
concurrent first login in that tenant failed again, because the winner
creates the user under the base config and login balance sync only
initializes the tenant balance afterwards.

The barrier guards against a previous-release creator's $inc landing on
a balance login balance sync already initialized, and that creator only
credits the base config's start balance. createOpenIDUser now holds the
recovered login only when the config new users are created under sets a
start balance; a tenant-only start balance is initialized insert-only by
login balance sync and cannot be added twice.
2026-10-05 17:56:57 -04:00
..
openapi 🫰 feat: Configure Tool Approval Modes Per Agent (#16707) 2026-10-04 13:14:48 -04:00
src 🚪 fix: Let Concurrent First OpenID Logins Continue as the New User (#16778) 2026-10-05 17:56:57 -04:00
types
.gitignore
babel.config.cjs
jest.config.mjs 🧩 feat: MCP Apps support (#13831) 2026-10-01 03:46:16 +00:00
jest.setup.cjs
package.json 🦉 feat: Compare Review Commit Ancestry Without Git (#16734) 2026-10-05 08:20:51 -04:00
tsconfig-paths-bootstrap.mjs
tsconfig.build.json
tsconfig.json
tsconfig.openapi.json
tsconfig.spec.json
tsdown.config.mjs 🏋️ fix: Bound Host File Edits Outside the API Event Loop (#16677) 2026-10-02 20:54:46 -04:00