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,6 +1,8 @@
|
||||
import type { OpencodeClient, Session } from "@opencode-ai/sdk/v2";
|
||||
import { retry } from "@/sync/retry";
|
||||
import { stripSessionListDetails } from "@/sync/sanitize";
|
||||
import { getRuntimeKey } from "@/lib/runtime-switch";
|
||||
import { startSessionLoadPerformanceEvent } from "@/sync/session-load-performance";
|
||||
|
||||
export type GlobalSessionRecord = Session & {
|
||||
project?: {
|
||||
@@ -86,21 +88,49 @@ export async function listGlobalSessionPages(
|
||||
const all: GlobalSessionRecord[] = [];
|
||||
const seenIds = new Set<string>();
|
||||
let cursor: number | undefined;
|
||||
let operation: string;
|
||||
if (!options.directory) {
|
||||
operation = `global-sessions.${options.archived ? "archived" : "active"}`;
|
||||
} else if (options.roots === true) {
|
||||
operation = "bootstrap.sessions.roots";
|
||||
} else if (options.archived) {
|
||||
operation = "bootstrap.sessions.archived";
|
||||
} else {
|
||||
operation = "bootstrap.sessions.all";
|
||||
}
|
||||
|
||||
while (true) {
|
||||
const response = await retry(
|
||||
() => apiClient.experimental.session.list({
|
||||
...(options.directory ? { directory: options.directory } : {}),
|
||||
archived: options.archived,
|
||||
...(options.roots !== undefined ? { roots: options.roots } : {}),
|
||||
limit: options.pageSize,
|
||||
...(cursor !== undefined ? { cursor } : {}),
|
||||
}),
|
||||
let attempts = 0;
|
||||
const finishPerformanceEvent = startSessionLoadPerformanceEvent({
|
||||
operation,
|
||||
runtimeKey: getRuntimeKey(),
|
||||
directory: options.directory,
|
||||
caller: cursor === undefined ? "initial-page" : "pagination",
|
||||
});
|
||||
const { response, payload } = await retry(
|
||||
async () => {
|
||||
attempts += 1;
|
||||
const response = await apiClient.experimental.session.list({
|
||||
...(options.directory ? { directory: options.directory } : {}),
|
||||
archived: options.archived,
|
||||
...(options.roots !== undefined ? { roots: options.roots } : {}),
|
||||
limit: options.pageSize,
|
||||
...(cursor !== undefined ? { cursor } : {}),
|
||||
});
|
||||
const payload = unwrapSessionList(response, "experimental.session.list")
|
||||
.map((session) => stripSessionListDetails(session) as GlobalSessionRecord);
|
||||
return { response, payload };
|
||||
},
|
||||
{ attempts: 3, delay: 500, retryIf: () => true },
|
||||
);
|
||||
).catch((error) => {
|
||||
finishPerformanceEvent("error", { retryCount: Math.max(0, attempts - 1) });
|
||||
throw error;
|
||||
});
|
||||
|
||||
const payload = unwrapSessionList(response, "experimental.session.list")
|
||||
.map((session) => stripSessionListDetails(session) as GlobalSessionRecord);
|
||||
finishPerformanceEvent("complete", {
|
||||
retryCount: Math.max(0, attempts - 1),
|
||||
recordCount: payload.length,
|
||||
});
|
||||
if (payload.length === 0) break;
|
||||
|
||||
let appended = 0;
|
||||
|
||||
Reference in New Issue
Block a user