Skip to content

The open-source app everyone uses to manage agents at work

Merge public-gh/master into pap-979-runtime-workspaces

dotta4d61dbfd3438
diff --cc ui/src/context/LiveUpdatesProvider.test.ts
index c24faf7091,0bbbaabcec..8aaa7581db
--- a/ui/src/context/LiveUpdatesProvider.test.ts
+++ b/ui/src/context/LiveUpdatesProvider.test.ts
@@@ -118,76 -118,54 +118,128 @@@ describe("LiveUpdatesProvider visible i
});
});
+describe("LiveUpdatesProvider run lifecycle toasts", () => {
+ it("does not build start or success toasts for agent runs", () => {
+ const queryClient = {
+ getQueryData: () => [],
+ };
+
+ expect(
+ __liveUpdatesTestUtils.buildAgentStatusToast(
+ {
+ agentId: "agent-1",
+ status: "running",
+ },
+ () => "CodexCoder",
+ queryClient as never,
+ "company-1",
+ ),
+ ).toBeNull();
+
+ expect(
+ __liveUpdatesTestUtils.buildRunStatusToast(
+ {
+ runId: "run-1",
+ agentId: "agent-1",
+ status: "succeeded",
+ },
+ () => "CodexCoder",
+ ),
+ ).toBeNull();
+ });
+
+ it("still builds failure toasts for agent errors and failed runs", () => {
+ const queryClient = {
+ getQueryData: () => [
+ {
+ id: "agent-1",
+ title: "Software Engineer",
+ },
+ ],
+ };
+
+ expect(
+ __liveUpdatesTestUtils.buildAgentStatusToast(
+ {
+ agentId: "agent-1",
+ status: "error",
+ },
+ () => "CodexCoder",
+ queryClient as never,
+ "company-1",
+ ),
+ ).toMatchObject({
+ title: "CodexCoder errored",
+ body: "Software Engineer",
+ tone: "error",
+ });
+
+ expect(
+ __liveUpdatesTestUtils.buildRunStatusToast(
+ {
+ runId: "run-1",
+ agentId: "agent-1",
+ status: "failed",
+ error: "boom",
+ },
+ () => "CodexCoder",
+ ),
+ ).toMatchObject({
+ title: "CodexCoder run failed",
+ body: "boom",
+ tone: "error",
+ });
+ });
+});
++
+ describe("LiveUpdatesProvider socket helpers", () => {
+ it("waits for the selected company object to catch up before connecting", () => {
+ expect(__liveUpdatesTestUtils.resolveLiveCompanyId("company-1", null)).toBeNull();
+ expect(__liveUpdatesTestUtils.resolveLiveCompanyId("company-1", "company-2")).toBeNull();
+ expect(__liveUpdatesTestUtils.resolveLiveCompanyId("company-1", "company-1")).toBe("company-1");
+ });
+
+ it("defers close until onopen for sockets that are still connecting", () => {
+ const socket = {
+ readyState: 0,
+ onopen: (() => undefined) as (() => void) | null,
+ onmessage: (() => undefined) as (() => void) | null,
+ onerror: (() => undefined) as (() => void) | null,
+ onclose: (() => undefined) as (() => void) | null,
+ close: vi.fn(),
+ };
+
+ __liveUpdatesTestUtils.closeSocketQuietly(socket as never, "provider_unmount");
+
+ expect(socket.close).not.toHaveBeenCalled();
+ expect(socket.onmessage).toBeNull();
+ expect(socket.onclose).toBeNull();
+ expect(socket.onopen).toBeTypeOf("function");
+ expect(socket.onerror).toBeTypeOf("function");
+
+ socket.onopen?.();
+
+ expect(socket.close).toHaveBeenCalledWith(1000, "provider_unmount");
+ expect(socket.onopen).toBeNull();
+ expect(socket.onerror).toBeNull();
+ });
+
+ it("closes open sockets immediately without leaving handlers behind", () => {
+ const socket = {
+ readyState: 1,
+ onopen: (() => undefined) as (() => void) | null,
+ onmessage: (() => undefined) as (() => void) | null,
+ onerror: (() => undefined) as (() => void) | null,
+ onclose: (() => undefined) as (() => void) | null,
+ close: vi.fn(),
+ };
+
+ __liveUpdatesTestUtils.closeSocketQuietly(socket as never, "stale_connection");
+
+ expect(socket.close).toHaveBeenCalledWith(1000, "stale_connection");
+ expect(socket.onopen).toBeNull();
+ expect(socket.onmessage).toBeNull();
+ expect(socket.onerror).toBeNull();
+ expect(socket.onclose).toBeNull();
+ });
+ });
diff --cc ui/src/context/LiveUpdatesProvider.tsx
index 20132721f2,b4f8338832..71e6fbc888
--- a/ui/src/context/LiveUpdatesProvider.tsx
+++ b/ui/src/context/LiveUpdatesProvider.tsx
@@@ -652,10 -663,49 +663,51 @@@ function handleLiveEvent
}
}
+ function resolveLiveCompanyId(
+ selectedCompanyId: string | null,
+ selectedCompanyLiveId: string | null,
+ ): string | null {
+ return selectedCompanyId && selectedCompanyId === selectedCompanyLiveId
+ ? selectedCompanyId
+ : null;
+ }
+
+ function resetSocketHandlers(target: LiveUpdatesSocketLike) {
+ target.onopen = null;
+ target.onmessage = null;
+ target.onerror = null;
+ target.onclose = null;
+ }
+
+ function closeSocketQuietly(target: LiveUpdatesSocketLike | null, reason: string) {
+ if (!target) return;
+
+ if (target.readyState === SOCKET_CONNECTING) {
+ // Let the handshake complete and then close. Calling close() while the
+ // socket is still CONNECTING is what triggers the noisy browser error.
+ target.onopen = () => {
+ resetSocketHandlers(target);
+ target.close(1000, reason);
+ };
+ target.onmessage = null;
+ target.onerror = () => undefined;
+ target.onclose = null;
+ return;
+ }
+
+ resetSocketHandlers(target);
+
+ if (target.readyState === SOCKET_OPEN) {
+ target.close(1000, reason);
+ }
+ }
+
export const __liveUpdatesTestUtils = {
+ buildAgentStatusToast,
+ buildRunStatusToast,
+ closeSocketQuietly,
invalidateActivityQueries,
+ resolveLiveCompanyId,
shouldSuppressActivityToastForVisibleIssue,
shouldSuppressRunStatusToastForVisibleIssue,
shouldSuppressAgentStatusToastForVisibleIssue,