From c917d8b4e37d6aa22f5cc122ab3de34e79573a30 Mon Sep 17 00:00:00 2001 From: lawrence <58159709+01JohnMa@users.noreply.github.com> Date: Wed, 19 Aug 2026 19:05:03 +0800 Subject: [PATCH] fix: clear stale tenant model ids (#18210) ### Summary Clear the paired tenant model ID when a model selection is explicitly cleared in a whitelisted API request. Replaces #18205. Co-authored-by: Jin Hai --- web/src/utils/llm-util.ts | 17 +++++++++++++---- web/src/utils/tests/llm-util.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/web/src/utils/llm-util.ts b/web/src/utils/llm-util.ts index 364a58c052..6e1e9fc43d 100644 --- a/web/src/utils/llm-util.ts +++ b/web/src/utils/llm-util.ts @@ -201,17 +201,26 @@ export function addTenantParams(data: any, url?: string): any { return data; } - const llmList = getCachedLlmList(); - if (!llmList) return data; - // Handle arrays if (Array.isArray(data)) { return data.map((item) => addTenantParams(item, url)); } const newData = { ...data }; + const llmList = getCachedLlmList(); + + // Clear the paired tenant ID when a model selection is explicitly cleared. + for (const [paramName, tenantParamName] of Object.entries(modelParamMap)) { + if ( + Object.hasOwn(newData, paramName) && + (newData[paramName] === '' || newData[paramName] == null) + ) { + newData[tenantParamName] = null; + } + } + + if (!llmList) return newData; - // Iterate through model parameters and add corresponding tenant parameters for (const [paramName, tenantParamName] of Object.entries(modelParamMap)) { if (newData[paramName]) { try { diff --git a/web/src/utils/tests/llm-util.test.ts b/web/src/utils/tests/llm-util.test.ts index 4b9392c26f..c38174e612 100644 --- a/web/src/utils/tests/llm-util.test.ts +++ b/web/src/utils/tests/llm-util.test.ts @@ -1,4 +1,5 @@ import { + addTenantParams, buildModelValue, getEmbeddingBaseName, parseModelUuid, @@ -160,3 +161,29 @@ describe('getEmbeddingBaseName — dataset co-selection grouping', () => { expect(getEmbeddingBaseName(undefined)).toBe(''); }); }); + +describe('addTenantParams — clearing model selections', () => { + test('clears a stale tenant rerank model id when rerank is explicitly cleared', () => { + expect( + addTenantParams( + { + rerank_id: '', + tenant_rerank_id: 'stale-tenant-model-id', + }, + '/api/v1/chats/chat-id', + ), + ).toEqual({ + rerank_id: '', + tenant_rerank_id: null, + }); + }); + + test('preserves the tenant rerank model id when rerank is not part of the request', () => { + expect( + addTenantParams( + { tenant_rerank_id: 'existing-tenant-model-id' }, + '/api/v1/chats/chat-id', + ), + ).toEqual({ tenant_rerank_id: 'existing-tenant-model-id' }); + }); +});