The Open Framework for Building Agents
fix(eve): post one notice when a failed turn ends the session (#4656)
Andrew Barba5d378430876e
diff --git a/.changeset/terminal-turn-failure-notice.md b/.changeset/terminal-turn-failure-notice.mdnew file mode 100644index 000000000..154e1f8e6--- /dev/null+++ b/.changeset/terminal-turn-failure-notice.md@@ -0,0 +1,5 @@+---+"eve": patch+---++When a failed turn ends the session, built-in channels now post one notice telling the person to start over, instead of a "please try again" notice followed by a "start a new session" notice for the same error. `turn.failed` events now carry `terminal: true` when `session.failed` follows (and `false` when the session waits for the next message), so custom channel handlers can make the same choice.diff --git a/docs/channels/custom.mdx b/docs/channels/custom.mdxindex d83b54b0a..6f5a166d2 100644--- a/docs/channels/custom.mdx+++ b/docs/channels/custom.mdx@@ -81,6 +81,13 @@ the exact session, while `channel.continuation` exposes the current address andreceives only `(eventData, channel)` because it runs outside session context;its event data contains `sessionId` directly.+A failed turn emits `turn.failed`, then either `session.waiting` or+`session.failed`. `turn.failed` carries `terminal: true` when the failure ends+the session and `session.failed` follows. The built-in channels skip terminal+`turn.failed` events, so a person sees one notice: the `session.failed` handler+tells them to start over instead of to try again. Check `eventData.terminal` the+same way in a custom channel that posts on both events.+A channel that renders questions and approvals from `input.requested` can handle`input.resolved` to learn when each request ends, however it ended: answered fromthe channel, answered by a plain-text reply, or withdrawn. A request that adiff --git a/docs/concepts/sessions-runs-and-streaming.md b/docs/concepts/sessions-runs-and-streaming.mdindex fba4ca02c..0a7af3faa 100644--- a/docs/concepts/sessions-runs-and-streaming.md+++ b/docs/concepts/sessions-runs-and-streaming.md@@ -95,7 +95,7 @@ The stream is newline-delimited JSON (NDJSON), one event per line:| `step.failed` | A model step failed; carries `{ code, message, details? }`. || `turn.waiting` | The open turn parked; carries `turnId` and `on`: `"input"` while a person must act on a sign-in, approval, or question, `"tasks"` while work it started runs. The turn has not ended. || `turn.completed` | The turn finished. |-| `turn.failed` | The turn failed; carries `{ code, message, details? }`. |+| `turn.failed` | The turn failed; carries `{ code, message, details?, terminal? }`. `terminal` is `true` when `session.failed` follows instead of `session.waiting`. || `turn.cancelled` | The turn was cancelled before finishing; always followed by `session.waiting`. || `session.waiting` | The session parked and is ready for the next message. || `session.failed` | The session failed. |@@ -131,7 +131,7 @@ A call to a tool that runs as a task, such as an agent tool, `agentRouter()`, thA turn doesn't end while tasks are working. When the model ends its text early, eve holds the turn and the stream emits `turn.waiting` for it; the turn continues once a result arrives or its caller writes. In a root session, that text completes as an ordinary `message.completed`. In a child session or a schedule's session, it reports `finishReason: "tool-calls"`, so channels post only the final reply. When the model calls `eve__task_wait` and no result is ready yet, the stream also emits `turn.waiting`. Either way, the next `step.started` for the same `turnId` means the turn resumed, and `session.waiting` comes only after the turn ends. See [Tasks](/docs/tools/tasks#turns-wait-for-their-tasks).-`step.failed` and `turn.failed` carry `{ code, message, details? }` for the failed fragment or turn, and `session.failed` is the terminal session-level variant. `turn.cancelled` is not a failure: the cancelled turn ends without any failure event, `session.waiting` follows, and the session accepts the next message normally. Whatever the turn streamed before cancellation stays on the stream. Durable history keeps the accepted user input and previously settled work, and discards incomplete assistant output. Tool calls the cancellation stopped stay in history, each answered as cancelled, so the model sees that the work started and stopped instead of a request left unanswered. Before `turn.cancelled`, the stream reports requests the cancel strands as `cancelled` in `input.resolved`. These include the turn's own questions, the session-limit prompt, and requests relayed from the work it stops. When a turn requested an output schema, the finalized payload lands on `result.completed` as `data.result` before the turn boundary. `authorization.required` carries the sign-in challenge (`data.authorization` may include `url`, `userCode`, `expiresAt`, `instructions`), and `authorization.completed` carries `data.outcome` (`"authorized" | "declined" | "failed" | "timed-out"`). Both carry `data.principalId` when a session principal started the sign-in. It holds the same value as `responderPrincipalId` on approval events, so a channel can deliver the challenge privately to that person even after someone else starts a later turn.+`step.failed` and `turn.failed` carry `{ code, message, details? }` for the failed fragment or turn, and `session.failed` is the terminal session-level variant. `turn.failed` also carries `terminal`: `true` when the failure ends the session and `session.failed` follows, `false` when `session.waiting` follows and the next message can retry. Events from eve versions before `terminal` was added omit it. `turn.cancelled` is not a failure: the cancelled turn ends without any failure event, `session.waiting` follows, and the session accepts the next message normally. Whatever the turn streamed before cancellation stays on the stream. Durable history keeps the accepted user input and previously settled work, and discards incomplete assistant output. Tool calls the cancellation stopped stay in history, each answered as cancelled, so the model sees that the work started and stopped instead of a request left unanswered. Before `turn.cancelled`, the stream reports requests the cancel strands as `cancelled` in `input.resolved`. These include the turn's own questions, the session-limit prompt, and requests relayed from the work it stops. When a turn requested an output schema, the finalized payload lands on `result.completed` as `data.result` before the turn boundary. `authorization.required` carries the sign-in challenge (`data.authorization` may include `url`, `userCode`, `expiresAt`, `instructions`), and `authorization.completed` carries `data.outcome` (`"authorized" | "declined" | "failed" | "timed-out"`). Both carry `data.principalId` when a session principal started the sign-in. It holds the same value as `responderPrincipalId` on approval events, so a channel can deliver the challenge privately to that person even after someone else starts a later turn.A provider response ending with `content-filter` fails with `MODEL_CALL_FAILED`,`details.semanticErrorId: "model-response-content-filtered"`, anddiff --git a/packages/eve/extension-contracts/compatibility/channel/v59.ts b/packages/eve/extension-contracts/compatibility/channel/v59.tsnew file mode 100644index 000000000..a00ffd27f--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/channel/v59.ts@@ -0,0 +1,15 @@+import { defineChannel } from "#public/channels/index.js";++// Epoch 59 `turn.failed` events had no `terminal`; epoch 60 adds it as optional.+// Handlers that read only the failure code and message keep working.+export default defineChannel({+ routes: [],+ events: {+ "turn.failed"(event) {+ console.info("turn failed", { code: event.code, message: event.message });+ },+ "session.failed"(event) {+ console.info("session failed", { code: event.code, sessionId: event.sessionId });+ },+ },+});diff --git a/packages/eve/extension-contracts/compatibility/connection/v46.ts b/packages/eve/extension-contracts/compatibility/connection/v46.tsnew file mode 100644index 000000000..2c00b0bae--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/connection/v46.ts@@ -0,0 +1,10 @@+import { defineMcpClientConnection } from "#public/connections/index.js";++// Epoch 46 `turn.failed` events had no `terminal`; epoch 47 adds it as optional.+export default defineMcpClientConnection({+ description: "Search the support knowledge base.",+ url: "https://support.example.com/mcp",+ approval({ toolName }) {+ return toolName.endsWith("__search") ? "approved" : "user-approval";+ },+});diff --git a/packages/eve/extension-contracts/compatibility/dynamicInstructions/v37.ts b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v37.tsnew file mode 100644index 000000000..99c5cb103--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v37.ts@@ -0,0 +1,9 @@+import { defineDynamic, defineInstructions } from "#public/instructions/index.js";++// Epoch 37 `turn.failed` events had no `terminal`; epoch 38 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/v36.ts b/packages/eve/extension-contracts/compatibility/dynamicSkill/v36.tsnew file mode 100644index 000000000..4490a000d--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicSkill/v36.ts@@ -0,0 +1,12 @@+import { defineDynamic, defineSkill } from "#public/skills/index.js";++// Epoch 36 `turn.failed` events had no `terminal`; epoch 37 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/v79.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v79.tsnew file mode 100644index 000000000..38e5b94f5--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v79.ts@@ -0,0 +1,14 @@+import { defineDynamic, defineTool } from "#public/tools/index.js";++// Epoch 79 `turn.failed` events had no `terminal`; epoch 80 adds it as optional.+export default defineDynamic({+ events: {+ "turn.started": (_event, ctx) => ({+ session_id: defineTool({+ description: "Return the current session id.",+ inputSchema: { type: "object", properties: {} },+ execute: () => ({ sessionId: ctx.session.id }),+ }),+ }),+ },+});diff --git a/packages/eve/extension-contracts/compatibility/hook/v44.ts b/packages/eve/extension-contracts/compatibility/hook/v44.tsnew file mode 100644index 000000000..0c523720d--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/hook/v44.ts@@ -0,0 +1,11 @@+import { defineHook } from "#public/hooks/index.js";++// Epoch 44 `turn.failed` events had no `terminal`; epoch 45 adds it as optional.+// Hooks that read failed turns keep working.+export default defineHook({+ events: {+ "turn.failed"(event) {+ console.info("turn failed", { code: event.data.code, turnId: event.data.turnId });+ },+ },+});diff --git a/packages/eve/extension-contracts/compatibility/schedule/v31.ts b/packages/eve/extension-contracts/compatibility/schedule/v31.tsnew file mode 100644index 000000000..c56ea99c9--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/schedule/v31.ts@@ -0,0 +1,19 @@+import { defineChannel } from "#public/channels/index.js";+import { defineSchedule } from "#public/schedules/index.js";++// Epoch 31 `turn.failed` events had no `terminal`; epoch 32 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/v35.ts b/packages/eve/extension-contracts/compatibility/subagent/v35.tsnew file mode 100644index 000000000..9b0be87de--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/subagent/v35.ts@@ -0,0 +1,7 @@+import { defineAgent } from "#public/index.js";++// Epoch 35 `turn.failed` events had no `terminal`; epoch 36 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/v85.ts b/packages/eve/extension-contracts/compatibility/tool/v85.tsnew file mode 100644index 000000000..0e33a38f1--- /dev/null+++ b/packages/eve/extension-contracts/compatibility/tool/v85.ts@@ -0,0 +1,12 @@+import { defineTool } from "#public/tools/index.js";++// Epoch 85 `turn.failed` events had no `terminal`; epoch 86 adds it as optional.+export default defineTool({+ description: "Look up an order by id.",+ inputSchema: {+ type: "object",+ properties: { id: { type: "string" } },+ required: ["id"],+ },+ execute: (input) => ({ id: (input as { readonly id: string }).id }),+});diff --git a/packages/eve/extension-contracts/reports/channel/v60.json b/packages/eve/extension-contracts/reports/channel/v60.jsonnew file mode 100644index 000000000..b92a02d76--- /dev/null+++ b/packages/eve/extension-contracts/reports/channel/v60.json@@ -0,0 +1,23 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "channel",+ "epoch": 60,+ "sha256": "f0044131e759b3ba9a283faaee3265859db24027902950138ffc80745bdda369",+ "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/v47.json b/packages/eve/extension-contracts/reports/connection/v47.jsonnew file mode 100644index 000000000..3177521c1--- /dev/null+++ b/packages/eve/extension-contracts/reports/connection/v47.json@@ -0,0 +1,16 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "connection",+ "epoch": 47,+ "sha256": "0847ed67a42720b933c70d09c58b6a269ccdff85a6cc289ef467336e83337cd6",+ "exports": [+ "ConnectionAuthorizationFailedError",+ "ConnectionAuthorizationRequiredError",+ "defineDynamic",+ "defineInteractiveAuthorization",+ "defineMcpClientConnection",+ "defineOpenAPIConnection",+ "isConnectionAuthorizationFailedError",+ "isConnectionAuthorizationRequiredError"+ ]+}diff --git a/packages/eve/extension-contracts/reports/dynamicInstructions/v38.json b/packages/eve/extension-contracts/reports/dynamicInstructions/v38.jsonnew file mode 100644index 000000000..1373b6808--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicInstructions/v38.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicInstructions",+ "epoch": 38,+ "sha256": "35920ad5ebde5bcbd982008f77aaf8c72f9eee16d972685b7c26d8ff4edead51",+ "exports": ["defineDynamic"]+}diff --git a/packages/eve/extension-contracts/reports/dynamicSkill/v37.json b/packages/eve/extension-contracts/reports/dynamicSkill/v37.jsonnew file mode 100644index 000000000..caa877471--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicSkill/v37.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicSkill",+ "epoch": 37,+ "sha256": "87a17000e06abfe4af91ecf53e7afed5a3aa6706a024861b0caa65c660dedf22",+ "exports": ["defineDynamic"]+}diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v80.json b/packages/eve/extension-contracts/reports/dynamicTool/v80.jsonnew file mode 100644index 000000000..e533b0a1a--- /dev/null+++ b/packages/eve/extension-contracts/reports/dynamicTool/v80.json@@ -0,0 +1,16 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "dynamicTool",+ "epoch": 80,+ "sha256": "f31f7ea66f2f3660aad26ab562e087f52a3b780e11134ba42d0ba81de96e0e7b",+ "exports": [+ "DynamicToolEntry",+ "DynamicToolEvents",+ "DynamicToolResult",+ "DynamicToolSet",+ "auto",+ "defineDurableCallback",+ "defineDurableSchema",+ "defineDynamic"+ ]+}diff --git a/packages/eve/extension-contracts/reports/hook/v45.json b/packages/eve/extension-contracts/reports/hook/v45.jsonnew file mode 100644index 000000000..67e93c9e8--- /dev/null+++ b/packages/eve/extension-contracts/reports/hook/v45.json@@ -0,0 +1,7 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "hook",+ "epoch": 45,+ "sha256": "c3b52f0fa7e2a731dbe9b43666b9f6d60388c249d994cd1b796b4be7d79178a3",+ "exports": ["defineHook"]+}diff --git a/packages/eve/extension-contracts/reports/schedule/v32.json b/packages/eve/extension-contracts/reports/schedule/v32.jsonnew file mode 100644index 000000000..e6b01a921--- /dev/null+++ b/packages/eve/extension-contracts/reports/schedule/v32.json@@ -0,0 +1,15 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "schedule",+ "epoch": 32,+ "sha256": "af9ac607ee3de5895dbafade25a0e55f15a1c5c903ce3a08ede07637ede77bae",+ "exports": [+ "ScheduleDefinition",+ "ScheduleHandlerArgs",+ "ScheduleRunHandler",+ "ScheduleToFn",+ "TypedReceiveTarget",+ "defineSchedule",+ "isScheduleAuth"+ ]+}diff --git a/packages/eve/extension-contracts/reports/subagent/v36.json b/packages/eve/extension-contracts/reports/subagent/v36.jsonnew file mode 100644index 000000000..f2ae7c776--- /dev/null+++ b/packages/eve/extension-contracts/reports/subagent/v36.json@@ -0,0 +1,23 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "subagent",+ "epoch": 36,+ "sha256": "fd2584223392e80cf9eea8d5bb0c6d90e30d901943d61022d9ab6f3309f8b525",+ "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/v86.json b/packages/eve/extension-contracts/reports/tool/v86.jsonnew file mode 100644index 000000000..35ebb1412--- /dev/null+++ b/packages/eve/extension-contracts/reports/tool/v86.json@@ -0,0 +1,29 @@+{+ "kind": "eve-extension-capability-contract",+ "capability": "tool",+ "epoch": 86,+ "sha256": "4b5beef0493bb47ebe54f8de6865e76e8790fdab9a5cb96ffe30055903bea20d",+ "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/cli/dev/tui/transcript.test.ts b/packages/eve/src/cli/dev/tui/transcript.test.tsindex a81091d4e..26e7dcfd8 100644--- a/packages/eve/src/cli/dev/tui/transcript.test.ts+++ b/packages/eve/src/cli/dev/tui/transcript.test.ts@@ -404,6 +404,7 @@ describe("ConversationTranscript", () => {code: "MODEL_CALL_FAILED",message: "Unavailable.",sequence: 1,+ terminal: false,turnId: "child_turn_2",}),]),diff --git a/packages/eve/src/client/message-reducer.test.ts b/packages/eve/src/client/message-reducer.test.tsindex f3a2a8b6c..d24c9efda 100644--- a/packages/eve/src/client/message-reducer.test.ts+++ b/packages/eve/src/client/message-reducer.test.ts@@ -400,6 +400,7 @@ describe("defaultMessageReducer", () => {code: "MODEL_FAILED",message: "model failed",sequence: 4,+ terminal: false,turnId: "turn_1",}),]);@@ -428,6 +429,7 @@ describe("defaultMessageReducer", () => {code: "MODEL_FAILED",message: "model failed",sequence: 1,+ terminal: false,turnId: "turn_1",}),] as const;@@ -553,6 +555,7 @@ describe("defaultMessageReducer", () => {code: "MODEL_FAILED",message: "model failed",sequence: 1,+ terminal: false,turnId: "turn_1",}),]);diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.tsindex a8cd30294..468250b86 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: 85,+ current: 86,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,+ 85, 86,],dropped: {14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",@@ -89,10 +89,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},dynamicTool: {- current: 79,+ current: 80,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,+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 75, 76, 77, 78, 79, 80,],dropped: {21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -133,10 +133,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},channel: {- current: 59,+ current: 60,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,+ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 60,],dropped: {12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -159,10 +159,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},schedule: {- current: 31,+ current: 32,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,+ 29, 30, 31, 32,],dropped: {5: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -171,10 +171,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},subagent: {- current: 35,+ current: 36,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,+ 34, 35, 36,],dropped: {1: "Persistent subagent sessions are now the default and the experimental opt-in was removed",@@ -188,10 +188,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},connection: {- current: 46,+ current: 47,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,+ 35, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47,],dropped: {9: "Dynamic connection resolvers no longer receive conversation or channel continuation data",@@ -207,8 +207,8 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},},hook: {- current: 44,- supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44],+ current: 45,+ supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45],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 +239,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},skill: { current: 3, supported: [1, 2, 3], dropped: {} },dynamicSkill: {- current: 36,+ current: 37,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,+ 31, 32, 33, 34, 35, 36, 37,],dropped: {13: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",@@ -253,10 +253,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {},instructions: { current: 2, supported: [1, 2], dropped: {} },dynamicInstructions: {- current: 37,+ current: 38,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,+ 31, 32, 33, 34, 35, 36, 37, 38,],dropped: {14: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",diff --git a/packages/eve/src/harness/session-machine/transitions.ts b/packages/eve/src/harness/session-machine/transitions.tsindex 9ebbbf228..033d29f6a 100644--- a/packages/eve/src/harness/session-machine/transitions.ts+++ b/packages/eve/src/harness/session-machine/transitions.ts@@ -208,9 +208,10 @@ function failedEvents(): UnstampedMessageStreamEvent[] {const { sequence, stepIndex, turnId } = at;const { code, details, message } = failure;+ const terminal = failure.terminal !== undefined;return [createStepFailedEvent({ code, details, message, sequence, stepIndex, turnId }),- createTurnFailedEvent({ code, details, message, sequence, turnId }),+ createTurnFailedEvent({ code, details, message, sequence, terminal, turnId }),failure.terminal === undefined? createSessionWaitingEvent(view.usage): createSessionFailedEvent({diff --git a/packages/eve/src/instrumentation/native-events.test.ts b/packages/eve/src/instrumentation/native-events.test.tsindex 3074d328d..067b545b2 100644--- a/packages/eve/src/instrumentation/native-events.test.ts+++ b/packages/eve/src/instrumentation/native-events.test.ts@@ -40,6 +40,7 @@ describe("createInstrumentationHandleEvent", () => {code: "MODEL_CALL_FAILED",message: "failed",sequence: 0,+ terminal: false,turnId: "turn_0",}),],diff --git a/packages/eve/src/protocol/message.ts b/packages/eve/src/protocol/message.tsindex 280bf1bb8..f90a9d74d 100644--- a/packages/eve/src/protocol/message.ts+++ b/packages/eve/src/protocol/message.ts@@ -669,6 +669,12 @@ export interface TurnFailedStreamEvent {details?: JsonObject;message: string;sequence: number;+ /**+ * `true` when the failure ends the session and `session.failed` follows;+ * `false` when `session.waiting` follows and the next message can retry.+ * Absent on events from eve versions before it was added.+ */+ terminal?: boolean;turnId: string;};type: "turn.failed";@@ -1769,6 +1775,7 @@ export function createTurnFailedEvent(input: {readonly details?: JsonObject;readonly message: string;readonly sequence: number;+ readonly terminal: boolean;readonly turnId: string;}): TurnFailedStreamEvent {return {@@ -1777,6 +1784,7 @@ export function createTurnFailedEvent(input: {details: input.details,message: input.message,sequence: input.sequence,+ terminal: input.terminal,turnId: input.turnId,},type: "turn.failed",diff --git a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.test.ts b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.test.tsindex 516599fb3..18cb1abab 100644--- a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.test.ts+++ b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.test.ts@@ -6,11 +6,14 @@ import { callAdapterEventHandler, type ChannelAdapter } from "#channel/adapter.jimport { isCompiledChannel, type CompiledChannel } from "#channel/compiled-channel.js";import { isHttpRouteDefinition } from "#channel/routes.js";import { ContextContainer, contextStorage } from "#context/container.js";+import { sessionView } from "#harness/session-machine/commit.js";import { enterSessionProjection, recordPublishedEvent } from "#harness/session-machine/current.js";+import { fail } from "#harness/session-machine/transitions.js";import { SessionKey } from "#context/keys.js";import { mockChannelContext } from "#internal/testing/mocks/mock-channel-operations.js";import { SEARCH_TOOL_NAME } from "#protocol/catalog-tools.js";import type { UnstampedMessageStreamEvent } from "#protocol/message.js";+import { initialSessionProjection } from "#protocol/session-projection.js";import { TASK_WAIT_TOOL_NAME } from "#protocol/task-tools.js";import {chatSdkChannel,@@ -433,6 +436,33 @@ describe("chatSdkChannel", () => {]);});+ it("posts only a restart notice when a failed turn ends the session", async () => {+ const adapter = testAdapter();+ const bridge = chatSdkChannel({+ adapters: { test: adapter },+ state: memoryState(),+ userName: "bot",+ });+ const channelAdapter = withState(getAdapter(bridge.channel), { thread: serializedThread() });+ const ctx = buildAdapterContext(channelAdapter, stubAccessor());+ const failure = fail(sessionView(initialSessionProjection(), undefined), {+ code: "MODEL_CALL_FAILED",+ details: { errorId: "err_1" },+ message: "The provider rejected the request",+ terminal: { sessionId: "test-session" },+ });++ for (const event of failure.events) await callEvent(channelAdapter, event, ctx);++ expect(adapter.posted).toEqual([+ {+ message:+ "This session could not recover from an error (The provider rejected the request).\n\nStart a new conversation to continue.\n\nError id: err_1",+ threadId: THREAD_ID,+ },+ ]);+ });+it("renders an authorization challenge in a direct-message thread and updates it on completion", async () => {const adapter = testAdapter();const bridge = chatSdkChannel({diff --git a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.tsindex f4d101f64..f23d88bd3 100644--- a/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts+++ b/packages/eve/src/public/channels/chat-sdk/chatSdkChannel.ts@@ -514,10 +514,21 @@ function defaultEvents<TAdapters extends ChatSdkAdapters>(await finalizeStreamedMessage(channel, event.message, true);},async "turn.failed"(event, channel, _ctx) {- await postFailure(channel.thread, "I hit an error while handling your request", event);+ if (event.terminal) return;+ await postFailure(+ channel.thread,+ "I hit an error while handling your request",+ "Please try again, rephrase, or reach out if it keeps failing.",+ event,+ );},async "session.failed"(event, channel) {- await postFailure(channel.thread, "This session could not recover from an error", event);+ await postFailure(+ channel.thread,+ "This session could not recover from an error",+ "Start a new conversation to continue.",+ event,+ );},};}@@ -608,17 +619,14 @@ function truncate(text: string, max = MAX_TYPING_STATUS): string {async function postFailure(thread: Thread | null,prefix: string,+ nextStep: string,event: EventData<"turn.failed"> | EventData<"session.failed">,): Promise<void> {if (!thread) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await thread.post(- [- `${prefix}${hint}.`,- "Please try again, rephrase, or reach out if it keeps failing.",- ...(errorId ? [`Error id: ${errorId}`] : []),- ].join("\n\n"),+ [`${prefix}${hint}.`, nextStep, ...(errorId ? [`Error id: ${errorId}`] : [])].join("\n\n"),);}diff --git a/packages/eve/src/public/channels/discord/defaults.ts b/packages/eve/src/public/channels/discord/defaults.tsindex 10fbb2a14..635ffa150 100644--- a/packages/eve/src/public/channels/discord/defaults.ts+++ b/packages/eve/src/public/channels/discord/defaults.ts@@ -139,6 +139,7 @@ export const defaultEvents: DiscordChannelEvents = {},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await channel.discord.post(diff --git a/packages/eve/src/public/channels/github/defaults.ts b/packages/eve/src/public/channels/github/defaults.tsindex 15c202fef..3dfec1f03 100644--- a/packages/eve/src/public/channels/github/defaults.ts+++ b/packages/eve/src/public/channels/github/defaults.ts@@ -134,6 +134,7 @@ export function createDefaultEvents(options: GitHubDefaultEventOptions = {}): Gi},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);const message = [diff --git a/packages/eve/src/public/channels/linear/defaults.test.ts b/packages/eve/src/public/channels/linear/defaults.test.tsindex 2d3a172c4..2d99b58ad 100644--- a/packages/eve/src/public/channels/linear/defaults.test.ts+++ b/packages/eve/src/public/channels/linear/defaults.test.ts@@ -1,5 +1,8 @@import { describe, expect, it, vi } from "vitest";+import { sessionView } from "#harness/session-machine/commit.js";+import { fail } from "#harness/session-machine/transitions.js";+import { initialSessionProjection } from "#protocol/session-projection.js";import type { SessionContext } from "#public/definitions/callback-context.js";import { createDefaultEvents } from "#public/channels/linear/defaults.js";import type {@@ -37,18 +40,19 @@ function buildChannelStub(): LinearEventContext {}function buildEvents() {- const fetch = vi.fn().mockResolvedValue(- new Response(- JSON.stringify({- data: {- agentActivityCreate: {- agentActivity: { id: "activity_1" },- success: true,+ const fetch = vi.fn().mockImplementation(+ async () =>+ new Response(+ JSON.stringify({+ data: {+ agentActivityCreate: {+ agentActivity: { id: "activity_1" },+ success: true,+ },},- },- }),- { headers: { "content-type": "application/json" }, status: 200 },- ),+ }),+ { headers: { "content-type": "application/json" }, status: 200 },+ ),);return {events: createDefaultEvents({@@ -67,6 +71,59 @@ function activityInput(fetch: ReturnType<typeof vi.fn>): Record<string, unknown>return body.variables.input;}+/** Delivers a failed step's events to the default handlers, as the Linear adapter does. */+async function failStep(+ events: ReturnType<typeof buildEvents>["events"],+ terminal: { sessionId: string } | undefined,+): Promise<void> {+ const failure = fail(sessionView(initialSessionProjection(), undefined), {+ code: "MODEL_CALL_FAILED",+ details: { errorId: "err_1" },+ message: "The provider rejected the request",+ terminal,+ });+ for (const event of failure.events) {+ const handler = events[event.type as keyof typeof events] as+ | ((data: unknown, channel: LinearEventContext, ctx: SessionContext) => Promise<void>)+ | undefined;+ await handler?.("data" in event ? event.data : undefined, buildChannelStub(), sessionContext());+ }+}++function errorNotices(fetch: ReturnType<typeof vi.fn>): string[] {+ return fetch.mock.calls+ .map((call) => {+ const body = JSON.parse(String((call[1] as RequestInit).body)) as {+ variables: { input: { content: { body?: string; type: string } } };+ };+ return body.variables.input.content;+ })+ .filter((content) => content.type === "error")+ .map((content) => content.body ?? "");+}++describe("createDefaultEvents failure notices", () => {+ it("posts only the restart notice when a failed turn ends the session", async () => {+ const { events, fetch } = buildEvents();++ await failStep(events, { sessionId: "test-session" });++ expect(errorNotices(fetch)).toEqual([+ expect.stringContaining("Start a new Linear agent session to continue."),+ ]);+ });++ it("posts only the retry notice when the session waits after a failed turn", async () => {+ const { events, fetch } = buildEvents();++ await failStep(events, undefined);++ expect(errorNotices(fetch)).toEqual([+ expect.stringContaining("Please try again, rephrase, or reach out if it keeps failing."),+ ]);+ });+});+describe("createDefaultEvents authorization.required", () => {it("posts Linear's native auth elicitation for the triggering user", async () => {const { events, fetch } = buildEvents();diff --git a/packages/eve/src/public/channels/linear/defaults.ts b/packages/eve/src/public/channels/linear/defaults.tsindex 04ee1db0e..f419c018f 100644--- a/packages/eve/src/public/channels/linear/defaults.ts+++ b/packages/eve/src/public/channels/linear/defaults.ts@@ -225,6 +225,7 @@ export function createDefaultEvents(options: LinearDefaultEventOptions = {}): Li},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await postActivity(channel, options, {diff --git a/packages/eve/src/public/channels/slack/defaults.ts b/packages/eve/src/public/channels/slack/defaults.tsindex 594a9ad6d..6e5ba7457 100644--- a/packages/eve/src/public/channels/slack/defaults.ts+++ b/packages/eve/src/public/channels/slack/defaults.ts@@ -354,6 +354,7 @@ export const defaultEvents: SlackChannelInternalEvents = {},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const errorId = extractErrorId(event.details);const semanticSummary = extractSemanticErrorSummary(event);if (semanticSummary !== null) {diff --git a/packages/eve/src/public/channels/teams/defaults.ts b/packages/eve/src/public/channels/teams/defaults.tsindex 4942f3ecc..c8c781204 100644--- a/packages/eve/src/public/channels/teams/defaults.ts+++ b/packages/eve/src/public/channels/teams/defaults.ts@@ -151,6 +151,7 @@ export const defaultEvents: TeamsChannelEvents = {},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await channel.thread.post(diff --git a/packages/eve/src/public/channels/telegram/defaults.ts b/packages/eve/src/public/channels/telegram/defaults.tsindex 90f16fc3e..ba83309a8 100644--- a/packages/eve/src/public/channels/telegram/defaults.ts+++ b/packages/eve/src/public/channels/telegram/defaults.ts@@ -206,6 +206,7 @@ export const defaultEvents: TelegramChannelEvents = {},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await channel.telegram.post(diff --git a/packages/eve/src/public/channels/twilio/defaults.ts b/packages/eve/src/public/channels/twilio/defaults.tsindex 593b063d2..71d81d1d3 100644--- a/packages/eve/src/public/channels/twilio/defaults.ts+++ b/packages/eve/src/public/channels/twilio/defaults.ts@@ -111,6 +111,7 @@ export const defaultEvents: TwilioChannelEvents = {},async "turn.failed"(event, channel, _ctx) {+ if (event.terminal) return;const hint = formatErrorHint(event);const errorId = extractErrorId(event.details);await channel.twilio.sendMessage(diff --git a/packages/eve/src/react/use-eve-agent.test.ts b/packages/eve/src/react/use-eve-agent.test.tsindex c6aa459e3..b53041018 100644--- a/packages/eve/src/react/use-eve-agent.test.ts+++ b/packages/eve/src/react/use-eve-agent.test.ts@@ -922,6 +922,7 @@ describe("useEveAgent", () => {code: "MODEL_CALL_FAILED",message: "Recoverable model failure",sequence: 0,+ terminal: false,turnId: "turn_1",}),createSessionWaitingEvent(TEST_USAGE),