ExportXMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: ABX
    • None
    • None
    • None
    • None
    • None
    • None

      TL;DR

      Two processes registering the same index name at the same time must not overwrite each other's mapping. createIndex() already guards against this. Verify that guard against a real deployment and close the remaining gap in createSearchIndex().

      Context

      MongoDBVector records each index in a registry collection, _mastra_vector_indexes_. Each entry maps a logical index name (for example precedents) to the collection and search indexes behind it. A call reads the entry, checks that it's compatible, then writes. Another process can change the entry between that read and the write.

      createIndex() only writes if the entry still has the collection and embedding settings it checked. A conflicting concurrent call gets a CONFLICT error ("registered concurrently"). Only a unit test with a mocked registry covers this today.

      createSearchIndex() updates an existing entry's text index name without that condition. If two calls with different text index names run at the same time, the last write wins. The other call's text index is still created on the collection, but nothing in the registry points to it, so deleteIndex() never removes it.

      Desired User Experience

      // Two processes register the same logical index at the same time.
      await Promise.allSettled([
        storeA.createIndex({ indexName: 'precedents', dimension: 1024, collectionName: 'transactions' }),
        storeB.createIndex({ indexName: 'precedents', dimension: 1024, collectionName: 'refunds' }),
      ]);
      // Before and after: one wins; the other throws CONFLICT. After: confirmed against a real deployment.
      
      await Promise.allSettled([
        storeA.createSearchIndex({ indexName: 'precedents', searchIndexName: 'txt_a' }),
        storeB.createSearchIndex({ indexName: 'precedents', searchIndexName: 'txt_b' }),
      ]);
      // Before: both succeed; the registry keeps one name and the other text index is left on the collection.
      // After:  one wins; the other gets a clear conflict error and leaves no unregistered index behind.
      

      Task

      Goals: Setting up indexes from several processes at once can't leave the registry pointing at a different index than the one that exists.

      Where: createIndex() registry write and createSearchIndex() registry write in stores/mongodb/src/vector/index.ts.

      Acceptance Criteria

      • [ ] Concurrent conflicting createIndex() calls are verified against a real MongoDB deployment: exactly one succeeds.
      • [ ] Concurrent createSearchIndex() calls with different text index names behave the same way and leave no unregistered text index.
      • [ ] Identical repeated or concurrent registrations still succeed.

            Assignee:
            Unassigned
            Reporter:
            Raschid Jimenez
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: