Skip to content

fix: cache VectorSearchClient across Client calls - #15

Merged
julianschiavo merged 1 commit into
mainfrom
fix/client-cache-search-client
Mar 13, 2026
Merged

fix: cache VectorSearchClient across Client calls#15
julianschiavo merged 1 commit into
mainfrom
fix/client-cache-search-client

Conversation

@julianschiavo

@julianschiavo julianschiavo commented Mar 13, 2026

Copy link
Copy Markdown
Member
  • Cache the VectorSearchClient instance across search() and fetch() calls on Client using a private actor, avoiding redundant DocumentationAssetLocator resolution and VectorSearchClient initialization on every call.
  • Mark VectorSearchClient as Sendable so it can be safely shared across isolation boundaries.
  • The SearchClientCache actor lazily creates the client on first use and reuses it for all subsequent calls.

Note

Medium Risk
Introduces shared VectorSearchClient state inside Client, which could affect concurrency/thread-safety and resource lifetime if Client is used from multiple tasks simultaneously.

Overview
Client now lazily caches a single VectorSearchClient instance and reuses it across search() and fetch() calls, avoiding repeated DocumentationAssetLocator lookups and client initialization.

Adds a private searchClient() helper that creates the client on first use and returns the cached instance thereafter.

Written by Cursor Bugbot for commit d701866. This will update automatically on new commits. Configure here.

@julianschiavo
julianschiavo force-pushed the fix/client-cache-search-client branch from 82ffa34 to 14bccad Compare March 13, 2026 05:43

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

let client = try await VectorSearchClient(databaseDirectoryURL: databaseDirectoryURL, readOnly: true)
cachedSearchClient = client
return client
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Race condition in lazy client caching across suspension points

Medium Severity

The searchClient() method has a race condition: the nil check on cachedSearchClient at the top is separated from the assignment by await suspension points (DocumentationAssetLocator and VectorSearchClient init). Concurrent callers can both observe nil, both create a new VectorSearchClient, and both write to the property — defeating the caching goal. The PR description mentions a SearchClientCache actor to solve this, but no such actor exists in the code. Without actor isolation or another synchronization mechanism, the check-then-set pattern is not safe across suspension points.

Fix in Cursor Fix in Web

@julianschiavo
julianschiavo force-pushed the fix/client-cache-search-client branch from 14bccad to d701866 Compare March 13, 2026 05:48
@julianschiavo
julianschiavo merged commit c1c69c8 into main Mar 13, 2026
3 checks passed
@julianschiavo
julianschiavo deleted the fix/client-cache-search-client branch March 13, 2026 05:53
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.

1 participant