Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep Brain lists paging past the first 25 records (#10870)
Adam Eivy829ccff51610
diff --git a/client/src/components/brain/tabs/MemoryTab.reader.test.jsx b/client/src/components/brain/tabs/MemoryTab.reader.test.jsxindex 1c7c17a7ca..078c6baabc 100644--- a/client/src/components/brain/tabs/MemoryTab.reader.test.jsx+++ b/client/src/components/brain/tabs/MemoryTab.reader.test.jsx@@ -109,6 +109,22 @@ describe('Brain memory reader', () => {});});+describe('Brain memory collection paging', () => {+ it('requests the first page with a null cursor and follows the first-page envelope continuation to the rest', async () => {+ // Shapes mirror GET /api/brain/memories?cursor=&limit=25 (cursor mode): rows plus total and nextCursor.+ const row = i => ({ id: `mem-${i}`, title: `Example memory ${i}`, content: 'Short', contentTruncated: false });+ api.getBrainMemories+ .mockResolvedValueOnce({ memories: [row(1), row(2)], items: [row(1), row(2)], total: 3, nextCursor: 'cursor-after-2' })+ .mockResolvedValueOnce({ memories: [row(3)], items: [row(3)], total: 3, nextCursor: null });+ mount();+ expect(await screen.findByText('Example memory 3')).toBeTruthy();+ expect(screen.getByText('Example memory 1')).toBeTruthy();+ expect(api.getBrainMemories).toHaveBeenCalledTimes(2);+ expect(api.getBrainMemories.mock.calls[0][0]).toMatchObject({ cursor: null, limit: 25 });+ expect(api.getBrainMemories.mock.calls[1][0]).toMatchObject({ cursor: 'cursor-after-2', limit: 25 });+ });+});+describe('Brain deletion preserves the list', () => {it('waits for success, collapses only the deleted row and keeps search and siblings mounted', async () => {diff --git a/client/src/services/apiBrain.js b/client/src/services/apiBrain.jsindex 96c76a27b9..75b31195e9 100644--- a/client/src/services/apiBrain.js+++ b/client/src/services/apiBrain.js@@ -1,6 +1,16 @@import { request } from './apiCore.js';// Brain - Second Brain Feature++// The entity-list routes select cursor mode only when `cursor` (or `search`) is+// present in the query. A caller that opts into cursor paging passes `null` for+// the first page (usePagedCollection), so serialize it as the empty initial+// cursor rather than dropping it — dropping it selects the legacy offset+// envelope, which carries no `nextCursor` and strands the list at page one.+// Callers that omit the option entirely keep the legacy contract.+const setEntityCursor = (params, cursor) => {+ if (cursor !== undefined) params.set('cursor', cursor ?? '');+};export const getBrainSummary = (options) => request('/brain/summary', options);export const getBrainSettings = (options) => request('/brain/settings', options);export const updateBrainSettings = (settings, options = {}) => request('/brain/settings', {@@ -61,7 +71,7 @@ export const markBrainInboxDone = (id, options = {}) => request(`/brain/inbox/${export const getBrainPeople = (options = {}) => {const params = new URLSearchParams();if (options.search) params.set('search', options.search);- if (options.cursor !== undefined && options.cursor !== null) params.set('cursor', options.cursor);+ setEntityCursor(params, options.cursor);if (options.limit) params.set('limit', options.limit);if (options.offset) params.set('offset', options.offset);const qs = params.toString();@@ -88,7 +98,7 @@ export const getBrainProjects = (filters = {}) => {const params = new URLSearchParams();if (filters?.status) params.set('status', filters.status);if (filters?.search) params.set('search', filters.search);- if (filters?.cursor !== undefined && filters?.cursor !== null) params.set('cursor', filters.cursor);+ setEntityCursor(params, filters?.cursor);if (filters?.limit) params.set('limit', filters.limit);if (filters?.offset) params.set('offset', filters.offset);const qs = params.toString();@@ -115,7 +125,7 @@ export const getBrainIdeas = (filters = {}) => {const params = new URLSearchParams();if (filters?.status) params.set('status', filters.status);if (filters?.search) params.set('search', filters.search);- if (filters?.cursor !== undefined && filters?.cursor !== null) params.set('cursor', filters.cursor);+ setEntityCursor(params, filters?.cursor);if (filters?.limit) params.set('limit', filters.limit);if (filters?.offset) params.set('offset', filters.offset);const qs = params.toString();@@ -174,7 +184,7 @@ export const getBrainAdmin = (filters = {}) => {const params = new URLSearchParams();if (filters?.status) params.set('status', filters.status);if (filters?.search) params.set('search', filters.search);- if (filters?.cursor !== undefined && filters?.cursor !== null) params.set('cursor', filters.cursor);+ setEntityCursor(params, filters?.cursor);if (filters?.limit) params.set('limit', filters.limit);if (filters?.offset) params.set('offset', filters.offset);const qs = params.toString();@@ -201,7 +211,7 @@ export const getBrainMemories = (options = {}) => {const params = new URLSearchParams();if (options.status) params.set('status', options.status);if (options.search) params.set('search', options.search);- if (options.cursor !== undefined && options.cursor !== null) params.set('cursor', options.cursor);+ setEntityCursor(params, options.cursor);if (options.limit) params.set('limit', options.limit);if (options.offset) params.set('offset', options.offset);const qs = params.toString();diff --git a/server/routes/brainCollectionPagination.test.js b/server/routes/brainCollectionPagination.test.jsindex dba3583121..fc00be0540 100644--- a/server/routes/brainCollectionPagination.test.js+++ b/server/routes/brainCollectionPagination.test.js@@ -27,7 +27,18 @@ vi.mock('../services/userActions.js', () => ({recordUserAction: vi.fn(async () => ({ id: 'evt' }))}));+// The real client wrappers run against the mounted router: only the transport+// (`request`) is replaced, so the URL each wrapper builds is what the router sees.+const transport = vi.hoisted(() => ({ calls: [], send: null }));+vi.mock('../../client/src/services/apiCore.js', () => ({+ request: async (path, options) => {+ transport.calls.push({ path, options });+ return transport.send(path);+ }+}));+// Import after hoisting mocks+import * as clientBrainApi from '../../client/src/services/apiBrain.js';import * as brainStorage from '../services/brainStorage.js';import brainRoutes from './brain.js';@@ -37,6 +48,14 @@ app.use('/api/brain', brainRoutes);const TOTAL_INBOX = 1200;const TOTAL_MEMORIES = 1500;+const TOTAL_ENTITIES = 60;+const ENTITY_TYPES = {+ people: clientBrainApi.getBrainPeople,+ projects: clientBrainApi.getBrainProjects,+ ideas: clientBrainApi.getBrainIdeas,+ admin: clientBrainApi.getBrainAdmin,+ memories: clientBrainApi.getBrainMemories+};const BASE_TIME = Date.parse('2026-08-01T00:00:00.000Z');async function seedRecord(type, id, record) {@@ -93,7 +112,25 @@ describe('Brain collection pagination (synthetic thousands-record fixtures)', ()};});+ for (const type of ['people', 'projects', 'ideas', 'admin']) {+ await seedRecords(type, TOTAL_ENTITIES, (i) => {+ const updatedAt = new Date(BASE_TIME + i * 60000).toISOString();+ return {+ name: `Example ${type} ${i}`,+ title: `Example ${type} ${i}`,+ status: i % 2 === 0 ? 'active' : 'done',+ tags: i === 7 ? ['wanted-tag'] : [],+ createdAt: updatedAt,+ updatedAt+ };+ });+ }+brainStorage.invalidateAllCaches();+ transport.send = async (path) => {+ const res = await request(app).get(`/api${path}`);+ return res.body;+ };});afterAll(() => {@@ -262,4 +299,57 @@ describe('Brain collection pagination (synthetic thousands-record fixtures)', ()expect(res.body.nextCursor).toBeUndefined();});});+ describe('Initial entity request from the client wrappers', () => {+ const lastPath = () => transport.calls[transport.calls.length - 1].path;++ it.each(Object.keys(ENTITY_TYPES))('%s: a first-page request (cursor: null) selects cursor mode and can reach every record', async (type) => {+ const total = type === 'memories' ? 1350 : TOTAL_ENTITIES;+ const fetchPage = ENTITY_TYPES[type];+ const first = await fetchPage({ cursor: null, limit: 25 });+ expect(lastPath()).toContain('cursor=');+ expect(first.items).toHaveLength(25);+ expect(first.total).toBe(total);+ expect(first.nextCursor).toBeTruthy();+ expect(first.offset).toBeUndefined();++ let seen = first.items.map(item => item.id);+ let cursor = first.nextCursor;+ while (cursor) {+ const next = await fetchPage({ cursor, limit: 25 });+ seen = seen.concat(next.items.map(item => item.id));+ cursor = next.nextCursor;+ }+ expect(seen).toHaveLength(total);+ expect(new Set(seen).size).toBe(total);+ });++ it('serves the compact memory projection on the initial page', async () => {+ const first = await clientBrainApi.getBrainMemories({ cursor: null, limit: 25 });+ expect(first.items.every(item => item.contentTruncated === true && item.content.length <= 300)).toBe(true);+ });++ it.each(['people', 'projects', 'ideas', 'admin', 'memories'])('%s: a caller that omits the cursor option keeps the legacy contract', async (type) => {+ const legacyArray = await ENTITY_TYPES[type]();+ expect(lastPath()).not.toContain('cursor');+ expect(Array.isArray(legacyArray)).toBe(true);++ const envelope = await ENTITY_TYPES[type]({ limit: 10, offset: 5 });+ expect(lastPath()).not.toContain('cursor');+ expect(envelope).toMatchObject({ limit: 10, offset: 5 });+ expect(envelope.nextCursor).toBeUndefined();+ });++ it('keeps search, status filters and request options alongside the initial cursor', async () => {+ const signal = new AbortController().signal;+ const filtered = await clientBrainApi.getBrainProjects({ cursor: null, limit: 25, status: 'active', signal, silent: true });+ expect(transport.calls[transport.calls.length - 1].options).toEqual({ silent: true, signal });+ expect(lastPath()).toContain('status=active');+ expect(filtered.total).toBe(TOTAL_ENTITIES / 2);+ expect(filtered.items.every(item => item.status === 'active')).toBe(true);++ const searched = await clientBrainApi.getBrainPeople({ cursor: null, limit: 25, search: 'wanted-tag' });+ expect(searched.total).toBe(1);+ expect(searched.nextCursor).toBeNull();+ });+ });});