From ce8d9eb3234f25390703348e9ad17311eb7987d5 Mon Sep 17 00:00:00 2001 From: "Cody (Radius Red)" Date: Tue, 31 Mar 2026 15:42:03 +0000 Subject: [PATCH] fix(server): preserve adapter-agnostic keys when changing adapter type When the adapter type changes via PATCH, the server only preserved instruction bundle keys (instructionsBundleMode, etc.) from the existing config. Adapter-agnostic keys like env, cwd, timeoutSec, graceSec, promptTemplate, and bootstrapPromptTemplate were silently dropped if the PATCH payload didn't explicitly include them. This caused env var data loss when adapter type was changed via the UI or API without sending the full existing adapterConfig. The fix preserves these adapter-agnostic keys from the existing config before applying the instruction bundle preservation, matching the UI's behavior in AgentConfigForm.handleSave. Co-Authored-By: Paperclip --- server/src/routes/agents.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/server/src/routes/agents.ts b/server/src/routes/agents.ts index 2ad85e63..c2cacfe4 100644 --- a/server/src/routes/agents.ts +++ b/server/src/routes/agents.ts @@ -1772,6 +1772,18 @@ export function agentRoutes(db: Db) { rawEffectiveAdapterConfig = { ...existingAdapterConfig, ...requestedAdapterConfig }; } if (changingAdapterType) { + // Preserve adapter-agnostic keys (env, cwd, etc.) from the existing config + // when the adapter type changes. Without this, a PATCH that includes + // adapterConfig but omits these keys would silently drop them. + const ADAPTER_AGNOSTIC_KEYS = [ + "env", "cwd", "timeoutSec", "graceSec", + "promptTemplate", "bootstrapPromptTemplate", + ] as const; + for (const key of ADAPTER_AGNOSTIC_KEYS) { + if (rawEffectiveAdapterConfig[key] === undefined && existingAdapterConfig[key] !== undefined) { + rawEffectiveAdapterConfig = { ...rawEffectiveAdapterConfig, [key]: existingAdapterConfig[key] }; + } + } rawEffectiveAdapterConfig = preserveInstructionsBundleConfig( existingAdapterConfig, rawEffectiveAdapterConfig,