Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): route AI SDK warnings to diagnostics (#3632)

e0-gh-vercel-connect[bot]fa92e5ec32b8
diff --git a/.changeset/calm-warnings-listen.md b/.changeset/calm-warnings-listen.md
new file mode 100644
index 000000000..57f8489c6
--- /dev/null
+++ b/.changeset/calm-warnings-listen.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Route AI SDK provider warnings to eve's diagnostics instead of presenting successful compatibility fallbacks as stderr errors. Existing custom warning handlers and `AI_SDK_LOG_WARNINGS=false` remain respected.
diff --git a/packages/eve/src/ai/evaluate.ts b/packages/eve/src/ai/evaluate.ts
index 06e988dda..41faad09d 100644
--- a/packages/eve/src/ai/evaluate.ts
+++ b/packages/eve/src/ai/evaluate.ts
@@ -4,6 +4,7 @@ import {
type Experimental_EvaluationQuestion as EvaluationQuestion,
} from "ai";
+import { ensureAiSdkWarningLogger } from "#instrumentation/ai-sdk-warnings.js";
import { localGatewayEvaluationModel } from "#internal/model-auth/transport.js";
export const DEFAULT_EVALUATION_MODEL = "typesafe-ai/jev";
@@ -16,6 +17,7 @@ export function evaluate<const Questions extends Record<string, EvaluationQuesti
/** Evaluation model instance or ID. Defaults to TypeSafe Jev. */
model?: EvaluationModel;
}) {
+ ensureAiSdkWarningLogger();
return evaluateWithAiSdk({
...options,
model:
diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.ts
index cd8636117..c1def1609 100644
--- a/packages/eve/src/harness/tool-loop.ts
+++ b/packages/eve/src/harness/tool-loop.ts
@@ -448,6 +448,7 @@ function buildHarnessToolsWithDynamicSubagents(
}
export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {
+ config.instrumentation?.installAiSdkWarningLogger();
const baseEmit = config.handleEvent;
async function runStep(
diff --git a/packages/eve/src/instrumentation/ai-sdk-warnings.test.ts b/packages/eve/src/instrumentation/ai-sdk-warnings.test.ts
new file mode 100644
index 000000000..dad44bf45
--- /dev/null
+++ b/packages/eve/src/instrumentation/ai-sdk-warnings.test.ts
@@ -0,0 +1,154 @@
+import type { LogWarningsFunction } from "ai";
+import { afterEach, describe, expect, it, vi } from "vitest";
+
+import { ensureAiSdkWarningLogger } from "#instrumentation/ai-sdk-warnings.js";
+import { setLogRecordSubscriber, type LogRecord } from "#internal/logging.js";
+
+describe("ensureAiSdkWarningLogger", () => {
+ const originalLogger = globalThis.AI_SDK_LOG_WARNINGS;
+ const originalEnvironmentValue = process.env.AI_SDK_LOG_WARNINGS;
+
+ afterEach(() => {
+ globalThis.AI_SDK_LOG_WARNINGS = originalLogger;
+ setLogRecordSubscriber(undefined);
+ vi.unstubAllEnvs();
+ vi.restoreAllMocks();
+ if (originalEnvironmentValue === undefined) {
+ delete process.env.AI_SDK_LOG_WARNINGS;
+ } else {
+ process.env.AI_SDK_LOG_WARNINGS = originalEnvironmentValue;
+ }
+ });
+
+ it("preserves an application-defined warning logger", () => {
+ const applicationLogger: LogWarningsFunction = vi.fn();
+ globalThis.AI_SDK_LOG_WARNINGS = applicationLogger;
+
+ ensureAiSdkWarningLogger();
+
+ expect(globalThis.AI_SDK_LOG_WARNINGS).toBe(applicationLogger);
+ });
+
+ it("preserves an application-defined false value", () => {
+ globalThis.AI_SDK_LOG_WARNINGS = false;
+
+ ensureAiSdkWarningLogger();
+
+ expect(globalThis.AI_SDK_LOG_WARNINGS).toBe(false);
+ });
+
+ it("translates AI_SDK_LOG_WARNINGS=false to the SDK global", () => {
+ globalThis.AI_SDK_LOG_WARNINGS = undefined;
+ vi.stubEnv("AI_SDK_LOG_WARNINGS", "false");
+
+ ensureAiSdkWarningLogger();
+
+ expect(globalThis.AI_SDK_LOG_WARNINGS).toBe(false);
+ });
+
+ it("installs one idempotent warning logger", () => {
+ globalThis.AI_SDK_LOG_WARNINGS = undefined;
+ vi.stubEnv("AI_SDK_LOG_WARNINGS", "true");
+
+ ensureAiSdkWarningLogger();
+ const installedLogger = globalThis.AI_SDK_LOG_WARNINGS;
+ ensureAiSdkWarningLogger();
+
+ expect(installedLogger).toBeTypeOf("function");
+ expect(globalThis.AI_SDK_LOG_WARNINGS).toBe(installedLogger);
+ });
+
+ it("records compatibility warnings as structured info instead of stderr", () => {
+ const records: LogRecord[] = [];
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+ const error = vi.spyOn(console, "error").mockImplementation(() => {});
+ globalThis.AI_SDK_LOG_WARNINGS = undefined;
+ vi.stubEnv("AI_SDK_LOG_WARNINGS", "true");
+ setLogRecordSubscriber((record) => records.push(record));
+
+ ensureAiSdkWarningLogger();
+ const logger = globalThis.AI_SDK_LOG_WARNINGS as LogWarningsFunction | false | undefined;
+ if (typeof logger !== "function") {
+ throw new Error("Expected eve to install an AI SDK warning logger");
+ }
+ logger({
+ model: "openai/gpt-5",
+ provider: "gateway",
+ warnings: [
+ {
+ type: "compatibility",
+ feature: "JSON Schema propertyNames",
+ details: "The provider removed it before sending the request.",
+ },
+ ],
+ });
+
+ expect(records).toEqual([
+ {
+ level: "info",
+ namespace: "harness.ai-sdk-warnings",
+ message: "The provider removed it before sending the request.",
+ fields: {
+ model: "openai/gpt-5",
+ provider: "gateway",
+ warning: {
+ type: "compatibility",
+ feature: "JSON Schema propertyNames",
+ details: "The provider removed it before sending the request.",
+ },
+ },
+ },
+ ]);
+ expect(warn).not.toHaveBeenCalled();
+ expect(error).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ {
+ expectedMessage: "The provider ignored it.",
+ type: "unsupported" as const,
+ feature: "temperature",
+ details: "The provider ignored it.",
+ },
+ {
+ expectedMessage: "Use providerOptions.current instead.",
+ type: "deprecated" as const,
+ setting: "providerOptions.legacy",
+ message: "Use providerOptions.current instead.",
+ },
+ {
+ expectedMessage: "The provider returned an actionable warning.",
+ type: "other" as const,
+ message: "The provider returned an actionable warning.",
+ },
+ ])("records $type warnings at warning level", ({ expectedMessage, ...warning }) => {
+ const records: LogRecord[] = [];
+ globalThis.AI_SDK_LOG_WARNINGS = undefined;
+ vi.stubEnv("AI_SDK_LOG_WARNINGS", "true");
+ setLogRecordSubscriber((record) => records.push(record));
+
+ ensureAiSdkWarningLogger();
+ const logger = globalThis.AI_SDK_LOG_WARNINGS as LogWarningsFunction | false | undefined;
+ if (typeof logger !== "function") {
+ throw new Error("Expected eve to install an AI SDK warning logger");
+ }
+ logger({
+ model: "openai/gpt-5",
+ provider: "gateway",
+ warnings: [warning],
+ });
+
+ expect(records).toEqual([
+ {
+ level: "warn",
+ namespace: "harness.ai-sdk-warnings",
+ message: expectedMessage,
+ fields: {
+ model: "openai/gpt-5",
+ provider: "gateway",
+ warning,
+ },
+ },
+ ]);
+ });
+});
diff --git a/packages/eve/src/instrumentation/ai-sdk-warnings.ts b/packages/eve/src/instrumentation/ai-sdk-warnings.ts
new file mode 100644
index 000000000..614eccfd1
--- /dev/null
+++ b/packages/eve/src/instrumentation/ai-sdk-warnings.ts
@@ -0,0 +1,38 @@
+import type { LogWarningsFunction } from "ai";
+
+import { createLogger } from "#internal/logging.js";
+
+const log = createLogger("harness.ai-sdk-warnings");
+
+/**
+ * Routes AI SDK provider warnings through eve's logger unless the application
+ * already configured the SDK's global warning hook. AI SDK warnings are
+ * successful-call diagnostics, so they use the info channel instead of stderr.
+ */
+export function ensureAiSdkWarningLogger(): void {
+ if (globalThis.AI_SDK_LOG_WARNINGS !== undefined) {
+ return;
+ }
+
+ // AI SDK reads the global, not the similarly named environment variable.
+ // Honor the conventional shell setting by translating it once at startup.
+ globalThis.AI_SDK_LOG_WARNINGS =
+ process.env.AI_SDK_LOG_WARNINGS === "false" ? false : logAiSdkWarnings;
+}
+
+const logAiSdkWarnings: LogWarningsFunction = ({ warnings, provider, model }) => {
+ for (const warning of warnings) {
+ const fields = {
+ model,
+ provider,
+ warning,
+ };
+ const message = "message" in warning ? warning.message : (warning.details ?? warning.feature);
+
+ if (warning.type === "compatibility") {
+ log.info(message, fields);
+ } else {
+ log.warn(message, fields);
+ }
+ }
+};
diff --git a/packages/eve/src/instrumentation/runtime.test.ts b/packages/eve/src/instrumentation/runtime.test.ts
index ccbb88afd..acd0110e0 100644
--- a/packages/eve/src/instrumentation/runtime.test.ts
+++ b/packages/eve/src/instrumentation/runtime.test.ts
@@ -882,6 +882,26 @@ describe("bindInstrumentationRuntime", () => {
});
describe("bindSessionInstrumentation", () => {
+ it("installs the AI SDK warning logger through the bound facade", () => {
+ const originalLogger = globalThis.AI_SDK_LOG_WARNINGS;
+ try {
+ globalThis.AI_SDK_LOG_WARNINGS = undefined;
+ registerInstrumentationRuntime(createRuntime({ capturesContent: true, publish: vi.fn() }));
+
+ const instrumentation = bindSessionInstrumentation({
+ agentName: "test-agent",
+ ctx: createContext(),
+ rootSessionId: "session-1",
+ sessionId: "session-1",
+ })?.prepareExecution();
+ instrumentation?.installAiSdkWarningLogger();
+
+ expect(globalThis.AI_SDK_LOG_WARNINGS).toBeTypeOf("function");
+ } finally {
+ globalThis.AI_SDK_LOG_WARNINGS = originalLogger;
+ }
+ });
+
it("uses a persisted decision without migrating the durable context", async () => {
const policy = vi.fn(() => true);
registerInstrumentationRuntime(
diff --git a/packages/eve/src/instrumentation/runtime.ts b/packages/eve/src/instrumentation/runtime.ts
index 25e0ee308..bce082eb0 100644
--- a/packages/eve/src/instrumentation/runtime.ts
+++ b/packages/eve/src/instrumentation/runtime.ts
@@ -71,6 +71,7 @@ import {
registerInstrumentationRuntime,
} from "#instrumentation/runtime-global.js";
import { initializeSessionInstrumentation } from "#instrumentation/session-init.js";
+import { ensureAiSdkWarningLogger } from "#instrumentation/ai-sdk-warnings.js";
export { getInstrumentationRuntime, registerInstrumentationRuntime };
export { initializeSessionInstrumentation };
@@ -162,6 +163,7 @@ export interface InstrumentationRuntime {
/** Worker-bound instrumentation operations consumed by one session execution. */
export interface SessionInstrumentation {
+ readonly installAiSdkWarningLogger: () => void;
readonly runStep: <TSession extends InstrumentedStepSession, TResult>(
input: {
readonly environment: string;
@@ -264,6 +266,7 @@ export function bindInstrumentationRuntime(
const prepareExecution = (): SessionInstrumentation => {
const executionRuntime = captureExecutionRuntime();
return {
+ installAiSdkWarningLogger: ensureAiSdkWarningLogger,
runStep: async (input, execute) => {
const policyContext = readSessionContext();
const hooks = bindHooks(policyContext);