refactor: stabilize live chat sync materialization (#1132)
Canonicalize session message/part materialization across load, prefetch, reconnect, and recovery paths so OpenChamber restores session snapshots through one consistent merge flow. Preserve live assistant streaming text when stale or delayed snapshots arrive, while still replacing optimistic user parts with confirmed server snapshots to avoid duplicated user messages. Narrow recovery triggers to explicit incomplete snapshot signals instead of broad session-event fallbacks, reducing unnecessary session refetches during active streaming. Keep turn windowing aligned with parented assistant replies and add regression coverage for materialization gaps, stale snapshot protection, optimistic user replacement, reconnect recovery, and turn grouping.
This commit is contained in:
committed by
GitHub
parent
ff830d3812
commit
e892346c6b
@@ -7,6 +7,7 @@
|
||||
|
||||
import type { OpencodeClient } from "@opencode-ai/sdk/v2/client"
|
||||
import type { ChildStoreManager } from "./child-store"
|
||||
import { getSessionMaterializationStatus } from "./materialization"
|
||||
import type { State } from "./types"
|
||||
|
||||
let _sdk: OpencodeClient | null = null
|
||||
@@ -83,6 +84,13 @@ export function getSyncMessages(sessionId: string, directory?: string) {
|
||||
return getDirectoryState(directory)?.message[sessionId] ?? []
|
||||
}
|
||||
|
||||
/** Read renderability of a session snapshot from current directory's child store */
|
||||
export function getSyncSessionMaterializationStatus(sessionId: string, directory?: string) {
|
||||
const state = getDirectoryState(directory)
|
||||
if (!state) return { hasMessages: false, renderable: false, missingPartMessageIDs: [] }
|
||||
return getSessionMaterializationStatus(state, sessionId)
|
||||
}
|
||||
|
||||
/** Read parts for a message from current directory's child store */
|
||||
export function getSyncParts(messageId: string, directory?: string) {
|
||||
return getDirectoryState(directory)?.part[messageId] ?? []
|
||||
|
||||
Reference in New Issue
Block a user