Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gateway-error-detail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eve": patch
---

Preserve specific AI Gateway 400 rejection details in model-call failure summaries so channels surface actionable context instead of only a generic request-rejected message.
19 changes: 19 additions & 0 deletions packages/eve/src/harness/model-call-error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,25 @@ describe("summarizeKnownModelCallRequestError", () => {
message: "AI Gateway rejected the model request before the agent produced a response.",
});
});

it("keeps specific Gateway 400 rejection details in the summary", () => {
const summary = summarizeKnownModelCallRequestError(
gatewayModelCallError({
gatewayName: "GatewayInvalidRequestError",
gatewayType: "invalid_request_error",
statusCode: 400,
upstreamMessage: "input tokens exceed the model context window",
upstreamStatusCode: 400,
upstreamType: "invalid_request_error",
}),
);

expect(summary).toEqual({
name: "AI Gateway model request rejected",
message:
"AI Gateway rejected the model request before the agent produced a response. Gateway detail: input tokens exceed the model context window",
});
});
});

/**
Expand Down
25 changes: 24 additions & 1 deletion packages/eve/src/harness/model-call-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isObject } from "#shared/guards.js";
import type { JsonObject, JsonValue } from "#shared/json.js";

const RESPONSE_BODY_SNIPPET_LIMIT = 1_000;
const GATEWAY_REQUEST_SUMMARY_DETAIL_LIMIT = 240;
const GATEWAY_MODEL_REQUEST_REJECTED_MESSAGE =
"AI Gateway rejected the model request before the agent produced a response.";

Expand Down Expand Up @@ -131,13 +132,35 @@ export function summarizeKnownModelCallRequestError(
if (signals.statusCode === 400 && isGatewayErrorSignal(signals)) {
return {
name: "AI Gateway model request rejected",
message: GATEWAY_MODEL_REQUEST_REJECTED_MESSAGE,
message: formatGatewayModelRequestRejectedMessage(signals),
};
}

return null;
}

function formatGatewayModelRequestRejectedMessage(signals: ModelCallErrorSignals): string {
const detail = signals.upstreamMessage?.trim();
if (detail === undefined || detail.length === 0 || isGenericGatewayRejectionMessage(detail)) {
return GATEWAY_MODEL_REQUEST_REJECTED_MESSAGE;
}

return `${GATEWAY_MODEL_REQUEST_REJECTED_MESSAGE} Gateway detail: ${truncateSummaryDetail(
detail,
)}`;
}

function isGenericGatewayRejectionMessage(message: string): boolean {
return /^(bad request|internal server error)$/i.test(message.trim());
}

function truncateSummaryDetail(value: string): string {
if (value.length <= GATEWAY_REQUEST_SUMMARY_DETAIL_LIMIT) {
return value;
}
return `${value.slice(0, GATEWAY_REQUEST_SUMMARY_DETAIL_LIMIT - 1).trimEnd()}…`;
}

/**
* Returns the distinct upstream tool types referenced by any
* "tool type 'X' is not supported" rejection in an AI Gateway error's
Expand Down
Loading