Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(realtime): invalidate chat/labels/invitations queries on WS reconnect (#3570)

xiaoyue2627945727af3c
diff --git a/packages/core/api/ws-client.test.ts b/packages/core/api/ws-client.test.ts
index 2acd70b19d..80f5d39e8a 100644
--- a/packages/core/api/ws-client.test.ts
+++ b/packages/core/api/ws-client.test.ts
@@ -127,4 +127,29 @@ describe("WSClient", () => {
undefined,
);
});
+
+ it("passes actor_id and actor_type to event handlers", () => {
+ const ws = new WSClient("ws://example.test/ws");
+ ws.setAuth("tok", "acme");
+ ws.connect();
+
+ const handler = vi.fn();
+ ws.on("issue:created", handler);
+
+ const fakeWs = (ws as any).ws as FakeWebSocket;
+ fakeWs.onmessage?.({
+ data: JSON.stringify({
+ type: "issue:created",
+ payload: { id: "issue-1" },
+ actor_id: "user-123",
+ actor_type: "user",
+ }),
+ });
+
+ expect(handler).toHaveBeenCalledWith(
+ { id: "issue-1" },
+ "user-123",
+ "user",
+ );
+ });
});
diff --git a/packages/core/platform/auth-initializer.tsx b/packages/core/platform/auth-initializer.tsx
index c085178796..81ef875439 100644
--- a/packages/core/platform/auth-initializer.tsx
+++ b/packages/core/platform/auth-initializer.tsx
@@ -130,6 +130,7 @@ export function AuthInitializer({
storage.removeItem("multica_token");
onAuthFailure();
});
+ // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return <>{children}</>;
diff --git a/packages/core/realtime/use-realtime-sync-ws-instance.test.tsx b/packages/core/realtime/use-realtime-sync-ws-instance.test.tsx
index 58ae33d647..9a349d6b1b 100644
--- a/packages/core/realtime/use-realtime-sync-ws-instance.test.tsx
+++ b/packages/core/realtime/use-realtime-sync-ws-instance.test.tsx
@@ -102,8 +102,8 @@ describe("useRealtimeSync — ws instance change", () => {
rerender({ ws: ws2 });
// Should have called invalidateQueries for all workspace-scoped keys
- // (12 workspace-scoped + 1 workspaceKeys.list() = 13 calls)
- expect(invalidateSpy).toHaveBeenCalledTimes(13);
+ // (15 workspace-scoped + 1 workspaceKeys.list() = 16 calls)
+ expect(invalidateSpy).toHaveBeenCalledTimes(16);
});
it("does not re-invalidate when rerendered with the same ws instance", () => {
@@ -119,4 +119,23 @@ describe("useRealtimeSync — ws instance change", () => {
expect(invalidateSpy).not.toHaveBeenCalled();
});
+
+ it("invalidates chat, pins, labels, and invitations queries on ws instance change", () => {
+ const ws1 = createMockWs();
+ const { rerender } = renderHook(
+ ({ ws }) => useRealtimeSync(ws, stores),
+ { initialProps: { ws: ws1 as WSClient | null }, wrapper: createWrapper(qc) },
+ );
+
+ invalidateSpy.mockClear();
+ rerender({ ws: null });
+
+ const ws2 = createMockWs();
+ rerender({ ws: ws2 });
+
+ const calls = invalidateSpy.mock.calls.map((call: [{ queryKey?: unknown }, ...unknown[]]) => call[0].queryKey);
+ expect(calls).toContainEqual(["chat", "ws-1"]);
+ expect(calls).toContainEqual(["labels", "ws-1"]);
+ expect(calls).toContainEqual(["workspaces", "ws-1", "invitations"]);
+ });
});
diff --git a/packages/core/realtime/use-realtime-sync.ts b/packages/core/realtime/use-realtime-sync.ts
index fb49d1ef5e..2d31176b0f 100644
--- a/packages/core/realtime/use-realtime-sync.ts
+++ b/packages/core/realtime/use-realtime-sync.ts
@@ -14,6 +14,7 @@ import { projectKeys } from "../projects/queries";
import { pinKeys } from "../pins/queries";
import { autopilotKeys } from "../autopilots/queries";
import { runtimeKeys } from "../runtimes/queries";
+import { labelKeys } from "../labels/queries";
import {
agentTaskSnapshotKeys,
agentActivityKeys,
@@ -157,12 +158,15 @@ function invalidateWorkspaceScopedQueries(qc: QueryClient): void {
qc.invalidateQueries({ queryKey: workspaceKeys.members(wsId) });
qc.invalidateQueries({ queryKey: workspaceKeys.squads(wsId) });
qc.invalidateQueries({ queryKey: workspaceKeys.skills(wsId) });
+ qc.invalidateQueries({ queryKey: workspaceKeys.invitations(wsId) });
qc.invalidateQueries({ queryKey: projectKeys.all(wsId) });
qc.invalidateQueries({ queryKey: runtimeKeys.all(wsId) });
qc.invalidateQueries({ queryKey: autopilotKeys.all(wsId) });
qc.invalidateQueries({ queryKey: agentTaskSnapshotKeys.all(wsId) });
qc.invalidateQueries({ queryKey: agentActivityKeys.all(wsId) });
qc.invalidateQueries({ queryKey: agentRunCountsKeys.all(wsId) });
+ qc.invalidateQueries({ queryKey: chatKeys.all(wsId) });
+ qc.invalidateQueries({ queryKey: labelKeys.all(wsId) });
}
qc.invalidateQueries({ queryKey: workspaceKeys.list() });
}