Skip to content

Fix model env var to use provider-specific name#40

Draft
jameswnl wants to merge 1 commit into
openshift:mainfrom
jameswnl:fix/provider-model-env-var
Draft

Fix model env var to use provider-specific name#40
jameswnl wants to merge 1 commit into
openshift:mainfrom
jameswnl:fix/provider-model-env-var

Conversation

@jameswnl
Copy link
Copy Markdown

@jameswnl jameswnl commented Jun 3, 2026

Summary

  • The sandbox reads OPENAI_MODEL for OpenAI and GEMINI_MODEL for Gemini providers, but the operator always set ANTHROPIC_MODEL regardless of provider type
  • This caused the sandbox to fall back to its default model (claude-opus-4-6) when using non-Anthropic providers, resulting in API errors (e.g., "model not found" when using OpenAI)
  • Adds modelEnvVarForProvider() helper that maps LLMProviderType to the correct env var name

Test plan

  • Verified with OpenAI provider: OPENAI_MODEL=gpt-5.5 correctly set in sandbox pod env
  • Verified with existing Anthropic provider: ANTHROPIC_MODEL still used (default case)
  • go test ./controller/proposal/... -count=1 passes
  • End-to-end test with GPT-5.5 SandboxAgent on Kind cluster

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed incorrect environment variable assignment in sandbox templates that now correctly applies provider-specific variables for OpenAI, Gemini, and Anthropic LLM providers.

@openshift-ci openshift-ci Bot requested review from harche and xrajesh June 3, 2026 03:33
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 3, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 8d6e61a0-4d71-4057-9c52-7a4ee06852b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR introduces provider-aware LLM model environment variable configuration. A new helper function modelEnvVarForProvider maps LLM provider types to their corresponding environment variable names, and patchLLMCredentials is updated to use this helper instead of hardcoding ANTHROPIC_MODEL for all providers.

Changes

Provider-aware LLM model environment variables

Layer / File(s) Summary
Provider-aware model environment variable setup
controller/proposal/sandbox_templates.go
modelEnvVarForProvider helper maps provider types to env var names (OPENAI_MODEL, GEMINI_MODEL, ANTHROPIC_MODEL); patchLLMCredentials now uses this helper to set the provider-specific model env var instead of the hardcoded ANTHROPIC_MODEL.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

lgtm

Suggested reviewers

  • harche
  • blublinsky
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing model environment variables to use provider-specific names instead of hardcoded ANTHROPIC_MODEL.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 3, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign joshuawilson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented Jun 3, 2026

