Skip to content

fix(adapters): make addDocuments atomic to prevent partial store corruption#2986

Merged
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
ionfwsrijan:fix/2981-vectorstore-add-documents-atomic
Jul 24, 2026
Merged

fix(adapters): make addDocuments atomic to prevent partial store corruption#2986
Karanjot786 merged 1 commit into
Karanjot786:mainfrom
ionfwsrijan:fix/2981-vectorstore-add-documents-atomic

Conversation

@ionfwsrijan

Copy link
Copy Markdown
Contributor

Summary

Made addDocuments atomic to prevent partial store corruption.

Problem

If ai.embed() failed on document N, documents 0..N-1 were already pushed into the store while N+1..end were missing, leaving the store in a corrupted partial state.

Fix

All documents are now embedded first via Promise.all, and only pushed to _documents after all embeddings succeed. If any embed fails, nothing is added to the store.

Changed

  • packages/adapters/src/ai/vectorStore.ts: Changed for loop to Promise.all with deferred push

Fixes #2981

…uption

If ai.embed() failed on document N, documents 0..N-1 were already pushed
into the store while N+1..end were missing, leaving the store in a
corrupted partial state. Now all documents are embedded first via
Promise.all, and only pushed to the store after all embeddings succeed.

Fixes Karanjot786#2981
@ionfwsrijan
ionfwsrijan requested a review from Karanjot786 as a code owner July 24, 2026 10:50
@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@ionfwsrijan, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bc24571c-f2ec-4275-b3fc-194bdc0d39ae

📥 Commits

Reviewing files that changed from the base of the PR and between 61eaa4e and 7a1eab1.

📒 Files selected for processing (1)
  • packages/adapters/src/ai/vectorStore.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the type:bug +10 pts. Bug fix. label Jul 24, 2026
@ionfwsrijan

Copy link
Copy Markdown
Contributor Author

@Karanjot786 Please review this

@Karanjot786
Karanjot786 merged commit d683e1a into Karanjot786:main Jul 24, 2026
7 checks passed
@Karanjot786 Karanjot786 added gssoc:approved Approved PR. Earns +50 base points. quality:clean x 1.2 multiplier. Clean implementation. level:intermediate +35 pts. Moderate task. labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved PR. Earns +50 base points. level:intermediate +35 pts. Moderate task. quality:clean x 1.2 multiplier. Clean implementation. type:bug +10 pts. Bug fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] LocalVectorStore addDocuments Leaves Store in Inconsistent State on Partial Failure

2 participants