1
0
Fork 0

fix(v5): recognize conversation depth errors (#2957)

Backport of #2881.\n\nOriginal commit: f68e52251c

Co-authored-by: Felipe Bermudez <felipeberm@gmail.com>
This commit is contained in:
Paul Jankowski 2026-08-05 12:11:58 -04:00 committed by GitHub
parent b28bc84904
commit b33a7f7b1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@docsearch/react": patch
---
Recognize current Agent Studio conversation-depth error messages.

View file

@ -10,10 +10,47 @@ import {
getSearchToolQueries, getSearchToolQueries,
isAIToolPart, isAIToolPart,
isAlgoliaMCPSearchOutputPart, isAlgoliaMCPSearchOutputPart,
isThreadDepthError,
sanitizeMessagesForRequest, sanitizeMessagesForRequest,
getMessageContent, getMessageContent,
} from '../ai'; } from '../ai';
describe('isThreadDepthError', () => {
it('detects AI-217 regardless of casing', () => {
expect(isThreadDepthError(new Error('AI-217: limit reached'))).toBe(true);
expect(isThreadDepthError(new Error('prefix ai-217 suffix'))).toBe(true);
});
it('detects conversation depth phrasing', () => {
expect(
isThreadDepthError(
new Error(
"You've hit the max conversation depth (4 messages), start a new conversation."
)
)
).toBe(true);
expect(
isThreadDepthError(new Error('Maximum conversation depth reached.'))
).toBe(true);
});
it('detects conversation depth in a JSON-shaped error message', () => {
expect(
isThreadDepthError(
new Error(
JSON.stringify({ message: 'Maximum conversation depth reached.' })
)
)
).toBe(true);
});
it('ignores unrelated errors', () => {
expect(isThreadDepthError()).toBe(false);
expect(isThreadDepthError(new Error('Network failed'))).toBe(false);
expect(isThreadDepthError(new Error('AI-214: rate limit'))).toBe(false);
});
});
function message(id: string, parts: AIMessagePart[]): AIMessage { function message(id: string, parts: AIMessagePart[]): AIMessage {
return { return {
id, id,

View file

@ -122,11 +122,11 @@ export const getMessageContent = (message: AIMessage | null): string =>
.map((part) => part.text) .map((part) => part.text)
.join('\n\n'); .join('\n\n');
/** Helper function to check if error is a thread depth error (AI-217). */ /** Helper function to check if an error reports the conversation depth limit. */
export function isThreadDepthError(error?: Error): boolean { export function isThreadDepthError(error?: Error): boolean {
if (!error) return false; if (!error) return false;
return error.message?.includes('AI-217') || false; return /(?:ai-217|conversation\s+depth)/i.test(error.message ?? '');
} }
export const EMPTY_TOOLS: Readonly<ToolCalls> = Object.freeze({}); export const EMPTY_TOOLS: Readonly<ToolCalls> = Object.freeze({});