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.

🐛 fix: render CLI detection timeout guide (#19117)

Arvin Xuf2189f45e5aa
diff --git a/locales/en-US/chat.json b/locales/en-US/chat.json
index 05ebd8cfe0b..bfaa8cf7626 100644
--- a/locales/en-US/chat.json
+++ b/locales/en-US/chat.json
@@ -109,6 +109,12 @@
"cliAuthGuide.errorDetails": "Error details",
"cliAuthGuide.runCommand": "Run this in Terminal",
"cliAuthGuide.title": "Sign in to {{name}}",
+ "cliDetectionTimeoutGuide.actions.openSystemTools": "Open System Tools",
+ "cliDetectionTimeoutGuide.actions.retry": "Detect again",
+ "cliDetectionTimeoutGuide.desc": "LobeHub took too long to locate `{{command}}` from your login shell environment.",
+ "cliDetectionTimeoutGuide.errorDetails": "Technical details",
+ "cliDetectionTimeoutGuide.hint": "This is often caused by a slow shell startup script. Try again, or open System Tools to check the detected command path.",
+ "cliDetectionTimeoutGuide.title": "Detection timed out for {{name}}",
"cliOverloadedGuide.actions.retry": "Retry",
"cliOverloadedGuide.autoRetry.actions.cancel": "Stop auto-retry",
"cliOverloadedGuide.autoRetry.actions.retryNow": "Retry now",
diff --git a/locales/zh-CN/chat.json b/locales/zh-CN/chat.json
index affbb460272..b69850336af 100644
--- a/locales/zh-CN/chat.json
+++ b/locales/zh-CN/chat.json
@@ -109,6 +109,12 @@
"cliAuthGuide.errorDetails": "错误详情",
"cliAuthGuide.runCommand": "在终端执行",
"cliAuthGuide.title": "登录 {{name}}",
+ "cliDetectionTimeoutGuide.actions.openSystemTools": "打开系统工具",
+ "cliDetectionTimeoutGuide.actions.retry": "重新检测",
+ "cliDetectionTimeoutGuide.desc": "LobeHub 从登录 Shell 环境中查找 `{{command}}` 命令时超时。",
+ "cliDetectionTimeoutGuide.errorDetails": "技术详情",
+ "cliDetectionTimeoutGuide.hint": "这通常是 Shell 启动脚本耗时过长导致的。你可以重新检测,或前往系统工具检查识别到的命令路径。",
+ "cliDetectionTimeoutGuide.title": "检测 {{name}} 超时",
"cliOverloadedGuide.actions.retry": "重试",
"cliOverloadedGuide.autoRetry.actions.cancel": "停止自动重试",
"cliOverloadedGuide.autoRetry.actions.retryNow": "立即重试",
diff --git a/packages/locales/src/default/chat.ts b/packages/locales/src/default/chat.ts
index e02f97ee7cb..5cd9c415aff 100644
--- a/packages/locales/src/default/chat.ts
+++ b/packages/locales/src/default/chat.ts
@@ -868,6 +868,14 @@ export default {
'cliAuthGuide.errorDetails': 'Error details',
'cliAuthGuide.runCommand': 'Run this in Terminal',
'cliAuthGuide.title': 'Sign in to {{name}}',
+ 'cliDetectionTimeoutGuide.actions.openSystemTools': 'Open System Tools',
+ 'cliDetectionTimeoutGuide.actions.retry': 'Detect again',
+ 'cliDetectionTimeoutGuide.desc':
+ 'LobeHub took too long to locate `{{command}}` from your login shell environment.',
+ 'cliDetectionTimeoutGuide.errorDetails': 'Technical details',
+ 'cliDetectionTimeoutGuide.hint':
+ 'This is often caused by a slow shell startup script. Try again, or open System Tools to check the detected command path.',
+ 'cliDetectionTimeoutGuide.title': 'Detection timed out for {{name}}',
'cliOverloadedGuide.actions.retry': 'Retry',
'cliOverloadedGuide.autoRetry.actions.cancel': 'Stop auto-retry',
'cliOverloadedGuide.autoRetry.actions.retryNow': 'Retry now',
diff --git a/src/features/Conversation/Error/heterogeneous.ts b/src/features/Conversation/Error/heterogeneous.ts
index 24d7006c7bc..b82bc2eddea 100644
--- a/src/features/Conversation/Error/heterogeneous.ts
+++ b/src/features/Conversation/Error/heterogeneous.ts
@@ -13,6 +13,7 @@ import type { UIChatMessage } from '@lobechat/types';
*/
export const HETEROGENEOUS_AGENT_STATUS_GUIDE_ERROR_CODES = new Set<string>([
HeterogeneousAgentSessionErrorCode.AuthRequired,
+ HeterogeneousAgentSessionErrorCode.CliDetectionTimeout,
HeterogeneousAgentSessionErrorCode.CliNotFound,
HeterogeneousAgentSessionErrorCode.Overloaded,
HeterogeneousAgentSessionErrorCode.RateLimit,
diff --git a/src/features/Conversation/Error/index.test.tsx b/src/features/Conversation/Error/index.test.tsx
index c92437d2de1..dbf4dac5d27 100644
--- a/src/features/Conversation/Error/index.test.tsx
+++ b/src/features/Conversation/Error/index.test.tsx
@@ -1,9 +1,10 @@
+import type * as lobechatConstModule from '@lobechat/const';
import { HeterogeneousAgentSessionErrorCode } from '@lobechat/electron-client-ipc';
import type * as modelRuntimeModule from '@lobechat/model-runtime';
import { AgentRuntimeErrorType } from '@lobechat/model-runtime';
import type * as lobechatTypesModule from '@lobechat/types';
import { ChatErrorType } from '@lobechat/types';
-import { fireEvent, render, screen } from '@testing-library/react';
+import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
@@ -15,6 +16,7 @@ const dynamicComponentPropsMock = vi.hoisted(() => vi.fn());
const serverConfigMock = vi.hoisted(() => ({ enableBusinessFeatures: false }));
const delAndRegenerateMessageMock = vi.hoisted(() => vi.fn());
+const detectHeterogeneousAgentCommandMock = vi.hoisted(() => vi.fn());
// Keyed by message id so a test can decide whether `data.id` is a top-level
// displayMessage hanging off a user turn — the condition that decides whether a
// self-contained retry can actually do anything.
@@ -30,6 +32,12 @@ const businessErrorContentMock = vi.hoisted(() =>
})),
);
+vi.mock('@lobechat/const', async (importOriginal) => {
+ const actual = (await importOriginal()) as typeof lobechatConstModule;
+
+ return { ...actual, isDesktop: true };
+});
+
vi.mock('@lobechat/model-runtime', async (importOriginal) => {
const actual = (await importOriginal()) as typeof modelRuntimeModule;
@@ -101,18 +109,27 @@ vi.mock('@/features/Electron/HeterogeneousAgent/StatusGuide', () => ({
agentType,
error,
onDismiss,
+ onRetry,
}: {
agentType?: string;
error?: { code?: string };
onDismiss?: () => void;
+ onRetry?: () => void;
}) => (
<div>
{`guide:${agentType}:${error?.code}`}
{onDismiss && <button onClick={onDismiss}>dismiss</button>}
+ {onRetry && <button onClick={onRetry}>guide-retry</button>}
</div>
),
}));
+vi.mock('@/services/electron/binary', () => ({
+ binaryService: {
+ detectHeterogeneousAgentCommand: detectHeterogeneousAgentCommandMock,
+ },
+}));
+
vi.mock('@/hooks/useProviderName', () => ({
useProviderName: () => 'Mock Provider',
}));
@@ -165,6 +182,8 @@ const ErrorMessageWithContent = ({ data }: { data: any }) => {
describe('ErrorMessageExtra', () => {
beforeEach(() => {
dynamicComponentPropsMock.mockClear();
+ detectHeterogeneousAgentCommandMock.mockReset();
+ detectHeterogeneousAgentCommandMock.mockResolvedValue({ available: true });
missingTranslationKeys.clear();
businessSlot.render = false;
serverConfigMock.enableBusinessFeatures = false;
@@ -440,6 +459,64 @@ describe('ErrorMessageExtra', () => {
expect(screen.getByText('guide:claude-code:auth_required')).toBeInTheDocument();
});
+ it('renders the CLI detection timeout guide instead of the generic JSON error', () => {
+ render(
+ <ErrorMessageExtra
+ error={{ message: 'response.AgentRuntimeError' }}
+ data={{
+ error: {
+ body: {
+ agentType: 'codex',
+ code: HeterogeneousAgentSessionErrorCode.CliDetectionTimeout,
+ command: 'codex',
+ message: 'Timed out looking for `codex` while reading PATH from your login shell.',
+ },
+ type: AgentRuntimeErrorType.AgentRuntimeError,
+ } as any,
+ id: 'msg-cli-detection-timeout',
+ }}
+ />,
+ );
+
+ expect(screen.getByText('guide:codex:cli_detection_timeout')).toBeInTheDocument();
+ expect(screen.queryByText(/Timed out looking for/)).not.toBeInTheDocument();
+ });
+
+ it('forces fresh CLI detection before retrying a detection timeout', async () => {
+ displayMessageMock.set('msg-cli-detection-timeout', { parentId: 'user-1' });
+
+ render(
+ <ErrorMessageExtra
+ error={{ message: 'response.AgentRuntimeError' }}
+ data={{
+ error: {
+ body: {
+ agentType: 'codex',
+ code: HeterogeneousAgentSessionErrorCode.CliDetectionTimeout,
+ command: 'codex',
+ message: 'Timed out looking for `codex` while reading PATH from your login shell.',
+ },
+ type: AgentRuntimeErrorType.AgentRuntimeError,
+ } as any,
+ id: 'msg-cli-detection-timeout',
+ }}
+ />,
+ );
+
+ fireEvent.click(screen.getByText('guide-retry'));
+
+ await waitFor(() => {
+ expect(detectHeterogeneousAgentCommandMock).toHaveBeenCalledWith({
+ agentType: 'codex',
+ command: 'codex',
+ });
+ expect(delAndRegenerateMessageMock).toHaveBeenCalledWith('msg-cli-detection-timeout');
+ });
+ expect(detectHeterogeneousAgentCommandMock.mock.invocationCallOrder[0]).toBeLessThan(
+ delAndRegenerateMessageMock.mock.invocationCallOrder[0],
+ );
+ });
+
it('renders the rate-limit guide when the refreshed error carries rate_limit code', () => {
render(
<ErrorMessageExtra
diff --git a/src/features/Conversation/Error/index.tsx b/src/features/Conversation/Error/index.tsx
index da2164f19b4..d9781d22387 100644
--- a/src/features/Conversation/Error/index.tsx
+++ b/src/features/Conversation/Error/index.tsx
@@ -22,6 +22,7 @@ import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwar
import { usePermission } from '@/hooks/usePermission';
import { useProviderName } from '@/hooks/useProviderName';
import dynamic from '@/libs/next/dynamic';
+import { binaryService } from '@/services/electron/binary';
import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
import { serverConfigSelectors, useServerConfigStore } from '@/store/serverConfig';
@@ -332,6 +333,30 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(
handleRetryAgentMessage();
}, [handleRetryAgentMessage, resetHeteroOverloadRetry, resolvedScopeId]);
+ const handleHeterogeneousRetry = useCallback(async () => {
+ if (
+ isDesktop &&
+ isHeterogeneousAgentStatusGuideError(sessionErrorBody) &&
+ sessionErrorBody.code === HeterogeneousAgentSessionErrorCode.CliDetectionTimeout &&
+ sessionErrorBody.agentType &&
+ sessionErrorBody.command
+ ) {
+ const { agentType, command } = sessionErrorBody;
+
+ try {
+ await binaryService.detectHeterogeneousAgentCommand({
+ agentType,
+ command,
+ });
+ } catch (error) {
+ console.error(error);
+ return;
+ }
+ }
+
+ handleManualRetry();
+ }, [handleManualRetry, sessionErrorBody]);
+
// Business cards get the surface-resolved retry rather than deriving one
// from `data.id`: on the group surface that id is a nested content block,
// so message-level store actions can't resolve it and silently no-op.
@@ -404,7 +429,7 @@ const ErrorMessageExtra = memo<ErrorExtraProps>(
error={sessionErrorBody}
schedule={schedule}
onDismiss={() => void updateMessageError(data.id, null)}
- onRetry={handleManualRetry}
+ onRetry={() => void handleHeterogeneousRetry()}
onOpenSystemTools={() =>
navigate(
isDesktop
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx b/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
index d0683f1c300..7b50912294f 100644
--- a/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/index.tsx
@@ -5,6 +5,7 @@ import { memo } from 'react';
import { resolveHeterogeneousAgentGuideConfig } from './config';
import AuthRequiredState from './states/AuthRequiredState';
+import CliDetectionTimeoutState from './states/CliDetectionTimeoutState';
import CliInstallState from './states/CliInstallState';
import OverloadedState from './states/OverloadedState';
import RateLimitState from './states/RateLimitState';
@@ -42,6 +43,10 @@ const HeterogeneousAgentStatusGuide = memo<HeterogeneousAgentStatusGuideProps>(
return <AuthRequiredState {...stateProps} />;
}
+ case HeterogeneousAgentSessionErrorCode.CliDetectionTimeout: {
+ return <CliDetectionTimeoutState {...stateProps} />;
+ }
+
case HeterogeneousAgentSessionErrorCode.RateLimit: {
return <RateLimitState {...stateProps} />;
}
diff --git a/src/features/Electron/HeterogeneousAgent/StatusGuide/states/CliDetectionTimeoutState.tsx b/src/features/Electron/HeterogeneousAgent/StatusGuide/states/CliDetectionTimeoutState.tsx
new file mode 100644
index 00000000000..2956d494889
--- /dev/null
+++ b/src/features/Electron/HeterogeneousAgent/StatusGuide/states/CliDetectionTimeoutState.tsx
@@ -0,0 +1,66 @@
+import { Flexbox, Highlighter } from '@lobehub/ui';
+import { Text } from '@lobehub/ui/base-ui';
+import { cssVar } from 'antd-style';
+import { ClockAlert } from 'lucide-react';
+import { useTranslation } from 'react-i18next';
+
+import GuideActions from '../GuideActions';
+import GuideShell from '../GuideShell';
+import type { HeterogeneousAgentGuideStateProps } from '../types';
+
+const CliDetectionTimeoutState = ({
+ config,
+ error,
+ onOpenSystemTools,
+ onRetry,
+ variant,
+}: HeterogeneousAgentGuideStateProps) => {
+ const { t } = useTranslation('chat');
+ const rawErrorDetails = error?.stderr || error?.message;
+
+ return (
+ <GuideShell
+ icon={<ClockAlert color={cssVar.colorWarning} size={20} />}
+ title={t('cliDetectionTimeoutGuide.title', { name: config.title })}
+ variant={variant}
+ actions={
+ <GuideActions
+ retryPrimary
+ openSystemToolsLabel={t('cliDetectionTimeoutGuide.actions.openSystemTools')}
+ retryLabel={t('cliDetectionTimeoutGuide.actions.retry')}
+ onOpenSystemTools={onOpenSystemTools}
+ onRetry={onRetry}
+ />
+ }
+ headerDescription={
+ <Text type="secondary">
+ {t('cliDetectionTimeoutGuide.desc', { command: error?.command || config.title })}
+ </Text>
+ }
+ >
+ <Text style={{ fontSize: 12 }} type="secondary">
+ {t('cliDetectionTimeoutGuide.hint')}
+ </Text>
+
+ {rawErrorDetails && (
+ <Flexbox gap={6}>
+ <Text strong style={{ fontSize: 12 }}>
+ {t('cliDetectionTimeoutGuide.errorDetails')}
+ </Text>
+ <Highlighter
+ wrap
+ actionIconSize={'small'}
+ language={'log'}
+ padding={0}
+ style={{ maxHeight: 160, overflow: 'auto' }}
+ variant={'outlined'}
+ >
+ {rawErrorDetails}
+ </Highlighter>
+ </Flexbox>
+ )}
+ </GuideShell>
+ );
+};
+
+export default CliDetectionTimeoutState;