Hi @jameswnl. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@openshift-ci openshift-ci Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 3, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controller/proposal/sandbox_templates.go`:
- Around line 308-317: The modelEnvVarForProvider switch incorrectly falls
through to default for Azure; update the function (modelEnvVarForProvider) to
add an explicit case for agenticv1alpha1.LLMProviderAzureOpenAI that returns the
correct env var (e.g., "OPENAI_MODEL") instead of letting it return
"ANTHROPIC_MODEL", and add/adjust a unit test (patchLLMCredentials_AzureOpenAI)
asserting that patchLLMCredentials produces the sandbox env var expected for
Azure (matching the AZURE_OPENAI_ENDPOINT mapping), mirroring the existing
Anthropic test pattern.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 7bdb95ac-91f6-49b0-a640-c400787e1bf4

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac45f7 and fee7df6.

📒 Files selected for processing (1)
  • controller/proposal/sandbox_templates.go

Comment on lines +308 to +317
func modelEnvVarForProvider(t agenticv1alpha1.LLMProviderType) string {
switch t {
case agenticv1alpha1.LLMProviderOpenAI:
return "OPENAI_MODEL"
case agenticv1alpha1.LLMProviderGoogleCloudVertex:
return "GEMINI_MODEL"
default:
return "ANTHROPIC_MODEL"
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find any references to model env var names to confirm expected sandbox contract.
rg -nP '\b(AZURE_OPENAI_MODEL|OPENAI_MODEL|GEMINI_MODEL|ANTHROPIC_MODEL)\b'
# Inspect tests covering modelEnvVarForProvider / patchLLMCredentials for each provider.
rg -nP -C3 'modelEnvVarForProvider|patchLLMCredentials' --type=go

Repository: openshift/lightspeed-agentic-operator

Length of output: 5061


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# 1) Find where AZURE_OPENAI_ENDPOINT is used/mapped
rg -n --hidden -S "AZURE_OPENAI_ENDPOINT" .

# 2) Find any other Azure-specific env var names (esp. *MODEL)
rg -n --hidden -S "AZURE.*MODEL|MODEL.*AZURE|AZURE_.*" controller/proposal/sandbox_templates.go controller/proposal/sandbox_templates_test.go || true

# 3) Check if tests cover AzureOpenAI in patchLLMCredentials / modelEnvVarForProvider
rg -n --hidden -S "AzureOpenAI|AZURE_OPENAI" controller/proposal/sandbox_templates_test.go

# 4) Show providerURLEnvVar implementation and nearby helpers for env var mapping
sed -n '280,380p' controller/proposal/sandbox_templates.go

Repository: openshift/lightspeed-agentic-operator

Length of output: 4434


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show AzureOpenAI-related tests (if any) and model/env var assertions
rg -n "AzureOpenAI|AZURE_OPENAI|OPENAI_MODEL|ANTHROPIC_MODEL|GEMINI_MODEL|AWSBedrock|CLAUDE_CODE_USE_BEDROCK" controller/proposal/sandbox_templates_test.go

# Print the relevant sections around patchLLMCredentials tests
sed -n '200,360p' controller/proposal/sandbox_templates_test.go

Repository: openshift/lightspeed-agentic-operator

Length of output: 6590


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Focused checks in the file under review
rg -n "AZURE_|OPENAI_|MODEL|ANTHROPIC_MODEL|OPENAI_MODEL|GEMINI_MODEL" controller/proposal/sandbox_templates.go

# Show the patchLLMCredentials + helper functions area with line context
sed -n '140,380p' controller/proposal/sandbox_templates.go

Repository: openshift/lightspeed-agentic-operator

Length of output: 8213


🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n "const Err|Err[A-Za-z0-9_]+" controller/proposal/sandbox_templates.go

Repository: openshift/lightspeed-agentic-operator

Length of output: 3470


Fix AzureOpenAI model env var mapping (avoid setting ANTHROPIC_MODEL for Azure)

controller/proposal/sandbox_templates.go lines 308-317: modelEnvVarForProvider has cases for OpenAI and GoogleCloudVertex only; LLMProviderAzureOpenAI falls to default, so patchLLMCredentials sets ANTHROPIC_MODEL for Azure. This is inconsistent with the Azure-specific URL mapping (AZURE_OPENAI_ENDPOINT set in patchLLMCredentials), and will likely break the sandbox contract for Azure by reintroducing the “non-Anthropic gets ANTHROPIC_MODEL” issue.

🐛 Proposed fix
func modelEnvVarForProvider(t agenticv1alpha1.LLMProviderType) string {
	switch t {
	case agenticv1alpha1.LLMProviderOpenAI:
+	case agenticv1alpha1.LLMProviderOpenAI, agenticv1alpha1.LLMProviderAzureOpenAI:
		return "OPENAI_MODEL"
	case agenticv1alpha1.LLMProviderGoogleCloudVertex:
		return "GEMINI_MODEL"
	default:
		return "ANTHROPIC_MODEL"
	}
}

Add/adjust a patchLLMCredentials_AzureOpenAI test asserting the model env var the sandbox expects for Azure (e.g., OPENAI_MODEL), similar to how the Anthropic test asserts ANTHROPIC_MODEL.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
func modelEnvVarForProvider(t agenticv1alpha1.LLMProviderType) string {
switch t {
case agenticv1alpha1.LLMProviderOpenAI:
return "OPENAI_MODEL"
case agenticv1alpha1.LLMProviderGoogleCloudVertex:
return "GEMINI_MODEL"
default:
return "ANTHROPIC_MODEL"
}
}
func modelEnvVarForProvider(t agenticv1alpha1.LLMProviderType) string {
switch t {
case agenticv1alpha1.LLMProviderOpenAI, agenticv1alpha1.LLMProviderAzureOpenAI:
return "OPENAI_MODEL"
case agenticv1alpha1.LLMProviderGoogleCloudVertex:
return "GEMINI_MODEL"
default:
return "ANTHROPIC_MODEL"
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controller/proposal/sandbox_templates.go` around lines 308 - 317, The
modelEnvVarForProvider switch incorrectly falls through to default for Azure;
update the function (modelEnvVarForProvider) to add an explicit case for
agenticv1alpha1.LLMProviderAzureOpenAI that returns the correct env var (e.g.,
"OPENAI_MODEL") instead of letting it return "ANTHROPIC_MODEL", and add/adjust a
unit test (patchLLMCredentials_AzureOpenAI) asserting that patchLLMCredentials
produces the sandbox env var expected for Azure (matching the
AZURE_OPENAI_ENDPOINT mapping), mirroring the existing Anthropic test pattern.

@jameswnl jameswnl marked this pull request as draft June 3, 2026 03:42
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 3, 2026
…ODEL

The sandbox reads OPENAI_MODEL for the OpenAI provider and GEMINI_MODEL
for Gemini, but the operator always set ANTHROPIC_MODEL regardless of
provider type. This caused the sandbox to fall back to its default model
(claude-opus-4-6) even when the Agent CR specified a different model,
breaking non-Anthropic providers.

Add modelEnvVarForProvider() that maps LLMProvider to the correct env
var name. For Vertex, consults GoogleCloudVertex.ModelProvider to pick
the right SDK env var (Anthropic on Vertex → ANTHROPIC_MODEL, Google
models → GEMINI_MODEL, OpenAI-compat → OPENAI_MODEL). AzureOpenAI
maps to OPENAI_MODEL since it uses the same SDK.

Note: this is a stopgap until both operator and sandbox migrate to the
generic LIGHTSPEED_MODEL env var per spec rule 16a (OLS-3153).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jameswnl jameswnl force-pushed the fix/provider-model-env-var branch from fee7df6 to aae895b Compare June 3, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant