Skip to content

Commit 783a3b1

Browse files
author
dingtao416
committed
plugins: deduplicate tool registration to prevent double-register (#52572)
1 parent f1bff0b commit 783a3b1

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/plugins/registry.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,32 @@ export function createPluginRegistry(registryParams: PluginRegistryParams) {
266266
names.push(tool.name);
267267
}
268268

269-
const normalized = names.map((name) => name.trim()).filter(Boolean);
269+
let normalized = names.map((name) => name.trim()).filter(Boolean);
270+
271+
// Deduplicate: skip if every resolved name from this plugin is already registered.
272+
if (normalized.length > 0) {
273+
const duplicateNames = normalized.filter((name) =>
274+
registry.tools.some(
275+
(existing) => existing.pluginId === record.id && existing.names.includes(name),
276+
),
277+
);
278+
if (duplicateNames.length > 0) {
279+
// All names already registered by the same plugin — silently skip the duplicate.
280+
if (duplicateNames.length === normalized.length) {
281+
return;
282+
}
283+
// Partial overlap is unexpected; warn but still register the novel names.
284+
pushDiagnostic({
285+
level: "warn",
286+
pluginId: record.id,
287+
source: record.source,
288+
message: `tool names already registered by same plugin, skipping duplicates: ${duplicateNames.join(", ")}`,
289+
});
290+
// Remove already-registered names so only novel ones are pushed below.
291+
normalized = normalized.filter((name) => !duplicateNames.includes(name));
292+
}
293+
}
294+
270295
if (normalized.length > 0) {
271296
record.toolNames.push(...normalized);
272297
}

0 commit comments

Comments
 (0)