The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(core): dispatch loadAgentProfiles on identity established at boot
shanu210a926b5cef
diff --git a/app/src/providers/CoreStateProvider.tsx b/app/src/providers/CoreStateProvider.tsxindex bdbaf77ddc..928b86cdb2 100644--- a/app/src/providers/CoreStateProvider.tsx+++ b/app/src/providers/CoreStateProvider.tsx@@ -29,6 +29,7 @@ import {import { daemonHealthService } from '../services/daemonHealthService';import { socketService } from '../services/socketService';import { store } from '../store';+import { loadAgentProfiles } from '../store/agentProfileSlice';import { resetUserScopedState } from '../store/resetActions';import { loadThreads, resetThreadCachesPreservingSelection } from '../store/threadSlice';import { getActiveUserId, setActiveUserId } from '../store/userScopedStorage';@@ -417,6 +418,19 @@ export default function CoreStateProvider({ children }: { children: ReactNode })}log('post-identity thread reload failed: %O', sanitizeError(err));});+ // Seed the active agent profile from the backend at the earliest safe+ // moment — before any chat request can fire with a stale 'default' id.+ // Without this, activeProfileId resets to 'default' on every reboot+ // because the agentProfile slice is not persisted (#5872).+ void store+ .dispatch(loadAgentProfiles())+ .unwrap()+ .catch(err => {+ if (threadReloadRequestId !== snapshotRequestIdRef.current) {+ return;+ }+ log('post-identity agent profiles load failed: %O', sanitizeError(err));+ });}if (nextIdentity && isLocalSession && seedUserId !== nextIdentity) {diff --git a/app/src/providers/__tests__/CoreStateProvider.test.tsx b/app/src/providers/__tests__/CoreStateProvider.test.tsxindex ef660c7aba..ac4f43abf6 100644--- a/app/src/providers/__tests__/CoreStateProvider.test.tsx+++ b/app/src/providers/__tests__/CoreStateProvider.test.tsx@@ -2,6 +2,7 @@ import { act, render, screen, waitFor } from '@testing-library/react';import { useEffect } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';+import * as agentProfilesModule from '../../services/api/agentProfilesApi';import * as coreStateApi from '../../services/coreStateApi';import * as tauriCommands from '../../utils/tauriCommands';import { __resetForTests as resetConfigRecoveryNotice } from '../../lib/configRecoveryNotice';@@ -17,6 +18,9 @@ import CoreStateProvider, {vi.mock('../../services/coreStateApi');vi.mock('../../services/analytics', () => ({ syncAnalyticsConsent: vi.fn() }));+vi.mock('../../services/api/agentProfilesApi', () => ({+ agentProfilesApi: { list: vi.fn(), select: vi.fn(), upsert: vi.fn(), delete: vi.fn() },+}));type Snapshot = Awaited<ReturnType<typeof coreStateApi.fetchCoreAppSnapshot>>;@@ -120,11 +124,15 @@ describe('CoreStateProvider — identity-change cache clearing', () => {const getTeamMembers = vi.mocked(coreStateApi.getTeamMembers);const getTeamInvites = vi.mocked(coreStateApi.getTeamInvites);+ const listProfiles = vi.mocked(agentProfilesModule.agentProfilesApi.list);+beforeEach(() => {fetchSnapshot.mockReset();listTeams.mockReset();getTeamMembers.mockReset();getTeamInvites.mockReset();+ listProfiles.mockReset();+ listProfiles.mockResolvedValue({ profiles: [], activeProfileId: 'default' } as never);resetCoreStateStore();setActiveUserId(null);});@@ -942,6 +950,30 @@ describe('CoreStateProvider — identity-change cache clearing', () => {expect(vi.mocked(tauriCommands.storeSession)).toHaveBeenCalled();});++ // Regression for #5872: the active agent profile must be fetched from the+ // backend immediately when identity is established so the first chat request+ // carries the correct profileId rather than the 'default' initialState value.+ it('dispatches loadAgentProfiles when identity is established (#5872)', async () => {+ // Returning user: seed matches snapshot userId so isFlip = false.+ // First snapshot transitions previousIdentity (null) → nextIdentity ('u1'),+ // which sets shouldClearScopedCaches = true and fires the !isFlip block.+ setActiveUserId('u1');+ fetchSnapshot.mockResolvedValue(makeSnapshot({ userId: 'u1', sessionToken: 'tok1' }));+ listTeams.mockResolvedValue([]);++ render(+ <CoreStateProvider>+ <Consumer />+ </CoreStateProvider>+ );++ await waitFor(() => expect(screen.getByTestId('ready').textContent).toBe('ready'));+ // Flush micro-tasks so the void-dispatched promise chain completes.+ await act(async () => {});++ expect(listProfiles).toHaveBeenCalled();+ });});describe('coreStatePollFailureWarningMessage', () => {