From 8f7cca3ae280d169a51dae195d05eb38b483fba6 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Thu, 3 Sep 2026 06:20:48 +0000 Subject: [PATCH] fix(web): guard LLM node model_selector against persisted null (#41707) --- .../workflow/nodes/llm/__tests__/utils.spec.ts | 15 ++++++++++++++- web/app/components/workflow/nodes/llm/utils.ts | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts b/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts index b54380a3a4c..89bea169235 100644 --- a/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts +++ b/web/app/components/workflow/nodes/llm/__tests__/utils.spec.ts @@ -1,4 +1,8 @@ -import type { EnvironmentVariable, ModelConfig } from '@/app/components/workflow/types' +import type { + EnvironmentVariable, + ModelConfig, + ValueSelector, +} from '@/app/components/workflow/types' import { AppModeEnum } from '@/types/app' import { getLLMEnvironmentModel, @@ -160,5 +164,14 @@ describe('llm utils', () => { expect(isEnvironmentModelSource(selector)).toBe(false) expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model) }) + + it('keeps the static model when the persisted selector is null', () => { + // A DSL exported from an older/AI-generated workflow can persist `model_selector: null` + // instead of omitting the key; this must not crash the same way `undefined` doesn't. + const selector = null as unknown as ValueSelector + + expect(isEnvironmentModelSource(selector)).toBe(false) + expect(resolveLLMNodeModel(model, selector, environmentVariables)).toBe(model) + }) }) }) diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts index 5ddadb70c07..f4cbd69649a 100644 --- a/web/app/components/workflow/nodes/llm/utils.ts +++ b/web/app/components/workflow/nodes/llm/utils.ts @@ -24,7 +24,7 @@ const isLLMEnvironmentVariableValue = (value: unknown): value is LLMEnvironmentV } export const isEnvironmentModelSource = (modelSelector: ValueSelector | undefined) => - modelSelector !== undefined && (modelSelector.length === 0 || modelSelector[0] === 'env') + modelSelector != null && (modelSelector.length === 0 || modelSelector[0] === 'env') export const getLLMEnvironmentModel = ( modelSelector: ValueSelector | undefined,