Serialize open-chat sync writes by server revision and fan out prunes

Server: chat_open_workspace is a compare-and-swap on base_revision; a stale
write is refused and answered with the current snapshot (rejected: true).
Each stored change increments the revision; identical writes store nothing.
A request with no body reads the set. Seeds apply only to a never-stored set.
Validation uses the operator registry (recorded, not closed). chat_close and
connection-time pruning store a new revision and push it to every
connection; otherwise a new connection gets the current set to catch up.

App: ChatOpenWorkspaceController keeps one write in flight, coalesces later
changes, sends from the last replied revision and ignores lower revisions;
pushes and rejected replies win over unsent changes. It starts after the
local layout restores (seed or read), keeps a deep-linked chat, and is
disposed on server/gateway rebind. Remote membership is applied by
reconcileChatWorkspaceTree, keeping pane ids and split sizes. Federated
lists keep their local layout.

Tests: Go store/handler fan-out tests; app controller, reconcile and screen
sync tests. Notes record a live two-client scratch check.
This commit is contained in:
2026-11-12 03:23:22 +00:00
parent f8e081825f
commit 4f8e99f316
20 changed files with 1333 additions and 276 deletions
+4 -17
View File
@@ -17,7 +17,7 @@ import (
// registry, not on one device. A session id that is not a recorded operator
// session is refused before anything is written, so a pipeline-owned run session
// is never touched.
func handleChatClose(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, registry operatorRegistry, store chatOpenWorkspaceStore, write func(protocol.Message) error) {
func handleChatClose(ctx context.Context, request protocol.Message, broker chatBroker, hub *chatHub, registry operatorRegistry, write func(protocol.Message) error) {
if broker == nil {
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "chat is not configured on this server"})
return
@@ -92,22 +92,9 @@ func handleChatClose(ctx context.Context, request protocol.Message, broker chatB
// chat_sessions without a re-list.
response.ChatSessions = []protocol.ChatSession{wire}
_ = write(response)
if store != nil {
workspace, workspaceErr := store.ChatOpenWorkspace(ctx, chatWorkspaceScope)
if workspaceErr == nil {
kept := workspace.Entries[:0]
for _, entry := range workspace.Entries {
if entry.SessionID != sessionID {
kept = append(kept, entry)
}
}
if len(kept) != len(workspace.Entries) {
if updated, saveErr := store.SaveChatOpenWorkspace(ctx, chatWorkspaceScope, kept, false); saveErr == nil && hub != nil {
hub.changes().broadcastWorkspace("", updated)
}
}
}
}
// A closed chat leaves every device's open-chat set, so no client can keep
// or restore it.
dropFromChatWorkspace(ctx, registry, hub.changes(), sessionID)
}
// handleChatReopen clears the closed state of an operator chat session so it