mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(server): keep slow direct connections alive during large transfers (#10651)
A direct client sees activity only after a complete WebSocket message arrives. Send large responses in existing transport chunks so the client sees progress while it waits for the full response. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Ouyang Xingyuan <galaxyroaming@qq.com>
This commit is contained in:
co-authored by
Ouyang Xingyuan
parent
0a856ab7fc
commit
cfcf0dc7d1
@@ -2,6 +2,8 @@ import { describe, test, expect, beforeEach, afterEach } from "vitest";
|
||||
import { mkdtempSync, rmSync } from "fs";
|
||||
import { tmpdir } from "os";
|
||||
import path from "path";
|
||||
import { WebSocket } from "ws";
|
||||
import { DaemonClient } from "@getpaseo/client/internal/daemon-client";
|
||||
import { createDaemonTestContext, type DaemonTestContext } from "../test-utils/index.js";
|
||||
|
||||
let ctx: DaemonTestContext;
|
||||
@@ -56,3 +58,49 @@ describe("a message larger than the daemon accepts", () => {
|
||||
expect(statuses).toEqual(["connected"]);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
test("a direct client receives progress before its large timeline page completes", async () => {
|
||||
const agent = await ctx.client.createAgent({ provider: "claude", cwd, title: "Large timeline" });
|
||||
const text = "Timeline entry ".repeat(8 * 1024);
|
||||
for (let row = 0; row < 8; row++) {
|
||||
await ctx.daemon.daemon.agentManager.appendTimelineItem(agent.id, {
|
||||
type: "user_message",
|
||||
text,
|
||||
});
|
||||
}
|
||||
|
||||
const receivedMessageSizes: number[] = [];
|
||||
const client = new DaemonClient({
|
||||
url: `ws://127.0.0.1:${ctx.daemon.port}/ws`,
|
||||
clientId: "timeline-wire-progress",
|
||||
clientType: "browser",
|
||||
webSocketFactory: (url) => {
|
||||
const ws = new WebSocket(url);
|
||||
ws.addEventListener("message", (event) => {
|
||||
receivedMessageSizes.push(
|
||||
typeof event.data === "string" ? Buffer.byteLength(event.data) : event.data.byteLength,
|
||||
);
|
||||
});
|
||||
return ws;
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await client.connect();
|
||||
receivedMessageSizes.length = 0;
|
||||
const timeline = await client.fetchAgentTimeline(agent.id, {
|
||||
direction: "tail",
|
||||
limit: 40,
|
||||
wholeTurns: true,
|
||||
});
|
||||
expect(timeline.entries).toHaveLength(8);
|
||||
for (const { item } of timeline.entries) {
|
||||
expect(item.type === "user_message" && item.text === text).toBe(true);
|
||||
}
|
||||
// The client can only observe liveness when a whole WebSocket message arrives.
|
||||
// A single message carrying the entire page hides progress on slow links.
|
||||
expect(Math.max(...receivedMessageSizes)).toBeLessThanOrEqual(512 * 1024);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -150,6 +150,8 @@ import {
|
||||
} from "./websocket/physical-socket.js";
|
||||
|
||||
const WS_CLOSE_DAEMON_AUTH_FAILED = 4401;
|
||||
// Give clients intermediate messages that count as progress during large transfers.
|
||||
const DIRECT_WEBSOCKET_FRAME_BYTES = 512 * 1024;
|
||||
|
||||
export interface ExternalSocketMetadata {
|
||||
transport: "relay" | "hub";
|
||||
@@ -951,7 +953,8 @@ export class VoiceAssistantWebSocketServer {
|
||||
},
|
||||
});
|
||||
wss.on("connection", (ws, request) => {
|
||||
void this.attachAuthenticatedSocket(ws, request, password);
|
||||
const socket = Object.assign(ws, { maxFrameBytes: DIRECT_WEBSOCKET_FRAME_BYTES });
|
||||
void this.attachAuthenticatedSocket(socket, request, password);
|
||||
});
|
||||
return wss;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user