Skip to content

fix: prevent nil dereference and dropped errors in RAGEngine validation - #1893

Open
archy-rock3t-cloud wants to merge 1 commit into
kaito-project:mainfrom
sophotechlabs:fix/ragengine-validation-nil-guards
Open

fix: prevent nil dereference and dropped errors in RAGEngine validation#1893
archy-rock3t-cloud wants to merge 1 commit into
kaito-project:mainfrom
sophotechlabs:fix/ragengine-validation-nil-guards

Conversation

@archy-rock3t-cloud

Copy link
Copy Markdown
Contributor

Reason for Change:
Add nil guards for InferenceService and Compute, and capture previously discarded embedding validation errors in both v1alpha1 and v1beta1.

Requirements

  • added unit tests and e2e tests (if applicable).

Issue Fixed:

Notes for Reviewers:

@kaito-pr-agent

Copy link
Copy Markdown
Contributor

Failed to generate code suggestions for PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates RAGEngine admission validation (both v1alpha1 and v1beta1) to avoid nil dereferences and to correctly aggregate/return embedding validation errors, along with corresponding unit test additions.

Changes:

  • Add nil guards around InferenceService validation to prevent dereferencing a nil pointer.
  • Guard Compute validation and start aggregating embedding validation errors via errs.Also(...).
  • Extend validation unit tests with cases for nil InferenceService, nil Compute, and invalid local embedding image.

Reviewed changes

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

File Description
api/v1beta1/ragengine_validation.go Adds nil guard for InferenceService and begins aggregating embedding validation errors; adds a nil check around Compute validation.
api/v1beta1/ragengine_validation_test.go Adds unit tests covering nil InferenceService, nil Compute, and embedding error propagation.
api/v1alpha1/ragengine_validation.go Same validation adjustments as v1beta1.
api/v1alpha1/ragengine_validation_test.go Same unit test additions as v1beta1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/v1beta1/ragengine_validation.go Outdated
Comment on lines +72 to +74
if w.Spec.Compute != nil {
errs = errs.Also(w.Spec.Compute.validateRAGCreate())
}

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

Compute is treated as optional here (validation is skipped when nil), but downstream RAGEngine controller/manifests dereference Spec.Compute unconditionally (e.g., to read InstanceType and LabelSelector). This can let invalid specs pass admission and then panic at reconcile time. Consider preserving the pre-existing effective requirement by returning a missing-field error when w.Spec.Compute == nil (or at least when local embedding is used), and only then calling validateRAGCreate().

Copilot uses AI. Check for mistakes.
Comment thread api/v1alpha1/ragengine_validation.go Outdated
Comment on lines +72 to +74
if w.Spec.Compute != nil {
errs = errs.Also(w.Spec.Compute.validateRAGCreate())
}

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

Compute is treated as optional here (validation is skipped when nil), but the RAGEngine controller/manifests dereference Spec.Compute unconditionally. This can let invalid specs pass admission and then panic at reconcile time. Consider returning a missing-field error when w.Spec.Compute == nil (or at least when local embedding is used) and only then calling validateRAGCreate().

Copilot uses AI. Check for mistakes.
},
},
},
wantErr: false,

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

This test asserts that Compute can be nil with a local embedding spec and still validate successfully. Given the controller/manifests dereference Spec.Compute (InstanceType/LabelSelector) when reconciling a RAGEngine, allowing nil here is likely to cause runtime panics. Either adjust validation to require Compute (and update this test accordingly), or update the controller/manifests to safely handle a nil Compute.

Suggested change
wantErr: false,
wantErr: true,
errField: "Compute must be specified",
Copilot uses AI. Check for mistakes.
},
},
},
wantErr: false,

Copilot AI Mar 31, 2026

Copy link

Choose a reason for hiding this comment

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

This test asserts that Compute can be nil with a local embedding spec and still validate successfully. Given the controller/manifests dereference Spec.Compute (InstanceType/LabelSelector) when reconciling a RAGEngine, allowing nil here is likely to cause runtime panics. Either adjust validation to require Compute (and update this test accordingly), or update the controller/manifests to safely handle a nil Compute.

Suggested change
wantErr: false,
wantErr: true,
errField: "",
Copilot uses AI. Check for mistakes.
errs = errs.Also(w.Spec.Compute.validateRAGCreate())
if w.Spec.Compute != nil {
errs = errs.Also(w.Spec.Compute.validateRAGCreate())
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We should error on nil compute as well

},
},
},
wantErr: false,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this should error

@bfoley13

bfoley13 commented Apr 3, 2026

Copy link
Copy Markdown
Collaborator

@archy-rock3t-cloud please make updates

@archy-rock3t-cloud
archy-rock3t-cloud force-pushed the fix/ragengine-validation-nil-guards branch 2 times, most recently from 05984b1 to b0eef6e Compare April 9, 2026 08:50
@archy-rock3t-cloud

Copy link
Copy Markdown
Contributor Author

@bfoley13 updated

@archy-rock3t-cloud
archy-rock3t-cloud force-pushed the fix/ragengine-validation-nil-guards branch from 9811b88 to 389e86d Compare April 9, 2026 08:53
Signed-off-by: Artem Muterko <artem@sopho.tech>
@archy-rock3t-cloud
archy-rock3t-cloud force-pushed the fix/ragengine-validation-nil-guards branch from 389e86d to 050037f Compare April 28, 2026 09:59
@archy-rock3t-cloud

Copy link
Copy Markdown
Contributor Author

@bfoley13 friendly bump — addressed both nil-Compute checks (v1alpha1 + v1beta1 validation.go) and added the corresponding "Nil Compute" test case asserting it errors. Rebased on main. Anything else needed?

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants