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:
Leonid
2026-07-11 15:19:24 +03:00
committed by GitHub
co-authored by bashrusakh Bohdan Triapitsyn
parent 9bfc5bf0be
commit d5745aaac9
9 changed files with 234 additions and 43 deletions
+1 -41
View File
@@ -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") {