[Bug]: Legacy Meilisearch missing-user cleanup can miss mixed indexes
What happened?
While reviewing #15465 and the overlapping index-settings work in #15522, I noticed an edge case in the legacy missing-user cleanup in api/db/indexSync.js. This may already be planned as part of the ongoing Meilisearch work; if so, please feel free to link or close this in favor of the existing item.
The cleanup is enabled by checking only the first search hit. A mixed index can therefore be skipped when the first hit has user but later documents do not.
When cleanup does run, it deletes the affected Meilisearch documents but does not reconcile matching MongoDB acknowledgements. In an unexpected state where a matching record is still marked current, normal reconciliation can continue treating the deleted search document as indexed.
#15484 already mitigates the normal legacy-projection case by treating missing/older schema versions as stale and reindexing them. #15522 adds the next projection migration. This issue is therefore about making the remaining legacy cleanup internally consistent, not requesting another full migration.
Expected behavior
Either retire this special cleanup if versioned reindexing and ordinary orphan cleanup fully supersede it, or:
- detect missing-
userdocuments reliably in mixed indexes; - after terminal deletion, reconcile matching MongoDB records with snapshot-safe updates so valid documents remain retryable;
- keep genuinely orphaned documents deleted without forcing an unrelated full rebuild.
Relevant code
ensureFilterableAttributes()deleteDocumentsWithoutUserField()
This is separate from the cross-replica ownership fix in #15465 and is best addressed against the final settings behavior from #15522.
Source: danny-avila/LibreChat