Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

test(eve): reproduce tool.call.failed losing the thrown error's class (#4826)

roboeve[bot]ec2862e69025
diff --git a/.changeset/tool-error-name.md b/.changeset/tool-error-name.md
new file mode 100644
index 000000000..0fb0d1dbd
--- /dev/null
+++ b/.changeset/tool-error-name.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+When a tool throws, the error on its `tool.call.failed` instrumentation event now keeps the thrown error's `name`, such as `QuotaError`, instead of always reading `Error`. The `action.result` stream event reports the same name as `error.name`.
diff --git a/docs/guides/instrumentation/instrumentation.mdx b/docs/guides/instrumentation/instrumentation.mdx
index 91571bbd1..feacb9613 100644
--- a/docs/guides/instrumentation/instrumentation.mdx
+++ b/docs/guides/instrumentation/instrumentation.mdx
@@ -170,6 +170,8 @@ Each call emits one `tool.call.*` lifecycle to authored providers. SDK execution
For local and remote subagents, `tool.call.completed` and `tool.call.failed` include the child turn's `usage` directly. Token counts are always present when the child reports usage; `usage.costUsd` is present only when the model provider reports a price.
+When a tool throws and outputs are recorded, `tool.call.failed` carries an `Error` with the thrown error's `name` and `message`, so a provider can classify the failure by `error.name`. It is rebuilt from the durable session record rather than being the object the tool threw, so `instanceof` checks against your own error classes do not match.
+
When upgrading, replace `action.started`, `action.completed`, and `action.failed` handlers with their `tool.call.*` equivalents. Read `event.toolName` instead of `event.name` on start events. The OpenTelemetry trace schema remains version 4.
Handlers from different files run concurrently and are failure-isolated. Do
diff --git a/packages/eve/extension-contracts/compatibility/channel/v60.ts b/packages/eve/extension-contracts/compatibility/channel/v60.ts
new file mode 100644
index 000000000..d6a4b0fe0
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/channel/v60.ts
@@ -0,0 +1,13 @@
+import { defineChannel } from "#public/channels/index.js";
+
+// Epoch 60 `action.result` errors had no `name`; epoch 61 adds it as optional.
+// Channels that read the failure code and message keep working.
+export default defineChannel({
+ routes: [],
+ events: {
+ "action.result"(event) {
+ if (event.error === undefined) return;
+ console.info("action failed", { code: event.error.code, message: event.error.message });
+ },
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/connection/v48.ts b/packages/eve/extension-contracts/compatibility/connection/v48.ts
new file mode 100644
index 000000000..f068caffd
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/connection/v48.ts
@@ -0,0 +1,7 @@
+import { defineMcpClientConnection } from "#public/connections/index.js";
+
+// Epoch 48 `action.result` errors had no `name`; epoch 49 adds it as optional.
+export default defineMcpClientConnection({
+ description: "Manage issues in the tracker.",
+ url: "https://tracker.example.com/mcp",
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicInstructions/v38.ts b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v38.ts
new file mode 100644
index 000000000..9aea591a3
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v38.ts
@@ -0,0 +1,9 @@
+import { defineDynamic, defineInstructions } from "#public/instructions/index.js";
+
+// Epoch 38 `action.result` errors had no `name`; epoch 39 adds it as optional.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) =>
+ defineInstructions({ markdown: `Review evidence for session ${ctx.session.id}.` }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicSkill/v37.ts b/packages/eve/extension-contracts/compatibility/dynamicSkill/v37.ts
new file mode 100644
index 000000000..da7f42f4a
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicSkill/v37.ts
@@ -0,0 +1,12 @@
+import { defineDynamic, defineSkill } from "#public/skills/index.js";
+
+// Epoch 37 `action.result` errors had no `name`; epoch 38 adds it as optional.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) =>
+ defineSkill({
+ description: "Review the active request.",
+ markdown: `Review evidence for session ${ctx.session.id}.`,
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v84.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v84.ts
new file mode 100644
index 000000000..b8e5f3fdd
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v84.ts
@@ -0,0 +1,17 @@
+import { defineDynamic, defineTool } from "#public/tools/index.js";
+
+// Epoch 84 failed tool results carried only the error message; epoch 85 adds
+// an optional `errorName`. Dynamic tools that throw keep failing the same way.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) => ({
+ quota: defineTool({
+ description: "Return the active session's remaining quota.",
+ inputSchema: { type: "object", properties: {} },
+ execute: () => {
+ throw new Error(`Quota exhausted for session ${ctx.session.id}`);
+ },
+ }),
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/hook/v45.ts b/packages/eve/extension-contracts/compatibility/hook/v45.ts
new file mode 100644
index 000000000..f630adaa2
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/hook/v45.ts
@@ -0,0 +1,13 @@
+import { defineHook } from "#public/hooks/index.js";
+
+// Epoch 45 `action.result` errors had no `name`; epoch 46 adds it as optional.
+// Hooks that read the failure code and message keep working.
+export default defineHook({
+ events: {
+ "action.result"(event) {
+ const { error } = event.data;
+ if (error === undefined) return;
+ console.info("action failed", { code: error.code, message: error.message });
+ },
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/schedule/v32.ts b/packages/eve/extension-contracts/compatibility/schedule/v32.ts
new file mode 100644
index 000000000..7d8d03bc5
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/schedule/v32.ts
@@ -0,0 +1,19 @@
+import { defineChannel } from "#public/channels/index.js";
+import { defineSchedule } from "#public/schedules/index.js";
+
+// Epoch 32 `action.result` errors had no `name`; epoch 33 adds it as optional.
+const reports = defineChannel({
+ routes: [],
+ receive(input, { from }) {
+ return from("nightly-report").send(input.message, { auth: input.auth });
+ },
+});
+
+export default defineSchedule({
+ cron: "0 2 * * *",
+ async run({ to, appAuth, waitUntil }) {
+ const session = await to(reports, {}).send("Prepare the nightly report.", { auth: appAuth });
+ const events = await session.getEventStream({ startIndex: 0 });
+ waitUntil(events.cancel());
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/subagent/v37.ts b/packages/eve/extension-contracts/compatibility/subagent/v37.ts
new file mode 100644
index 000000000..4efdd0a3b
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/subagent/v37.ts
@@ -0,0 +1,7 @@
+import { defineAgent } from "#public/index.js";
+
+// Epoch 37 `action.result` errors had no `name`; epoch 38 adds it as optional.
+export default defineAgent({
+ description: "Summarize a customer's open support tickets.",
+ model: "anthropic/claude-sonnet-5",
+});
diff --git a/packages/eve/extension-contracts/compatibility/tool/v90.ts b/packages/eve/extension-contracts/compatibility/tool/v90.ts
new file mode 100644
index 000000000..88648e5a2
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v90.ts
@@ -0,0 +1,18 @@
+import { z } from "zod";
+import { defineTool } from "#public/tools/index.js";
+
+class QuotaError extends Error {
+ override name = "QuotaError";
+}
+
+// Epoch 90 failed tool results carried only the error message; epoch 91 adds
+// an optional `errorName`. Tools that throw their own error classes keep
+// compiling and failing the same way.
+export default defineTool({
+ description: "Look up the remaining quota for a project.",
+ inputSchema: z.object({ project: z.string() }),
+ execute: ({ project }) => {
+ if (project === "") throw new QuotaError("Quota exhausted");
+ return { project, remaining: 1 };
+ },
+});
diff --git a/packages/eve/extension-contracts/reports/channel/v61.json b/packages/eve/extension-contracts/reports/channel/v61.json
new file mode 100644
index 000000000..1974a364e
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/channel/v61.json
@@ -0,0 +1,23 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "channel",
+ "epoch": 61,
+ "sha256": "b30289e7f935ab8a50050b5af50c46dcb4ad1990d3fb0aa6fd3ee7583c24daf8",
+ "exports": [
+ "DELETE",
+ "GET",
+ "HEAD",
+ "OPTIONS",
+ "PATCH",
+ "POST",
+ "PUT",
+ "SessionStrandedError",
+ "WS",
+ "attachmentError",
+ "createWebSocketUpgradeServer",
+ "defineChannel",
+ "disableRoute",
+ "isChannel",
+ "isDisabledRouteSentinel"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/connection/v49.json b/packages/eve/extension-contracts/reports/connection/v49.json
new file mode 100644
index 000000000..9070a8008
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/connection/v49.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "connection",
+ "epoch": 49,
+ "sha256": "3b2247bc0c62cf6c073adb53644b45c9fe3090a33ded50d01d96efd40cec7a31",
+ "exports": [
+ "ConnectionAuthorizationFailedError",
+ "ConnectionAuthorizationRequiredError",
+ "defineDynamic",
+ "defineInteractiveAuthorization",
+ "defineMcpClientConnection",
+ "defineOpenAPIConnection",
+ "isConnectionAuthorizationFailedError",
+ "isConnectionAuthorizationRequiredError"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicInstructions/v39.json b/packages/eve/extension-contracts/reports/dynamicInstructions/v39.json
new file mode 100644
index 000000000..34d36784b
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicInstructions/v39.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicInstructions",
+ "epoch": 39,
+ "sha256": "f962c5207ee4584cc9ecb72ab0f8ff52590d9e9fd745b04b51a0f74ca26cb495",
+ "exports": ["defineDynamic"]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicSkill/v38.json b/packages/eve/extension-contracts/reports/dynamicSkill/v38.json
new file mode 100644
index 000000000..5e952af0a
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicSkill/v38.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicSkill",
+ "epoch": 38,
+ "sha256": "1461f18113f1e310c2a13d17f6c20ac10202df7f46484e18bc61781e5cee63b3",
+ "exports": ["defineDynamic"]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v85.json b/packages/eve/extension-contracts/reports/dynamicTool/v85.json
new file mode 100644
index 000000000..0a6becf38
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicTool/v85.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicTool",
+ "epoch": 85,
+ "sha256": "bb2d63d81d3deb95968097e73edae29d9a5b529583eb156c383c103a71762b75",
+ "exports": [
+ "DynamicToolEntry",
+ "DynamicToolEvents",
+ "DynamicToolResult",
+ "DynamicToolSet",
+ "auto",
+ "defineDurableCallback",
+ "defineDurableSchema",
+ "defineDynamic"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/hook/v46.json b/packages/eve/extension-contracts/reports/hook/v46.json
new file mode 100644
index 000000000..7574664ee
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/hook/v46.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "hook",
+ "epoch": 46,
+ "sha256": "53a373adceff879ca5a70f8c1f80ce0099a89070f89329b15200cfc0c926e6bb",
+ "exports": ["defineHook"]
+}
diff --git a/packages/eve/extension-contracts/reports/schedule/v33.json b/packages/eve/extension-contracts/reports/schedule/v33.json
new file mode 100644
index 000000000..0b985ace5
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/schedule/v33.json
@@ -0,0 +1,15 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "schedule",
+ "epoch": 33,
+ "sha256": "3b39d3e17ca59c4751368b05029809b621677fe0081a1cae6e1cefcf4771389e",
+ "exports": [
+ "ScheduleDefinition",
+ "ScheduleHandlerArgs",
+ "ScheduleRunHandler",
+ "ScheduleToFn",
+ "TypedReceiveTarget",
+ "defineSchedule",
+ "isScheduleAuth"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/subagent/v38.json b/packages/eve/extension-contracts/reports/subagent/v38.json
new file mode 100644
index 000000000..a87a2317c
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/subagent/v38.json
@@ -0,0 +1,23 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "subagent",
+ "epoch": 38,
+ "sha256": "44b8373072a879ac9df8290c4b430bbc43547cd7106e58a9c7b50649e2abb504",
+ "exports": [
+ "AgentCompactionDefinition",
+ "AgentDefinition",
+ "AgentModelDefinition",
+ "AgentStaticModelDefinition",
+ "DefinedAgent",
+ "DynamicLocalSubagentDefinition",
+ "DynamicSubagentDefinition",
+ "RemoteAgentDefinition",
+ "RemoteAgentDefinitionInput",
+ "WorkspaceAgentDefinition",
+ "WorkspaceAgentTransport",
+ "defineAgent",
+ "defineDynamic",
+ "defineRemoteAgent",
+ "defineWorkspaceAgent"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/tool/v91.json b/packages/eve/extension-contracts/reports/tool/v91.json
new file mode 100644
index 000000000..5cc32feed
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v91.json
@@ -0,0 +1,29 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 91,
+ "sha256": "e85a99c0eb2ec62361c4850454f5eaba875ab1376029e225491f2e9d868d4896",
+ "exports": [
+ "AgentRouterInput",
+ "AgentRouterTool",
+ "WorkflowStepToolContext",
+ "WorkflowTool",
+ "WorkflowToolDefinition",
+ "WorkflowToolInput",
+ "WorkflowToolOptions",
+ "agentRouter",
+ "decide",
+ "defaultWebSearch",
+ "defineTool",
+ "defineWorkflowTool",
+ "disableTool",
+ "isDisabledToolSentinel",
+ "isWebSearchToolDefinition",
+ "serializeModelInputSchema",
+ "toolOutput",
+ "toolOutputPart",
+ "toolResultFrom",
+ "webSearch",
+ "workflow"
+ ]
+}
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index 0fdcf25ea..0b6ea5c1b 100644
--- a/packages/eve/src/compiler/extension-compatibility.ts
+++ b/packages/eve/src/compiler/extension-compatibility.ts
@@ -22,10 +22,10 @@ interface ExtensionCapabilityContract {
const EXTENSION_CAPABILITY_CONTRACTS = {
extension: { current: 1, supported: [1], dropped: {} },
tool: {
- current: 90,
+ current: 91,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 29, 30, 31, 32, 34, 35, 76, 77, 78, 80, 81, 82, 84,
- 85, 86, 87, 88, 89, 90,
+ 85, 86, 87, 88, 89, 90, 91,
],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
@@ -89,10 +89,11 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
dynamicTool: {
- current: 84,
+ current: 85,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 31, 32, 33, 52, 54,
60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
+ 85,
],
dropped: {
21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -133,10 +134,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
channel: {
- current: 60,
+ current: 61,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 29, 31, 36, 37, 38, 39, 40, 41, 42,
- 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60,
+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60, 61,
],
dropped: {
12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -159,10 +160,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
schedule: {
- current: 32,
+ current: 33,
supported: [
1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
- 29, 30, 31, 32,
+ 29, 30, 31, 32, 33,
],
dropped: {
5: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -171,10 +172,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
subagent: {
- current: 37,
+ current: 38,
supported: [
3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
- 34, 35, 36, 37,
+ 34, 35, 36, 37, 38,
],
dropped: {
1: "Persistent subagent sessions are now the default and the experimental opt-in was removed",
@@ -188,10 +189,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
connection: {
- current: 48,
+ current: 49,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 32, 33, 34,
- 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48,
+ 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49,
],
dropped: {
9: "Dynamic connection resolvers no longer receive conversation or channel continuation data",
@@ -207,8 +208,8 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
hook: {
- current: 45,
- supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45],
+ current: 46,
+ supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46],
dropped: {
1: "Model identity moved from session.started runtime metadata to step.started call attribution.",
2: "Model identity moved from session.started runtime metadata to step.started call attribution.",
@@ -239,10 +240,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
skill: { current: 3, supported: [1, 2, 3], dropped: {} },
dynamicSkill: {
- current: 37,
+ current: 38,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, 29, 30,
- 31, 32, 33, 34, 35, 36, 37,
+ 31, 32, 33, 34, 35, 36, 37, 38,
],
dropped: {
13: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -253,10 +254,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
instructions: { current: 2, supported: [1, 2], dropped: {} },
dynamicInstructions: {
- current: 38,
+ current: 39,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 26, 27, 28, 29, 30,
- 31, 32, 33, 34, 35, 36, 37, 38,
+ 31, 32, 33, 34, 35, 36, 37, 38, 39,
],
dropped: {
14: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
diff --git a/packages/eve/src/execution/tools/workflow/owner-inbox.test.ts b/packages/eve/src/execution/tools/workflow/owner-inbox.test.ts
index 60be78d41..1d73e9460 100644
--- a/packages/eve/src/execution/tools/workflow/owner-inbox.test.ts
+++ b/packages/eve/src/execution/tools/workflow/owner-inbox.test.ts
@@ -1,9 +1,15 @@
import { describe, expect, it } from "vitest";
+import { ContextContainer, contextStorage } from "#context/container.js";
+import { toFailedOutcome } from "#execution/tools/workflow/body.js";
import {
workflowToolRunFailureOutput,
+ workflowToolRunOutcomeToToolResult,
workflowToolRunRequestToInputRequestPayload,
} from "#execution/tools/workflow/owner-inbox.js";
+import type { InstrumentationEvent } from "#instrumentation/lifecycle.js";
+import { createInstrumentationHandleEvent } from "#instrumentation/native-events.js";
+import { createActionResultEvent, createActionsRequestedEvent } from "#protocol/message.js";
const from = {
callId: "call-1",
@@ -128,3 +134,58 @@ describe("workflow-tool task outcomes", () => {
).toEqual("export failed");
});
});
+
+// https://github.com/vercel/eve/issues/4820
+describe("a workflow body's failure", () => {
+ async function toolCallFailed(error: Error): Promise<InstrumentationEvent | undefined> {
+ const result = workflowToolRunOutcomeToToolResult({
+ from,
+ result: toFailedOutcome(error, new AbortController().signal),
+ });
+ const events: InstrumentationEvent[] = [];
+ const handleEvent = createInstrumentationHandleEvent({
+ getAttemptScope: () => ({
+ attemptId: "session-1:turn-1:0:0",
+ attemptIndex: 0,
+ sessionId: "session-1",
+ stepIndex: 0,
+ turnId: "turn-1",
+ }),
+ handleEvent: async () => {},
+ hooks: { capturesContent: true, publish: async (event) => void events.push(event) },
+ sessionId: "session-1",
+ })!;
+ await contextStorage.run(new ContextContainer(), async () => {
+ await handleEvent(
+ createActionsRequestedEvent({
+ actions: [{ callId: from.callId, input: {}, kind: "tool-call", toolName: from.toolName }],
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "turn-1",
+ }),
+ );
+ await handleEvent(
+ createActionResultEvent({ result, sequence: 0, stepIndex: 0, turnId: "turn-1" }),
+ );
+ });
+ return events.find((event) => event.type === "tool.call.failed");
+ }
+
+ it("keeps the name of the error the body threw on tool.call.failed", async () => {
+ const failed = await toolCallFailed(
+ Object.assign(new Error("quota exceeded"), { name: "QuotaError" }),
+ );
+
+ expect(failed).toHaveProperty("error.name", "QuotaError");
+ expect(failed).toHaveProperty("error.message", "quota exceeded");
+ });
+
+ it("keeps the name of a coded error the body threw on tool.call.failed", async () => {
+ const failed = await toolCallFailed(
+ Object.assign(new Error("quota exceeded"), { code: "QUOTA", name: "QuotaError" }),
+ );
+
+ expect(failed).toHaveProperty("error.name", "QuotaError");
+ expect(failed).toHaveProperty("errorCode", "QUOTA");
+ });
+});
diff --git a/packages/eve/src/execution/tools/workflow/owner-inbox.ts b/packages/eve/src/execution/tools/workflow/owner-inbox.ts
index dafe4a303..40cd7d9e5 100644
--- a/packages/eve/src/execution/tools/workflow/owner-inbox.ts
+++ b/packages/eve/src/execution/tools/workflow/owner-inbox.ts
@@ -6,6 +6,7 @@ import type {
WorkflowToolRequest,
WorkflowToolRunRequestMessage,
} from "#execution/tools/workflow/messages.js";
+import { rebuildSerializableError } from "#execution/workflow-errors.js";
import type { RuntimeToolResultActionResult } from "#shared/action-types.js";
import type { InputRequest } from "#shared/input.js";
import type { ToolInputRequest } from "#tools/definition.js";
@@ -23,14 +24,22 @@ export function workflowToolRunOutcomeToToolResult(
toolName: from.toolName,
};
}
+ if (result.status === "failed") {
+ return {
+ callId: from.callId,
+ // The output keeps what the model reads; the serialized error still carries the thrown name.
+ errorName: rebuildSerializableError(result.error).name,
+ isError: true,
+ kind: "tool-result",
+ output: workflowToolRunFailureOutput(message),
+ toolName: from.toolName,
+ };
+ }
return {
callId: from.callId,
isError: true,
kind: "tool-result",
- output:
- result.status === "failed"
- ? workflowToolRunFailureOutput(message)
- : (result.reason ?? "The workflow tool run was cancelled."),
+ output: result.reason ?? "The workflow tool run was cancelled.",
toolName: from.toolName,
};
}
diff --git a/packages/eve/src/execution/tools/workflow/start.test.ts b/packages/eve/src/execution/tools/workflow/start.test.ts
index b25e671d9..c429d6af7 100644
--- a/packages/eve/src/execution/tools/workflow/start.test.ts
+++ b/packages/eve/src/execution/tools/workflow/start.test.ts
@@ -1,6 +1,6 @@
import { afterEach, describe, expect, it, vi } from "vitest";
-import { startWorkflowToolRun } from "./start.js";
+import { startFailureResult, startWorkflowToolRun } from "./start.js";
import type { WorkflowToolRunInput } from "./types.js";
import type { AgentSessionContext } from "#execution/agent-sessions/context.js";
import {
@@ -65,3 +65,24 @@ describe("startWorkflowToolRun", () => {
expect(retried.hookToken).not.toBe(firstInput.hookToken);
});
});
+
+// https://github.com/vercel/eve/issues/4820
+describe("startFailureResult", () => {
+ it("keeps the name of the error the start threw", () => {
+ const error = Object.assign(new Error("no capacity"), { name: "CapacityError" });
+
+ expect(
+ startFailureResult(
+ { callId: "call-1", toolName: "deploy" } as Parameters<typeof startFailureResult>[0],
+ error,
+ ),
+ ).toEqual({
+ callId: "call-1",
+ errorName: "CapacityError",
+ isError: true,
+ kind: "tool-result",
+ output: "no capacity",
+ toolName: "deploy",
+ });
+ });
+});
diff --git a/packages/eve/src/harness/action-result-helpers.test.ts b/packages/eve/src/harness/action-result-helpers.test.ts
index e7201df74..81984d486 100644
--- a/packages/eve/src/harness/action-result-helpers.test.ts
+++ b/packages/eve/src/harness/action-result-helpers.test.ts
@@ -38,11 +38,12 @@ describe("createRuntimeToolResultFromValue", () => {
createRuntimeToolResultFromValue({
callId: "call_failed",
isError: true,
- output: new Error("tool failed"),
+ output: Object.assign(new Error("tool failed"), { name: "QuotaError" }),
toolName: "broken",
}),
).toEqual({
callId: "call_failed",
+ errorName: "QuotaError",
isError: true,
kind: "tool-result",
output: "tool failed",
@@ -63,6 +64,7 @@ describe("createRuntimeToolResultFromToolError", () => {
}),
).toEqual({
callId: "call_lookup",
+ errorName: "Error",
isError: true,
kind: "tool-result",
output: 'No skill named "demo"',
diff --git a/packages/eve/src/harness/action-result-helpers.ts b/packages/eve/src/harness/action-result-helpers.ts
index fbcabcd35..d086a17b6 100644
--- a/packages/eve/src/harness/action-result-helpers.ts
+++ b/packages/eve/src/harness/action-result-helpers.ts
@@ -53,16 +53,14 @@ export function createRuntimeToolResultFromValue(input: {
readonly output: unknown;
readonly isError?: boolean;
}): RuntimeToolResultActionResult {
+ const thrown = input.isError === true && input.output instanceof Error ? input.output : undefined;
const result: RuntimeToolResultActionResult = {
callId: input.callId,
kind: "tool-result",
output: toolResultOutputToJsonValue({
output: {
type: input.isError === true ? "error-json" : "json",
- value:
- input.isError === true && input.output instanceof Error
- ? input.output.message
- : input.output,
+ value: thrown === undefined ? input.output : thrown.message,
},
toolCallId: input.callId,
toolName: input.toolName,
@@ -70,7 +68,11 @@ export function createRuntimeToolResultFromValue(input: {
toolName: input.toolName,
};
- return input.isError === true ? { ...result, isError: true } : result;
+ if (input.isError !== true) return result;
+ // The output keeps only a thrown error's message; its name lets instrumentation classify the failure.
+ return thrown === undefined
+ ? { ...result, isError: true }
+ : { ...result, errorName: thrown.name, isError: true };
}
/**
diff --git a/packages/eve/src/harness/emission.test.ts b/packages/eve/src/harness/emission.test.ts
index e3508a970..03fd92830 100644
--- a/packages/eve/src/harness/emission.test.ts
+++ b/packages/eve/src/harness/emission.test.ts
@@ -676,9 +676,10 @@ describe("emitStreamContent action requests", () => {
expect(events).toEqual([
expect.objectContaining({
data: expect.objectContaining({
- error: { code: "ACTION_RESULT_FAILED", message },
+ error: { code: "ACTION_RESULT_FAILED", message, name: "TypeError" },
result: {
callId: "call-bad",
+ errorName: "TypeError",
isError: true,
kind: "tool-result",
output: message,
@@ -735,9 +736,10 @@ describe("emitStreamContent action requests", () => {
expect(events).toEqual([
expect.objectContaining({
data: expect.objectContaining({
- error: { code: "ACTION_RESULT_FAILED", message },
+ error: { code: "ACTION_RESULT_FAILED", message, name: "TypeError" },
result: {
callId: "call-bad",
+ errorName: "TypeError",
isError: true,
kind: "tool-result",
output: message,
diff --git a/packages/eve/src/harness/hitl/approvals.ts b/packages/eve/src/harness/hitl/approvals.ts
index c41e15658..3fdb866c1 100644
--- a/packages/eve/src/harness/hitl/approvals.ts
+++ b/packages/eve/src/harness/hitl/approvals.ts
@@ -318,7 +318,7 @@ export function answer(
if (unavailable.has(request.requestId)) {
const failed = failedCall({
callId,
- message: unavailableToolMessage(toolName, input.searchable(request)),
+ failure: unavailableToolMessage(toolName, input.searchable(request)),
toolName,
});
messages = withResult(messages, failed.part);
diff --git a/packages/eve/src/harness/hitl/approved-calls.test.ts b/packages/eve/src/harness/hitl/approved-calls.test.ts
index 4d75fd4d0..a291bd9f1 100644
--- a/packages/eve/src/harness/hitl/approved-calls.test.ts
+++ b/packages/eve/src/harness/hitl/approved-calls.test.ts
@@ -8,6 +8,7 @@ import {
import { TurnCancelledError } from "#harness/turn-cancellation.js";
import type { HarnessToolDefinition } from "#harness/execute-tool.js";
import type { InputRequest } from "#shared/input.js";
+import type { HandleEventFn } from "#harness/types.js";
function approval(callId: string, toolName: string): InputRequest {
return {
@@ -82,3 +83,57 @@ it("leaves a call the cancellation stopped before it started without a result",
expect(execute).not.toHaveBeenCalled();
expect(result.settled).toEqual([]);
});
+
+// https://github.com/vercel/eve/issues/4820
+it("keeps the name of the error an approved call threw on its failed result", async () => {
+ class QuotaError extends Error {
+ override name = "QuotaError";
+ }
+ const throwing = tool("throwing", async () => {
+ throw new QuotaError("quota exceeded");
+ });
+ const unprojectable = {
+ ...tool("unprojectable", async () => "done"),
+ toModelOutput: () => {
+ throw new QuotaError("projection quota exceeded");
+ },
+ } as HarnessToolDefinition;
+ const published: Parameters<HandleEventFn>[0][] = [];
+
+ const result = await runApprovedCalls({
+ abortSignal: new AbortController().signal,
+ messages: [],
+ position: { sequence: 0, stepIndex: 0, turnId: "turn_0" },
+ publish: async (event) => {
+ published.push(event);
+ },
+ responderOf: () => undefined,
+ requests: [
+ approval("call-throwing", "throwing"),
+ approval("call-unprojectable", "unprojectable"),
+ ],
+ tools: new Map([
+ ["throwing", throwing],
+ ["unprojectable", unprojectable],
+ ]),
+ });
+
+ expect(result.settled.map(({ part }) => [part.toolCallId, part.output])).toEqual([
+ ["call-throwing", { type: "error-text", value: "quota exceeded" }],
+ ["call-unprojectable", { type: "error-text", value: "projection quota exceeded" }],
+ ]);
+ expect(
+ published.flatMap((event) =>
+ event.type === "action.result" ? [[event.data.result.callId, event.data.error]] : [],
+ ),
+ ).toEqual([
+ [
+ "call-throwing",
+ { code: "ACTION_RESULT_FAILED", message: "quota exceeded", name: "QuotaError" },
+ ],
+ [
+ "call-unprojectable",
+ { code: "ACTION_RESULT_FAILED", message: "projection quota exceeded", name: "QuotaError" },
+ ],
+ ]);
+});
diff --git a/packages/eve/src/harness/hitl/approved-calls.ts b/packages/eve/src/harness/hitl/approved-calls.ts
index 80a93e4b5..6c2721bf3 100644
--- a/packages/eve/src/harness/hitl/approved-calls.ts
+++ b/packages/eve/src/harness/hitl/approved-calls.ts
@@ -77,9 +77,9 @@ export async function runApprovedCalls(input: {
const settleFailure = async (
callId: string,
toolName: string,
- message: string,
+ failure: Error | string,
): Promise<ApprovedCallResult> => {
- const failed = failedCall({ callId, message, toolName });
+ const failed = failedCall({ callId, failure, toolName });
await input.publish(createActionResultEvent({ ...at, result: failed.result }));
return { part: failed.part };
};
@@ -136,7 +136,8 @@ export async function runApprovedCalls(input: {
return { settled, toolResults };
}
let output: unknown;
- let failed = false;
+ /** The error the tool threw, kept whole so the result records its name. */
+ let failure: Error | undefined;
const telemetry = toolTelemetry(input.telemetry, {
messages: [...input.messages],
toolCall: { input: args, toolCallId: callId, toolName, type: "tool-call" },
@@ -189,10 +190,10 @@ export async function runApprovedCalls(input: {
);
throwIfTurnAborted(input.abortSignal);
logError(log, "tool execution failed", error, { toolName, toolCallId: callId });
- failed = true;
- output = toError(error).message;
+ failure = toError(error);
+ output = failure.message;
}
- if (!failed) {
+ if (failure === undefined) {
await telemetry.ended(
{ input: args, output, toolCallId: callId, toolName, type: "tool-result" },
executionMs,
@@ -209,9 +210,10 @@ export async function runApprovedCalls(input: {
if (isInlineAuthorizationToolResult(result)) return { settled, toolResults };
completed = {
part: {
- output: failed
- ? { type: "error-text", value: String(output) }
- : await toolCallModelOutput(definition, output, callId),
+ output:
+ failure !== undefined
+ ? { type: "error-text", value: failure.message }
+ : await toolCallModelOutput(definition, output, callId),
toolCallId: callId,
toolName,
type: "tool-result",
@@ -221,10 +223,16 @@ export async function runApprovedCalls(input: {
await input.publish(
createActionResultEvent({
...at,
- presentation: failed
- ? undefined
- : projectResultPresentation(definition, callId, parseJsonObject(args), output),
- result: createRuntimeToolResultFromValue({ callId, isError: failed, output, toolName }),
+ presentation:
+ failure !== undefined
+ ? undefined
+ : projectResultPresentation(definition, callId, parseJsonObject(args), output),
+ result: createRuntimeToolResultFromValue({
+ callId,
+ isError: failure !== undefined,
+ output: failure ?? output,
+ toolName,
+ }),
}),
);
return { settled, toolResults };
@@ -236,7 +244,7 @@ export async function runApprovedCalls(input: {
}
logError(log, "approved tool failed", error, { toolName, toolCallId: callId });
return {
- settled: [await settleFailure(callId, toolName, toError(error).message)],
+ settled: [await settleFailure(callId, toolName, toError(error))],
toolResults,
};
}
diff --git a/packages/eve/src/harness/input-request-resolution.ts b/packages/eve/src/harness/input-request-resolution.ts
index ec4e32f85..d36722bbf 100644
--- a/packages/eve/src/harness/input-request-resolution.ts
+++ b/packages/eve/src/harness/input-request-resolution.ts
@@ -2,6 +2,7 @@ import { createRuntimeToolResultFromValue } from "#harness/action-result-helpers
import type { SettledCall } from "#harness/session-machine/transitions.js";
import type { StepCoordinates as PendingInputBatchEvent } from "#harness/session-machine/view.js";
import { SEARCH_TOOL_NAME } from "#protocol/catalog-tools.js";
+import { toErrorMessage } from "#shared/errors.js";
import type { InputRequest, InputResponse } from "#shared/input.js";
const IGNORED_INPUT_REASON = "Ignored because the user continued without responding.";
@@ -89,17 +90,18 @@ export function unavailableToolMessage(toolName: string, searchable: boolean): s
*/
export function failedCall(call: {
readonly callId: string;
- readonly message: string;
+ /** Why the call failed: the error it threw, or a message when it never ran. */
+ readonly failure: Error | string;
readonly toolName: string;
}): Required<SettledCall> {
- const { callId, message, toolName } = call;
+ const { callId, failure, toolName } = call;
return {
part: {
- output: { type: "error-text", value: message },
+ output: { type: "error-text", value: toErrorMessage(failure) },
toolCallId: callId,
toolName,
type: "tool-result",
},
- result: createRuntimeToolResultFromValue({ callId, isError: true, output: message, toolName }),
+ result: createRuntimeToolResultFromValue({ callId, isError: true, output: failure, toolName }),
};
}
diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.ts
index aea9765b5..7fc48567c 100644
--- a/packages/eve/src/harness/tool-loop.test.ts
+++ b/packages/eve/src/harness/tool-loop.test.ts
@@ -7393,9 +7393,11 @@ describe("createToolLoopHarness", () => {
error: {
code: "ACTION_RESULT_FAILED",
message: "Search failed",
+ name: "Error",
},
result: {
callId: toolCallId,
+ errorName: "Error",
isError: true,
kind: "tool-result",
output: "Search failed",
diff --git a/packages/eve/src/instrumentation/native-events.test.ts b/packages/eve/src/instrumentation/native-events.test.ts
index 067b545b2..0ab6eda7a 100644
--- a/packages/eve/src/instrumentation/native-events.test.ts
+++ b/packages/eve/src/instrumentation/native-events.test.ts
@@ -28,6 +28,7 @@ import {
sessionIdempotencyKey,
turnIdempotencyKey,
} from "#instrumentation/lifecycle.js";
+import { createRuntimeToolResultFromToolError } from "#harness/action-result-helpers.js";
import { RuntimeActionSettlementTimesKey } from "#harness/runtime-action-settlement-state.js";
describe("createInstrumentationHandleEvent", () => {
@@ -482,6 +483,59 @@ describe("createInstrumentationHandleEvent", () => {
expect(events.every(Object.isFrozen)).toBe(true);
});
+ // https://github.com/vercel/eve/issues/4820
+ it("keeps the class name of the error a tool threw", async () => {
+ class QuotaError extends Error {
+ override name = "QuotaError";
+ }
+ const events: InstrumentationEvent[] = [];
+ const handleEvent = createInstrumentationHandleEvent({
+ getAttemptScope: () => ({
+ attemptId: "session-1:turn-1:0:0",
+ attemptIndex: 0,
+ sessionId: "session-1",
+ stepIndex: 0,
+ turnId: "turn-1",
+ }),
+ handleEvent: async () => {},
+ hooks: {
+ capturesContent: true,
+ publish: async (event) => void events.push(event),
+ },
+ sessionId: "session-1",
+ })!;
+
+ await contextStorage.run(new ContextContainer(), async () => {
+ await handleEvent(
+ createActionsRequestedEvent({
+ actions: [{ callId: "charge-1", input: {}, kind: "tool-call", toolName: "charge" }],
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "turn-1",
+ }),
+ );
+ await handleEvent(
+ createActionResultEvent({
+ result: createRuntimeToolResultFromToolError({
+ error: new QuotaError("quota exceeded"),
+ input: {},
+ toolCallId: "charge-1",
+ toolName: "charge",
+ type: "tool-error",
+ }),
+ sequence: 0,
+ stepIndex: 0,
+ turnId: "turn-1",
+ }),
+ );
+ });
+
+ const failed = events.find((event) => event.type === "tool.call.failed");
+ expect(failed).toMatchObject({ outcome: "failed", type: "tool.call.failed" });
+ expect(failed).toHaveProperty("error.message", "quota exceeded");
+ expect(failed).toHaveProperty("error.name", "QuotaError");
+ });
+
it("publishes each input request and resolves it in a replacement worker", async () => {
const events: unknown[] = [];
const scope = {
diff --git a/packages/eve/src/instrumentation/native-events.ts b/packages/eve/src/instrumentation/native-events.ts
index 625d75fdc..ade221bfa 100644
--- a/packages/eve/src/instrumentation/native-events.ts
+++ b/packages/eve/src/instrumentation/native-events.ts
@@ -1,4 +1,4 @@
-import type { UnstampedMessageStreamEvent } from "#protocol/message.js";
+import type { ActionResultError, UnstampedMessageStreamEvent } from "#protocol/message.js";
import { contextStorage } from "#context/container.js";
import { instrumentChannelDelivery } from "#instrumentation/channel-delivery.js";
import type {
@@ -283,7 +283,7 @@ async function publishActionTerminal(
const error = capturesOutputs
? event.data.error === undefined
? event.data.result.output
- : Object.assign(new Error(event.data.error.message), { code: event.data.error.code })
+ : toThrownError(event.data.error)
: undefined;
await hooks.publish(
Object.freeze({
@@ -301,6 +301,12 @@ async function publishActionTerminal(
);
}
+function toThrownError({ code, message, name }: ActionResultError): Error {
+ const error = Object.assign(new Error(message), { code });
+ if (name !== undefined) error.name = name;
+ return error;
+}
+
function actionUsage(result: RuntimeActionResult): InstrumentationUsage | undefined {
if (
result.kind !== "subagent-result" ||
diff --git a/packages/eve/src/protocol/message.ts b/packages/eve/src/protocol/message.ts
index 0be91ee1e..15073cb6f 100644
--- a/packages/eve/src/protocol/message.ts
+++ b/packages/eve/src/protocol/message.ts
@@ -104,6 +104,8 @@ export type ActionResultStatus = "completed" | "failed" | "rejected";
export interface ActionResultError {
readonly code: string;
readonly message: string;
+ /** The `name` of the error a tool threw, such as `"QuotaError"`. */
+ readonly name?: string;
}
/**
@@ -1967,15 +1969,13 @@ function normalizeActionResultOutcome(result: RuntimeActionResult): {
}
function buildActionResultError(result: RuntimeActionResult): ActionResultError {
- const outputError = readActionResultOutputError(result.output);
- if (outputError !== undefined) {
- return outputError;
- }
-
- return {
+ const error = readActionResultOutputError(result.output) ?? {
code: "ACTION_RESULT_FAILED",
message: formatActionResultOutput(result.output),
};
+ return result.kind === "tool-result" && result.errorName !== undefined
+ ? { ...error, name: result.errorName }
+ : error;
}
function readActionResultOutputError(output: unknown): ActionResultError | undefined {
diff --git a/packages/eve/src/shared/action-types.ts b/packages/eve/src/shared/action-types.ts
index 8b5234d29..f26ebe5aa 100644
--- a/packages/eve/src/shared/action-types.ts
+++ b/packages/eve/src/shared/action-types.ts
@@ -225,6 +225,8 @@ export type RuntimeToolResultActionResult = z.infer<typeof runtimeToolResultActi
const runtimeToolResultActionResultSchema = z
.object({
callId: z.string(),
+ /** The `name` of the error the tool threw, such as `"QuotaError"`. */
+ errorName: z.string().optional(),
isError: z.boolean().optional(),
kind: z.literal("tool-result"),
output: jsonValueSchema,