Repository navigation
fix(agent-runner): reconcile an environment's LLM env (key, base URL, model) on every start #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pikann
merged 1 commit into
Paca-AI:master
from
siedlegroup:fix/environment-llm-env-reconcile
Oct 28, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -823,3 +823,103 @@ func deploymentEnvMap(t *testing.T, m *Manager, name string) map[string]string { | |
| } | ||
| return out | ||
| } | ||
|
|
||
| // envMapOf reads backendRef's Deployment container env into a map. | ||
| func envMapOf(t *testing.T, m *Manager, name string) map[string]string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| t.Helper() | ||
| got, err := m.clientset.AppsV1().Deployments(m.namespace).Get(context.Background(), name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| t.Fatalf("get deployment: %v", err) | ||
| } | ||
| out := map[string]string{} | ||
| for _, ev := range got.Spec.Template.Spec.Containers[0].Env { | ||
| out[ev.Name] = ev.Value | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| // TestEnsureEnvironmentInfraEnv_RefreshesSameProviderLLMKeys pins the fix | ||
| // for a static environment that fails every attach with "Authentication | ||
| // required": the Pod keeps whatever model, key and base URL it was created | ||
| // with while the agent row has moved on, so the next start must reconcile | ||
| // all three — a rotated key is the case that actually breaks the turn. | ||
| func TestEnsureEnvironmentInfraEnv_RefreshesSameProviderLLMKeys(t *testing.T) { | ||
| const name = "paca-env-env5" | ||
| existing := []corev1.EnvVar{ | ||
| {Name: "GOOSE_PROVIDER", Value: "openai"}, | ||
| {Name: "GOOSE_MODEL", Value: "old-model"}, | ||
| {Name: "OPENAI_API_KEY", Value: "sk-revoked"}, | ||
| {Name: "OPENAI_HOST", Value: "https://gateway.example"}, | ||
| {Name: "GITHUB_TOKEN", Value: "gh-keep"}, | ||
| } | ||
| m := managerWithDeployment("paca", deploymentFixtureWithEnv(name, existing)) | ||
|
|
||
| cfg := sandbox.EnvironmentConfig{ | ||
| Env: map[string]string{ | ||
| "GOOSE_PROVIDER": "openai", | ||
| "GOOSE_MODEL": "new-model", | ||
| "OPENAI_API_KEY": "sk-fresh", | ||
| "OPENAI_HOST": "https://ollama.com", | ||
| "PACA_API_KEY": "paca-key", | ||
| "GITHUB_TOKEN": "gh-keep", | ||
| }, | ||
| LLMKeyEnvVar: "OPENAI_API_KEY", | ||
| } | ||
| if err := m.ensureEnvironmentInfraEnv(context.Background(), name, cfg); err != nil { | ||
| t.Fatalf("ensureEnvironmentInfraEnv: %v", err) | ||
| } | ||
|
|
||
| got := envMapOf(t, m, name) | ||
| for k, want := range cfg.Env { | ||
| if got[k] != want { | ||
| t.Errorf("deployment env[%q] = %q, want %q", k, got[k], want) | ||
| } | ||
| } | ||
| if got["GITHUB_TOKEN"] != "gh-keep" { | ||
| t.Errorf("deployment env[GITHUB_TOKEN] = %q, want the user env var left alone", got["GITHUB_TOKEN"]) | ||
| } | ||
| } | ||
|
|
||
| // TestEnsureEnvironmentInfraEnv_LeavesLLMKeysWhenProviderDiffers is the | ||
| // other half of the gate: a model id, key var and base URL belonging to a | ||
| // different provider than the one the Pod is frozen to are meaningless | ||
| // there, so they must not be applied — only the PACA_* keys reconcile. | ||
| func TestEnsureEnvironmentInfraEnv_LeavesLLMKeysWhenProviderDiffers(t *testing.T) { | ||
| const name = "paca-env-env6" | ||
| existing := []corev1.EnvVar{ | ||
| {Name: "GOOSE_PROVIDER", Value: "openai"}, | ||
| {Name: "GOOSE_MODEL", Value: "frozen-model"}, | ||
| {Name: "OPENAI_API_KEY", Value: "sk-frozen"}, | ||
| {Name: "OPENAI_HOST", Value: "https://ollama.com"}, | ||
| } | ||
| m := managerWithDeployment("paca", deploymentFixtureWithEnv(name, existing)) | ||
|
|
||
| cfg := sandbox.EnvironmentConfig{ | ||
| Env: map[string]string{ | ||
| "GOOSE_PROVIDER": "anthropic", | ||
| "GOOSE_MODEL": "claude-sonnet-5", | ||
| "ANTHROPIC_API_KEY": "sk-ant", | ||
| "PACA_API_KEY": "paca-key", | ||
| }, | ||
| LLMKeyEnvVar: "ANTHROPIC_API_KEY", | ||
| } | ||
| if err := m.ensureEnvironmentInfraEnv(context.Background(), name, cfg); err != nil { | ||
| t.Fatalf("ensureEnvironmentInfraEnv: %v", err) | ||
| } | ||
|
|
||
| got := envMapOf(t, m, name) | ||
| for k, want := range map[string]string{ | ||
| "GOOSE_PROVIDER": "openai", | ||
| "GOOSE_MODEL": "frozen-model", | ||
| "OPENAI_API_KEY": "sk-frozen", | ||
| "OPENAI_HOST": "https://ollama.com", | ||
| "PACA_API_KEY": "paca-key", | ||
| } { | ||
| if got[k] != want { | ||
| t.Errorf("deployment env[%q] = %q, want %q", k, got[k], want) | ||
| } | ||
| } | ||
| if _, ok := got["ANTHROPIC_API_KEY"]; ok { | ||
| t.Errorf("deployment env[ANTHROPIC_API_KEY] = %q, want it absent (another provider's key var)", got["ANTHROPIC_API_KEY"]) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
provider_clibranch also has a native auth key:buildProviderCLIContainerEnvwritesANTHROPIC_API_KEY/GEMINI_API_KEY/OPENAI_API_KEYfromCLIAPIKeySecretwhenCLIAuthMode == "api_key". LeavingLLMKeyEnvVarempty for these agents keeps a rotated CLI key frozen on the Pod — the same failure this PR fixes for LLM agents.Technical details