fix(app): session sync issue

This commit is contained in:
adamelmore
2026-01-26 13:36:36 -06:00
parent 04337f6202
commit d4e3acf17e
2 changed files with 16 additions and 28 deletions

View File

@@ -16,7 +16,6 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
const sdk = useSDK() const sdk = useSDK()
type Child = ReturnType<(typeof globalSync)["child"]> type Child = ReturnType<(typeof globalSync)["child"]>
type Store = Child[0]
type Setter = Child[1] type Setter = Child[1]
const current = createMemo(() => globalSync.child(sdk.directory)) const current = createMemo(() => globalSync.child(sdk.directory))
@@ -43,18 +42,6 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
return Math.ceil(count / chunk) * chunk return Math.ceil(count / chunk) * chunk
} }
const hydrateMessages = (directory: string, store: Store, sessionID: string) => {
const key = keyFor(directory, sessionID)
if (meta.limit[key] !== undefined) return
const messages = store.message[sessionID]
if (!messages) return
const limit = limitFor(messages.length)
setMeta("limit", key, limit)
setMeta("complete", key, messages.length < limit)
}
const loadMessages = async (input: { const loadMessages = async (input: {
directory: string directory: string
client: typeof sdk.client client: typeof sdk.client
@@ -150,21 +137,20 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
const directory = sdk.directory const directory = sdk.directory
const client = sdk.client const client = sdk.client
const [store, setStore] = globalSync.child(directory) const [store, setStore] = globalSync.child(directory)
const key = keyFor(directory, sessionID)
const hasSession = (() => { const hasSession = (() => {
const match = Binary.search(store.session, sessionID, (s) => s.id) const match = Binary.search(store.session, sessionID, (s) => s.id)
return match.found return match.found
})() })()
hydrateMessages(directory, store, sessionID)
const hasMessages = store.message[sessionID] !== undefined const hasMessages = store.message[sessionID] !== undefined
if (hasSession && hasMessages) return const hydrated = meta.limit[key] !== undefined
if (hasSession && hasMessages && hydrated) return
const key = keyFor(directory, sessionID)
const pending = inflight.get(key) const pending = inflight.get(key)
if (pending) return pending if (pending) return pending
const limit = meta.limit[key] ?? chunk const count = store.message[sessionID]?.length ?? 0
const limit = hydrated ? (meta.limit[key] ?? chunk) : limitFor(count)
const sessionReq = hasSession const sessionReq = hasSession
? Promise.resolve() ? Promise.resolve()
@@ -184,15 +170,16 @@ export const { use: useSync, provider: SyncProvider } = createSimpleContext({
) )
}) })
const messagesReq = hasMessages const messagesReq =
? Promise.resolve() hasMessages && hydrated
: loadMessages({ ? Promise.resolve()
directory, : loadMessages({
client, directory,
setStore, client,
sessionID, setStore,
limit, sessionID,
}) limit,
})
const promise = Promise.all([sessionReq, messagesReq]) const promise = Promise.all([sessionReq, messagesReq])
.then(() => {}) .then(() => {})

View File

@@ -283,6 +283,7 @@ export function SessionTurn(
const shellModePart = createMemo(() => { const shellModePart = createMemo(() => {
const p = parts() const p = parts()
if (p.length === 0) return
if (!p.every((part) => part?.type === "text" && part?.synthetic)) return if (!p.every((part) => part?.type === "text" && part?.synthetic)) return
const msgs = assistantMessages() const msgs = assistantMessages()