Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🔨 chore: skip branded provider llm retries (#14975)

YuTengjing1285f601df34
diff --git a/src/server/modules/AgentRuntime/RuntimeExecutors.ts b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
index b27ef7e1dfa..57449afdcb5 100644
--- a/src/server/modules/AgentRuntime/RuntimeExecutors.ts
+++ b/src/server/modules/AgentRuntime/RuntimeExecutors.ts
@@ -15,6 +15,7 @@ import {
import { LobeActivatorIdentifier } from '@lobechat/builtin-tool-activator';
import { CredsIdentifier, type CredSummary, generateCredsList } from '@lobechat/builtin-tool-creds';
import { LocalSystemManifest } from '@lobechat/builtin-tool-local-system';
+import { BRANDING_PROVIDER } from '@lobechat/business-const';
import {
AGENT_DOCUMENT_INJECTION_POSITIONS,
type AgentContextDocument,
@@ -138,6 +139,11 @@ const buildPostProcessUrl = (ctx: Pick<RuntimeExecutorContext, 'serverDB' | 'use
const shouldRetryLLM = (kind: LLMErrorKind, attempt: number, maxRetries: number) =>
kind === 'retry' && attempt <= maxRetries;
+const resolveLLMMaxRetries = (provider: string) =>
+ // The branded provider already routes through its own fallback chain. Retrying
+ // again here multiplies the same failed routed request across every channel.
+ provider === BRANDING_PROVIDER ? 0 : LLM_MAX_RETRIES;
+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
const getLLMRetryDelayMs = (attempt: number) =>
@@ -783,7 +789,8 @@ export const createRuntimeExecutors = (
}
};
- const maxAttempts = LLM_MAX_RETRIES + 1;
+ const llmMaxRetries = resolveLLMMaxRetries(provider);
+ const maxAttempts = llmMaxRetries + 1;
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
let content = '';
@@ -1136,7 +1143,7 @@ export const createRuntimeExecutors = (
const classified = classifyLLMError(error);
const interrupted = await isOperationInterrupted(ctx);
- if (!interrupted && shouldRetryLLM(classified.kind, attempt, LLM_MAX_RETRIES)) {
+ if (!interrupted && shouldRetryLLM(classified.kind, attempt, llmMaxRetries)) {
const delayMs = getLLMRetryDelayMs(attempt);
log(
@@ -1522,7 +1529,9 @@ export const createRuntimeExecutors = (
typeof chatToolPayload.arguments === 'string'
? JSON.parse(chatToolPayload.arguments)
: (chatToolPayload.arguments ?? {});
- } catch {}
+ } catch {
+ // Keep malformed tool arguments as an empty preview payload; execution still uses raw args.
+ }
try {
// Check if this is a client-side function tool — pause instead of executing
@@ -2043,7 +2052,9 @@ export const createRuntimeExecutors = (
typeof chatToolPayload.arguments === 'string'
? JSON.parse(chatToolPayload.arguments)
: (chatToolPayload.arguments ?? {});
- } catch {}
+ } catch {
+ // Keep malformed tool arguments as an empty preview payload; execution still uses raw args.
+ }
try {
log(`[${operationLogId}] Executing tool ${toolName} ...`);
diff --git a/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts b/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
index 53aafb739ac..038fa12b1ef 100644
--- a/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
+++ b/src/server/modules/AgentRuntime/__tests__/RuntimeExecutors.test.ts
@@ -3365,6 +3365,37 @@ describe('RuntimeExecutors', () => {
);
});
+ it('should disable llm execution retry for the branding provider', async () => {
+ const mockChat = vi
+ .fn()
+ .mockRejectedValueOnce(new Error('network timeout'))
+ .mockResolvedValueOnce(new Response('done'));
+
+ vi.mocked(initModelRuntimeFromDB).mockResolvedValue({ chat: mockChat } as any);
+
+ const executors = createRuntimeExecutors(ctx);
+ const state = createMockState();
+ const instruction = {
+ payload: {
+ messages: [{ content: 'Hello', role: 'user' }],
+ model: 'gpt-4',
+ parentMessageId: 'parent-msg-123',
+ provider: 'lobehub',
+ tools: [],
+ },
+ type: 'call_llm' as const,
+ };
+
+ await expect(executors.call_llm!(instruction, state)).rejects.toThrow('network timeout');
+
+ expect(mockChat).toHaveBeenCalledTimes(1);
+ expect(
+ mockStreamManager.publishStreamEvent.mock.calls.some(
+ ([, event]: [string, { type: string }]) => event.type === 'stream_retry',
+ ),
+ ).toBe(false);
+ });
+
it('should retry llm execution, emit stream_retry, and commit only the successful attempt', async () => {
vi.useFakeTimers();