Reduce workspace, agent, and chat sync traffic (#2028)

* feat(sync): keep live data scoped and current

Only viewed chats receive live timeline rows, while directory state now uses one subscribed bootstrap followed by ordered deltas. Legacy clients and daemons retain their existing behavior through centralized compatibility gates.

* fix(sync): preserve selective delivery boundaries

Keep selective timeline capability app-owned, union viewed sets across shared sockets, and reconcile directory side effects from accepted state. Visibility and archive suppression now follow their existing authoritative boundaries.

* test(app): align browser fixtures with runtime contracts

* fix(sync): preserve mixed-client delivery guarantees

* fix(sync): finish paged history before advancing

* fix(sync): replay live deltas after refresh failures

* test(server): model socket capability lookup

* test(app): use platform shortcut for split-pane coverage

* fix(app): keep hidden timelines dormant

* test(app): normalize split-pane shortcut setup

* fix(app): preserve sync state across retries

* fix(app): preserve background sync state across races

* fix directory bootstrap reconciliation edge cases

* fix selective timeline compatibility races

* fix superseded directory sync races

* fix(sync): centralize directory replica ordering

Own agent and workspace refresh transactions in HostRuntime so reconnect epochs, buffered updates, and lifecycle invalidation share one ordering boundary. Route timeline metadata and mixed-capability stream delivery through their authoritative runtime sources.

* fix(app): keep timeline requests runtime-scoped

* fix(app): close directory bootstrap races
This commit is contained in:
Mohamed Boudra
2026-07-17 17:03:34 +02:00
committed by GitHub
parent 6c99efae52
commit 1977d330ed
57 changed files with 5783 additions and 1343 deletions
+34 -7
View File
@@ -2,6 +2,7 @@ import equal from "fast-deep-equal";
import { create } from "zustand";
import { subscribeWithSelector } from "zustand/middleware";
import type { DaemonClient } from "@getpaseo/client/internal/daemon-client";
import type { ViewedTimelineUiBridge } from "@/timeline/viewed-timeline-sync";
import type { AgentDirectoryEntry } from "@/types/agent-directory";
import {
handoffCreatedAgentUserMessageToStream,
@@ -325,6 +326,8 @@ export interface SessionState {
// Daemon client (immutable reference)
client: DaemonClient | null;
clientGeneration: number;
viewedTimelineSync: ViewedTimelineUiBridge | null;
// Server metadata (from server_info handshake)
serverInfo: DaemonServerInfo | null;
@@ -390,10 +393,11 @@ interface SessionStoreState {
// Action types
interface SessionStoreActions {
// Session management
initializeSession: (serverId: string, client: DaemonClient) => void;
initializeSession: (serverId: string, client: DaemonClient, clientGeneration?: number) => void;
clearSession: (serverId: string) => void;
getSession: (serverId: string) => SessionState | undefined;
updateSessionClient: (serverId: string, client: DaemonClient) => void;
updateSessionClient: (serverId: string, client: DaemonClient, clientGeneration?: number) => void;
setViewedTimelineSync: (serverId: string, sync: ViewedTimelineUiBridge | null) => void;
updateSessionServerInfo: (serverId: string, info: DaemonServerInfo) => void;
// Audio state
@@ -531,10 +535,16 @@ type SessionStore = SessionStoreState & SessionStoreActions;
const agentLastActivityCoalescer = createAgentLastActivityCoalescer();
// Helper to create initial session state
function createInitialSessionState(serverId: string, client: DaemonClient): SessionState {
function createInitialSessionState(
serverId: string,
client: DaemonClient,
clientGeneration = 0,
): SessionState {
return {
serverId,
client,
clientGeneration,
viewedTimelineSync: null,
serverInfo: null,
hasHydratedAgents: false,
hasHydratedWorkspaces: false,
@@ -637,7 +647,7 @@ export const useSessionStore = create<SessionStore>()(
agentLastActivity: new Map(),
// Session management
initializeSession: (serverId, client) => {
initializeSession: (serverId, client, clientGeneration) => {
set((prev) => {
if (prev.sessions[serverId]) {
return prev;
@@ -646,7 +656,7 @@ export const useSessionStore = create<SessionStore>()(
...prev,
sessions: {
...prev.sessions,
[serverId]: createInitialSessionState(serverId, client),
[serverId]: createInitialSessionState(serverId, client, clientGeneration),
},
};
});
@@ -686,7 +696,7 @@ export const useSessionStore = create<SessionStore>()(
});
},
updateSessionClient: (serverId, client) => {
updateSessionClient: (serverId, client, clientGeneration = 0) => {
set((prev) => {
const session = prev.sessions[serverId];
@@ -694,7 +704,7 @@ export const useSessionStore = create<SessionStore>()(
return prev;
}
if (session.client === client) {
if (session.client === client && session.clientGeneration === clientGeneration) {
return prev;
}
@@ -705,12 +715,29 @@ export const useSessionStore = create<SessionStore>()(
[serverId]: {
...session,
client,
clientGeneration,
},
},
};
});
},
setViewedTimelineSync: (serverId, viewedTimelineSync) => {
set((prev) => {
const session = prev.sessions[serverId];
if (!session || session.viewedTimelineSync === viewedTimelineSync) {
return prev;
}
return {
...prev,
sessions: {
...prev.sessions,
[serverId]: { ...session, viewedTimelineSync },
},
};
});
},
updateSessionServerInfo: (serverId, info) => {
set((prev) => {
const session = prev.sessions[serverId];