Skip to content
Merged
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
12 changes: 5 additions & 7 deletions apps/web/src/lib/rewriteModelResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe.each(rewriters)('%s response read errors', (_name, rewrite) => {
});
});

test('includes the vercel request id in the JSON read error', async () => {
test('includes the vercel request id only in the JSON read error message', async () => {
const result = await rewrite(
failingResponse('application/json', 'ResponseAborted'),
true,
Expand All @@ -152,26 +152,25 @@ describe.each(rewriters)('%s response read errors', (_name, rewrite) => {
error_type: 'upstream_disconnect',
message:
'The upstream response was interrupted while streaming. The provider may have disconnected or the request may have timed out. (request id: iad1::iad1::request-id)',
vercel_request_id: 'iad1::iad1::request-id',
});
});

test('includes the vercel request id in the emitted stream error event', async () => {
test('includes the vercel request id only in the stream error message', async () => {
const result = await rewrite(
failingResponse('text/event-stream', 'ResponseAborted'),
true,
null,
'iad1::iad1::request-id'
);
const events = dataObjects(await readOutputStream(result)) as {
error: { message: string; vercel_request_id?: string };
error: { message: string };
}[];

expect(events).toHaveLength(1);
expect(events[0].error.message).toBe(
'The upstream response was interrupted while streaming. The provider may have disconnected or the request may have timed out. (request id: iad1::iad1::request-id)'
);
expect(events[0].error.vercel_request_id).toBe('iad1::iad1::request-id');
expect(events[0].error).not.toHaveProperty('vercel_request_id');
});

test('omits the request id suffix when no vercel request id is available', async () => {
Expand All @@ -182,13 +181,12 @@ describe.each(rewriters)('%s response read errors', (_name, rewrite) => {
null
);
const events = dataObjects(await readOutputStream(result)) as {
error: { message: string; vercel_request_id?: string };
error: { message: string };
}[];

expect(events[0].error.message).toBe(
'The upstream response was interrupted while streaming. The provider may have disconnected or the request may have timed out.'
);
expect(events[0].error.vercel_request_id).toBeUndefined();
});
});

Expand Down
15 changes: 0 additions & 15 deletions apps/web/src/lib/rewriteModelResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ type ResponseReadError = {
errorType: 'timeout' | 'upstream_disconnect';
/** Already carries the request id suffix when one is available. */
message: string;
vercelRequestId?: string;
};

const STREAM_PROGRESS_LOG_INTERVAL_MS = 30_000;
Expand Down Expand Up @@ -212,7 +211,6 @@ function getResponseReadError(
'The upstream response was interrupted while streaming. The provider may have disconnected or the request may have timed out.',
vercelRequestId
),
vercelRequestId: vercelRequestId ?? undefined,
};
}

Expand All @@ -223,7 +221,6 @@ function getResponseReadError(
'The upstream provider timed out while sending the response.',
vercelRequestId
),
vercelRequestId: vercelRequestId ?? undefined,
};
}

Expand Down Expand Up @@ -254,9 +251,6 @@ async function readResponseText(
error: responseReadError.message,
error_type: responseReadError.errorType,
message: responseReadError.message,
...(responseReadError.vercelRequestId && {
vercel_request_id: responseReadError.vercelRequestId,
}),
},
{ status: 503, headers }
),
Expand Down Expand Up @@ -482,9 +476,6 @@ export async function rewriteModelResponse_ChatCompletions(
code: 503,
message: responseReadError.message,
type: responseReadError.errorType,
...(responseReadError.vercelRequestId && {
vercel_request_id: responseReadError.vercelRequestId,
}),
},
}) +
'\n\n',
Expand Down Expand Up @@ -665,9 +656,6 @@ export async function rewriteModelResponse_Messages(
type: 'api_error',
message: responseReadError.message,
error_type: responseReadError.errorType,
...(responseReadError.vercelRequestId && {
vercel_request_id: responseReadError.vercelRequestId,
}),
},
}) +
'\n\n',
Expand Down Expand Up @@ -819,9 +807,6 @@ export async function rewriteModelResponse_Responses(
type: responseReadError.errorType,
code: responseReadError.errorType === 'timeout' ? '504' : '503',
message: responseReadError.message,
...(responseReadError.vercelRequestId && {
vercel_request_id: responseReadError.vercelRequestId,
}),
},
}) +
'\n\n',
Expand Down