perf: overhaul session loading, caching, and runtime isolation (#2360)

Improve OpenChamber responsiveness under large session workloads while fixing
cache, synchronization, and persistence correctness across runtimes, projects,
directories, and worktrees.

- prioritize selected and visible sessions during bootstrap and defer
  non-critical enrichment work
- reduce redundant message loading, event processing, store publication, and
  hidden sidebar work
- prevent stale session and message requests from overwriting newer
  authoritative state
- preserve existing data when authoritative fetches fail instead of treating
  failures as successful empty responses
- scope session materialization, messages, drafts, queues, todos, pins,
  permissions, folders, tabs, Git state, and pull request data by runtime and
  directory identity
- harden runtime switching, reconnect, cleanup, mutation reconciliation, and
  persisted-state ordering
- preserve live subagent Task linkage when metadata arrives after an older
  message request or while streaming parts are suspended
- coalesce overlapping tail refreshes without losing newer refresh demand
- improve cold-session loading by moving deferrable work out of the critical
  bootstrap path
- isolate URL authentication, mobile credentials, native secrets, and other
  runtime-owned state across endpoint changes
- bound long-lived caches and remove avoidable allocations from event and
  rendering hot paths
- limit virtualization to archive collections where it improves rendering
  without disrupting active sidebar layout
- stabilize session folders, pin ordering, expanded state, and persisted
  sidebar behavior
- open skill files through the same secure editor and outside-workspace grant
  flow used by file navigation, including worktree sessions
- expand regression coverage for stale completions, runtime collisions,
  reconnect behavior, persistence races, authoritative empty results, and
  subagent refresh ordering
- document the updated synchronization, cache ownership, performance, and
  runtime-isolation invariants
This commit is contained in:
Bohdan Triapitsyn
2026-07-21 20:52:20 +03:00
committed by GitHub
parent 485efc7117
commit 85400459e9
197 changed files with 10835 additions and 3400 deletions
+84
View File
@@ -5,8 +5,10 @@ import { registerRuntimeAPIs } from '@/contexts/runtimeAPIRegistry';
import { startModelPrefsAutoSave } from '@/lib/modelPrefsAutoSave';
import { startAppearanceAutoSave } from '@/lib/appearanceAutoSave';
import { useUIStore } from '@/stores/useUIStore';
import { useMessageQueueStore } from '@/stores/messageQueueStore';
import {
applyPersistedHomeDirectoryToWindow,
getRuntimeSettingsMirrorStorageKey,
getSettingsSaveState,
invalidateSettingsCache,
subscribeToSettingsSaveState,
@@ -315,6 +317,88 @@ describe('updateDesktopSettings', () => {
expect(useUIStore.getState().terminalShell).toBe('bash');
});
test('isolates local settings mirrors and removes values omitted by the next runtime', async () => {
getWindow();
localStorage.clear();
switchRuntimeEndpoint({ apiBaseUrl: 'https://mirror-a.example', runtimeKey: 'mirror-a' });
registerSettingsApi(async () => ({}), async () => ({
settings: {
themeId: 'theme-a',
directoryShowHidden: true,
sttModel: 'model-a',
draftStartersCraftGoalAdded: true,
},
source: 'web',
}));
await syncDesktopSettings();
switchRuntimeEndpoint({ apiBaseUrl: 'https://mirror-b.example', runtimeKey: 'mirror-b' });
registerSettingsApi(async () => ({}), async () => ({
settings: { draftStartersCraftGoalAdded: true },
source: 'web',
}));
await syncDesktopSettings();
expect(localStorage.getItem('selectedThemeId')).toBeNull();
expect(localStorage.getItem('directoryTreeShowHidden')).toBeNull();
expect(localStorage.getItem('sttModel')).toBeNull();
expect(JSON.parse(localStorage.getItem(getRuntimeSettingsMirrorStorageKey('mirror-a')) ?? '{}')).toEqual({
themeId: 'theme-a',
directoryShowHidden: true,
sttModel: 'model-a',
});
expect(JSON.parse(localStorage.getItem(getRuntimeSettingsMirrorStorageKey('mirror-b')) ?? '{}')).toEqual({});
});
test('resets in-memory preferences omitted by an authoritative runtime snapshot', async () => {
getWindow();
switchRuntimeEndpoint({ apiBaseUrl: 'https://preferences-a.example', runtimeKey: 'preferences-a' });
registerSettingsApi(async () => ({}), async () => ({
settings: {
showReasoningTraces: false,
terminalShell: 'fish',
favoriteModels: [{ providerID: 'anthropic', modelID: 'claude-sonnet-4' }],
followUpBehavior: 'steer',
draftStarters: [{ type: 'command', name: 'runtime-a' }],
draftStartersCraftGoalAdded: true,
},
source: 'web',
}));
await syncDesktopSettings();
expect(useUIStore.getState().showReasoningTraces).toBe(false);
expect(useUIStore.getState().terminalShell).toBe('fish');
expect(useUIStore.getState().favoriteModels).toHaveLength(1);
expect(useUIStore.getState().globalDraftStarters).toEqual([{ type: 'command', name: 'runtime-a' }]);
expect(useMessageQueueStore.getState().followUpBehavior).toBe('steer');
switchRuntimeEndpoint({ apiBaseUrl: 'https://preferences-b.example', runtimeKey: 'preferences-b' });
registerSettingsApi(async () => ({}), async () => ({
settings: { draftStartersCraftGoalAdded: true },
source: 'web',
}));
await syncDesktopSettings();
expect(useUIStore.getState().showReasoningTraces).toBe(true);
expect(useUIStore.getState().terminalShell).toBe('auto');
expect(useUIStore.getState().favoriteModels).toEqual([]);
expect(useUIStore.getState().globalDraftStarters).toBeNull();
expect(useMessageQueueStore.getState().followUpBehavior).toBe('queue');
});
test('treats settings save responses as partial patches', async () => {
getWindow();
localStorage.setItem('selectedThemeId', 'existing-theme');
useUIStore.getState().setTerminalShell('fish');
registerSettingsSave(async () => ({ showReasoningTraces: false }));
await updateDesktopSettings({ showReasoningTraces: false });
expect(useUIStore.getState().showReasoningTraces).toBe(false);
expect(useUIStore.getState().terminalShell).toBe('fish');
expect(localStorage.getItem('selectedThemeId')).toBe('existing-theme');
});
test('applies model selector settings from server settings', async () => {
getWindow();
const settings = {