Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): report why a task was cancelled, and show task_cancel as done in Slack (#4091)

Andrew Barba79fa2aaa6b14
diff --git a/.changeset/slack-task-card-cancel-success.md b/.changeset/slack-task-card-cancel-success.md
new file mode 100644
index 000000000..79944fb94
--- /dev/null
+++ b/.changeset/slack-task-card-cancel-success.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+`task.settled` for a cancelled call now carries `cancel.reason`: `"task_cancel"` when the model called `task_cancel`, `"turn_cancelled"` when someone cancelled the turn, or `"turn_ended"` when the turn ended while the task still worked. The Slack task card uses it: a task the model cancelled now shows a success check and `Stopped early since it was no longer needed`, and other stopped tasks say why, such as `Stopped by request` or `Stopped when the turn ended`.
diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdx
index f17ce098e..22f6ec7bf 100644
--- a/docs/channels/slack.mdx
+++ b/docs/channels/slack.mdx
@@ -482,9 +482,9 @@ Each row shows:
- **Title:** the tool's [`label.start`](/docs/tools#label-tool-activity), or the tool name. An agent task shows the agent name and the first sentence of its brief (`researcher: Find the incidents behind the checkout spike`). A task the agent hands to its own copy shows the brief alone.
- **Waiting:** while the task waits on an approval, an answer, or a sign-in, the row says so, as in `Waiting for approval`. In a DM or private channel it also shows the request's prompt; elsewhere it shows only what kind of request is waiting, since `approvalChannel` can send the request to one person. The request itself posts wherever `approvalChannel` sends it, and the row goes back to working once the request resolves.
-- **How it ended:** the first sentence of the result or the agent's reply, cut to about 100 characters, `Failed` for a failure, or `Stopped` for a cancelled task. Failed and stopped rows never show a success check. In a DM or private channel, a failure also shows the first sentence of its error, as in `Failed: Rate limited`. Error text can carry internal details, so everywhere else, including proactive sessions without a known `audience`, shows `Failed` alone.
+- **How it ended:** the first sentence of the result or the agent's reply, cut to about 100 characters, `Failed` for a failure, or a line for a cancelled task that says why it stopped. A task the model cancelled with `task_cancel` shows `Stopped early since it was no longer needed` with a success check, since the model no longer needed that work. A task stopped by [cancelling the turn](#message-hooks) shows `Stopped by request`, one stopped because its turn ended shows `Stopped when the turn ended`, and one whose run stopped on its own shows `Stopped`. Those rows and failed rows never show a success check. In a DM or private channel, a failure also shows the first sentence of its error, as in `Failed: Rate limited`. Error text can carry internal details, so everywhere else, including proactive sessions without a known `audience`, shows `Failed` alone.
-The plan title summarizes the turn: `Working on 2 tasks`, `1 of 2 tasks done`, `Waiting for approval`, then `Finished 2 tasks` or `Finished 3 tasks: 1 failed, 1 stopped`. A resumable task continued in a later turn appears in that turn's card.
+The plan title summarizes the turn: `Working on 2 tasks`, `1 of 2 tasks done`, `Waiting for approval`, then `Finished 2 tasks` or `Finished 3 tasks: 1 failed, 1 stopped`. Tasks the model cancelled with `task_cancel` count as finished, not stopped. A resumable task continued in a later turn appears in that turn's card.
eve writes the card from the session's own events as they happen, and only when it changed. A failed Slack call never fails the turn: eve tries a failed write once more after a second, then again on the turn's next change. If someone deletes the card, eve posts it again on its next change. Card posts never unfurl links. Schedule sessions and sessions without a Slack thread get no card.
diff --git a/docs/concepts/sessions-runs-and-streaming.md b/docs/concepts/sessions-runs-and-streaming.md
index 461cc1217..d3babc363 100644
--- a/docs/concepts/sessions-runs-and-streaming.md
+++ b/docs/concepts/sessions-runs-and-streaming.md
@@ -81,7 +81,7 @@ The stream is newline-delimited JSON (NDJSON), one event per line:
| `input.resolved` | The server accepted terminal human-input outcomes; carries `resolutions` with responses when provided. |
| `agent.started` | A workflow run opened a session with `ctx.agent`, such as an agent tool's; carries `taskId` when the run is a task, `sessionId`, and the `streamPath` that `session.agent(started).stream()` follows. |
| `task.started` | A tool call started a [task](#task-events); carries `taskId`, `callId`, `turnId`, the tool `name`, and `kind`: `"agent"` for an agent tool, `"tool"` otherwise. |
-| `task.settled` | A task's call settled; carries `taskId`, `callId`, `turnId`, the tool `name`, `kind`, `status`, and `output` or `error.message`; a cancelled call carries neither. |
+| `task.settled` | A task's call settled; carries `taskId`, `callId`, `turnId`, the tool `name`, `kind`, `status`, and `output` or `error.message`; a cancelled call carries `cancel.reason` instead. |
| `reasoning.appended` | A reasoning text delta. |
| `reasoning.completed` | The finalized reasoning block. |
| `message.appended` | An assistant text delta. |
@@ -236,7 +236,7 @@ curl -X POST http://127.0.0.1:2000/eve/v1/session/<sessionId>/cancel
# {"ok":true,"sessionId":"<sessionId>","status":"accepted"}
```
-`"accepted"` means the live session durably queued the request; cancellation completes asynchronously. Confirm turn cancellation on the stream as `turn.cancelled` followed by `session.waiting`. The session then accepts the next message normally. Each cancelled child reports its own boundary on its child-session stream. Cancelling also stops every working task, each reported as `task.settled` with `status: "cancelled"`, including while the session waits between turns. A live but already-parked session returns `"accepted"`; with no working tasks, cancellation is a no-op there. `"no_active_turn"` means the session or channel address is unknown or terminal. Both statuses are success, so clients can fire and forget. See the [eve channel](../channels/eve) for the full route contract.
+`"accepted"` means the live session durably queued the request; cancellation completes asynchronously. Confirm turn cancellation on the stream as `turn.cancelled` followed by `session.waiting`. The session then accepts the next message normally. Each cancelled child reports its own boundary on its child-session stream. Cancelling also stops every working task, each reported as `task.settled` with `status: "cancelled"` and `cancel.reason: "turn_cancelled"`, including while the session waits between turns. A live but already-parked session returns `"accepted"`; with no working tasks, cancellation is a no-op there. `"no_active_turn"` means the session or channel address is unknown or terminal. Both statuses are success, so clients can fire and forget. See the [eve channel](../channels/eve) for the full route contract.
The HTTP route returns `202` for `"accepted"` and `200` for
`"no_active_turn"`. Only the accepted result includes `sessionId`.
diff --git a/docs/tools/tasks.md b/docs/tools/tasks.md
index f1d4539cb..d921b635b 100644
--- a/docs/tools/tasks.md
+++ b/docs/tools/tasks.md
@@ -263,19 +263,23 @@ same `taskId` continues where it left off. A `serve` body that doesn't return to
## Stream events
-| Event | When | Data |
-| --------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------ |
-| `task.started` | A call starts a task, or reaches a resumable task by its `taskId` | `taskId`, `callId`, `turnId`, the tool `name`, and `kind` |
-| `task.settled` | A reply, return, failure, or cancel settles one call | `taskId`, `callId`, `turnId`, `name`, `kind`, `status`, and `output` or `error` unless cancelled |
-| `agent.started` | A workflow run, including an agent tool's, opens a session with an agent | `callId`, `turnId`, `taskId`, `name`, `sessionId`, `streamPath` |
-| `turn.waiting` | An open turn parks on its tasks, a `task_wait`, a question, or a sign-in | `turnId` and `sequence` |
+| Event | When | Data |
+| --------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ |
+| `task.started` | A call starts a task, or reaches a resumable task by its `taskId` | `taskId`, `callId`, `turnId`, the tool `name`, and `kind` |
+| `task.settled` | A reply, return, failure, or cancel settles one call | `taskId`, `callId`, `turnId`, `name`, `kind`, `status`, and `output`, `error`, or `cancel` |
+| `agent.started` | A workflow run, including an agent tool's, opens a session with an agent | `callId`, `turnId`, `taskId`, `name`, `sessionId`, `streamPath` |
+| `turn.waiting` | An open turn parks on its tasks, a `task_wait`, a question, or a sign-in | `turnId` and `sequence` |
`task.started` and `task.settled` come once each per call, and `(taskId, callId)` identifies the
call. Both carry that call's `turnId`, which for a resumable task's later call can be a later turn
than the one that started the task, and the task's tool `name` and `kind`. `kind` is `"agent"` for
an agent tool's call and `"tool"` otherwise. Events recorded by earlier eve versions omit `name`
and `kind` on `task.settled`; match those to their `task.started` by `callId`. `status` is `"completed"`, `"failed"`, or `"cancelled"`. A completed call carries
-`output`, a failed call carries `error`, and a cancelled call carries neither.
+`output`, a failed call carries `error`, and a cancelled call carries `cancel.reason`:
+`"task_cancel"` when the model called `task_cancel`, `"turn_cancelled"` when someone cancelled
+the turn, or the working tasks between turns, or `"turn_ended"` when the turn ended, such as by
+failing, while the task still worked. `cancel` is absent when the task's run stopped on its own, and on events recorded by
+earlier eve versions.
`agent.started` names the call and turn whose run opened the session, and its `taskId` is absent
when an `execute` call opened it. Results reach the model as a message in its history, not as a
stream event, so read outcomes from `task.settled`. An `input.requested`,
diff --git a/packages/eve/extension-contracts/compatibility/channel/v41.ts b/packages/eve/extension-contracts/compatibility/channel/v41.ts
new file mode 100644
index 000000000..2b9617436
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/channel/v41.ts
@@ -0,0 +1,12 @@
+import { defineChannel } from "#public/channels/index.js";
+
+// Epoch 41 `task.settled` events had no `cancel`; epoch 42 adds it as optional.
+// Channels that read only `status` still see `"cancelled"`.
+export default defineChannel({
+ routes: [],
+ events: {
+ "task.settled"(event) {
+ console.info("task settled", { name: event.name, status: event.status });
+ },
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/connection/v35.ts b/packages/eve/extension-contracts/compatibility/connection/v35.ts
new file mode 100644
index 000000000..bb3fd492a
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/connection/v35.ts
@@ -0,0 +1,10 @@
+import { defineMcpClientConnection } from "#public/connections/index.js";
+
+// Epoch 35 `task.settled` events had no `cancel`; epoch 36 adds it as optional.
+export default defineMcpClientConnection({
+ description: "Search the incident tracker.",
+ url: "https://incidents.example.com/mcp",
+ approval({ toolName }) {
+ return toolName.endsWith("__search") ? "approved" : "user-approval";
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicInstructions/v29.ts b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v29.ts
new file mode 100644
index 000000000..91f2c5e89
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicInstructions/v29.ts
@@ -0,0 +1,11 @@
+import { defineDynamic, defineInstructions } from "#public/instructions/index.js";
+
+// Epoch 29 `task.settled` events had no `cancel`; epoch 30 adds it as optional.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) =>
+ defineInstructions({
+ markdown: `Triage the incident reported in session ${ctx.session.id}.`,
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicSkill/v28.ts b/packages/eve/extension-contracts/compatibility/dynamicSkill/v28.ts
new file mode 100644
index 000000000..c803b426f
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicSkill/v28.ts
@@ -0,0 +1,12 @@
+import { defineDynamic, defineSkill } from "#public/skills/index.js";
+
+// Epoch 28 `task.settled` events had no `cancel`; epoch 29 adds it as optional.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) =>
+ defineSkill({
+ description: "Triage the active incident.",
+ markdown: `Triage the incident reported in session ${ctx.session.id}.`,
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v67.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v67.ts
new file mode 100644
index 000000000..82d387947
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v67.ts
@@ -0,0 +1,14 @@
+import { defineDynamic, defineTool } from "#public/tools/index.js";
+
+// Epoch 67 `task.settled` events had no `cancel`; epoch 68 adds it as optional.
+export default defineDynamic({
+ events: {
+ "turn.started": (_event, ctx) => ({
+ session: defineTool({
+ description: "Return the active session identifier.",
+ inputSchema: { type: "object", properties: {} },
+ execute: () => ({ sessionId: ctx.session.id }),
+ }),
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/hook/v34.ts b/packages/eve/extension-contracts/compatibility/hook/v34.ts
new file mode 100644
index 000000000..356dd9c92
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/hook/v34.ts
@@ -0,0 +1,15 @@
+import { defineHook } from "#public/hooks/index.js";
+
+// Epoch 34 `task.settled` events had no `cancel`; epoch 35 adds it as optional.
+// Hooks that read only `status` still see `"cancelled"`.
+export default defineHook({
+ events: {
+ "task.settled"(event, ctx) {
+ console.info("task settled", {
+ sessionId: ctx.session.id,
+ status: event.data.status,
+ taskId: event.data.taskId,
+ });
+ },
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/schedule/v23.ts b/packages/eve/extension-contracts/compatibility/schedule/v23.ts
new file mode 100644
index 000000000..ebfb20e8f
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/schedule/v23.ts
@@ -0,0 +1,22 @@
+import { defineChannel } from "#public/channels/index.js";
+import { defineSchedule } from "#public/schedules/index.js";
+
+// Epoch 23 `task.settled` events had no `cancel`; epoch 24 adds it as optional.
+const reports = defineChannel({
+ routes: [],
+ events: {
+ "task.settled"(event) {
+ console.info("report task settled", { status: event.status, taskId: event.taskId });
+ },
+ },
+ receive(input, { from }) {
+ return from("nightly-report").send(input.message, { auth: input.auth });
+ },
+});
+
+export default defineSchedule({
+ cron: "0 2 * * *",
+ async run({ to, appAuth, waitUntil }) {
+ waitUntil(to(reports, {}).send("Prepare the nightly report.", { auth: appAuth }));
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/subagent/v26.ts b/packages/eve/extension-contracts/compatibility/subagent/v26.ts
new file mode 100644
index 000000000..54de8c938
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/subagent/v26.ts
@@ -0,0 +1,7 @@
+import { defineAgent } from "#public/index.js";
+
+// Epoch 26 `task.settled` events had no `cancel`; epoch 27 adds it as optional.
+export default defineAgent({
+ description: "Research the incidents behind a metric change.",
+ model: "openai/gpt-5.6-sol",
+});
diff --git a/packages/eve/extension-contracts/compatibility/tool/v70.ts b/packages/eve/extension-contracts/compatibility/tool/v70.ts
new file mode 100644
index 000000000..514132603
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v70.ts
@@ -0,0 +1,11 @@
+import { z } from "zod";
+import { defineTool } from "#public/tools/index.js";
+
+// Epoch 70 `task.settled` events had no `cancel`; epoch 71 adds it as optional.
+// Tools that start tasks keep working.
+export default defineTool({
+ description: "Summarize the open incidents for a service.",
+ inputSchema: z.object({ service: z.string() }),
+ outputSchema: z.object({ service: z.string(), summary: z.string() }),
+ execute: ({ service }) => ({ service, summary: `No open incidents for ${service}.` }),
+});
diff --git a/packages/eve/extension-contracts/reports/channel/v42.json b/packages/eve/extension-contracts/reports/channel/v42.json
new file mode 100644
index 000000000..d8738ee9d
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/channel/v42.json
@@ -0,0 +1,21 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "channel",
+ "epoch": 42,
+ "sha256": "0b4c2c994fc225add3d9e93bd6fb86ddc095f3424f7b9484c904ff8020ba7464",
+ "exports": [
+ "DELETE",
+ "GET",
+ "HEAD",
+ "OPTIONS",
+ "PATCH",
+ "POST",
+ "PUT",
+ "WS",
+ "createWebSocketUpgradeServer",
+ "defineChannel",
+ "disableRoute",
+ "isChannel",
+ "isDisabledRouteSentinel"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/connection/v36.json b/packages/eve/extension-contracts/reports/connection/v36.json
new file mode 100644
index 000000000..1d49ca25f
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/connection/v36.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "connection",
+ "epoch": 36,
+ "sha256": "d2a8230fcbf566ebcd83a1baf23cc5830bb7942bcfa13831a838ff7fcb1c383f",
+ "exports": [
+ "ConnectionAuthorizationFailedError",
+ "ConnectionAuthorizationRequiredError",
+ "defineDynamic",
+ "defineInteractiveAuthorization",
+ "defineMcpClientConnection",
+ "defineOpenAPIConnection",
+ "isConnectionAuthorizationFailedError",
+ "isConnectionAuthorizationRequiredError"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicInstructions/v30.json b/packages/eve/extension-contracts/reports/dynamicInstructions/v30.json
new file mode 100644
index 000000000..16540f055
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicInstructions/v30.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicInstructions",
+ "epoch": 30,
+ "sha256": "f6feae1fceea5f54ce2405d7a72b900349b63c8ac2559bc2b72af664d3e296b1",
+ "exports": ["defineDynamic"]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicSkill/v29.json b/packages/eve/extension-contracts/reports/dynamicSkill/v29.json
new file mode 100644
index 000000000..2dd672698
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicSkill/v29.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicSkill",
+ "epoch": 29,
+ "sha256": "d76bb66e46e6f70c294eab970ee272f872d29458641494955e4db3ee3ece93fc",
+ "exports": ["defineDynamic"]
+}
diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v68.json b/packages/eve/extension-contracts/reports/dynamicTool/v68.json
new file mode 100644
index 000000000..34098295b
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicTool/v68.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicTool",
+ "epoch": 68,
+ "sha256": "97e8e55c6a79599abcd0b9360a388065437626af117c37ba62fd312b079a7334",
+ "exports": [
+ "DynamicToolEntry",
+ "DynamicToolEvents",
+ "DynamicToolResult",
+ "DynamicToolSet",
+ "auto",
+ "defineDurableCallback",
+ "defineDurableSchema",
+ "defineDynamic"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/hook/v35.json b/packages/eve/extension-contracts/reports/hook/v35.json
new file mode 100644
index 000000000..021fa9871
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/hook/v35.json
@@ -0,0 +1,7 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "hook",
+ "epoch": 35,
+ "sha256": "4ebe1c78a8d466b66b57998556a21d6d508a5cf8d236ad89b0c6601dac36c782",
+ "exports": ["defineHook"]
+}
diff --git a/packages/eve/extension-contracts/reports/schedule/v24.json b/packages/eve/extension-contracts/reports/schedule/v24.json
new file mode 100644
index 000000000..3e3c5bf5e
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/schedule/v24.json
@@ -0,0 +1,15 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "schedule",
+ "epoch": 24,
+ "sha256": "f3757f954a5f6bc3031ac7824c478181258a3e6bde9d615cf30b62fa79f22bfd",
+ "exports": [
+ "ScheduleDefinition",
+ "ScheduleHandlerArgs",
+ "ScheduleRunHandler",
+ "ScheduleToFn",
+ "TypedReceiveTarget",
+ "defineSchedule",
+ "isScheduleAuth"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/subagent/v27.json b/packages/eve/extension-contracts/reports/subagent/v27.json
new file mode 100644
index 000000000..0b47b321e
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/subagent/v27.json
@@ -0,0 +1,23 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "subagent",
+ "epoch": 27,
+ "sha256": "2f4dcecba2a0042453156552ea68d6279fb9a8af8a17ca0bad58e31dd141d63e",
+ "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/v71.json b/packages/eve/extension-contracts/reports/tool/v71.json
new file mode 100644
index 000000000..64be27de9
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v71.json
@@ -0,0 +1,29 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 71,
+ "sha256": "c06dec6b6d4bdcba2d5484a8399bc14d3bf9d681893e8960a64fd4d2ac043975",
+ "exports": [
+ "AgentRouterInput",
+ "AgentRouterTool",
+ "WorkflowStepToolContext",
+ "WorkflowTool",
+ "WorkflowToolDefinition",
+ "WorkflowToolInput",
+ "WorkflowToolOptions",
+ "agentRouter",
+ "defaultWebSearch",
+ "defineTool",
+ "defineWorkflowTool",
+ "disableTool",
+ "evaluate",
+ "isDisabledToolSentinel",
+ "isWebSearchToolDefinition",
+ "serializeModelInputSchema",
+ "toolOutput",
+ "toolOutputPart",
+ "toolResultFrom",
+ "webSearch",
+ "workflow"
+ ]
+}
diff --git a/packages/eve/src/channel/task-card.ts b/packages/eve/src/channel/task-card.ts
index a7e733062..7bccc8175 100644
--- a/packages/eve/src/channel/task-card.ts
+++ b/packages/eve/src/channel/task-card.ts
@@ -1,5 +1,5 @@
import { isTaskControlTool } from "#protocol/task-tools.js";
-import type { UnstampedMessageStreamEvent } from "#protocol/message.js";
+import type { TaskCancelReason, UnstampedMessageStreamEvent } from "#protocol/message.js";
import { actionRequestName } from "#shared/action-request-name.js";
import type { RuntimeActionRequest } from "#shared/action-types.js";
import type { ChannelAudience } from "#shared/channel-audience.js";
@@ -46,6 +46,11 @@ export interface TaskCardTask {
* only in a private conversation, since error text can carry internals.
*/
readonly summary?: string;
+ /**
+ * Why a cancelled task stopped: `task_cancel` when the model no longer
+ * needed it. Absent when the task's run stopped on its own.
+ */
+ readonly cancelReason?: TaskCancelReason;
readonly startedAt: string;
readonly settledAt?: string;
}
@@ -93,6 +98,7 @@ interface TrackedCall {
readonly id: string;
readonly kind: "agent" | "tool";
readonly summary?: string;
+ readonly cancelReason?: TaskCancelReason;
/** Open requests and sign-ins the task waits on, oldest first. */
readonly blockers?: readonly (TaskCardBlocker & { readonly id: string })[];
};
@@ -268,6 +274,8 @@ function trackTurnEvent(
};
const summary = taskSummary(event.data);
if (summary !== undefined) task.summary = summary;
+ const cancelReason = event.data.cancel?.reason;
+ if (cancelReason !== undefined) task.cancelReason = cancelReason;
return { turn: replaceCall(current, { ...call, settledAt: at, status, task }), turnId };
}
case "turn.completed":
@@ -365,6 +373,7 @@ function toTask(
}
const shown = call.status !== "failed" || shareable;
if (task.summary !== undefined && shown) row.summary = task.summary;
+ if (task.cancelReason !== undefined) row.cancelReason = task.cancelReason;
if (call.settledAt !== undefined) row.settledAt = call.settledAt;
return row;
}
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index f358cb557..a00bf5a0a 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: 70,
+ current: 71,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 29, 30, 31, 32, 34, 35, 54, 55, 63, 64, 65, 66, 67,
- 68, 69, 70,
+ 68, 69, 70, 71,
],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
@@ -72,10 +72,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
dynamicTool: {
- current: 67,
+ current: 68,
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,
+ 60, 61, 62, 63, 64, 65, 66, 67, 68,
],
dropped: {
21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -114,9 +114,9 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
channel: {
- current: 41,
+ current: 42,
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,
+ 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,
],
dropped: {
12: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -138,8 +138,8 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
schedule: {
- current: 23,
- supported: [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23],
+ current: 24,
+ supported: [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19, 20, 21, 22, 23, 24],
dropped: {
5: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
16: 'Background task delivery was removed: sends no longer accept taskDeliveryPolicy and message.completed always carries text. input.resolved reports outcome "cancelled" when a workflow tool withdraws a ctx.ask() request, and stream events gained agent.started, published when a workflow run opens a ctx.agent session, and turn.waiting, which parks the open turn instead of emitting turn.completed and session.waiting.',
@@ -147,8 +147,8 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
subagent: {
- current: 26,
- supported: [3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 23, 24, 25, 26],
+ current: 27,
+ supported: [3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 23, 24, 25, 26, 27],
dropped: {
1: "Persistent subagent sessions are now the default and the experimental opt-in was removed",
2: "Persistent subagent sessions are now the default and the experimental opt-in was removed",
@@ -161,10 +161,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
connection: {
- current: 35,
+ current: 36,
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,
+ 35, 36,
],
dropped: {
9: "Dynamic connection resolvers no longer receive conversation or channel continuation data",
@@ -179,8 +179,8 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
hook: {
- current: 34,
- supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34],
+ current: 35,
+ supported: [20, 21, 22, 23, 25, 27, 31, 32, 33, 34, 35],
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.",
@@ -210,9 +210,9 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
skill: { current: 2, supported: [1, 2], dropped: {} },
dynamicSkill: {
- current: 28,
+ current: 29,
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,
+ 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,
],
dropped: {
13: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
@@ -223,9 +223,9 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
instructions: { current: 2, supported: [1, 2], dropped: {} },
dynamicInstructions: {
- current: 29,
+ current: 30,
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,
+ 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,
],
dropped: {
14: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
diff --git a/packages/eve/src/execution/session/program.ts b/packages/eve/src/execution/session/program.ts
index a97132e1f..f8d2f195e 100644
--- a/packages/eve/src/execution/session/program.ts
+++ b/packages/eve/src/execution/session/program.ts
@@ -224,7 +224,7 @@ async function runSessionLoop(
continue;
}
if (next.kind === "cancel-working-tasks") {
- await cancelWorkingTasks(cursor);
+ await cancelWorkingTasks(cursor, "turn_cancelled");
continue;
}
return next;
@@ -348,7 +348,7 @@ async function runSessionLoop(
await cancelDescendantTurnsStep({
sessionState: cursor.sessionState,
});
- await cancelWorkingTasks(cursor);
+ await cancelWorkingTasks(cursor, "turn_cancelled");
await settleCancelledTurn(false);
// Cancellation consumes any outstanding caller; do not report the prior turn.
action = { ...action, settled: undefined };
diff --git a/packages/eve/src/execution/session/turn.ts b/packages/eve/src/execution/session/turn.ts
index 0f892b419..6296206a7 100644
--- a/packages/eve/src/execution/session/turn.ts
+++ b/packages/eve/src/execution/session/turn.ts
@@ -114,7 +114,7 @@ export class SessionExecution {
// The turn rule holds a turn while its tasks work, so a turn that ends
// anyway, such as by failing, cancels them.
if (outcome.kind === "park" && outcome.settled !== undefined) {
- await cancelWorkingTasks(this.input.cursor);
+ await cancelWorkingTasks(this.input.cursor, "turn_ended");
}
return turn.caller === undefined ? outcome : { ...outcome, caller: turn.caller };
} finally {
@@ -256,7 +256,7 @@ export class SessionExecution {
await cancelDescendantTurnsStep({
sessionState: cursor.sessionState,
});
- await cancelWorkingTasks(cursor);
+ await cancelWorkingTasks(cursor, "turn_cancelled");
return { cancelled: true, kind: "park" };
}
diff --git a/packages/eve/src/execution/tasks/session.test.ts b/packages/eve/src/execution/tasks/session.test.ts
index 4fe3456d5..72fd3a081 100644
--- a/packages/eve/src/execution/tasks/session.test.ts
+++ b/packages/eve/src/execution/tasks/session.test.ts
@@ -83,6 +83,7 @@ describe("answerTaskCancel", () => {
event: {
data: {
callId: "research-call",
+ cancel: { reason: "task_cancel" },
kind: "tool",
name: "research",
status: "cancelled",
diff --git a/packages/eve/src/execution/tasks/session.ts b/packages/eve/src/execution/tasks/session.ts
index 215109523..46eeb517d 100644
--- a/packages/eve/src/execution/tasks/session.ts
+++ b/packages/eve/src/execution/tasks/session.ts
@@ -9,6 +9,7 @@ import {
type TaskTable,
} from "#execution/tasks/table.js";
import type { WorkflowToolRunMessage } from "#execution/tools/workflow/messages.js";
+import type { TaskCancelReason } from "#protocol/message.js";
import { TASK_CANCEL_TOOL_NAME, UNKNOWN_TASK_CODE } from "#protocol/task-tools.js";
import type { RuntimeActionResult } from "#shared/action-types.js";
@@ -33,13 +34,16 @@ export function sessionTaskTable(cursor: SessionStateCursor): TaskTable {
}
/**
- * Cancels every working task: a turn that ends anyway, such as by failing,
- * cancels the tasks it held on.
+ * Cancels every working task: `session.cancel()` stops them, and a turn that
+ * ends anyway, such as by failing, cancels the tasks it held on.
*/
-export async function cancelWorkingTasks(cursor: SessionStateCursor): Promise<void> {
+export async function cancelWorkingTasks(
+ cursor: SessionStateCursor,
+ reason: Exclude<TaskCancelReason, "task_cancel">,
+): Promise<void> {
const taskIds = workingTasks(sessionTaskTable(cursor)).map((record) => record.id);
if (taskIds.length === 0) return;
- await cursor.advance((state) => cancelTasksStep({ ...state, taskIds }));
+ await cursor.advance((state) => cancelTasksStep({ ...state, reason, taskIds }));
}
export async function answerTaskCancel(
@@ -55,7 +59,9 @@ export async function answerTaskCancel(
return { ...taskToolResult(call.callId, TASK_CANCEL_TOOL_NAME, error), isError: true };
}
if (result.status === "cancelled") {
- await cursor.advance((state) => cancelTasksStep({ ...state, taskIds: [call.taskId] }));
+ await cursor.advance((state) =>
+ cancelTasksStep({ ...state, reason: "task_cancel", taskIds: [call.taskId] }),
+ );
}
return taskToolResult(
call.callId,
diff --git a/packages/eve/src/execution/tasks/steps.ts b/packages/eve/src/execution/tasks/steps.ts
index f5bc5c033..51d0f4c12 100644
--- a/packages/eve/src/execution/tasks/steps.ts
+++ b/packages/eve/src/execution/tasks/steps.ts
@@ -43,6 +43,7 @@ import { withdrawProxyInputRequests } from "#harness/proxy-input-requests.js";
import { resumeHook } from "#internal/workflow/runtime.js";
import {
createTaskSettledEvent,
+ type TaskCancelReason,
type TaskSettledStreamEvent,
type UnstampedMessageStreamEvent,
} from "#protocol/message.js";
@@ -124,24 +125,30 @@ async function applyTaskRunMessage(
* run withdraws its stretch's questions itself, and the session decides each one.
*/
export async function cancelTasksStep(
- input: SessionStepState & { readonly taskIds: readonly string[] },
+ input: SessionStepState & TaskCancellationInput,
): Promise<SessionStateTransition> {
"use step";
return await withSessionStateDelta(input, cancelTasks);
}
+interface TaskCancellationInput {
+ readonly reason: TaskCancelReason;
+ readonly taskIds: readonly string[];
+}
+
async function cancelTasks(
- input: SessionStepState & { readonly taskIds: readonly string[] },
+ input: SessionStepState & TaskCancellationInput,
): Promise<PublishedSessionEvents> {
const session = readDurableSession(input.sessionState);
let table = readTaskTable(session.state);
const events: TaskSettledStreamEvent[] = [];
const stoppedRunIds = new Set<string>();
+ const outcome: TaskOutcome = { reason: input.reason, status: "cancelled" };
for (const taskId of input.taskIds) {
const record = findTask(table, taskId);
const cancelled = cancelTask(table, taskId);
table = cancelled.table;
- events.push(...taskSettledEvents(record, cancelled.settled, CANCELLED));
+ events.push(...taskSettledEvents(record, cancelled.settled, outcome));
if (cancelled.send === undefined) continue;
if (record?.resumable === false) stoppedRunIds.add(cancelled.send.run.runId);
await sendTaskRunCommands(cancelled.send);
@@ -157,8 +164,6 @@ async function cancelTasks(
return await publishSessionEvents({ ...input, ...relayed }, events);
}
-const CANCELLED: TaskOutcome = { status: "cancelled" };
-
/** The `task.settled` events for a task's settled calls; calls only settle on a known task. */
function taskSettledEvents(
record: TaskRecord | undefined,
@@ -191,7 +196,11 @@ function taskSettledEvent(
status: "failed",
});
case "cancelled":
- return createTaskSettledEvent({ ...base, status: "cancelled" });
+ return createTaskSettledEvent(
+ outcome.reason === undefined
+ ? { ...base, status: "cancelled" }
+ : { ...base, cancel: { reason: outcome.reason }, status: "cancelled" },
+ );
}
}
diff --git a/packages/eve/src/execution/tasks/table.ts b/packages/eve/src/execution/tasks/table.ts
index 7f6f8be3c..e7acdb5ba 100644
--- a/packages/eve/src/execution/tasks/table.ts
+++ b/packages/eve/src/execution/tasks/table.ts
@@ -4,7 +4,7 @@ import type { SessionStateMap } from "#harness/types.js";
import { isNonEmptyString, isObject } from "#shared/guards.js";
import type { JsonValue } from "#shared/json.js";
import type { TokenUsage } from "#shared/token-usage.js";
-import type { TaskStartedStreamEvent } from "#protocol/message.js";
+import type { TaskCancelReason, TaskStartedStreamEvent } from "#protocol/message.js";
import { UNREADABLE_TASK_ERROR } from "#execution/tasks/render.js";
// The session's task table. Every write to a task record goes through this
@@ -62,7 +62,7 @@ export interface TaskRunCommands {
export type TaskOutcome =
| { readonly output: JsonValue; readonly status: "completed" }
| { readonly error: string; readonly status: "failed" }
- | { readonly status: "cancelled" };
+ | { readonly reason?: TaskCancelReason; readonly status: "cancelled" };
/**
* An outcome the model receives, one per reply or run end, however many calls
diff --git a/packages/eve/src/protocol/message.ts b/packages/eve/src/protocol/message.ts
index a4e5a892d..da0d4008d 100644
--- a/packages/eve/src/protocol/message.ts
+++ b/packages/eve/src/protocol/message.ts
@@ -424,6 +424,12 @@ export interface TaskStartedStreamEvent {
export interface TaskSettledStreamEvent {
data: {
callId: string;
+ /**
+ * Why the call was cancelled; present only when `status` is `"cancelled"`
+ * and the session stopped it. Absent when the task's run stopped on its
+ * own, and on events recorded by eve versions before it was added.
+ */
+ cancel?: { reason: TaskCancelReason };
/** Why the call failed; present only when `status` is `"failed"`. */
error?: { message: string };
/**
@@ -445,6 +451,13 @@ export interface TaskSettledStreamEvent {
type: "task.settled";
}
+/**
+ * Why the session cancelled a task call: the model called `task_cancel`,
+ * someone cancelled the turn (or, between turns, the tasks still working), or
+ * the turn ended while the task still worked.
+ */
+export type TaskCancelReason = "task_cancel" | "turn_cancelled" | "turn_ended";
+
/**
* Stream event emitted when one assistant text delta is appended to the
* current message for the current step.
@@ -1427,6 +1440,7 @@ export function createTaskSettledEvent(
};
if (input.output !== undefined) data.output = input.output;
if (input.error !== undefined) data.error = input.error;
+ if (input.cancel !== undefined) data.cancel = input.cancel;
return { data, type: "task.settled" };
}
diff --git a/packages/eve/src/public/channels/slack/task-card.ts b/packages/eve/src/public/channels/slack/task-card.ts
index 69cd64bfc..d27405bfb 100644
--- a/packages/eve/src/public/channels/slack/task-card.ts
+++ b/packages/eve/src/public/channels/slack/task-card.ts
@@ -46,8 +46,9 @@ interface SlackTaskObject {
/**
* eve's default task card: a `task_card` block for one task, or a `plan` block
* for several, and no card for a turn that started none. A settled task shows
- * one line about how it ended. A stopped task shows as an error, never as a
- * success.
+ * one line about how it ended. A task the model cancelled with `task_cancel`
+ * shows as done, since it no longer needed the work; a failed task, or one
+ * stopped any other way, shows as an error.
*/
export function renderDefaultSlackTaskCard(view: TaskCardView): SlackTaskCard | null {
if (view.tasks.length === 0) return null;
@@ -75,7 +76,7 @@ function planTitle(view: TaskCardView): string {
: `${String(done)} of ${countTasks(total)} done`;
}
const failed = statuses.filter((status) => status === "failed").length;
- const stopped = statuses.filter((status) => status === "cancelled").length;
+ const stopped = view.tasks.filter(isInterrupted).length;
const outcomes: string[] = [];
if (failed > 0) outcomes.push(`${String(failed)} failed`);
if (stopped > 0) outcomes.push(`${String(stopped)} stopped`);
@@ -83,6 +84,11 @@ function planTitle(view: TaskCardView): string {
return outcomes.length === 0 ? finished : `${finished}: ${outcomes.join(", ")}`;
}
+/** A task stopped before it finished for any reason but the model's own `task_cancel`. */
+function isInterrupted(task: TaskCardTask): boolean {
+ return task.status === "cancelled" && task.cancelReason !== "task_cancel";
+}
+
function countTasks(count: number): string {
return count === 1 ? "1 task" : `${String(count)} tasks`;
}
@@ -100,7 +106,7 @@ function collapseEarlierRows(tasks: readonly TaskCardTask[]): readonly TaskCardT
const kept = tasks.filter((task) => !folded.has(task.id));
if (folded.size === 0) return kept.slice(-MAX_PLAN_ROWS);
const foldedFailure = tasks.some(
- (task) => folded.has(task.id) && (task.status === "failed" || task.status === "cancelled"),
+ (task) => folded.has(task.id) && (task.status === "failed" || isInterrupted(task)),
);
const earlier: TaskCardTask = {
id: "earlier",
@@ -133,8 +139,9 @@ function slackStatus(task: TaskCardTask): SlackTaskStatus {
return "in_progress";
case "completed":
return "complete";
- case "failed":
case "cancelled":
+ return isInterrupted(task) ? "error" : "complete";
+ case "failed":
return "error";
}
}
@@ -146,12 +153,25 @@ function outputLine(task: TaskCardTask): string | undefined {
case "failed":
return task.summary === undefined ? "Failed" : `Failed: ${task.summary}`;
case "cancelled":
- return "Stopped";
+ return stoppedLine(task.cancelReason);
default:
return undefined;
}
}
+function stoppedLine(reason: TaskCardTask["cancelReason"]): string {
+ switch (reason) {
+ case "task_cancel":
+ return "Stopped early since it was no longer needed";
+ case "turn_cancelled":
+ return "Stopped by request";
+ case "turn_ended":
+ return "Stopped when the turn ended";
+ case undefined:
+ return "Stopped";
+ }
+}
+
function blockerLine(blocker: TaskCardBlocker): string {
const waiting = waitingText(blocker.kind);
return blocker.label === undefined ? waiting : `${waiting}: ${blocker.label}`;