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
@@ -103,3 +103,27 @@ func TestChatOpenWorkspaceRejectsDuplicatesAndBounds(t *testing.T) {
t.Fatal("oversized workspace accepted")
}
}
func TestChatOpenWorkspaceReplacesARestartedChatInPlace(t *testing.T) {
store := openWorkspaceStore(t, t.TempDir()+"/workspace.db")
defer store.Close()
ctx := context.Background()
entries := []protocol.ChatOpenWorkspaceEntry{{SessionID: "ses_a"}, {SessionID: "ses_b", Floating: true}, {SessionID: "ses_c"}}
if _, _, err := store.SaveChatOpenWorkspace(ctx, "default", entries, false, 0); err != nil {
t.Fatal(err)
}
moved, changed, err := store.ReplaceChatOpenWorkspaceSession(ctx, "default", "ses_b", "ses_new")
if err != nil || !changed || moved.Revision != 2 {
t.Fatalf("replace = %+v changed=%v err=%v", moved, changed, err)
}
if got := moved.Entries; len(got) != 3 || got[1].SessionID != "ses_new" || !got[1].Floating || got[0].SessionID != "ses_a" || got[2].SessionID != "ses_c" {
t.Fatalf("entries after replace = %+v", got)
}
if _, changed, _ := store.ReplaceChatOpenWorkspaceSession(ctx, "default", "ses_gone", "ses_x"); changed {
t.Fatal("replacing a chat that is not open stored a revision")
}
merged, changed, err := store.ReplaceChatOpenWorkspaceSession(ctx, "default", "ses_a", "ses_c")
if err != nil || !changed || len(merged.Entries) != 2 || merged.Entries[0].SessionID != "ses_new" || merged.Entries[1].SessionID != "ses_c" {
t.Fatalf("replace onto an open chat = %+v changed=%v err=%v", merged, changed, err)
}
}