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:
@@ -2,8 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
import type { DaemonClient, FetchAgentsEntry } from "@getpaseo/client/internal/daemon-client";
|
||||
import type { AgentSnapshotPayload } from "@getpaseo/protocol/messages";
|
||||
import { PARENT_AGENT_ID_LABEL } from "@getpaseo/protocol/agent-labels";
|
||||
import type { AgentPermissionRequest } from "@getpaseo/protocol/agent-types";
|
||||
import { useSessionStore } from "@/stores/session-store";
|
||||
import { replaceFetchedAgentDirectory } from "./agent-directory-sync";
|
||||
import { normalizeAgentSnapshot } from "@/utils/agent-snapshots";
|
||||
import { isAgentArchiving, setAgentArchiving } from "@/hooks/use-archive-agent";
|
||||
import { queryClient } from "@/data/query-client";
|
||||
import { applyAgentDirectoryDelta, replaceFetchedAgentDirectory } from "./agent-directory-sync";
|
||||
|
||||
function createAgentPayload(
|
||||
input: Partial<Omit<AgentSnapshotPayload, "labels">> & {
|
||||
@@ -56,7 +60,28 @@ function createEntry(agent: AgentSnapshotPayload): FetchAgentsEntry {
|
||||
};
|
||||
}
|
||||
|
||||
function permission(id: string): AgentPermissionRequest {
|
||||
return { id, provider: "codex", name: id, kind: "tool", title: id };
|
||||
}
|
||||
|
||||
describe("replaceFetchedAgentDirectory", () => {
|
||||
it("preserves timeline initialization while replacing directory state", () => {
|
||||
const serverId = "server-initializing";
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, null as unknown as DaemonClient);
|
||||
store.setInitializingAgents(serverId, new Map([["agent", true]]));
|
||||
|
||||
replaceFetchedAgentDirectory({
|
||||
serverId,
|
||||
entries: [createEntry(createAgentPayload({ id: "agent" }))],
|
||||
});
|
||||
|
||||
expect(useSessionStore.getState().sessions[serverId]?.initializingAgents.get("agent")).toBe(
|
||||
true,
|
||||
);
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
it("re-derives parentAgentId every time an agent snapshot is ingested", () => {
|
||||
const serverId = "server-1";
|
||||
const store = useSessionStore.getState();
|
||||
@@ -92,4 +117,142 @@ describe("replaceFetchedAgentDirectory", () => {
|
||||
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
it("removes every replica-owned artifact for a removed agent", () => {
|
||||
const serverId = "server-removal";
|
||||
const agentId = "removed-agent";
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, null as unknown as DaemonClient);
|
||||
const agent = {
|
||||
...normalizeAgentSnapshot(createAgentPayload({ id: agentId }), serverId),
|
||||
projectPlacement: null,
|
||||
};
|
||||
store.setAgents(serverId, new Map([[agentId, agent]]));
|
||||
store.setAgentDetails(serverId, new Map([[agentId, agent]]));
|
||||
store.setQueuedMessages(
|
||||
serverId,
|
||||
new Map([[agentId, [{ id: "queued", text: "next", attachments: [] }]]]),
|
||||
);
|
||||
store.setAgentTimelineCursor(
|
||||
serverId,
|
||||
new Map([[agentId, { epoch: "epoch", startSeq: 1, endSeq: 2 }]]),
|
||||
);
|
||||
store.setPendingPermissions(
|
||||
serverId,
|
||||
new Map([["permission", { key: "permission", agentId, request: null as never }]]),
|
||||
);
|
||||
store.setInitializingAgents(serverId, new Map([[agentId, true]]));
|
||||
setAgentArchiving({ queryClient, serverId, agentId, isArchiving: true });
|
||||
|
||||
applyAgentDirectoryDelta({ serverId, delta: { kind: "remove", agentId } });
|
||||
|
||||
const session = useSessionStore.getState().sessions[serverId];
|
||||
expect({
|
||||
agents: session?.agents.has(agentId),
|
||||
details: session?.agentDetails.has(agentId),
|
||||
queued: session?.queuedMessages.has(agentId),
|
||||
cursor: session?.agentTimelineCursor.has(agentId),
|
||||
permissions: session?.pendingPermissions.size,
|
||||
initializing: session?.initializingAgents.has(agentId),
|
||||
archivePending: isAgentArchiving({ queryClient, serverId, agentId }),
|
||||
}).toEqual({
|
||||
agents: false,
|
||||
details: false,
|
||||
queued: false,
|
||||
cursor: false,
|
||||
permissions: 0,
|
||||
initializing: false,
|
||||
archivePending: false,
|
||||
});
|
||||
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
|
||||
it("keeps newer metadata while accepting usage-only updates and legacy workspace ownership", () => {
|
||||
const serverId = "server-usage";
|
||||
const agentId = "usage-agent";
|
||||
const store = useSessionStore.getState();
|
||||
store.initializeSession(serverId, null as unknown as DaemonClient);
|
||||
store.setWorkspaces(
|
||||
serverId,
|
||||
new Map([
|
||||
[
|
||||
"legacy-workspace",
|
||||
{
|
||||
id: "legacy-workspace",
|
||||
projectId: "project",
|
||||
projectDisplayName: "Project",
|
||||
projectRootPath: "/repo",
|
||||
workspaceDirectory: "/repo",
|
||||
projectKind: "git",
|
||||
workspaceKind: "worktree",
|
||||
name: "repo",
|
||||
status: "done",
|
||||
statusEnteredAt: null,
|
||||
archivingAt: null,
|
||||
diffStat: null,
|
||||
scripts: [],
|
||||
},
|
||||
],
|
||||
]),
|
||||
);
|
||||
const current = createAgentPayload({
|
||||
id: agentId,
|
||||
title: "current",
|
||||
status: "running",
|
||||
updatedAt: "2026-07-12T11:00:00.000Z",
|
||||
lastUsage: { inputTokens: 10, outputTokens: 5 },
|
||||
pendingPermissions: [permission("current-permission")],
|
||||
});
|
||||
applyAgentDirectoryDelta({
|
||||
serverId,
|
||||
delta: { kind: "upsert", agent: current, project: createEntry(current).project },
|
||||
});
|
||||
store.flushAgentLastActivity();
|
||||
setAgentArchiving({ queryClient, serverId, agentId, isArchiving: true });
|
||||
|
||||
const staleResult = applyAgentDirectoryDelta({
|
||||
serverId,
|
||||
delta: {
|
||||
kind: "upsert",
|
||||
agent: {
|
||||
...current,
|
||||
title: "stale",
|
||||
status: "idle",
|
||||
updatedAt: "2026-07-12T10:00:00.000Z",
|
||||
lastUsage: { inputTokens: 20, outputTokens: 8 },
|
||||
pendingPermissions: [permission("stale-permission")],
|
||||
archivedAt: "2026-07-12T10:00:00.000Z",
|
||||
},
|
||||
project: createEntry(current).project,
|
||||
},
|
||||
});
|
||||
store.flushAgentLastActivity();
|
||||
|
||||
const state = useSessionStore.getState();
|
||||
const agent = state.sessions[serverId]?.agents.get(agentId);
|
||||
expect({
|
||||
title: agent?.title,
|
||||
status: agent?.status,
|
||||
usage: agent?.lastUsage,
|
||||
workspaceId: agent?.workspaceId,
|
||||
stoppedRunning: staleResult.stoppedRunning,
|
||||
permissions: Array.from(state.sessions[serverId]?.pendingPermissions.values() ?? []).map(
|
||||
({ request }) => request.id,
|
||||
),
|
||||
archivePending: isAgentArchiving({ queryClient, serverId, agentId }),
|
||||
activity: state.agentLastActivity.get(agentId)?.toISOString(),
|
||||
}).toEqual({
|
||||
title: "current",
|
||||
status: "running",
|
||||
usage: { inputTokens: 20, outputTokens: 8 },
|
||||
workspaceId: "legacy-workspace",
|
||||
stoppedRunning: false,
|
||||
permissions: ["current-permission"],
|
||||
archivePending: true,
|
||||
activity: "2026-07-12T11:00:00.000Z",
|
||||
});
|
||||
|
||||
store.clearSession(serverId);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user