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:
committed by
GitHub
parent
485efc7117
commit
85400459e9
@@ -1,7 +1,12 @@
|
||||
import { beforeEach, describe, expect, test } from 'bun:test';
|
||||
import type { Session } from '@opencode-ai/sdk/v2';
|
||||
|
||||
import { resolveGlobalSessionDirectory, mergeLiveSessionWithGlobalSession, useGlobalSessionsStore } from './useGlobalSessionsStore';
|
||||
import {
|
||||
isGlobalSessionRecencyOnlyUpdate,
|
||||
resolveGlobalSessionDirectory,
|
||||
mergeLiveSessionWithGlobalSession,
|
||||
useGlobalSessionsStore,
|
||||
} from './useGlobalSessionsStore';
|
||||
|
||||
type SessionExtra = Partial<Session> & {
|
||||
directory?: string | null;
|
||||
@@ -78,6 +83,44 @@ describe('useGlobalSessionsStore', () => {
|
||||
expect(useGlobalSessionsStore.getState().activeSessions).toEqual([]);
|
||||
expect(resolveGlobalSessionDirectory(useGlobalSessionsStore.getState().archivedSessions[0])).toBe('/repo/app');
|
||||
});
|
||||
|
||||
test('preserves the opposite session-list reference during an upsert', () => {
|
||||
const active = buildSession('https://share.example/active');
|
||||
const archived = buildSession('https://share.example/archived', {
|
||||
id: 'ses_archived',
|
||||
time: { created: 1, updated: 2, archived: 3 },
|
||||
});
|
||||
useGlobalSessionsStore.getState().applySnapshot([active], [archived]);
|
||||
|
||||
const archivedSessions = useGlobalSessionsStore.getState().archivedSessions;
|
||||
useGlobalSessionsStore.getState().upsertSession(buildSession('https://share.example/active-updated', {
|
||||
time: { created: 1, updated: 3 },
|
||||
}));
|
||||
expect(useGlobalSessionsStore.getState().archivedSessions).toBe(archivedSessions);
|
||||
|
||||
const activeSessions = useGlobalSessionsStore.getState().activeSessions;
|
||||
useGlobalSessionsStore.getState().upsertSession({
|
||||
...archived,
|
||||
time: { created: 1, updated: 4, archived: 3 },
|
||||
});
|
||||
expect(useGlobalSessionsStore.getState().activeSessions).toBe(activeSessions);
|
||||
});
|
||||
|
||||
test('applies a batch of session upserts in one store publication', () => {
|
||||
let publications = 0;
|
||||
const unsubscribe = useGlobalSessionsStore.subscribe(() => {
|
||||
publications += 1;
|
||||
});
|
||||
|
||||
useGlobalSessionsStore.getState().upsertSessions([
|
||||
buildSession('https://share.example/a'),
|
||||
buildSession('https://share.example/b', { id: 'ses_2' }),
|
||||
]);
|
||||
|
||||
unsubscribe();
|
||||
expect(useGlobalSessionsStore.getState().activeSessions.map((session) => session.id)).toEqual(['ses_2', 'ses_1']);
|
||||
expect(publications).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mergeLiveSessionWithGlobalSession', () => {
|
||||
@@ -106,3 +149,52 @@ describe('mergeLiveSessionWithGlobalSession', () => {
|
||||
expect(resolveGlobalSessionDirectory(merged)).toBe('/repo/worktree');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isGlobalSessionRecencyOnlyUpdate', () => {
|
||||
test('accepts an updated timestamp while preserving omitted directory metadata', () => {
|
||||
const existing = buildSession('https://share.example/s', {
|
||||
directory: '/repo/app',
|
||||
time: { created: 1, updated: 2 },
|
||||
});
|
||||
const incoming = buildSession('https://share.example/s', {
|
||||
time: { created: 1, updated: 3 },
|
||||
});
|
||||
|
||||
expect(isGlobalSessionRecencyOnlyUpdate(existing, incoming)).toBe(true);
|
||||
});
|
||||
|
||||
test('rejects title and archive changes as structural updates', () => {
|
||||
const existing = buildSession('https://share.example/s', { time: { created: 1, updated: 2 } });
|
||||
const renamed = buildSession('https://share.example/s', {
|
||||
title: 'Renamed',
|
||||
time: { created: 1, updated: 3 },
|
||||
});
|
||||
const archived = buildSession('https://share.example/s', {
|
||||
time: { created: 1, updated: 3, archived: 4 },
|
||||
});
|
||||
|
||||
expect(isGlobalSessionRecencyOnlyUpdate(existing, renamed)).toBe(false);
|
||||
expect(isGlobalSessionRecencyOnlyUpdate(existing, archived)).toBe(false);
|
||||
});
|
||||
|
||||
test('rejects parent and slug changes as structural updates', () => {
|
||||
const existing = buildSession('https://share.example/s', {
|
||||
parentID: 'parent-a',
|
||||
slug: 'slug-a',
|
||||
time: { created: 1, updated: 2 },
|
||||
});
|
||||
const reparented = buildSession('https://share.example/s', {
|
||||
parentID: 'parent-b',
|
||||
slug: 'slug-a',
|
||||
time: { created: 1, updated: 3 },
|
||||
});
|
||||
const reslugged = buildSession('https://share.example/s', {
|
||||
parentID: 'parent-a',
|
||||
slug: 'slug-b',
|
||||
time: { created: 1, updated: 3 },
|
||||
});
|
||||
|
||||
expect(isGlobalSessionRecencyOnlyUpdate(existing, reparented)).toBe(false);
|
||||
expect(isGlobalSessionRecencyOnlyUpdate(existing, reslugged)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user