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(chat-input): stop the "model offline" warning from flashing on cold load (#17404)

Arvin Xu0f81a56cf312
diff --git a/.agents/acceptance/probe-mock-patterns.md b/.agents/acceptance/probe-mock-patterns.md
index fff0373de52..6889eca1cca 100644
--- a/.agents/acceptance/probe-mock-patterns.md
+++ b/.agents/acceptance/probe-mock-patterns.md
@@ -1061,3 +1061,55 @@ ingest-report <dir> --subject topic:<id> …` β€” and verify attachment in the D
continuation only runs when an external event arrives (a CDP poll, mouse move), the cause is the
native-callback context not draining microtasks on an idle loop β€” fix by deferring the handler
body via `setImmediate` at the registration site, then verify variance collapses.
+
+### E39. `apps/desktop` installed with `--ignore-scripts` breaks EVERY native module, not just electron
+
+- **Situation**: a worktree where `apps/desktop` was installed with `pnpm install --ignore-scripts`
+ (e.g. to save time). Electron then crashes at boot before any window appears.
+- **Doesn't work**: `pnpm rebuild electron` alone. It fixes the missing `electron/dist` but the app
+ still dies in `node-mac-permissions` with `Could not locate the bindings file ... permissions.node`
+ and `ELIFECYCLE Command failed with exit code 7` β€” every other native addon is unbuilt too.
+- **Works**: re-run a plain `pnpm install` (no `--ignore-scripts`) inside `apps/desktop`, then follow
+ E8b and re-run the ROOT install afterwards. Order: root β†’ desktop (with scripts) β†’ root again.
+
+### E40. `electron-dev.sh`: the saved snapshot beats `LOBE_GOLDEN_PROFILE`, and the seeded login targets LOCAL dev
+
+- **Situation**: wanting a pristine (signed-out) instance to log into PRODUCTION with the user's real
+ account, per E14's "no source edit" path.
+- **Doesn't work**: setting only `LOBE_GOLDEN_PROFILE=/tmp/empty-golden`. The script seeds from the
+ saved snapshot first (`LOGIN_STATE_DIR`, default `~/.lobehub/agent-testing/electron-login`) and only
+ falls back to the golden profile when no snapshot exists β€” the log still says
+ "Seeding userData from saved login state" and you get the old login back.
+- **Also worth knowing**: that seeded agent-testing login is bound to a LOCAL dev server β€”
+ `ud-<id>/lobehub-settings.json` has `dataSyncConfig.remoteServerUrl = http://localhost:3010`. With
+ nothing on 3010 the app shows `Authentication failed: signature verification failed` plus
+ `BackendProxy upstream fetch failed (net::ERR_CONNECTION_REFUSED)`, and the renderer sits at
+ `isLoaded:true, isUserStateInit:false, isSignedIn:false` β€” an E14 lookalike that is really a
+ wrong-server problem. Read `ud-<id>/lobehub-settings.json` before blaming the token.
+- **Works** (pristine + production login): point BOTH at empty dirs and keep the real snapshot safe β€”
+ ```bash
+ LOBE_GOLDEN_PROFILE=/tmp/empty-golden LOBE_LOGIN_STATE_DIR=/tmp/empty-loginstate \
+ SKIP_LOGIN_SAVE=1 .agents/acceptance/scripts/electron-dev.sh start <id>
+ ```
+ The instance lands on `/desktop-onboarding`; drive εΌ€ε§‹ β†’ δΈ‹δΈ€ζ­₯ Γ—2 β†’ 登录 LobeHub Cloud and the
+ device-code flow auto-approves against the browser's existing app.lobehub.com session. A pristine
+ profile defaults to production, so `remoteServerUrl` stays unset. `SKIP_LOGIN_SAVE=1` keeps `stop`
+ from overwriting the user's real snapshot.
+
+### C14. Read a topic's hetero binding straight from the server β€” the store's paginated view usually lacks it
+
+- **Situation**: needing a topic's `heteroSessionId` / `workingDirectory` to reason about whether a
+ turn will `--resume`.
+- **Doesn't work**: `chat().topicDataMap['agent_<agentId>'].items.find(...)` β€” the view is paginated,
+ so any topic past the first page is simply absent (`found:false`) even while it is the ACTIVE topic.
+ UI messages in `messagesMap` also carry `metadata.heteroSessionId` only on rows the current session
+ produced, so an old conversation yields `{}`.
+- **Works**: call the server from the page β€”
+ `fetch('/trpc/lambda/topic.getTopicDetail?input=' + encodeURIComponent(JSON.stringify({json:{id:'<topicId>'}})), {credentials:'include'})`
+ and read `result.data.json.metadata`. That returns the authoritative `heteroSessionId`,
+ `workingDirectory`, and `heteroSessionIdByWorkingDirectory`.
+- **Why it matters**: `resolveHeteroResume` silently drops `--resume` when the bound `workingDirectory`
+ differs from the device's current cwd (`cwd_changed`) or is absent (`missing_bound_cwd`). The turn
+ then SUCCEEDS with a brand-new CC session and no error β€” context loss with no visible symptom. To
+ detect it, compare the CC session id before/after a turn (or diff `~/.claude/projects/*/*.jsonl`):
+ a new file per turn, each containing only its own user message, means resume never happened.
diff --git a/src/features/ChatInput/ChatInputNotice/useChatInputNotice.test.tsx b/src/features/ChatInput/ChatInputNotice/useChatInputNotice.test.tsx
index 1a3c286cfb1..0cdbc81e80b 100644
--- a/src/features/ChatInput/ChatInputNotice/useChatInputNotice.test.tsx
+++ b/src/features/ChatInput/ChatInputNotice/useChatInputNotice.test.tsx
@@ -19,9 +19,17 @@ const testState = vi.hoisted(() => ({
agent: {
agencyConfig: undefined as
{ executionTarget?: string; heterogeneousProvider?: { type: string } } | undefined,
+ isConfigLoading: false,
model: 'gpt-4o',
provider: 'openai',
},
+ /** Effective (override-resolved) selection, as `useAgentModelSelection` returns it. */
+ agentModelSelection: {
+ isPreferenceLoading: false,
+ model: undefined as string | undefined,
+ provider: undefined as string | undefined,
+ selectionPolicy: 'fixed' as 'fixed' | 'member',
+ },
aiInfra: {
enabledChatModelList: [] as TestProviderWithModels[],
isInitAiProviderRuntimeState: false,
@@ -42,6 +50,17 @@ vi.mock('@/features/ChatInput/hooks/useAgentId', () => ({
useAgentId: () => 'agent-id',
}));
+vi.mock('@/features/ChatInput/hooks/useAgentModelSelection', () => ({
+ useAgentModelSelection: () => ({
+ isPreferenceLoading: testState.agentModelSelection.isPreferenceLoading,
+ // Default to the shared agent config, matching `resolveAgentModelConfig`
+ // when there is no member override.
+ model: testState.agentModelSelection.model ?? testState.agent.model,
+ provider: testState.agentModelSelection.provider ?? testState.agent.provider,
+ selectionPolicy: testState.agentModelSelection.selectionPolicy,
+ }),
+}));
+
vi.mock('@/features/ChatInput/hooks/useChatInputResourceAccess', () => ({
useChatInputResourceAccess: () => testState.resourceAccess,
}));
@@ -57,9 +76,7 @@ vi.mock('@/store/agent', () => ({
vi.mock('@/store/agent/selectors', () => ({
agentByIdSelectors: {
- getAgencyConfigById: () => (s: typeof testState.agent) => s.agencyConfig,
- getAgentModelById: () => (s: typeof testState.agent) => s.model,
- getAgentModelProviderById: () => (s: typeof testState.agent) => s.provider,
+ isAgentConfigLoadingById: () => (s: typeof testState.agent) => s.isConfigLoading,
isAgentHeterogeneousById: () => (s: typeof testState.agent) =>
Boolean(s.agencyConfig?.heterogeneousProvider),
},
@@ -76,6 +93,13 @@ vi.mock('@/store/aiInfra', () => ({
describe('useChatInputNotice', () => {
beforeEach(() => {
testState.agent.agencyConfig = undefined;
+ testState.agent.isConfigLoading = false;
+ testState.agentModelSelection = {
+ isPreferenceLoading: false,
+ model: undefined,
+ provider: undefined,
+ selectionPolicy: 'fixed',
+ };
testState.agent.model = 'gpt-4o';
testState.agent.provider = 'openai';
testState.aiInfra.enabledChatModelList = [];
@@ -116,6 +140,63 @@ describe('useChatInputNotice', () => {
expect(result.current).toEqual({ key: 'input.modelUnavailable', type: 'warning' });
});
+ it('does not return unavailable model copy while the agent config is still loading', () => {
+ // Cold page load: runtime config is ready but `agentMap` has no entry yet,
+ // so the model selectors still report the DEFAULT_MODEL fallback.
+ testState.aiInfra.isInitAiProviderRuntimeState = true;
+ testState.agent.isConfigLoading = true;
+ testState.agent.model = 'default-model';
+ testState.agent.provider = 'default-provider';
+ testState.aiInfra.enabledChatModelList = [
+ { children: [{ abilities: { functionCall: true }, id: 'gpt-4o' }], id: 'openai' },
+ ];
+
+ const { result } = renderHook(() => useChatInputNotice());
+
+ expect(result.current).toBeUndefined();
+ });
+
+ it('judges the member override rather than the shared model on a workspace agent', () => {
+ testState.aiInfra.isInitAiProviderRuntimeState = true;
+ // Shared model is retired, but this member overrode it with a live one β€”
+ // the trigger shows the override, so the notice must judge the override.
+ testState.agent.model = 'gpt-4-32k';
+ testState.agentModelSelection.selectionPolicy = 'member';
+ testState.agentModelSelection.model = 'gpt-4o';
+ testState.agentModelSelection.provider = 'openai';
+ testState.aiInfra.enabledChatModelList = [
+ { children: [{ abilities: { functionCall: true }, id: 'gpt-4o' }], id: 'openai' },
+ ];
+
+ const { result } = renderHook(() => useChatInputNotice());
+
+ expect(result.current).toBeUndefined();
+ });
+
+ it('does not return unavailable model copy while a member-policy preference is still loading', () => {
+ testState.aiInfra.isInitAiProviderRuntimeState = true;
+ testState.agentModelSelection.selectionPolicy = 'member';
+ testState.agentModelSelection.isPreferenceLoading = true;
+ testState.agent.model = 'gpt-4-32k';
+
+ const { result } = renderHook(() => useChatInputNotice());
+
+ expect(result.current).toBeUndefined();
+ });
+
+ it('still warns on a fixed-policy workspace agent while the preference request is in flight', () => {
+ // `fixed` ignores the member override, so the effective model is already
+ // settled β€” the unrelated preferences fetch must not swallow the warning.
+ testState.aiInfra.isInitAiProviderRuntimeState = true;
+ testState.agentModelSelection.selectionPolicy = 'fixed';
+ testState.agentModelSelection.isPreferenceLoading = true;
+ testState.agent.model = 'gpt-4-32k';
+
+ const { result } = renderHook(() => useChatInputNotice());
+
+ expect(result.current).toEqual({ key: 'input.modelUnavailable', type: 'warning' });
+ });
+
it('does not return unsupported tool-use copy when the selected model exists but lacks tool calls', () => {
testState.aiInfra.isInitAiProviderRuntimeState = true;
testState.aiInfra.enabledChatModelList = [
diff --git a/src/features/ChatInput/ChatInputNotice/useChatInputNotice.ts b/src/features/ChatInput/ChatInputNotice/useChatInputNotice.ts
index 6aa6806eb68..257c76ad122 100644
--- a/src/features/ChatInput/ChatInputNotice/useChatInputNotice.ts
+++ b/src/features/ChatInput/ChatInputNotice/useChatInputNotice.ts
@@ -1,4 +1,5 @@
import { useAgentId } from '@/features/ChatInput/hooks/useAgentId';
+import { useAgentModelSelection } from '@/features/ChatInput/hooks/useAgentModelSelection';
import { useChatInputResourceAccess } from '@/features/ChatInput/hooks/useChatInputResourceAccess';
import { useEnabledChatModels } from '@/hooks/useEnabledChatModels';
import { useAgentStore } from '@/store/agent';
@@ -8,6 +9,7 @@ import { type EnabledProviderWithModels } from '@/types/aiProvider';
interface ResolveChatInputNoticeParams {
currentChatModel?: unknown;
+ isAgentModelPending: boolean;
isGroupContext?: boolean;
isHeterogeneousAgent: boolean;
isModelConfigReady: boolean;
@@ -26,6 +28,7 @@ const findEnabledChatModel = (
export const resolveChatInputNotice = ({
currentChatModel,
+ isAgentModelPending,
isGroupContext,
isHeterogeneousAgent,
isModelConfigReady,
@@ -40,11 +43,18 @@ export const resolveChatInputNotice = ({
type: 'warning',
} as const;
- // Model-config notices don't apply to heterogeneous agents (own toolchain) or
- // before the model runtime config is ready.
+ // Model-config notices don't apply to heterogeneous agents (own toolchain),
+ // before the model runtime config is ready, or before the agent's effective
+ // model is settled. The last one matters on a cold page load: until
+ // `agentMap` has the agent (and, for a member-selection workspace agent,
+ // until the member override is fetched), the model resolves to the
+ // DEFAULT_MODEL/DEFAULT_PROVIDER fallback, which is often absent from the
+ // user's enabled list β€” that used to flash the "model offline" warning for a
+ // frame before the real config resolved.
if (
!isHeterogeneousAgent &&
- isModelConfigReady && // Example: an agent still references `gpt-4-32k`, or a model reclassified to
+ isModelConfigReady &&
+ !isAgentModelPending && // Example: an agent still references `gpt-4-32k`, or a model reclassified to
// image/video; once absent from the chat selector, it should read as unavailable.
!currentChatModel
)
@@ -57,12 +67,21 @@ export type ChatInputNotice = NonNullable<ReturnType<typeof resolveChatInputNoti
export const useChatInputNotice = (): ChatInputNotice | undefined => {
const agentId = useAgentId();
- const [isHeterogeneousAgent, model, provider] = useAgentStore((s) => [
+ const [isAgentConfigLoading, isHeterogeneousAgent] = useAgentStore((s) => [
+ agentByIdSelectors.isAgentConfigLoadingById(agentId)(s),
agentByIdSelectors.isAgentHeterogeneousById(agentId)(s),
- agentByIdSelectors.getAgentModelById(agentId)(s),
- agentByIdSelectors.getAgentModelProviderById(agentId)(s),
]);
+ // Same source as the model trigger renders, so the notice can never judge a
+ // different model than the one the user sees (member overrides included).
+ const { isPreferenceLoading, model, provider, selectionPolicy } = useAgentModelSelection(agentId);
+
+ // `isPreferenceLoading` is true for every workspace agent while the shared
+ // preferences request is in flight, but the override only feeds the
+ // effective model under the `member` policy (`resolveAgentModelConfig`).
+ // Waiting on it for a `fixed` agent would swallow a genuine warning.
+ const isMemberOverridePending = selectionPolicy === 'member' && isPreferenceLoading;
+
const enabledChatModelList = useEnabledChatModels();
const isModelConfigReady = useAiInfraStore((s) =>
aiProviderSelectors.isInitAiProviderRuntimeState(s),
@@ -72,6 +91,7 @@ export const useChatInputNotice = (): ChatInputNotice | undefined => {
return resolveChatInputNotice({
currentChatModel,
+ isAgentModelPending: isAgentConfigLoading || isMemberOverridePending,
isGroupContext,
isHeterogeneousAgent,
isModelConfigReady,