fix(server): bound stale websocket connections

Track application ownership per physical socket and terminate abandoned or backpressured transports without disrupting replacement connections.
This commit is contained in:
Mohamed Boudra
2026-07-17 19:39:45 +00:00
parent a1de743ef6
commit 5feaa01dc2
13 changed files with 735 additions and 75 deletions
@@ -21,6 +21,7 @@ export const CLIENT_CAPS = {
// COMPAT(projectUpdates): added in v0.1.109, remove gate after 2027-01-15.
projectUpdates: "project_updates",
browserHost: "browser_host",
applicationSocketLease: "application_socket_lease",
} as const;
export type ClientCapability = (typeof CLIENT_CAPS)[keyof typeof CLIENT_CAPS];
@@ -0,0 +1,25 @@
import { expect, test } from "vitest";
import { CLIENT_CAPS } from "./client-capabilities.js";
import { WSHelloMessageSchema } from "./messages.js";
const legacyHello = {
type: "hello" as const,
clientId: "client-1",
clientType: "browser" as const,
protocolVersion: 1,
};
test("hello accepts the application socket lease capability", () => {
const hello = WSHelloMessageSchema.parse({
...legacyHello,
capabilities: { [CLIENT_CAPS.applicationSocketLease]: true },
});
expect(hello.capabilities?.[CLIENT_CAPS.applicationSocketLease]).toBe(true);
});
test("hello remains compatible when the application socket lease capability is absent", () => {
const hello = WSHelloMessageSchema.parse(legacyHello);
expect(hello.capabilities).toBeUndefined();
});
+1
View File
@@ -5565,6 +5565,7 @@ export const WSHelloMessageSchema = z.object({
[CLIENT_CAPS.providerSubagents]: z.boolean().optional(),
[CLIENT_CAPS.projectUpdates]: z.boolean().optional(),
[CLIENT_CAPS.browserHost]: BrowserAutomationHostCapabilitySchema.optional(),
[CLIENT_CAPS.applicationSocketLease]: z.boolean().optional(),
})
.passthrough()
.optional(),