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
+15 -2
View File
@@ -7,14 +7,27 @@ type ChatOpenWorkspaceEntry struct {
Floating bool `json:"floating,omitempty"`
}
// ChatOpenWorkspaceRequest replaces the open-chat set. A chat_open_workspace
// without a request only reads the current snapshot.
type ChatOpenWorkspaceRequest struct {
Entries []ChatOpenWorkspaceEntry `json:"entries"`
// Seed is honored only when the server has no saved workspace yet. It makes
// migration from the old device-local snapshot race-safe.
// BaseRevision is the snapshot revision the client's entries were derived
// from. A write whose base is not the current revision is refused, and the
// reply carries the current snapshot with Rejected set, so a late write
// can never overwrite a newer change.
BaseRevision int64 `json:"base_revision"`
// Seed is honored only when the server has never stored a workspace. It
// makes migration from the old device-local snapshot race-safe; otherwise
// the reply is the existing snapshot, unchanged.
Seed bool `json:"seed,omitempty"`
}
// ChatOpenWorkspaceSnapshot is the complete open-chat set. Revision grows by
// one with every stored change.
type ChatOpenWorkspaceSnapshot struct {
Revision int64 `json:"revision"`
Entries []ChatOpenWorkspaceEntry `json:"entries"`
// Rejected marks a reply to a write whose base revision was stale: the
// write was not applied and the snapshot is the current state.
Rejected bool `json:"rejected,omitempty"`
}