From d935c3113afac1d12106979ee52814adcbac7b3b Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Mon, 22 Jun 2026 12:39:05 -0700 Subject: [PATCH] Preserve existing environment overrides Keep saved non-local overrides visible even when they are not runnable so operators can inspect or clear stale environment selections. Co-Authored-By: Paperclip --- .../AgentConfigForm.render.test.tsx | 27 +++++++++++++++++-- ui/src/components/AgentConfigForm.tsx | 10 ++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ui/src/components/AgentConfigForm.render.test.tsx b/ui/src/components/AgentConfigForm.render.test.tsx index 4540f47a42f..9d94ed50738 100644 --- a/ui/src/components/AgentConfigForm.render.test.tsx +++ b/ui/src/components/AgentConfigForm.render.test.tsx @@ -155,7 +155,7 @@ function makeEnvironment(overrides: Partial): Environment { }; } -async function renderForm(environments: Environment[]) { +async function renderForm(environments: Environment[], agentOverrides: Partial = {}) { mockEnvironmentsApi.list.mockResolvedValue(environments); const container = document.createElement("div"); @@ -174,7 +174,7 @@ async function renderForm(environments: Environment[]) { { expect(text).not.toContain("Leave this unset to inherit the instance default"); expect(text).not.toContain("Inherit instance default"); }); + + it("keeps an existing non-runnable override visible so it can be cleared", async () => { + const result = await renderForm( + [ + makeEnvironment({ id: "local-1", name: "Local", driver: "local" }), + makeEnvironment({ + id: "fake-sandbox-1", + name: "Fake Sandbox", + driver: "sandbox", + config: { provider: "fake" }, + }), + ], + { defaultEnvironmentId: "fake-sandbox-1" }, + ); + roots.push(result.root); + + const text = result.container.textContent ?? ""; + const selector = result.container.querySelector("select"); + + expect(text).toContain("Environment override"); + expect(selector?.textContent).toContain("Default: Local"); + expect(selector?.textContent).toContain("Fake Sandbox · sandbox"); + }); }); diff --git a/ui/src/components/AgentConfigForm.tsx b/ui/src/components/AgentConfigForm.tsx index c1c69ecae00..a673f2ca078 100644 --- a/ui/src/components/AgentConfigForm.tsx +++ b/ui/src/components/AgentConfigForm.tsx @@ -400,11 +400,19 @@ export function AgentConfigForm(props: AgentConfigFormProps) { }), [environments, supportedEnvironmentDrivers], ); + const environmentOptions = useMemo(() => { + if (!currentDefaultEnvironment) return runnableEnvironments; + if (runnableEnvironments.some((environment) => environment.id === currentDefaultEnvironment.id)) { + return runnableEnvironments; + } + return [...runnableEnvironments, currentDefaultEnvironment]; + }, [currentDefaultEnvironment, runnableEnvironments]); // `runnableEnvironments` excludes the always-available Local environment, so a // single entry already means the user has more than one environment configured // (Local + that environment) and the override selector is meaningful. const showEnvironmentOverrideControl = environmentsEnabled && ( forcedKubernetes || + currentDefaultEnvironmentId.length > 0 || runnableEnvironments.length >= 1 ); const inheritedEnvironmentLabel = instanceDefaultEnvironment @@ -929,7 +937,7 @@ export function AgentConfigForm(props: AgentConfigFormProps) { }} > - {runnableEnvironments.map((environment) => ( + {environmentOptions.map((environment) => (