Open chats: the server moves a restarted chat (/new) to its new session

The server-stored open-chat set kept a /new'd chat's old session unless the
restarting device's own write landed, so another device (the phone) came
back to the old conversation. chat_new_session now replaces the session in
the stored set in place (position and floating kept) and pushes the new
revision to every connection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-27 00:43:33 +00:00
parent fd5d4b783c
commit 4eb9b2e934
5 changed files with 136 additions and 0 deletions
+19
View File
@@ -20,6 +20,7 @@ type chatOpenWorkspaceStore interface {
ChatOpenWorkspace(context.Context, string) (protocol.ChatOpenWorkspaceSnapshot, error)
SaveChatOpenWorkspace(ctx context.Context, scope string, entries []protocol.ChatOpenWorkspaceEntry, seed bool, baseRevision int64) (protocol.ChatOpenWorkspaceSnapshot, bool, error)
RemoveChatOpenWorkspaceSessions(ctx context.Context, scope string, sessionIDs []string) (protocol.ChatOpenWorkspaceSnapshot, bool, error)
ReplaceChatOpenWorkspaceSession(ctx context.Context, scope, oldID, newID string) (protocol.ChatOpenWorkspaceSnapshot, bool, error)
}
func openWorkspaceStoreOf(registry operatorRegistry) chatOpenWorkspaceStore {
@@ -101,6 +102,24 @@ func dropFromChatWorkspace(ctx context.Context, registry operatorRegistry, chang
}
}
// replaceInChatWorkspace moves a chat that /new restarted to its new session
// in the open-chat set, so every device opens the new session (not the old
// one) even if the restarting device's own write never lands.
func replaceInChatWorkspace(ctx context.Context, registry operatorRegistry, changes *chatSessionChanges, oldID, newID string) {
store := openWorkspaceStoreOf(registry)
if store == nil {
return
}
snapshot, changed, err := store.ReplaceChatOpenWorkspaceSession(ctx, chatWorkspaceScope, oldID, newID)
if err != nil {
log.Printf("move restarted chat %s to %s in open workspace: %v", oldID, newID, err)
return
}
if changed {
changes.broadcastWorkspace("", snapshot)
}
}
// validChatWorkspaceEntries checks a client's snapshot and keeps only its open
// operator chats. Malformed or duplicate ids are refused; closed or unknown
// chats are dropped, so a stale client can never restore them.