Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): warn about ambiguous toolResultFrom fallbacks only on lookup (#4880)

roboeve[bot]b05d8e5d04df
diff --git a/.changeset/toolresultfrom-warn-on-lookup.md b/.changeset/toolresultfrom-warn-on-lookup.md
new file mode 100644
index 000000000..726c57b2e
--- /dev/null
+++ b/.changeset/toolresultfrom-warn-on-lookup.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Connections or tools that share a `toolResultFrom` fallback identity, such as two MCP connections with the same URL and description, no longer log the "could not assign a unique toolResultFrom identity" warning at startup. eve now warns once, only when a `toolResultFrom` lookup actually needs that ambiguous fallback.
diff --git a/packages/eve/src/internal/authored-definition/source-identity.ts b/packages/eve/src/internal/authored-definition/source-identity.ts
index 96101f6e3..8784a8bf2 100644
--- a/packages/eve/src/internal/authored-definition/source-identity.ts
+++ b/packages/eve/src/internal/authored-definition/source-identity.ts
@@ -16,7 +16,7 @@ type FallbackDefinitionSource =
readonly definitions: WeakSet<object>;
readonly firstEntry: DefinitionSourceEntry;
})
- | { readonly kind: "ambiguous" };
+ | { readonly kind: "ambiguous"; readonly conflict: string; warned: boolean };
export type RegisteredDefinitionSource =
| { readonly kind: DefinitionSourceKind; readonly names: ReadonlySet<string> }
@@ -81,7 +81,22 @@ export function readDefinitionSource(definition: object): RegisteredDefinitionSo
const resolved = resolvedSources.get(definition);
if (resolved !== undefined) return resolved;
const key = readDefinitionKey(definition);
- return key === undefined ? undefined : fallbackSources.get(key);
+ if (key === undefined) return undefined;
+ const fallback = fallbackSources.get(key);
+ if (fallback?.kind === "ambiguous" && !fallback.warned) {
+ // Warn only when a lookup needs the shared fallback. Loaded definitions
+ // resolve above through their source identity.
+ fallback.warned = true;
+ console.warn(
+ [
+ `eve could not assign a unique toolResultFrom identity for ${JSON.stringify(key)}.`,
+ `Conflicting definitions: ${fallback.conflict}.`,
+ "Multiple authored definitions share that fallback identity, so toolResultFrom will not match through it.",
+ "Use the original definition object loaded by eve so source-derived identity can be used instead.",
+ ].join(" "),
+ );
+ }
+ return fallback;
}
function registerFallbackSource(
@@ -108,15 +123,11 @@ function registerFallbackSource(
existing.names.add(entry.name);
return;
}
- console.warn(
- [
- `eve could not assign a unique toolResultFrom identity for ${JSON.stringify(key)}.`,
- `Conflicting definitions: ${formatDefinitionSourceForWarning(existing.firstEntry)} and ${formatDefinitionSourceForWarning(entry)}.`,
- "Multiple authored definitions share that fallback identity, so toolResultFrom will not match through it.",
- "Use the original definition object loaded by eve so source-derived identity can be used instead.",
- ].join(" "),
- );
- fallbackSources.set(key, { kind: "ambiguous" });
+ fallbackSources.set(key, {
+ conflict: `${formatDefinitionSourceForWarning(existing.firstEntry)} and ${formatDefinitionSourceForWarning(entry)}`,
+ kind: "ambiguous",
+ warned: false,
+ });
}
function readDefinitionKey(definition: object): string | undefined {
diff --git a/packages/eve/src/public/tools/result.test.ts b/packages/eve/src/public/tools/result.test.ts
index a4916e6aa..e37c5eb0b 100644
--- a/packages/eve/src/public/tools/result.test.ts
+++ b/packages/eve/src/public/tools/result.test.ts
@@ -159,26 +159,16 @@ describe("toolResultFrom", () => {
"tool:Run the shared action.",
);
- expect(warn).toHaveBeenCalledOnce();
- expect(warn).toHaveBeenCalledWith(
- expect.stringContaining(
- 'eve could not assign a unique toolResultFrom identity for "tool:Run the shared action."',
- ),
- );
- expect(warn).toHaveBeenCalledWith(
- expect.stringContaining(
- 'Conflicting definitions: tool "first_tool" from "tools/first.ts" and tool "second_tool" from "tools/second.ts".',
- ),
- );
expect(toolResultFrom(toolResult("first_tool", { source: "first" }), first)).toEqual({
callId: "call_1",
output: { source: "first" },
toolName: "first_tool",
});
expect(toolResultFrom(toolResult("first_tool", { source: "first" }), second)).toBeUndefined();
+ expect(warn).not.toHaveBeenCalled();
});
- it("does not use a colliding description fallback to narrow the wrong tool", () => {
+ it("does not use a colliding description fallback to narrow the wrong tool, and warns once", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const copy = defineTool({
description: "Run the fallback action.",
@@ -197,8 +187,20 @@ describe("toolResultFrom", () => {
"tool:Run the fallback action.",
);
- expect(warn).toHaveBeenCalledOnce();
+ expect(warn).not.toHaveBeenCalled();
expect(toolResultFrom(toolResult("first_tool", { source: "first" }), copy)).toBeUndefined();
+ expect(toolResultFrom(toolResult("second_tool", { source: "second" }), copy)).toBeUndefined();
+ expect(warn).toHaveBeenCalledOnce();
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining(
+ 'eve could not assign a unique toolResultFrom identity for "tool:Run the fallback action."',
+ ),
+ );
+ expect(warn).toHaveBeenCalledWith(
+ expect.stringContaining(
+ 'Conflicting definitions: tool "first_tool" from "tools/first.ts" and tool "second_tool" from "tools/second.ts".',
+ ),
+ );
});
it("matches a connection tool result with qualified name", () => {
@@ -244,17 +246,6 @@ describe("toolResultFrom", () => {
connectionDefinitionKey("https://mcp.example.test", "Shared"),
);
- expect(warn).toHaveBeenCalledOnce();
- expect(warn).toHaveBeenCalledWith(
- expect.stringContaining(
- `eve could not assign a unique toolResultFrom identity for ${JSON.stringify(connectionDefinitionKey("https://mcp.example.test", "Shared"))}`,
- ),
- );
- expect(warn).toHaveBeenCalledWith(
- expect.stringContaining(
- 'Conflicting definitions: connection "first" from "connections/first.ts" and connection "second" from "connections/second.ts".',
- ),
- );
expect(toolResultFrom(toolResult("first__search", []), first)).toEqual({
callId: "call_1",
connectionToolName: "search",
@@ -262,11 +253,12 @@ describe("toolResultFrom", () => {
toolName: "first__search",
});
expect(toolResultFrom(toolResult("first__search", []), second)).toBeUndefined();
+ expect(warn).not.toHaveBeenCalled();
});
// #3085: loaded definitions match by source identity, so a shared fallback
// key alone should not warn at registration time.
- it.fails("does not warn when loaded connections share a fallback identity", () => {
+ it("does not warn when loaded connections share a fallback identity", () => {
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const key = connectionDefinitionKey("https://api.githubcopilot.com/mcp/", "GitHub");
const github = defineMcpClientConnection({