fix(sync): keep session renames stable (#2043)
* fix(sync): keep session renames stable * fix(sync): clarify rename mirror flow * fix(sync): clarify archive comment --------- Co-authored-by: bashrusakh <bashrusakh@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
bashrusakh
Bohdan Triapitsyn
parent
9bfc5bf0be
commit
d5745aaac9
@@ -25,6 +25,7 @@ import { updateStreamingState } from "./streaming"
|
||||
import { setActionRefs } from "./session-actions"
|
||||
import { setSyncRefs, getAllSyncSessions } from "./sync-refs"
|
||||
import { stripMessageDiffSnapshots, stripSessionDiffSnapshots } from "./sanitize"
|
||||
import { applySessionEventToGlobalSessions } from "./session-event-router"
|
||||
import { syncDebug } from "./debug"
|
||||
import { getReconnectCandidateSessionIds } from "./reconnect-recovery"
|
||||
import { opencodeClient } from "@/lib/opencode/client"
|
||||
@@ -46,7 +47,6 @@ import { getRuntimeKey } from "@/lib/runtime-switch"
|
||||
import { getRegisteredRuntimeAPIs } from "@/contexts/runtimeAPIRegistry"
|
||||
import { setSessionPrefetch } from "./session-prefetch-cache"
|
||||
import { listGlobalSessionPages } from "@/stores/globalSessions"
|
||||
import { useGlobalSessionsStore } from "@/stores/useGlobalSessionsStore"
|
||||
import { areRequestArraysReferentiallyEqual, collectScopedBlockingRequests } from "./scoped-blocking-requests"
|
||||
import { EMPTY_USER_MESSAGE_HISTORY_SNAPSHOT, buildUserMessageHistorySnapshot, type UserMessageHistorySnapshot } from "./user-message-history"
|
||||
import { runtimeFetch } from "@/lib/runtime-fetch"
|
||||
@@ -659,46 +659,6 @@ const getSessionIdFromPayload = (event: Event): string | null => {
|
||||
return null
|
||||
}
|
||||
|
||||
const getSessionInfoFromPayload = (event: Event): Session | null => {
|
||||
if (event.type !== "session.created" && event.type !== "session.updated" && event.type !== "session.deleted") {
|
||||
return null
|
||||
}
|
||||
|
||||
const properties = (event as { properties?: unknown }).properties
|
||||
if (!properties || typeof properties !== "object") {
|
||||
return null
|
||||
}
|
||||
|
||||
const info = (properties as { info?: unknown }).info
|
||||
if (!info || typeof info !== "object") {
|
||||
return null
|
||||
}
|
||||
|
||||
const session = info as Partial<Session>
|
||||
if (typeof session.id !== "string" || !session.time) {
|
||||
return null
|
||||
}
|
||||
|
||||
return stripSessionDiffSnapshots(session as Session)
|
||||
}
|
||||
|
||||
const applySessionEventToGlobalSessions = (payload: Event) => {
|
||||
if (payload.type === "session.created" || payload.type === "session.updated") {
|
||||
const session = getSessionInfoFromPayload(payload)
|
||||
if (session) {
|
||||
useGlobalSessionsStore.getState().upsertSession(session)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.type === "session.deleted") {
|
||||
const sessionID = getSessionIdFromPayload(payload) ?? getSessionInfoFromPayload(payload)?.id
|
||||
if (sessionID) {
|
||||
useGlobalSessionsStore.getState().removeSessions([sessionID])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getMessageIdFromPayload = (event: Event): string | null => {
|
||||
const properties = (event as { properties?: unknown }).properties
|
||||
if (!properties || typeof properties !== "object") {
|
||||
|
||||
Reference in New Issue
Block a user