Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(soup): show newly imported calls in Soup lists without a reload (#8701)

Eric Hayesba85ba5cd434
diff --git a/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.test.ts b/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.test.ts
new file mode 100644
index 0000000000..3ea270aae9
--- /dev/null
+++ b/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.test.ts
@@ -0,0 +1,96 @@
+import type { SoupUpdatesSubscription } from '@service-storage/graphql/generated/graphql';
+import { describe, expect, it, onTestFinished, vi } from 'vitest';
+import { registerActiveGraphqlSoupQuery } from './active-queries';
+import {
+ listCanIncludeCalls,
+ revalidateCallListsForSoupUpdates,
+} from './call-list-revalidation';
+
+const NIL_UUID = '00000000-0000-0000-0000-000000000000';
+
+type SoupPatch = SoupUpdatesSubscription['soupUpdates'][number];
+
+function updated(typename: string): SoupPatch {
+ return {
+ __typename: 'SoupUpdated',
+ item: { __typename: typename, id: crypto.randomUUID() },
+ } as unknown as SoupPatch;
+}
+
+function registerList(body: unknown) {
+ const refresh = vi.fn(async () => {});
+ onTestFinished(
+ registerActiveGraphqlSoupQuery({
+ isEnabled: () => true,
+ refresh,
+ body: () => body,
+ })
+ );
+ return refresh;
+}
+
+describe('listCanIncludeCalls', () => {
+ it('includes lists that leave calls unfiltered or filter them by status', () => {
+ expect(listCanIncludeCalls({ df: { l: { id: NIL_UUID } } })).toBe(true);
+ expect(listCanIncludeCalls({ callf: { l: { Status: 'MISSED' } } })).toBe(
+ true
+ );
+ });
+
+ it('excludes lists whose call filter provably selects nothing', () => {
+ expect(listCanIncludeCalls({ callf: { l: { CallId: NIL_UUID } } })).toBe(
+ false
+ );
+ expect(
+ listCanIncludeCalls({
+ callf: {
+ '&': [{ l: { Status: 'MISSED' } }, { l: { CallId: NIL_UUID } }],
+ },
+ })
+ ).toBe(false);
+ });
+
+ it('keeps negated or OR-ed exclusions refreshable', () => {
+ expect(
+ listCanIncludeCalls({ callf: { '!': { l: { CallId: NIL_UUID } } } })
+ ).toBe(true);
+ expect(
+ listCanIncludeCalls({
+ callf: {
+ '|': [{ l: { CallId: NIL_UUID } }, { l: { Status: 'MISSED' } }],
+ },
+ })
+ ).toBe(true);
+ });
+
+ it('skips readers without a list filter body', () => {
+ expect(listCanIncludeCalls(undefined)).toBe(false);
+ });
+});
+
+describe('revalidateCallListsForSoupUpdates', () => {
+ it('refreshes only mounted lists that can contain a newly updated call', async () => {
+ const callsList = registerList({ df: { l: { id: NIL_UUID } } });
+ const documentsList = registerList({ callf: { l: { CallId: NIL_UUID } } });
+
+ await revalidateCallListsForSoupUpdates([updated('GraphqlSoupCall')]);
+
+ expect(callsList).toHaveBeenCalledTimes(1);
+ expect(documentsList).not.toHaveBeenCalled();
+ });
+
+ it('ignores patches that carry no call update', async () => {
+ const callsList = registerList({});
+
+ await revalidateCallListsForSoupUpdates([
+ updated('GraphqlSoupDocument'),
+ {
+ __typename: 'GraphqlCacheDeletion',
+ graphqlTypeName: 'GraphqlSoupCall',
+ entityId: crypto.randomUUID(),
+ },
+ ]);
+
+ expect(callsList).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.ts b/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.ts
new file mode 100644
index 0000000000..046ef81d22
--- /dev/null
+++ b/apps/web/src/lib/queries/soup/graphql/call-list-revalidation.ts
@@ -0,0 +1,45 @@
+import type { SoupUpdatesSubscription } from '@service-storage/graphql/generated/graphql';
+import { refreshActiveGraphqlSoupQueries } from './active-queries';
+
+const NIL_UUID = '00000000-0000-0000-0000-000000000000';
+
+type SoupPatch = SoupUpdatesSubscription['soupUpdates'][number];
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return typeof value === 'object' && value !== null;
+}
+
+/** Mirrors `item_filter_index`: only a positive nil `CallId`, possibly AND-ed
+ * with anything, proves a call filter selects nothing. */
+function excludesCalls(ast: unknown): boolean {
+ if (!isRecord(ast)) return false;
+ const and = ast['&'];
+ if (Array.isArray(and)) return and.some(excludesCalls);
+ const literal = ast.l;
+ return isRecord(literal) && literal.CallId === NIL_UUID;
+}
+
+/** Whether a Soup list's REST-shaped filter body can contain calls. */
+export function listCanIncludeCalls(body: unknown): boolean {
+ return isRecord(body) && !excludesCalls(body.callf);
+}
+
+function updatesCall(patch: SoupPatch): boolean {
+ return (
+ patch.__typename === 'SoupUpdated' &&
+ patch.item.__typename === 'GraphqlSoupCall'
+ );
+}
+
+/**
+ * Calls have no local Soup projection, so the normalized cache stores a call
+ * from `soupUpdates` but cannot place an unseen one in any list. Mounted lists
+ * that can contain calls refetch instead; the only call patches today come
+ * from imports, so this stays rare.
+ */
+export async function revalidateCallListsForSoupUpdates(
+ patches: readonly SoupPatch[]
+): Promise<void> {
+ if (!patches.some(updatesCall)) return;
+ await refreshActiveGraphqlSoupQueries({ where: listCanIncludeCalls });
+}
diff --git a/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.test.ts b/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.test.ts
index 3ee56c36bb..806a41e1dd 100644
--- a/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.test.ts
+++ b/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.test.ts
@@ -34,6 +34,7 @@ afterEach(() => {
setVisibility('visible');
});
+import { registerActiveGraphqlSoupQuery } from '../../queries/soup/graphql/active-queries';
import {
ActivityUpdatesDocument,
NotificationUpdatesDocument,
@@ -229,6 +230,45 @@ describe('GraphQL Soup subscription lifecycle', () => {
for (const unsubscribe of unsubscribes)
expect(unsubscribe).toHaveBeenCalledOnce();
});
+ it('refetches mounted call lists when a Soup update carries a call', async () => {
+ const receive = new Map<unknown, (result: { data?: unknown }) => void>();
+ const client = {
+ query: vi.fn(),
+ subscription: vi.fn((document) => ({
+ subscribe: (next: (result: { data?: unknown }) => void) => {
+ receive.set(document, next);
+ return { unsubscribe: vi.fn() };
+ },
+ })),
+ };
+ const refresh = vi.fn(async () => {});
+ const unregister = registerActiveGraphqlSoupQuery({
+ isEnabled: () => true,
+ refresh,
+ body: () => ({}),
+ });
+ const lifecycle = createGraphqlSoupSubscriptionsLifecycle();
+ lifecycle.replace(
+ client as never,
+ { disabled: false, onCacheGenerationChanged: () => () => {} } as never
+ );
+
+ receive.get(SoupUpdatesDocument)?.({
+ data: {
+ soupUpdates: [
+ {
+ __typename: 'SoupUpdated',
+ item: { __typename: 'GraphqlSoupCall', id: 'imported-call' },
+ },
+ ],
+ },
+ });
+ await vi.waitFor(() => expect(refresh).toHaveBeenCalledOnce());
+
+ lifecycle.dispose();
+ unregister();
+ });
+
it('pauses subscriptions for navigation and reconnects in place exactly once per restore', () => {
const unsubscribes: Array<ReturnType<typeof vi.fn>> = [];
const client = {
diff --git a/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.ts b/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.ts
index fcd0dfd828..105a02e2b5 100644
--- a/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.ts
+++ b/apps/web/src/lib/service-clients/service-storage/graphql-soup-websocket.ts
@@ -9,12 +9,14 @@ import {
channelNotificationRefresh,
disposeChannelNotificationRefresh,
} from '../../queries/channel/notification-refresh';
+import { revalidateCallListsForSoupUpdates } from '../../queries/soup/graphql/call-list-revalidation';
import {
ActivityUpdatesDocument,
type ActivityUpdatesSubscription,
NotificationUpdatesDocument,
type NotificationUpdatesSubscription,
SoupUpdatesDocument,
+ type SoupUpdatesSubscription,
} from './graphql/generated/graphql';
import { createActivityUpdatesHandler } from './graphql-activity-updates';
import { createChannelListUpdatesHandler } from './graphql-channel-list-updates';
@@ -288,6 +290,14 @@ export function createGraphqlSoupSubscriptionsLifecycle(
result as OperationResult<ActivityUpdatesSubscription>
);
}
+ if (document === SoupUpdatesDocument && result.data != null) {
+ fireAndForget(
+ revalidateCallListsForSoupUpdates(
+ (result.data as SoupUpdatesSubscription).soupUpdates
+ ),
+ 'graphql-soup-subscriptions'
+ );
+ }
if (
document === NotificationUpdatesDocument &&
result.data != null
diff --git a/crates/soup_realtime/AGENTS.md b/crates/soup_realtime/AGENTS.md
index 50f7fbb4af..d320558bbd 100644
--- a/crates/soup_realtime/AGENTS.md
+++ b/crates/soup_realtime/AGENTS.md
@@ -56,7 +56,9 @@ tasks itself.
don't identify every affected entity.
- Channel threads use their containing channel as the access source.
- Only `call.record_imported` patches calls; native call lifecycle events on
- `macro.calls` are ignored.
+ `macro.calls` are ignored. The web cache has no local call projection, so a
+ call patch makes mounted lists that can contain calls refetch
+ (`apps/web/src/lib/queries/soup/graphql/call-list-revalidation.ts`).
## Related