From 030a325cd51967a926101dda200be87784b15dfb Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 25 Mar 2026 16:47:08 -0700 Subject: [PATCH] fix: allow multiple context providers of the same type in config.yaml (#11853) The BlockDuplicationDetector used only the `provider` field as the deduplication key for context entries, so multiple HTTP context providers with different URLs/titles were collapsed to just the first one. Use `name ?? params.title ?? provider` as the key instead, matching how HTTP context providers identify themselves via params.title. Fixes #9416 --- .../src/load/blockDuplicationDetector.ts | 3 +- .../src/load/mergeUnrolledAssistants.test.ts | 60 ++++++++++++++++--- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/packages/config-yaml/src/load/blockDuplicationDetector.ts b/packages/config-yaml/src/load/blockDuplicationDetector.ts index c95a5e1be..c12ada5b5 100644 --- a/packages/config-yaml/src/load/blockDuplicationDetector.ts +++ b/packages/config-yaml/src/load/blockDuplicationDetector.ts @@ -19,7 +19,8 @@ export class BlockDuplicationDetector { } private isContextDuplicated(context: any): boolean { - return this.check(context.provider, "context"); + const key = context.name ?? context.params?.title ?? context.provider; + return this.check(key, "context"); } private isCommonBlockDuplicated(block: any, blockType: BlockType): boolean { diff --git a/packages/config-yaml/src/load/mergeUnrolledAssistants.test.ts b/packages/config-yaml/src/load/mergeUnrolledAssistants.test.ts index 9f7ec1d7f..ef44d4b49 100644 --- a/packages/config-yaml/src/load/mergeUnrolledAssistants.test.ts +++ b/packages/config-yaml/src/load/mergeUnrolledAssistants.test.ts @@ -205,15 +205,15 @@ describe("mergeUnrolledAssistants", () => { expect(result.models?.[0]?.model).toBe("gpt-4"); }); - it("should deduplicate context by provider", () => { + it("should deduplicate context by name when present", () => { const base = createBaseConfig(); const incoming: AssistantUnrolled = { name: "Incoming Assistant", version: "1.1.0", context: [ { - name: "file-context", // Different name but same provider - provider: "file", // Same provider as base + name: "file-context", + provider: "file", }, { name: "terminal", @@ -224,14 +224,60 @@ describe("mergeUnrolledAssistants", () => { const result = mergeUnrolledAssistants(base, incoming); - // Should only have 2 context providers (incoming file and incoming terminal) - expect(result.context).toHaveLength(2); + // Base has unnamed file provider, incoming has named "file-context" — different keys, both kept + expect(result.context).toHaveLength(3); expect(result.context?.map((c) => c?.provider)).toEqual([ "file", "terminal", + "file", + ]); + }); + + it("should keep multiple context providers of the same type with different params.title", () => { + const base: AssistantUnrolled = { + name: "Base Assistant", + version: "1.0.0", + }; + const incoming: AssistantUnrolled = { + name: "Incoming Assistant", + version: "1.1.0", + context: [ + { + provider: "http", + params: { + url: "http://localhost:5000/context", + title: "http-provider-5000", + displayTitle: "HTTP Provider 5000", + }, + }, + { + provider: "http", + params: { + url: "http://localhost:5001/context", + title: "http-provider-5001", + displayTitle: "HTTP Provider 5001", + }, + }, + { + provider: "http", + params: { + url: "http://localhost:5002/context", + title: "http-provider-5002", + displayTitle: "HTTP Provider 5002", + }, + }, + ], + }; + + const result = mergeUnrolledAssistants(base, incoming); + + // All three HTTP providers should be kept since they have different params.title + expect(result.context).toHaveLength(3); + expect(result.context?.map((c) => c?.params?.title)).toEqual([ + "http-provider-5000", + "http-provider-5001", + "http-provider-5002", ]); - // Should keep the incoming version of file provider (base version filtered as duplicate) - expect(result.context?.[0]?.name).toBe("file-context"); }); it("should deduplicate rules by name", () => {