The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(conversations): correct background activity hook to handle empty state
Steven Enamakel374bac4bd07c
diff --git a/app/src/features/conversations/hooks/useBackgroundActivity.test.ts b/app/src/features/conversations/hooks/useBackgroundActivity.test.tsindex 7a3dba6386..a1c165bd44 100644--- a/app/src/features/conversations/hooks/useBackgroundActivity.test.ts+++ b/app/src/features/conversations/hooks/useBackgroundActivity.test.ts@@ -1,20 +1,17 @@import { act, renderHook, waitFor } from '@testing-library/react';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';-import { callCoreRpc } from '../../../services/coreRpcClient';+import { memorySourcesList } from '../../../services/api/memoryApi';import { isTauri } from '../../../utils/tauriCommands/common';import { openhumanCronList } from '../../../utils/tauriCommands/cron';-import { memorySyncStatusList } from '../../../utils/tauriCommands/memoryTree';import { useBackgroundActivity, useMemorySyncActive } from './useBackgroundActivity';vi.mock('../../../utils/tauriCommands/common', () => ({ isTauri: vi.fn(() => true) }));vi.mock('../../../utils/tauriCommands/cron', () => ({ openhumanCronList: vi.fn() }));-vi.mock('../../../utils/tauriCommands/memoryTree', () => ({ memorySyncStatusList: vi.fn() }));-vi.mock('../../../services/coreRpcClient', () => ({ callCoreRpc: vi.fn() }));+vi.mock('../../../services/api/memoryApi', () => ({ memorySourcesList: vi.fn() }));const mockCron = vi.mocked(openhumanCronList);-const mockSyncList = vi.mocked(memorySyncStatusList);-const mockRpc = vi.mocked(callCoreRpc);+const mockSources = vi.mocked(memorySourcesList);const mockIsTauri = vi.mocked(isTauri);function fixtures() {@@ -36,18 +33,19 @@ function fixtures() {],logs: [],});- mockRpc.mockResolvedValue({ running: true, current_title: 'Inbox', queue_depth: 1 });- mockSyncList.mockResolvedValue([- {- provider: 'slack',- chunks_synced: 5,- chunks_pending: 0,- batch_total: 0,- batch_processed: 0,- last_chunk_at_ms: null,- freshness: 'active',- },- ]);+ mockSources.mockResolvedValue({+ sources: [+ {+ id: 's1',+ kind: 'folder',+ target: '/notes',+ label: 'Inbox',+ status: 'syncing',+ items: 3,+ },+ { id: 's2', kind: 'rss', target: 'https://example.com/feed', label: '', status: 'idle', items: 0 },+ ],+ });}describe('useBackgroundActivity', () => {@@ -71,7 +69,22 @@ describe('useBackgroundActivity', () => {currentTitle: 'Inbox',queueDepth: 1,});- expect(result.current.memory.providers).toHaveLength(1);+ expect(result.current.memory.providers).toEqual([+ { provider: 'Inbox', freshness: 'active' },+ { provider: 'https://example.com/feed', freshness: 'idle' },+ ]);+ });++ it('shows no memory activity when memory is off', async () => {+ mockSources.mockRejectedValue(new Error('MEMORY_OFF'));+ const { result } = renderHook(() => useBackgroundActivity(true));+ await waitFor(() => expect(result.current.cronJobs).toHaveLength(1));+ expect(result.current.memory).toEqual({+ ingesting: false,+ currentTitle: undefined,+ queueDepth: 0,+ providers: [],+ });});it('polls core RPC outside Tauri too (browser attached to a core)', async () => {diff --git a/app/src/features/conversations/hooks/useBackgroundActivity.ts b/app/src/features/conversations/hooks/useBackgroundActivity.tsindex 05699f0717..924ea5101e 100644--- a/app/src/features/conversations/hooks/useBackgroundActivity.ts+++ b/app/src/features/conversations/hooks/useBackgroundActivity.ts@@ -1,11 +1,7 @@import { useCallback, useEffect, useRef, useState } from 'react';-import { callCoreRpc } from '../../../services/coreRpcClient';+import { memorySourcesList, type Source } from '../../../services/api/memoryApi';import { type CoreCronJob, openhumanCronList } from '../../../utils/tauriCommands/cron';-import {- memorySyncStatusList,- type MemorySyncStatusRow,-} from '../../../utils/tauriCommands/memoryTree';/*** Aggregated, view-only snapshot of the background work the app runs on the@@ -17,13 +13,21 @@ import {* never poll in the background to keep this off the hot path.*/-/** Memory worker + per-provider freshness rows. */+/** One synced memory source, reduced to what the activity card shows. */+export interface MemorySyncRow {+ provider: string;+ /** `active` while the source is syncing. */+ freshness: 'active' | 'idle';+}++/** Memory sources (Memory v2 Documents registry) and whether any is syncing. */export interface MemorySyncSummary {- /** True while the ingestion worker is processing a document. */+ /** True while at least one source is syncing. */ingesting: boolean;currentTitle?: string;+ /** How many sources are syncing right now. */queueDepth: number;- providers: MemorySyncStatusRow[];+ providers: MemorySyncRow[];}interface BackgroundActivity {@@ -32,12 +36,6 @@ interface BackgroundActivity {loading: boolean;}-interface IngestionStatusEnvelope {- running: boolean;- current_title?: string;- queue_depth: number;-}-const EMPTY_MEMORY: MemorySyncSummary = { ingesting: false, queueDepth: 0, providers: [] };const DEFAULT_POLL_MS = 5000;@@ -67,10 +65,9 @@ export function useBackgroundActivity(open: boolean): BackgroundActivity {const busyRef = useRef(false);const fetchOnce = useCallback(async () => {- const [cronRes, ingestRes, providerRes] = await Promise.allSettled([+ const [cronRes, sourcesRes] = await Promise.allSettled([openhumanCronList(),- callCoreRpc<IngestionStatusEnvelope>({ method: 'openhuman.memory_ingestion_status' }),- memorySyncStatusList(),+ memorySourcesList(),]);if (cancelledRef.current) return;@@ -80,26 +77,26 @@ export function useBackgroundActivity(open: boolean): BackgroundActivity {console.debug('[background-activity] cron_list failed: %o', cronRes.reason);}- const ingest = ingestRes.status === 'fulfilled' ? ingestRes.value : null;- const providers = providerRes.status === 'fulfilled' ? providerRes.value : [];- if (ingestRes.status === 'rejected') {- console.debug('[background-activity] ingestion_status failed: %o', ingestRes.reason);+ // Memory off (or no sources) answers with an error / empty list; either+ // way there is no memory activity to show.+ const sources: Source[] =+ sourcesRes.status === 'fulfilled' ? (sourcesRes.value.sources ?? []) : [];+ if (sourcesRes.status === 'rejected') {+ console.debug('[background-activity] memory_sources_list failed: %o', sourcesRes.reason);}+ const syncing = sources.filter(source => source.status === 'syncing');setMemory({- ingesting: Boolean(ingest?.running),- currentTitle: ingest?.current_title,- queueDepth: ingest?.queue_depth ?? 0,- providers,+ ingesting: syncing.length > 0,+ currentTitle: syncing[0] ? syncing[0].label || syncing[0].target : undefined,+ queueDepth: syncing.length,+ providers: sources.map(source => ({+ provider: source.label || source.target,+ freshness: source.status === 'syncing' ? 'active' : 'idle',+ })),});- // Only consider work *genuinely live* for the fast-poll cadence: the- // ingestion worker actually running/queued, or a provider with a fresh- // chunk (<30s). A stale, un-drained embedding wave (batch_total >- // batch_processed but idle freshness) must NOT pin us to fast-poll.- busyRef.current =- Boolean(ingest?.running) ||- (ingest?.queue_depth ?? 0) > 0 ||- providers.some(p => p.freshness === 'active');+ // Fast-poll only while a source is genuinely syncing.+ busyRef.current = syncing.length > 0;setLoading(false);}, []);diff --git a/vendor/tinymemory b/vendor/tinymemoryindex 68a6a3e1b6..e5479173c6 160000--- a/vendor/tinymemory+++ b/vendor/tinymemory@@ -1 +1 @@-Subproject commit 68a6a3e1b64b4cbf1cc44aabb1aa9e34e0e75f14+Subproject commit e5479173c6e7afc580a348a83bcd53d0421da91c