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,