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
address review (codex): bound cos/tasks pagination by dropping full-set derived collections
[._.]/ Adam Eivy552207d2abe4
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 0d9da84efc..6d8ef7da2c 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1,6 +1,6 @@## Brain & CoS API-- **[issue-1835] Brain & CoS list endpoints now support opt-in `limit`/`offset` pagination** — `GET /api/brain/people|projects|ideas|admin|memories` and `GET /api/cos/tasks` previously returned their entire backing store with no bound, while sibling endpoints (`GET /api/brain/links`, `GET /api/memory`) already exposed pagination envelopes. Each of these endpoints now accepts `limit`/`offset` query params: when neither is present they return the exact same shape as before (raw array for the brain collections; the `{ user, cos }` grouped structure for tasks), so every existing client keeps working; when a pagination param is passed they return a bounded `{ <collection>, total, limit, offset }` envelope (tasks window each source's `tasks` array and add a `pagination` block). `limit` defaults to 50 and is clamped to 500. Shared `isPaginationRequested` / `paginateArray` helpers were added to `server/lib/validation.js` alongside the existing `parsePagination`. (#1835)+- **[issue-1835] Brain & CoS list endpoints now support opt-in `limit`/`offset` pagination** — `GET /api/brain/people|projects|ideas|admin|memories` and `GET /api/cos/tasks` previously returned their entire backing store with no bound, while sibling endpoints (`GET /api/brain/links`, `GET /api/memory`) already exposed pagination envelopes. Each of these endpoints now accepts `limit`/`offset` query params: when neither is present they return the exact same shape as before (raw array for the brain collections; the `{ user, cos }` grouped structure for tasks), so every existing client keeps working; when a pagination param is passed they return a bounded `{ <collection>, total, limit, offset }` envelope — and for `/api/cos/tasks` the paginated branch windows each source's `tasks` array, adds a `pagination` block, and drops the full-set derived collections (`grouped`, `autoApproved`, `awaitingApproval`) so the response is genuinely bounded rather than re-leaking the whole queue. `limit` defaults to 50 and is clamped to 500. Shared `isPaginationRequested` / `paginateArray` helpers were added to `server/lib/validation.js` alongside the existing `parsePagination`. (#1835)## Securitydiff --git a/server/routes/cos.test.js b/server/routes/cos.test.jsindex d26b980648..bd20043170 100644--- a/server/routes/cos.test.js+++ b/server/routes/cos.test.js@@ -244,11 +244,21 @@ describe('CoS Routes', () => {const mockTasks = {user: {tasks: [{ id: 'u1' }, { id: 'u2' }, { id: 'u3' }],- grouped: { pending: [{ id: 'u1' }] }+ grouped: { pending: [{ id: 'u1' }, { id: 'u2' }, { id: 'u3' }] },+ awaitingApproval: [{ id: 'u1' }],+ autoApproved: [{ id: 'u2' }],+ file: 'data/cos/user-tasks.md',+ exists: true,+ type: 'user'},cos: {tasks: [{ id: 'c1' }, { id: 'c2' }],- grouped: {}+ grouped: { pending: [{ id: 'c1' }, { id: 'c2' }] },+ awaitingApproval: [],+ autoApproved: [],+ file: 'data/cos/cos-tasks.md',+ exists: true,+ type: 'internal'}};cos.getAllTasks.mockResolvedValue(mockTasks);@@ -259,8 +269,14 @@ describe('CoS Routes', () => {// Inner task arrays are windowed...expect(response.body.user.tasks).toEqual([{ id: 'u2' }]);expect(response.body.cos.tasks).toEqual([{ id: 'c2' }]);- // ...but grouped buckets keep reflecting the full set.- expect(response.body.user.grouped).toEqual({ pending: [{ id: 'u1' }] });+ // ...scalar metadata is preserved...+ expect(response.body.user).toMatchObject({ file: 'data/cos/user-tasks.md', exists: true, type: 'user' });+ // ...and the full-set derived collections are dropped so the response is+ // genuinely bounded (not re-leaked through grouped/awaiting/auto-approved).+ expect(response.body.user).not.toHaveProperty('grouped');+ expect(response.body.user).not.toHaveProperty('awaitingApproval');+ expect(response.body.user).not.toHaveProperty('autoApproved');+ expect(response.body.cos).not.toHaveProperty('grouped');expect(response.body.pagination).toEqual({limit: 1,offset: 1,diff --git a/server/routes/cosTaskRoutes.js b/server/routes/cosTaskRoutes.jsindex 2e695374d1..964073c6d0 100644--- a/server/routes/cosTaskRoutes.js+++ b/server/routes/cosTaskRoutes.js@@ -76,10 +76,14 @@ const router = Router();// GET /api/cos/tasks - Get all tasks (user + internal), grouped by source.//// Backward-compatible by default: with no pagination params it returns the full-// `{ user, cos }` structure every existing consumer expects. When a client-// passes `limit`/`offset`, each source's `tasks` array is bounded to that window-// (the `grouped` buckets still reflect the full set) and a `pagination` block is-// added so the caller can page without pulling an unbounded list.+// `{ user, cos }` structure every existing consumer expects (tasks + grouped+// buckets + awaiting/auto-approved derived lists). When a client passes+// `limit`/`offset`, each source is reduced to a *genuinely bounded* shape: the+// windowed `tasks` slice plus scalar metadata only. The full-set derived+// collections (`grouped`, `autoApproved`, `awaitingApproval`) are dropped from+// the paginated branch — keeping them would re-include the entire queue the+// caller asked to page through, defeating the bound. A `pagination` block with+// the true per-source totals is added so the caller can page.router.get('/tasks', asyncHandler(async (req, res) => {const tasks = await cos.getAllTasks();if (!isPaginationRequested(req.query)) {@@ -87,8 +91,12 @@ router.get('/tasks', asyncHandler(async (req, res) => {}const { limit, offset } = parsePagination(req.query, { defaultLimit: 50, maxLimit: 500 });const sliceSource = (src) => {- const list = Array.isArray(src?.tasks) ? src.tasks : [];- return { ...src, tasks: list.slice(offset, offset + limit) };+ if (!src || typeof src !== 'object') return { tasks: [] };+ // Strip the full-set derived collections so the response is actually bounded;+ // keep only scalar metadata (file/exists/type) + the windowed task slice.+ const { tasks: list, grouped, autoApproved, awaitingApproval, ...meta } = src;+ const arr = Array.isArray(list) ? list : [];+ return { ...meta, tasks: arr.slice(offset, offset + limit) };};const userTotal = Array.isArray(tasks?.user?.tasks) ? tasks.user.tasks.length : 0;const cosTotal = Array.isArray(tasks?.cos?.tasks) ? tasks.cos.tasks.length : 0;