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
@@ -14,6 +14,7 @@ import type { FileDiff, GlobalState, State } from "./types"
|
||||
import { dropSessionCaches } from "./session-cache"
|
||||
import { stripSessionDiffSnapshots } from "./sanitize"
|
||||
import { syncDebug } from "./debug"
|
||||
import { shouldSkipStaleSessionEvent } from "./session-event-freshness"
|
||||
|
||||
const SKIP_PARTS = new Set(["patch", "step-start", "step-finish"])
|
||||
const DELTA_OVERLAP_FIELDS = ["text", "output"] as const
|
||||
@@ -226,6 +227,9 @@ export function applyDirectoryEvent(
|
||||
const info = stripSessionDiffSnapshots((event.properties as { info: Session }).info)
|
||||
const sessions = draft.session
|
||||
const result = Binary.search(sessions, info.id, (s) => s.id)
|
||||
if (result.found && shouldSkipStaleSessionEvent(sessions[result.index], info)) {
|
||||
return false
|
||||
}
|
||||
if (result.found) {
|
||||
sessions[result.index] = info
|
||||
} else {
|
||||
@@ -240,6 +244,13 @@ export function applyDirectoryEvent(
|
||||
const info = stripSessionDiffSnapshots((event.properties as { info: Session }).info)
|
||||
const sessions = draft.session
|
||||
const result = Binary.search(sessions, info.id, (s) => s.id)
|
||||
// Keep the freshness check ahead of the archive branch: direct archive
|
||||
// responses handle the store update on their own (optimistic removal +
|
||||
// SDK response), so stale SSE echoes should not win just because they
|
||||
// mark the session archived.
|
||||
if (result.found && shouldSkipStaleSessionEvent(sessions[result.index], info)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (info.time.archived) {
|
||||
if (result.found) sessions.splice(result.index, 1)
|
||||
|
||||
Reference in New Issue
Block a user