Skip to content

Commit 47e051f

Browse files
committed
fix(ui): restore responsive session switching
Keep the experimental persistent message cache disabled in desktop restore flows. The bounded cache could expose only a transcript suffix while progressive IndexedDB hydration repeatedly copied and measured large histories on the renderer thread, preventing responsive session changes. Tab restoration and in-memory session eviction remain enabled; selected sessions now use the established authoritative HTTP load path. Add a regression check and validate request authority, memory eviction, UI typechecking, and the production build.
1 parent 3e9763d commit 47e051f

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

packages/ui/src/stores/client-state.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ const boot = async (api?: NativeApi, storage?: MemoryStorage) => {
3434
const transact = (state: ClientState, kind: TransactionKind) => kind === "clear"
3535
? state.clearRestoredClientState() : state.setRestorePreviousStateEnabled(false)
3636
describe("client state ownership and persistence", () => {
37+
it("keeps persistent message caching disabled during desktop restore", async () => {
38+
const cache = await import("../lib/session-message-cache.ts")
39+
cache.setSessionMessageCacheEnabled(false)
40+
await boot({ loadClientState: async () => loadResult(snapshot("project")) })
41+
assert.equal(cache.isSessionMessageCacheEnabled(), false)
42+
})
3743
it("treats a rejected access claim as secondary without loading", async () => {
3844
let loads = 0
3945
const state = await boot({

packages/ui/src/stores/client-state.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ export async function setRestorePreviousStateEnabled(enabled: boolean): Promise<
272272
if (!await setNativeRestoreEnabled(true)) throw new Error("Native restore preference update was rejected")
273273
writeBlock = false
274274
setRestorePreviousStateEnabledSignal(true)
275-
setSessionMessageCacheEnabled(true)
275+
// ponytail: keep message caching off until restore no longer blocks the renderer on large sessions.
276+
setSessionMessageCacheEnabled(false)
276277
return
277278
}
278279
setRestorePreviousStateEnabledSignal(false)
@@ -287,7 +288,7 @@ export async function setRestorePreviousStateEnabled(enabled: boolean): Promise<
287288
await executeDestructiveTransaction(() => setNativeRestoreEnabled(false), "Native restore preference update was rejected")
288289
} catch (error) {
289290
setRestorePreviousStateEnabledSignal(true)
290-
setSessionMessageCacheEnabled(!isSessionMessageCacheUnsafe())
291+
setSessionMessageCacheEnabled(false)
291292
throw error
292293
}
293294
cacheClearPending = true
@@ -341,7 +342,7 @@ export function initializeClientState(): Promise<void> {
341342
writeBlock = isFutureClientSnapshot(loaded.snapshot) ? "snapshot" : false
342343
const snapshot = decodeClientSnapshot(loaded.snapshot)
343344
resetLoadedState(snapshot, true)
344-
setSessionMessageCacheEnabled(!writeBlock)
345+
setSessionMessageCacheEnabled(false)
345346
if (!writeBlock && migrateLegacyLayoutValues()) scheduleSave()
346347
} catch (error) {
347348
initialized = true

0 commit comments

Comments
 (0)