Skip to content

aiEmbeddingVector: reject empty model during provider registration#300254

Open
cohenvelazquez wants to merge 3 commits intomicrosoft:mainfrom
cohenvelazquez:cohenvelazquez/issue297161
Open

aiEmbeddingVector: reject empty model during provider registration#300254
cohenvelazquez wants to merge 3 commits intomicrosoft:mainfrom
cohenvelazquez:cohenvelazquez/issue297161

Conversation

@cohenvelazquez
Copy link

@cohenvelazquez cohenvelazquez commented Mar 9, 2026

Fixes #297161

Summary

Reject empty/whitespace model values when registering AI embedding vector providers.

Changes

  • Added isFalsyOrWhitespace(model) validation with a clear error in:
    • src/vs/workbench/api/common/extHostEmbeddingVector.ts
    • src/vs/workbench/api/browser/mainThreadAiEmbeddingVector.ts
    • src/vs/workbench/services/aiEmbeddingVector/common/aiEmbeddingVectorService.ts
  • Added tests in:
    • src/vs/workbench/services/aiEmbeddingVector/test/common/aiEmbeddingVectorService.test.ts

How to test

  1. Run unit tests for the new suite and confirm:
    • empty model is rejected
    • whitespace-only model is rejected
    • valid model still registers/unregisters
  2. (Optional runtime verification) attempt registration with '' and confirm error:
    • Embedding vector model must be a non-empty string.

Copilot AI review requested due to automatic review settings March 9, 2026 20:25
Copy link
Author

@cohenvelazquez cohenvelazquez left a comment

Choose a reason for hiding this comment

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

@microsoft-github-policy-service agree

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds stricter input validation to the AI embedding vector provider registration flow to prevent empty/whitespace model identifiers from being accepted, improving API contract robustness across ext host, main thread, and the underlying service.

Changes:

  • Validate model with isFalsyOrWhitespace(model) during provider registration and throw a clear error on invalid values.
  • Add unit tests ensuring empty/whitespace models are rejected and valid models still register/unregister correctly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/vs/workbench/api/common/extHostEmbeddingVector.ts Rejects empty/whitespace model at the extension-host API boundary.
src/vs/workbench/api/browser/mainThreadAiEmbeddingVector.ts Adds model validation on the main thread registration entrypoint.
src/vs/workbench/services/aiEmbeddingVector/common/aiEmbeddingVectorService.ts Enforces model validation at the service level.
src/vs/workbench/services/aiEmbeddingVector/test/common/aiEmbeddingVectorService.test.ts Adds coverage for invalid/valid model registration scenarios.

Comment on lines +26 to +30
$registerAiEmbeddingVectorProvider(model: string, handle: number): void {
if (isFalsyOrWhitespace(model)) {
throw new Error('Embedding vector model must be a non-empty string.');
}

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

Throwing from $registerAiEmbeddingVectorProvider is risky because this method is invoked via the ext host RPC proxy where the caller does not await/handle failures (the protocol declares void). A thrown error becomes a rejected LazyPromise, and if nobody is listening it is reported via onUnexpectedError, which can surface as an unexpected error rather than a clean argument rejection. Consider either (1) changing the protocol shape to return Promise<void> and awaiting it on the ext-host side so the error is properly propagated, or (2) avoid throwing here (e.g., log + ignore) and rely on ext-host/service-side validation for rejection.

Copilot uses AI. Check for mistakes.
Copy link
Author

@cohenvelazquez cohenvelazquez Mar 9, 2026

Choose a reason for hiding this comment

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

Thanks for the review — agreed on the RPC risk.

I’ve updated the fix so we no longer throw from mainThread RPC registration ($registerAiEmbeddingVectorProvider, which is void) in the latest commit.

Validation/rejection now lives in:

  • ext-host registration boundary
  • aiEmbeddingVectorService registration (defense-in-depth)

I also kept/updated unit tests to cover empty and whitespace-only model rejection, plus valid registration behavior.

Addressed in commit: aiEmbeddingVector: avoid throwing from main-thread RPC registration

@cohenvelazquez
Copy link
Author

@microsoft-github-policy-service agree

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.

aiEmbeddingVector: reject empty/whitespace model when registering providers

3 participants