Skip to content

🏃 fix: Improve OpenID Lookup Planning#13229

Merged
danny-avila merged 4 commits into
devfrom
danny-avila/fix-openid-cosmos-lookup
May 21, 2026
Merged

🏃 fix: Improve OpenID Lookup Planning#13229
danny-avila merged 4 commits into
devfrom
danny-avila/fix-openid-cosmos-lookup

Conversation

@danny-avila

@danny-avila danny-avila commented May 21, 2026

Copy link
Copy Markdown
Owner

Summary

I fixed the OpenID user lookup path to avoid a Cosmos vCore planner regression caused by nested $or filters combined with findOne/limit: 1.

  • Replaced the issuer-bound OpenID primary lookup with ordered simple filters for openidId and idOnTheSource, preserving legacy issuer-less migration without nested disjunctions.
  • Applied the same ordered-filter approach to admin refresh fallback lookup so it avoids $or + limit shapes as well.
  • Preserved admin refresh recency semantics by selecting the newest updatedAt match across legacy issuer fallback filters before minting a token.
  • Added a plain issuer-bound idOnTheSource/openidIssuer/tenantId user index to match the new source-ID fallback lookup while avoiding partial-index requirements for FerretDB compatibility.
  • Updated JWT strategy and auth unit tests to assert the new query shape.
  • Added MongoMemoryServer coverage that captures emitted Mongo find filters and verifies the exact issuer lookup remains index-backed with IXSCAN and totalDocsExamined <= 1.
  • Added data-schemas coverage for the new source-ID compound index.

Change Type

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • npm run build:data-provider && npm run build:data-schemas && npm run build:api
  • npx jest --config jest.config.mjs --runTestsByPath src/auth/openid.spec.ts src/auth/refresh.spec.ts --runInBand --coverage=false
  • npx jest --runTestsByPath strategies/openIdJwtStrategy.spec.js --runInBand
  • npx jest --runTestsByPath src/methods/user.methods.spec.ts --runInBand --coverage=false
  • npm run build:data-schemas && npm run build:api
  • git diff --check

Test Configuration:

  • Local MongoDB compatibility coverage uses mongodb-memory-server.
  • The query changes avoid hints, aggregation, and server-specific operators so the lookup path remains compatible with MongoDB-compatible backends such as DocumentDB, Azure Cosmos DB for MongoDB vCore, and FerretDB.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI review requested due to automatic review settings May 21, 2026 15:21
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts OpenID user/admin lookup queries to avoid query shapes ($or + findOne/limit: 1, including nested disjunctions) that can trigger planner regressions in MongoDB-compatible backends (e.g., Cosmos DB vCore). It does so by replacing the single $or query with an ordered sequence of simple filters, while preserving legacy “issuer-less” migration behavior.

Changes:

  • Refactored OpenID user resolution to try issuer-exact and legacy issuer-less filters sequentially (instead of a single $or), preserving migration semantics.
  • Applied the same “ordered simple filters” approach to the admin refresh fallback lookup path.
  • Updated/added tests to assert the new query shapes and added MongoMemoryServer coverage that validates index-backed plans for the issuer-exact lookup.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/api/src/auth/refresh.ts Replaces $or-based admin user lookup with sequential simple filters, with optional tenant scoping.
packages/api/src/auth/refresh.spec.ts Updates assertions to expect the new non-$or filter shape for issuer-bound refresh lookups.
packages/api/src/auth/openid.ts Refactors OpenID lookup condition generation and performs sequential findUser attempts instead of a single $or query.
packages/api/src/auth/openid.spec.ts Updates existing unit tests for sequential lookups and adds MongoMemoryServer tests to validate emitted filters and index-backed execution.
api/strategies/openIdJwtStrategy.spec.js Updates strategy tests to expect the new issuer-bound filter shape rather than $or conditions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@danny-avila danny-avila force-pushed the danny-avila/fix-openid-cosmos-lookup branch from 3ef0ed2 to bde5c9e Compare May 21, 2026 17:31
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bde5c9e0e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/src/auth/refresh.ts Outdated
@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila marked this pull request as ready for review May 21, 2026 17:52
@danny-avila danny-avila force-pushed the danny-avila/fix-openid-cosmos-lookup branch from 5203788 to f3fd114 Compare May 21, 2026 17:56
@danny-avila

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions

Copy link
Copy Markdown
Contributor

GitNexus: 🚀 deployed

The LibreChat-pr-13229 index is now live on the MCP server.
Deploy run

@danny-avila danny-avila changed the title 🧭 fix: Improve OpenID Lookup Planning 🏃 fix: Improve OpenID Lookup Planning May 21, 2026
@danny-avila danny-avila changed the base branch from main to dev May 21, 2026 18:17
@danny-avila danny-avila merged commit cbdfe46 into dev May 21, 2026
12 checks passed
@danny-avila danny-avila deleted the danny-avila/fix-openid-cosmos-lookup branch May 21, 2026 18:17
fuuuzzy pushed a commit to fuuuzzy/LibreChat that referenced this pull request May 22, 2026
* fix: improve OpenID lookup planning

* fix: add issuer-bound source id index

* fix: align OpenID source id index

* fix: preserve admin refresh recency
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