Skip to content

fix(operator): move vmcp embedding defaulting out of Validate - #7053

Merged
ChrisJBurns merged 3 commits into
stacklok:mainfrom
feiiiiii5:fix/vmcp-embedding-defaulting
Nov 25, 2026
Merged

ChrisJBurns merged 3 commits into
stacklok:mainfrom
feiiiiii5:fix/vmcp-embedding-defaulting

Conversation

@feiiiiii5

Copy link
Copy Markdown
Contributor

Summary

  • VirtualMCPServer.Validate() filled the default Spec.Config.Optimizer while validating. Validate runs on a cached object, so the default never reached the API and callers could not tell validation from defaulting.
  • Move the defaulting into a new ApplyDefaults() and make Validate() pure; the controller calls ApplyDefaults() before Validate() so the existing behaviour is preserved.

Fixes #4628

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (go test ./cmd/thv-operator/api/v1beta1 -count=1 passes; controllers package compiles)
  • E2E tests (task test-e2e)
  • Linting (go vet on both packages and gofmt clean)
  • Manual testing (describe below)

New regressions assert that Validate() leaves Optimizer nil (and reports the same validation result), and that ApplyDefaults() fills only the nil optimizer when an embedding server ref is set. The existing test that relied on the mutation now calls ApplyDefaults() explicitly.

API Compatibility

  • This PR does not break the v1beta1 API, OR the api-break-allowed label is applied and the migration guidance is described above.

Changes

File Change
virtualmcpserver_types.go Add ApplyDefaults(); Validate() no longer mutates the optimizer
virtualmcpserver_types_test.go Validate-is-pure and ApplyDefaults regressions; update the old mutation-dependent test
virtualmcpserver_controller.go Call ApplyDefaults() before Validate() in validateSpec

Does this introduce a user-facing change?

No. The default optimizer is still applied before reconciliation; it is now applied explicitly instead of as a side effect of validation.

Implementation plan

Approved implementation plan
  1. Confirm the mutation in validateEmbeddingServer and identify the controller call site.
  2. Extract it to ApplyDefaults() with the same guard (embedding server ref set, optimizer nil).
  3. Make Validate() non-mutating and call ApplyDefaults() from validateSpec before Validate().
  4. Add the two regressions and run the api package tests plus a controllers compile.

Special notes for reviewers

Validate() keeps returning the same errors; only the side effect is gone. A caller that relied on Validate() to populate the optimizer must now call ApplyDefaults() (the controller does).

VirtualMCPServer.Validate mutated the cached object by filling Spec.Config.Optimizer, a hidden defaulting that never reached the API. Add ApplyDefaults for the embedding optimizer default, make Validate pure, and call ApplyDefaults from the controller validateSpec before Validate so existing behavior is preserved. Add regressions for Validate not mutating and ApplyDefaults filling only the nil optimizer.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-04T12:11:39.232798Z
We couldn’t complete this review. Comment @codex review to try again.
181cd4c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Exercise controller-side defaulting through validateSpec before checking the
embedding URL. Avoid shadowing the vmcp import and cover preservation of
explicit optimizer settings and repeated defaulting. Update the stale
validation-side defaulting comment.
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.70%. Comparing base (a364591) to head (40a2bf2).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7053      +/-   ##
==========================================
- Coverage   80.76%   80.70%   -0.06%     
==========================================
  Files         859      859              
  Lines       87914    87915       +1     
==========================================
- Hits        71001    70956      -45     
- Misses      16908    16954      +46     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Bring in the upstream codespell correction for percent-encoded Unicode
resource URI examples, together with the v0.62.0 release baseline.
@ChrisJBurns
ChrisJBurns merged commit 7a249a5 into stacklok:main Nov 25, 2026
43 checks passed
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.

Extract mutation from Validate method into separate defaulting logic

2 participants