Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): expose callback failures in logs and evals (#3051)

Rui09cb57e46876
diff --git a/.changeset/log-callback-delivery-failures.md b/.changeset/log-callback-delivery-failures.md
new file mode 100644
index 000000000..6a68af34b
--- /dev/null
+++ b/.changeset/log-callback-delivery-failures.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Failed session and task callback attempts now emit error-level logs with HTTP status or transport failure, a token-redacted destination, and available call, task, and session identifiers. Workflow retries are unchanged; best-effort activity failures keep their single warning.
diff --git a/docs/guides/instrumentation.md b/docs/guides/instrumentation.md
index 0a75eebaf..b4458d1e7 100644
--- a/docs/guides/instrumentation.md
+++ b/docs/guides/instrumentation.md
@@ -84,6 +84,19 @@ The built-in OpenTelemetry provider maps each pair to an
span links to it with `eve.link.type=channel.request` rather than using the
short-lived request span as its parent.
+## Callback delivery errors
+
+Failed outbound session and task callback attempts emit an error-level
+`[eve:execution.session-callback] callback delivery failed` runtime log without
+requiring an instrumentation provider. Filter by `statusCode` for HTTP failures
+or `failure` (`http`, `transport`, or `timeout`). The log includes the callback
+origin, token-redacted route, payload kind, and available call, task, and child
+session identifiers. Payload content, credentials, and callback tokens are
+excluded. Each retry can emit a separate error; logging does not change Workflow
+retry behavior. Best-effort activity delivery keeps its single
+`[eve:execution.activity-submit] activity sink request failed` warning and does
+not mark the active span as failed.
+
## Runtime context
_Runtime context_ is an [AI SDK concept](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text): a user-defined object that flows through a generation lifecycle. eve exposes it through `events["step.started"]`, a callback that runs once eve has assembled the model input for an attempt and returns `{ runtimeContext }`. Because eve registers the AI SDK's OpenTelemetry integration with runtime context enabled, those returned values ride onto the model-call span and its children. The field is named `runtimeContext`, not `metadata`, because AI SDK v7 carries per-call attributes on runtime context rather than a dedicated metadata field.
diff --git a/e2e/fixtures/fixture-tasks/agent/agent.ts b/e2e/fixtures/fixture-tasks/agent/agent.ts
index f3cd705e8..038245332 100644
--- a/e2e/fixtures/fixture-tasks/agent/agent.ts
+++ b/e2e/fixtures/fixture-tasks/agent/agent.ts
@@ -21,42 +21,6 @@ function respond(request: MockModelRequest): MockModelResponse | string {
// Framework agent-list notes are model context, not scenario turns.
const message = [...request.userMessages].reverse().find(isScenarioMessage) ?? "";
- if (message.includes("TASK-REMOTE-UPDATE-CHILD")) {
- const result = resultById(request, "remote-update-progress");
- if (result === undefined) {
- return {
- toolCalls: [
- {
- id: "remote-update-progress",
- name: "task_update",
- input: { message: "TASK-UPDATE-PROGRESS" },
- },
- ],
- };
- }
- if (
- result.output === null ||
- typeof result.output !== "object" ||
- Reflect.get(result.output, "status") !== "sent"
- ) {
- throw new Error("Remote task_update did not confirm delivery.");
- }
- return "TASK-REMOTE-UPDATE-DONE";
- }
- if (message === "TASK-REMOTE-UPDATE-SETUP") {
- if (resultById(request, "remote-update-worker") === undefined) {
- return {
- toolCalls: [
- {
- id: "remote-update-worker",
- name: "remote-loopback",
- input: { message: "TASK-REMOTE-UPDATE-CHILD" },
- },
- ],
- };
- }
- return "TASK-UPDATE-STARTED";
- }
if (request.userMessages.some((entry) => entry.includes("TASK-UPDATE-PROGRESS"))) {
return "TASK-UPDATE-RECEIVED";
}
diff --git a/e2e/fixtures/fixture-tasks/evals/README.md b/e2e/fixtures/fixture-tasks/evals/README.md
index 5b92a4349..d2cd1aaac 100644
--- a/e2e/fixtures/fixture-tasks/evals/README.md
+++ b/e2e/fixtures/fixture-tasks/evals/README.md
@@ -1,5 +1,24 @@
# Task eval transitions
+## Remote callback routing regression
+
+`task.input.answer.accepted-complete.remote.eval.ts` reuses the existing remote
+HITL and completion round trip to cover the callback-prefix bug from
+[eve #3047](https://github.com/vercel/eve/pull/3047). The fixture's `vercel.json`
+sets the service route to `/eve/v1`.
+
+The eval uses event assertions labeled "remote input callback reaches the parent"
+and "remote completion callback reaches the parent". It also logs which delivery
+it is waiting for. These assertions check the live round trip through the public
+eval APIs; they do not inspect the generated callback URL.
+
+The [build scenario](../../../../packages/eve/src/internal/nitro/host/build-application.scenario.test.ts)
+separately checks that this service route adds no extra public prefix. Local and
+Postgres runs exercise the remote round trip, but only the Vercel build exercises
+service-prefix inference.
+
+## Transition declarations
+
These evals are executable evidence for the background-task contract. They do
not define that contract.
diff --git a/e2e/fixtures/fixture-tasks/evals/task.input.answer.accepted-complete.remote.eval.ts b/e2e/fixtures/fixture-tasks/evals/task.input.answer.accepted-complete.remote.eval.ts
index 4a605574a..22d577a6d 100644
--- a/e2e/fixtures/fixture-tasks/evals/task.input.answer.accepted-complete.remote.eval.ts
+++ b/e2e/fixtures/fixture-tasks/evals/task.input.answer.accepted-complete.remote.eval.ts
@@ -5,15 +5,22 @@ import {
requireTaskView,
waitForCompletedTask,
waitForTaskInput,
+ waitForTaskNotification,
} from "./shared.js";
import { defineTaskEval } from "./task-transition.js";
const REMOTE_PRINCIPAL_MARKER = "C8-REMOTE-PRINCIPAL:user:remote-http-child";
-/** A remote task's HITL answer must use its persisted HTTP child route. */
+/**
+ * Also covers the /eve/v1 callback-prefix regression (#3047): vercel.json
+ * mounts this fixture at /eve/v1. Both the input request and completion must
+ * reach the parent through its generated callback URL. A doubled /eve/v1 prefix
+ * prevents these deliveries. The build scenario checks the prefix itself;
+ * this eval checks the remote round trip through the public event stream.
+ */
export default defineTaskEval({
description:
- "A loopback remote child surfaces HITL and resumes over its remote response route with the remote transport principal intact.",
+ "A remote child delivers HITL and completion through /eve/v1/callback/* and resumes with its HTTP principal intact.",
transition: {
primary: "task.input.answer.accepted-complete",
dimensions: { transport: "remote" },
@@ -32,6 +39,11 @@ export default defineTaskEval({
});
const taskId = requireBackgroundTaskId(started);
+ t.event("input.requested", {
+ count: 1,
+ data: { requests: [{ action: { toolName: "remote_gate" } }] },
+ }).label("remote input callback reaches the parent");
+ t.log("Waiting for the remote input callback to reach the parent.");
const gate = await waitForTaskInput(t, t, "remote_gate");
const answered = await gate.session.respond([
{
@@ -52,7 +64,26 @@ export default defineTaskEval({
);
answered.noFailedActions();
- const terminal = await waitForCompletedTask(t, gate.session, "TASK-C8-REMOTE-VERIFY", taskId);
+ t.eventsSatisfy("remote completion callback reaches the parent", (events) =>
+ events.some(
+ (event) =>
+ event.type === "message.received" &&
+ messageText(event.data.message).includes(`Background task ${taskId}`) &&
+ messageText(event.data.message).includes(REMOTE_PRINCIPAL_MARKER),
+ ),
+ );
+ t.log("Waiting for the remote completion callback to reach the parent.");
+ const completed = await waitForTaskNotification(t, gate.session, taskId, "completed", [
+ answered,
+ ]);
+ completed.turn.expectOk();
+
+ const terminal = await waitForCompletedTask(
+ t,
+ completed.session,
+ "TASK-C8-REMOTE-VERIFY",
+ taskId,
+ );
terminal.expectOk();
const view = requireTaskView(terminal.requireToolCall("task_cancel").output, taskId);
await t.require(
@@ -66,10 +97,6 @@ export default defineTaskEval({
),
);
- t.event("input.requested", {
- count: 1,
- data: { requests: [{ action: { toolName: "remote_gate" } }] },
- });
t.notEvent("authorization.required");
t.noFailedActions();
},
diff --git a/e2e/fixtures/fixture-tasks/evals/task.update.emitted-working.remote.eval.ts b/e2e/fixtures/fixture-tasks/evals/task.update.emitted-working.remote.eval.ts
deleted file mode 100644
index 019e3527c..000000000
--- a/e2e/fixtures/fixture-tasks/evals/task.update.emitted-working.remote.eval.ts
+++ /dev/null
@@ -1,77 +0,0 @@
-import { satisfies } from "eve/evals/expect";
-
-import { defineTaskEval } from "./task-transition.js";
-import {
- requireBackgroundTaskId,
- requireSessionStreamIndex,
- waitForTaskNotification,
-} from "./shared.js";
-
-const UPDATE = "TASK-UPDATE-PROGRESS";
-
-export default defineTaskEval({
- description:
- "A remote child delivers progress and completion through the canonical service callback mount.",
- transition: {
- primary: "task.update.emitted-working",
- setup: ["task.dispatch.start.accepted-acknowledged"],
- dimensions: { transport: "remote", parentPhase: "parked" },
- },
- async test(t) {
- const started = await t.send("TASK-REMOTE-UPDATE-SETUP");
- started.expectOk();
- started.messageIncludes("TASK-UPDATE-STARTED");
- const taskId = requireBackgroundTaskId(started);
-
- const sessionId = t.sessionId;
- if (sessionId === undefined) throw new Error("Task update eval has no parent session id.");
- const live = t.target.watchTurn(sessionId, {
- startIndex: requireSessionStreamIndex(t, "Task update wait"),
- });
- const updateTurn = await live.result();
- updateTurn.expectOk();
- updateTurn.messageIncludes("TASK-UPDATE-RECEIVED");
- await t.require(
- updateTurn.events,
- satisfies(
- (events: typeof updateTurn.events) =>
- events.some(
- (event) =>
- event.type === "message.received" &&
- messageText(event.data.message).includes(
- `Background task ${taskId} (remote-loopback) update: ${UPDATE}`,
- ),
- ),
- "parent receives the child update with its owning task identity",
- ),
- );
- updateTurn.notEvent("subagent.completed");
- const completed = await waitForTaskNotification(t, live.session, taskId, "completed", [
- updateTurn,
- ]);
- completed.turn.expectOk();
- completed.turn.eventsSatisfy("parent receives the remote final answer", (events) =>
- events.some(
- (event) =>
- event.type === "message.received" &&
- messageText(event.data.message).includes("TASK-REMOTE-UPDATE-DONE"),
- ),
- );
- t.noFailedActions();
- },
-});
-
-function messageText(message: unknown): string {
- if (typeof message === "string") return message;
- if (!Array.isArray(message)) return "";
- return message
- .flatMap((part) =>
- part !== null &&
- typeof part === "object" &&
- Reflect.get(part, "type") === "text" &&
- typeof Reflect.get(part, "text") === "string"
- ? [Reflect.get(part, "text") as string]
- : [],
- )
- .join("\n");
-}
diff --git a/packages/eve/src/execution/multi-agent-callback-routing.scenario.test.ts b/packages/eve/src/execution/multi-agent-callback-routing.scenario.test.ts
index 5d2268730..179b82df2 100644
--- a/packages/eve/src/execution/multi-agent-callback-routing.scenario.test.ts
+++ b/packages/eve/src/execution/multi-agent-callback-routing.scenario.test.ts
@@ -13,7 +13,7 @@ import {
notifyTurnCallerStep,
resolveInitialTurnCallerStep,
} from "#subagents/parent-notification.js";
-import { fireSessionCallbackStep } from "#subagents/callback-step.js";
+import { fireSessionCallbackStep, fireTaskUpdateCallbackStep } from "#subagents/callback-step.js";
import { startRemoteAgentSession } from "#subagents/remote-dispatch.js";
import { resolveWorkflowCallbackBaseUrl } from "#execution/workflow-callback-url.js";
import { authHookToken, CallbackBaseUrlKey, getHookUrl } from "#harness/authorization.js";
@@ -256,6 +256,7 @@ describe("multi-agent callback routing", () => {
afterEach(() => {
vi.unstubAllEnvs();
+ vi.restoreAllMocks();
});
function stubAgentRuntimeEnvironment(publicRoutePrefix: string | undefined): void {
@@ -397,29 +398,70 @@ describe("multi-agent callback routing", () => {
}
});
- it("reproduces the 404 when the public route prefix is absent (pre-fix behavior)", async () => {
- stubAgentRuntimeEnvironment(undefined);
-
- const { callback } = await mintRemoteAgentCallback("support");
-
- // Without the prefix the minted URL targets the bare /eve/v1 path that
- // nothing serves in multi-agent mode — the exact production failure.
- expect(callback.url).toBe(
- `${deploymentOrigin}${createEveCallbackRoutePath("support-session:callback-token")}`,
- );
- await expect(
- fireSessionCallbackStep({
- output: "report done",
- serializedContext: {
- [SessionIdKey.name]: "remote-session-1",
- [SessionCallbackKey.name]: {
+ it.each(["session.completed", "task.update", "turn.completed", "turn.failed"] as const)(
+ "logs %s delivery failures when the public route prefix is absent",
+ async (kind) => {
+ stubAgentRuntimeEnvironment(undefined);
+ vi.stubEnv("EVE_LOG_LEVEL", "error");
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
+
+ const { callback } = await mintRemoteAgentCallback("support");
+
+ // Without the prefix the minted URL targets the bare /eve/v1 path that
+ // nothing serves in multi-agent mode — the exact production failure.
+ expect(callback.url).toBe(
+ `${deploymentOrigin}${createEveCallbackRoutePath("support-session:callback-token")}`,
+ );
+ const sessionCallback = {
+ callId: "call-support",
+ subagentName: "research",
+ taskId: "task-support",
+ ...callback,
+ };
+ const serializedContext = {
+ [SessionIdKey.name]: "remote-session-1",
+ [SessionCallbackKey.name]: sessionCallback,
+ };
+ const deliver = async () => {
+ if (kind === "task.update") {
+ await fireTaskUpdateCallbackStep({
+ callback: sessionCallback,
callId: "call-support",
- subagentName: "research",
- ...callback,
- },
- },
- status: "completed",
- }),
- ).rejects.toThrow("Session callback failed with HTTP 404.");
- });
+ message: "private progress",
+ updateEpoch: "turn-child",
+ updateIndex: 1,
+ });
+ } else if (kind === "session.completed") {
+ await fireSessionCallbackStep({
+ output: "report done",
+ serializedContext,
+ status: "completed",
+ });
+ } else {
+ await notifyTurnCallerStep({
+ caller: await resolveInitialTurnCallerStep({ serializedContext }),
+ lifecycle: "terminal",
+ sessionId: "remote-session-1",
+ settled:
+ kind === "turn.failed"
+ ? { isError: true, output: { message: "private failure" } }
+ : { output: "report done" },
+ });
+ }
+ };
+ await expect(deliver()).rejects.toThrow(/callback failed with HTTP 404/);
+ expect(errorSpy).toHaveBeenCalledExactlyOnceWith(
+ "[eve:execution.session-callback] callback delivery failed",
+ expect.objectContaining({
+ kind,
+ callId: "call-support",
+ callbackOrigin: deploymentOrigin,
+ callbackPath: "/eve/v1/callback/[redacted]",
+ statusCode: 404,
+ }),
+ );
+ expect(JSON.stringify(errorSpy.mock.calls)).not.toContain("callback-token");
+ expect(JSON.stringify(errorSpy.mock.calls)).not.toContain("private");
+ },
+ );
});
diff --git a/packages/eve/src/execution/session-callback-request.test.ts b/packages/eve/src/execution/session-callback-request.test.ts
index 9e06cf7f2..26fe8053a 100644
--- a/packages/eve/src/execution/session-callback-request.test.ts
+++ b/packages/eve/src/execution/session-callback-request.test.ts
@@ -1,4 +1,4 @@
-import { afterEach, describe, expect, it, vi } from "vitest";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { postSessionCallbackRequest } from "#execution/session-callback-request.js";
@@ -7,12 +7,92 @@ const requestContextSymbol = Symbol.for("@vercel/request-context");
const requestContextGlobal = globalThis as typeof globalThis & { [key: symbol]: unknown };
describe("postSessionCallbackRequest", () => {
+ let errorSpy: ReturnType<typeof vi.spyOn>;
+
+ beforeEach(() => {
+ vi.stubEnv("EVE_LOG_LEVEL", "error");
+ errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
+ });
+
afterEach(() => {
delete requestContextGlobal[requestContextSymbol];
vi.unstubAllEnvs();
vi.unstubAllGlobals();
+ vi.restoreAllMocks();
});
+ it.each(["task.update", "turn.completed", "turn.failed"])(
+ "logs %s HTTP failures with correlation fields and a redacted destination",
+ async (kind) => {
+ const response = new Response("private response body", { status: 404 });
+ vi.stubGlobal("fetch", vi.fn().mockResolvedValue(response));
+
+ await expect(
+ postSessionCallbackRequest({
+ body: {
+ kind,
+ callId: "call-1",
+ taskId: "task-1",
+ sessionId: "child-session",
+ subagentName: "research",
+ message: "private update",
+ output: "private result",
+ error: "private failure",
+ token: "private-body-token",
+ },
+ url: "https://user:[email protected]/eve/v1/eve/v1/callback/private-token?secret=query#fragment",
+ }),
+ ).resolves.toBe(response);
+
+ expect(errorSpy).toHaveBeenCalledExactlyOnceWith(
+ "[eve:execution.session-callback] callback delivery failed",
+ expect.objectContaining({
+ kind,
+ callId: "call-1",
+ taskId: "task-1",
+ sessionId: "child-session",
+ subagentName: "research",
+ callbackOrigin: "https://agent.example.com",
+ callbackPath: "/eve/v1/eve/v1/callback/[redacted]",
+ failure: "http",
+ statusCode: 404,
+ }),
+ );
+ const logged = JSON.stringify(errorSpy.mock.calls);
+ for (const secret of ["private", "password", "user:", "secret=query", "fragment"]) {
+ expect(logged).not.toContain(secret);
+ }
+ },
+ );
+
+ it.each(["transport", "timeout"])(
+ "logs %s failures without exposing the original error and preserves retry semantics",
+ async (failure) => {
+ const error = new Error(`request to ${callbackUrl} failed`, {
+ cause: { authorization: "secret-credential" },
+ });
+ if (failure === "timeout") {
+ vi.spyOn(AbortSignal, "timeout").mockReturnValue(AbortSignal.abort());
+ }
+ vi.stubGlobal("fetch", vi.fn().mockRejectedValue(error));
+
+ await expect(
+ postSessionCallbackRequest({
+ body: { kind: "task.update", taskId: "task-1" },
+ url: callbackUrl,
+ timeoutMs: 123,
+ }),
+ ).rejects.toBe(error);
+
+ expect(errorSpy).toHaveBeenCalledExactlyOnceWith(
+ "[eve:execution.session-callback] callback delivery failed",
+ expect.objectContaining({ failure, timeoutMs: 123, taskId: "task-1" }),
+ );
+ expect(JSON.stringify(errorSpy.mock.calls)).not.toContain("opaque-token");
+ expect(JSON.stringify(errorSpy.mock.calls)).not.toContain("secret-credential");
+ },
+ );
+
it("uses the request OIDC token for a callback to the current Vercel deployment", async () => {
vi.stubEnv("VERCEL", "1");
vi.stubEnv("VERCEL_PROJECT_PRODUCTION_URL", "agent.example.com");
@@ -23,6 +103,8 @@ describe("postSessionCallbackRequest", () => {
await postSessionCallbackRequest({ body: { ok: true }, url: callbackUrl });
+ expect(errorSpy).not.toHaveBeenCalled();
+
expect(fetchMock).toHaveBeenCalledWith(
callbackUrl,
expect.objectContaining({
diff --git a/packages/eve/src/execution/session-callback-request.ts b/packages/eve/src/execution/session-callback-request.ts
index a3aa72b40..cfe763244 100644
--- a/packages/eve/src/execution/session-callback-request.ts
+++ b/packages/eve/src/execution/session-callback-request.ts
@@ -1,3 +1,7 @@
+import { createLogger } from "#internal/logging.js";
+import { isObject } from "#shared/guards.js";
+
+const log = createLogger("execution.session-callback");
const SESSION_CALLBACK_TIMEOUT_MS = 30_000;
const VERCEL_TRUSTED_OIDC_IDP_TOKEN_HEADER = "x-vercel-trusted-oidc-idp-token";
const VERCEL_CALLBACK_HOST_ENVS = [
@@ -10,19 +14,71 @@ const VERCEL_REQUEST_CONTEXT = Symbol.for("@vercel/request-context");
/** Posts one framework callback payload with the shared callback transport policy. */
export async function postSessionCallbackRequest(input: {
readonly body: unknown;
+ /** Set false when the caller owns failure logging, such as best-effort activity. */
+ readonly logFailures?: boolean;
readonly timeoutMs?: number;
readonly url: string;
}): Promise<Response> {
- return await fetch(input.url, {
- body: JSON.stringify(input.body),
- headers: await resolveSessionCallbackHeaders(input.url),
- method: "POST",
- // Do not follow redirects: a validated callback host could otherwise
- // 3xx-bounce the framework to an internal/metadata address after the
- // path/token check has already passed.
- redirect: "error",
- signal: AbortSignal.timeout(input.timeoutMs ?? SESSION_CALLBACK_TIMEOUT_MS),
- });
+ const timeoutMs = input.timeoutMs ?? SESSION_CALLBACK_TIMEOUT_MS;
+ const signal = AbortSignal.timeout(timeoutMs);
+ let response: Response;
+ try {
+ response = await fetch(input.url, {
+ body: JSON.stringify(input.body),
+ headers: await resolveSessionCallbackHeaders(input.url),
+ method: "POST",
+ // Do not follow redirects: a validated callback host could otherwise
+ // 3xx-bounce the framework to an internal/metadata address after the
+ // path/token check has already passed.
+ redirect: "error",
+ signal,
+ });
+ } catch (error) {
+ // Fetch errors can contain the capability URL or credentials in their
+ // cause chain. Log a safe summary, but preserve the original rejection.
+ if (input.logFailures !== false) {
+ log.error("callback delivery failed", {
+ ...callbackLogFields(input),
+ failure: signal.aborted ? "timeout" : "transport",
+ timeoutMs,
+ error: new Error("Callback request failed before receiving a response."),
+ });
+ }
+ throw error;
+ }
+ if (!response.ok && input.logFailures !== false) {
+ log.error("callback delivery failed", {
+ ...callbackLogFields(input),
+ failure: "http",
+ statusCode: response.status,
+ error: new Error(`Callback request failed with HTTP ${response.status}.`),
+ });
+ }
+ return response;
+}
+
+function callbackLogFields(input: { readonly body: unknown; readonly url: string }) {
+ const url = URL.parse(input.url);
+ const route = url?.pathname.match(/^(.*?\/(?:callback|activity))\//)?.[1];
+ const fields: Record<string, string | number | undefined> = {
+ callbackOrigin: url?.origin,
+ callbackPath: route === undefined ? "[redacted]" : `${route}/[redacted]`,
+ };
+ if (isObject(input.body)) {
+ for (const key of [
+ "kind",
+ "callId",
+ "taskId",
+ "sessionId",
+ "childSessionId",
+ "subagentName",
+ "updateEpoch",
+ ]) {
+ if (typeof input.body[key] === "string") fields[key] = input.body[key];
+ }
+ if (typeof input.body.updateIndex === "number") fields.updateIndex = input.body.updateIndex;
+ }
+ return fields;
}
async function resolveSessionCallbackHeaders(urlValue: string): Promise<Record<string, string>> {
diff --git a/packages/eve/src/execution/submit-activity.test.ts b/packages/eve/src/execution/submit-activity.test.ts
index 6e50c7a5c..90cf6d22d 100644
--- a/packages/eve/src/execution/submit-activity.test.ts
+++ b/packages/eve/src/execution/submit-activity.test.ts
@@ -15,7 +15,45 @@ const event = {
};
describe("submitActivity", () => {
- afterEach(() => vi.unstubAllGlobals());
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ vi.unstubAllEnvs();
+ vi.restoreAllMocks();
+ });
+
+ it.each(["http", "transport", "timeout"])(
+ "logs a %s failure once at warning severity and does not fail the session",
+ async (failure) => {
+ vi.stubEnv("EVE_LOG_LEVEL", "warn");
+ const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
+ const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
+ const fetchMock = vi.fn();
+ if (failure === "http") {
+ fetchMock.mockResolvedValue(new Response(null, { status: 404 }));
+ } else {
+ if (failure === "timeout") {
+ vi.spyOn(AbortSignal, "timeout").mockReturnValue(AbortSignal.abort());
+ }
+ fetchMock.mockRejectedValue(new Error("activity delivery failed"));
+ }
+ vi.stubGlobal("fetch", fetchMock);
+
+ await expect(
+ submitActivity({
+ sink: {
+ url: "https://agent.example.com/eve/v1/activity/abcdefghijklmnopqrstuvwxyz123456",
+ version: 1,
+ },
+ events: [event],
+ }),
+ ).resolves.toBeUndefined();
+
+ expect(warnSpy).toHaveBeenCalledExactlyOnceWith(
+ "[eve:execution.activity-submit] activity sink request failed",
+ );
+ expect(errorSpy).not.toHaveBeenCalled();
+ },
+ );
it("does nothing without a sink", async () => {
const fetchMock = vi.fn();
diff --git a/packages/eve/src/execution/submit-activity.ts b/packages/eve/src/execution/submit-activity.ts
index 06da84dce..a143ac6c6 100644
--- a/packages/eve/src/execution/submit-activity.ts
+++ b/packages/eve/src/execution/submit-activity.ts
@@ -18,6 +18,7 @@ export async function submitActivity(input: {
if (batch === undefined) return;
const response = await postSessionCallbackRequest({
body: batch,
+ logFailures: false,
timeoutMs: ACTIVITY_SUBMIT_TIMEOUT_MS,
url: input.sink.url,
});
diff --git a/packages/eve/src/subagents/callback-step.ts b/packages/eve/src/subagents/callback-step.ts
index 617cdb396..3dfc4cc81 100644
--- a/packages/eve/src/subagents/callback-step.ts
+++ b/packages/eve/src/subagents/callback-step.ts
@@ -100,40 +100,38 @@ export async function fireSessionCallbackStep(input: {
return;
}
+ let callback: SessionCallback;
try {
- const callback = parseSerializedSessionCallback(value);
- const body =
- input.status === "completed"
- ? buildCompletedCallbackBody({
- callback,
- output: input.output,
- sessionId,
- usage: input.usage,
- })
- : {
- callId: callback.callId,
- error: {
- code: SESSION_FAILED,
- message: toErrorMessage(input.error),
- },
- kind: "session.failed" as const,
- sessionId,
- subagentName: callback.subagentName,
- usage: input.usage,
- };
-
- const response = await postSessionCallbackRequest({ body, url: callback.url });
-
- if (!response.ok) {
- throw new Error(`Session callback failed with HTTP ${response.status}.`);
- }
+ callback = parseSerializedSessionCallback(value);
} catch (error) {
- log.error("failed to post session callback", {
- error,
- sessionId,
- });
+ log.error("invalid session callback metadata", { error, sessionId });
throw error;
}
+ const body =
+ input.status === "completed"
+ ? buildCompletedCallbackBody({
+ callback,
+ output: input.output,
+ sessionId,
+ usage: input.usage,
+ })
+ : {
+ callId: callback.callId,
+ error: {
+ code: SESSION_FAILED,
+ message: toErrorMessage(input.error),
+ },
+ kind: "session.failed" as const,
+ sessionId,
+ subagentName: callback.subagentName,
+ usage: input.usage,
+ };
+
+ const response = await postSessionCallbackRequest({ body, url: callback.url });
+
+ if (!response.ok) {
+ throw new Error(`Session callback failed with HTTP ${response.status}.`);
+ }
}
function buildCompletedCallbackBody(input: {