Conversation
`initializeRoles`'s SHARED_GLOBAL -> SHARE migration reads and writes the
Role collection through the raw driver, filtered on `{ name: roleName }`
alone. Role is tenant-scoped (`{name, tenantId}` unique index) and this
runs under system context, so the name-only filter matches an arbitrary
tenant's document on both the read and the write. Every other tenant
sharing that role name keeps its legacy SHARED_GLOBAL field, and the
migration is idempotent-by-absence, so a later boot skips the tenant it
already cleared and still never reaches the rest.
The read now loads every document matching the role name and migrates
each one by _id, so no tenant is left behind.
The same block also tested SHARE presence with `'SHARE' in block`, which
is true for a stored `SHARE: null`. That skipped inheriting from
SHARED_GLOBAL while still $unsetting it, discarding the deployment's
sharing intent -- the per-field merge later in the same function treats
null as missing (`== null`), so the two checks disagreed about what null
means. The presence check is now nullish, matching the merge.
Fixes LibreChat-AI#16213
Contributor
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The migration fixes are covered by focused regression tests, with no unresolved review issues.
Review effort: Lite
Findings: None
What changed in this PR
Fixes tenant-scoped legacy role-permission migration and correctly handles SHARE: null.
Changes:
- Migrates every matching role document by
_id. - Treats nullish
SHAREvalues as absent. - Adds regression tests for both cases.
| File | Description |
|---|---|
packages/data-schemas/src/methods/role.ts |
Corrects migration filtering and null handling. |
packages/data-schemas/src/methods/role.methods.spec.ts |
Adds regression coverage for both defects. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.
Pull Request
Summary
initializeRoles'sSHARED_GLOBAL→SHAREmigration inpackages/data-schemas/src/methods/role.tsreads and writes theRolecollection through the raw driver, filtered on{ name: roleName }alone.Roleis tenant-scoped ({name, tenantId}unique index) and the migration runs under system context, so the name-only filter matches an arbitrary tenant's document on both the read and the write, leaving every other tenant sharing that role name permanently unmigrated since the migration is idempotent-by-absence. The same block also testsSHAREpresence with'SHARE' in block, which is true for a storedSHARE: null, so a document holding{ SHARED_GLOBAL: true, SHARE: null }skips inheriting the legacy value while still$unsettingSHARED_GLOBAL, discarding the deployment's sharing intent — the per-field merge later in the same function treatsnullas missing, so the two checks disagreed about whatnullmeans. This PR reads every document matching the role name and migrates each one by_id, and switches the presence check to a nullish check so a storednullis treated the same as absent.Fixes #16213
Type of change
Testing
Tested environments/configuration:
mongodb-memory-server)Automated tests:
packages/data-schemas/src/methods/role.methods.spec.ts: one seeds two tenants' legacy documents and asserts both migrate, the other seeds a storedSHARE: nulland asserts it inherits fromSHARED_GLOBALinstead of being treated as present.npx jest role.methods.spec.ts— 72 passednpx tsc --noEmit— cleanScreenshots / recordings
N/A — server-side data migration, no UI change.