Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(notices): add tests for memory quarantine polling and app notices

Steven Enamakel22cbb87b1679
diff --git a/app/src/components/notices/__tests__/NoticeCenter.test.tsx b/app/src/components/notices/__tests__/NoticeCenter.test.tsx
index fe2bc694f4..e38998e580 100644
--- a/app/src/components/notices/__tests__/NoticeCenter.test.tsx
+++ b/app/src/components/notices/__tests__/NoticeCenter.test.tsx
@@ -27,8 +27,6 @@ vi.mock('../../../hooks/useEmbeddingBudgetState', () => ({
useEmbeddingBudgetState: () => budgetState,
}));
vi.mock('../../../hooks/useUsageState', () => ({ useUsageState: () => usageState }));
-// openhuman#5820: the quarantine poll needs CoreStateProvider; not under test here.
-vi.mock('../useMemoryQuarantinePoll', () => ({ useMemoryQuarantinePoll: () => undefined }));
vi.mock('../../../lib/nativeNotifications/tauriBridge', () => ({ showNativeNotification }));
vi.mock('../../../utils/openUrl', () => ({ openUrl: vi.fn() }));
vi.mock('../../../services/api/openrouterFreeModels', () => ({ applyOpenRouterFreeModels }));
diff --git a/app/src/components/notices/__tests__/useMemoryQuarantinePoll.test.tsx b/app/src/components/notices/__tests__/useMemoryQuarantinePoll.test.tsx
deleted file mode 100644
index f017bc441f..0000000000
--- a/app/src/components/notices/__tests__/useMemoryQuarantinePoll.test.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import { act, renderHook } from '@testing-library/react';
-import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-
-import { MEMORY_QUARANTINE_POLL_MS, useMemoryQuarantinePoll } from '../useMemoryQuarantinePoll';
-
-const mockStatus = vi.fn();
-const mockDispatch = vi.fn();
-let mockAuthenticated = true;
-
-vi.mock('../../../utils/tauriCommands/memoryTree', async importOriginal => {
- const actual = await importOriginal<typeof import('../../../utils/tauriCommands/memoryTree')>();
- return { ...actual, memoryTreePipelineStatus: (...args: unknown[]) => mockStatus(...args) };
-});
-vi.mock('../../../store/hooks', () => ({ useAppDispatch: () => mockDispatch }));
-vi.mock('../../../providers/CoreStateProvider', () => ({
- useCoreState: () => ({ snapshot: { auth: { isAuthenticated: mockAuthenticated } } }),
-}));
-
-function statusWith(quarantine: unknown) {
- return {
- status: 'idle',
- reason: null,
- last_sync_ms: 0,
- total_chunks: 0,
- wiki_size_bytes: 0,
- pipeline_jobs: { ready: 0, running: 0, failed: 0, done: 0 },
- is_syncing: false,
- is_paused: false,
- quarantine,
- };
-}
-
-describe('useMemoryQuarantinePoll', () => {
- beforeEach(() => {
- vi.useFakeTimers();
- mockStatus.mockReset();
- mockDispatch.mockReset();
- mockAuthenticated = true;
- });
- afterEach(() => {
- vi.useRealTimers();
- });
-
- it('reports an outstanding quarantine on mount and again on the interval', async () => {
- mockStatus.mockResolvedValue(
- statusWith({ quarantined_at_ms: 1, quarantined_path: '/x', resynced: false })
- );
- renderHook(() => useMemoryQuarantinePoll());
- await act(async () => {
- await Promise.resolve();
- });
- expect(mockStatus).toHaveBeenCalledTimes(1);
- expect(mockDispatch).toHaveBeenCalledWith(
- expect.objectContaining({
- type: 'userErrors/reportUserError',
- payload: expect.objectContaining({
- descriptor: expect.objectContaining({ kind: 'memory_store_corrupt' }),
- }),
- })
- );
-
- await act(async () => {
- vi.advanceTimersByTime(MEMORY_QUARANTINE_POLL_MS);
- await Promise.resolve();
- });
- expect(mockStatus).toHaveBeenCalledTimes(2);
- });
-
- it('resolves the notice once the store has been re-synced', async () => {
- mockStatus.mockResolvedValue(
- statusWith({ quarantined_at_ms: 1, quarantined_path: '/x', resynced: true })
- );
- renderHook(() => useMemoryQuarantinePoll());
- await act(async () => {
- await Promise.resolve();
- });
- expect(mockDispatch).toHaveBeenCalledWith(
- expect.objectContaining({ type: 'userErrors/resolveUserError' })
- );
- });
-
- it('does nothing while signed out, and swallows a failed status read', async () => {
- mockAuthenticated = false;
- renderHook(() => useMemoryQuarantinePoll());
- await act(async () => {
- await Promise.resolve();
- });
- expect(mockStatus).not.toHaveBeenCalled();
-
- mockAuthenticated = true;
- mockStatus.mockRejectedValue(new Error('core restarting'));
- renderHook(() => useMemoryQuarantinePoll());
- await act(async () => {
- await Promise.resolve();
- });
- expect(mockDispatch).not.toHaveBeenCalled();
- });
-});
diff --git a/app/src/components/notices/useAppNotices.ts b/app/src/components/notices/useAppNotices.ts
index ac08afb221..3d13c784ee 100644
--- a/app/src/components/notices/useAppNotices.ts
+++ b/app/src/components/notices/useAppNotices.ts
@@ -32,7 +32,6 @@ import type { UserActionableError, UserErrorAction } from '../../types/userError
import { PRICING_URL } from '../../utils/links';
import { openUrl } from '../../utils/openUrl';
import { dismissBanner, shouldShowBanner } from '../upsell/upsellDismissState';
-import { useMemoryQuarantinePoll } from './useMemoryQuarantinePoll';
export type NoticeSeverity = 'error' | 'warning' | 'info';
@@ -72,10 +71,9 @@ const ACTION_ROUTE: Record<Exclude<UserErrorAction, 'dismiss'>, string> = {
// Opening this screen also restarts the integration health poll, so it is
// both the explanation and the retry.
open_connections: '/connections?tab=skills',
- // openhuman#5820: after a corrupt-store quarantine the rebuilt tree is
- // empty; the per-source Sync and All In controls that repopulate it live on
- // Brain's Sources tab (the Sync tab only shows status and history).
- open_memory_sync: '/connections?tab=brain&brain=sources',
+ // openhuman#5820: re-syncing memory's sources happens on the Memory page's
+ // Documents chip (per-source Sync and Sync all).
+ open_memory_sync: '/connections?tab=brain&brain=documents',
};
const ACTION_LABEL_KEY: Record<Exclude<UserErrorAction, 'dismiss'>, string> = {
@@ -121,8 +119,6 @@ export function useAppNotices(): AppNotice[] {
const navigate = useNavigate();
const active = useAppSelector(selectActiveUserErrors);
const { level: budgetLevel, pct: budgetPct } = useEmbeddingBudgetState();
- // openhuman#5820: durable, app-wide replay of a corrupt-store quarantine.
- useMemoryQuarantinePoll();
const {
teamUsage,
isLoading: usageLoading,
diff --git a/app/src/components/notices/useMemoryQuarantinePoll.ts b/app/src/components/notices/useMemoryQuarantinePoll.ts
deleted file mode 100644
index b43dd3b832..0000000000
--- a/app/src/components/notices/useMemoryQuarantinePoll.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import { useEffect } from 'react';
-
-import { reportMemoryQuarantine } from '../../lib/userErrors/report';
-import { useCoreState } from '../../providers/CoreStateProvider';
-import { useAppDispatch } from '../../store/hooks';
-import { memoryTreePipelineStatus } from '../../utils/tauriCommands/memoryTree';
-
-/**
- * How often the shell asks the core whether a corrupt-store quarantine is
- * outstanding. The condition changes on the order of a sync, not a keystroke,
- * and the status call is a handful of counters plus a directory walk.
- */
-export const MEMORY_QUARANTINE_POLL_MS = 60_000;
-
-/**
- * App-wide replay of the corrupt-store notice (openhuman#5820).
- *
- * The live `memory_store_corrupt` socket broadcast reaches only a renderer
- * that is connected when the quarantine happens; a boot-time integrity check
- * fires before that socket exists, and the broadcast has no replay. The
- * core derives the quarantine from disk in `memory_tree_pipeline_status`, so
- * polling it from the shell — not just from the Brain panel — puts the notice
- * in front of a user who never opens Brain, and retires it once they have
- * re-synced. Same descriptor id as the socket path, so the two never stack.
- */
-export function useMemoryQuarantinePoll(): void {
- const dispatch = useAppDispatch();
- const { snapshot } = useCoreState();
- const isAuthenticated = snapshot.auth.isAuthenticated;
-
- useEffect(() => {
- if (!isAuthenticated) return;
- let cancelled = false;
- // A slow response must not overwrite a newer one: a delayed
- // `resynced: false` landing after a fresh `resynced: true` would re-open
- // a notice the user has already earned the retirement of.
- let latestRequest = 0;
- const tick = async () => {
- const request = ++latestRequest;
- try {
- const status = await memoryTreePipelineStatus();
- if (!cancelled && request === latestRequest) {
- reportMemoryQuarantine(dispatch, status.quarantine);
- }
- } catch (err) {
- // Signed out mid-poll, core restarting: nothing to report, try again
- // next tick.
- console.debug('[memory-quarantine-poll] status read failed: %o', err);
- }
- };
- void tick();
- const id = window.setInterval(() => void tick(), MEMORY_QUARANTINE_POLL_MS);
- return () => {
- cancelled = true;
- window.clearInterval(id);
- };
- }, [dispatch, isAuthenticated]);
-}
diff --git a/app/src/components/settings/panels/useReembedBackfillModal.test.tsx b/app/src/components/settings/panels/useReembedBackfillModal.test.tsx
index 885985fbea..fd59574e68 100644
--- a/app/src/components/settings/panels/useReembedBackfillModal.test.tsx
+++ b/app/src/components/settings/panels/useReembedBackfillModal.test.tsx
@@ -1,12 +1,12 @@
import { act, renderHook } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
-import { memoryTreeBackfillStatus } from '../../../utils/tauriCommands/memoryTree';
+import { callCoreRpc } from '../../../services/coreRpcClient';
import { useReembedBackfillModal } from './useReembedBackfillModal';
-vi.mock('../../../utils/tauriCommands/memoryTree', () => ({ memoryTreeBackfillStatus: vi.fn() }));
+vi.mock('../../../services/coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
-const status = vi.mocked(memoryTreeBackfillStatus);
+const status = vi.mocked(callCoreRpc);
beforeEach(() => {
vi.clearAllMocks();
diff --git a/vendor/tinymemory b/vendor/tinymemory
index 489fb1ba1a..2b7ec0af4b 160000
--- a/vendor/tinymemory
+++ b/vendor/tinymemory
@@ -1 +1 @@
-Subproject commit 489fb1ba1af9006adf2b3f609157f3a2240a2bfc
+Subproject commit 2b7ec0af4bfeaaa90fbe26d3c27cc4c5e64e689b