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: preserve legacy issue list handling in lean reads (#7042)
[._.]/ Adam Eivy7eb87c899fd5
diff --git a/server/services/pipeline/issuesStore/db.js b/server/services/pipeline/issuesStore/db.jsindex 14a72fe5d6..9c3a584f96 100644--- a/server/services/pipeline/issuesStore/db.js+++ b/server/services/pipeline/issuesStore/db.js@@ -11,7 +11,7 @@* snapshot ephemeral-filter, and LWW staleness.** PURE leaf I/O — the store facade owns serialization + sanitize; reads return- * `data` verbatim (the columns are a queryable mirror, never read back).+ * full `data` verbatim by default, or explicit lean/summary projections.*/import { query } from '../../../lib/db.js';@@ -20,8 +20,11 @@ import { PIPELINE_STAGE_IDS } from '../../../lib/pipelineStages.js';// Only trusted, closed stage IDs form SQL paths. PostgreSQL removes history// before serializing JSONB for Node; every other field remains lossless.+// A malformed stage is left for the sanitizer, never traversed as a JSON array.const LEAN_DATA = PIPELINE_STAGE_IDS.reduce(- (sql, stageId) => `${sql} #- '{stages,${stageId},runHistory}'`, 'data',+ (sql, stageId) => `${sql} #- CASE+ WHEN jsonb_typeof(data->'stages'->'${stageId}') = 'object'+ THEN '{stages,${stageId},runHistory}'::text[] ELSE '{}'::text[] END`, 'data',);/** Raw on-disk-equivalent record (the `data` JSONB), or null. No sanitize. */@@ -83,12 +86,12 @@ export async function listRawBySeriesIds(seriesIds, { withHistory = true } = {})*/export async function listRecentRaw({ limit, withHistory = true, includeDeleted = false, summary = false }) {const projection = summary- ? "jsonb_build_object('id', id, 'title', data->'title', 'number', number, 'seriesId', series_id, 'updatedAt', data->'updatedAt')"+ ? "jsonb_build_object('id', id, 'title', data->'title', 'number', number, 'seriesId', series_id, 'updatedAt', data->'updatedAt', 'createdAt', data->'createdAt')": withHistory ? 'data' : LEAN_DATA;const { rows } = await query(`SELECT ${projection} AS data FROM pipeline_issues- ${includeDeleted ? '' : 'WHERE deleted = FALSE'}- ORDER BY updated_at DESC LIMIT $1`,+ ${includeDeleted ? '' : 'WHERE deleted IS NOT TRUE'}+ ORDER BY updated_at DESC NULLS LAST, id DESC LIMIT $1`,[limit],);return rows.map((r) => r.data);diff --git a/server/services/pipeline/issuesStore/db.test.js b/server/services/pipeline/issuesStore/db.test.jsindex 776bd9d7df..3e65e52ad2 100644--- a/server/services/pipeline/issuesStore/db.test.js+++ b/server/services/pipeline/issuesStore/db.test.js@@ -103,10 +103,10 @@ describe.skipIf(!runDb)('pipeline issues DB adapter round-trip', () => {const querySpy = vi.spyOn(dbConnection, 'query');const summaries = await db.listRecentRaw({ limit: 2, summary: true });expect(summaries.map((r) => r.id)).toEqual(['iss-58', 'iss-57']);- expect(Object.keys(summaries[0]).sort()).toEqual(['id', 'number', 'seriesId', 'title', 'updatedAt']);+ expect(Object.keys(summaries[0]).sort()).toEqual(['createdAt', 'id', 'number', 'seriesId', 'title', 'updatedAt']);expect(querySpy).toHaveBeenCalledTimes(1);const [sql, params] = querySpy.mock.calls[0];- expect(sql).toMatch(/WHERE deleted = FALSE\s+ORDER BY updated_at DESC LIMIT \$1/);+ expect(sql).toMatch(/WHERE deleted IS NOT TRUE\s+ORDER BY updated_at DESC NULLS LAST, id DESC LIMIT \$1/);expect(sql).toContain('jsonb_build_object');expect(params).toEqual([2]);querySpy.mockRestore();@@ -148,6 +148,29 @@ describe.skipIf(!runDb)('pipeline issues DB adapter round-trip', () => {}]);});+ it('lean SQL tolerates malformed stage containers and recent summaries sanitize legacy fields', async () => {+ const svc = await import('../issueCrud.js');+ for (const [n, stages] of [[], 'invalid', { idea: [] }, { idea: 'invalid' }].entries()) {+ await db.writeRaw(`iss-malformed-${n}`, I(`iss-malformed-${n}`, { stages }));+ }+ expect(await svc.listIssues({ withHistory: false })).toHaveLength(4);+ await db.writeRaw('iss-legacy', I('iss-legacy', {+ title: ' Legacy title ', number: null, updatedAt: '2026-02-01T00:00:00.000Z',+ }));+ await query("UPDATE pipeline_issues SET deleted = NULL WHERE id = 'iss-legacy'");+ const summary = await svc.listRecentIssues({ limit: 1, summary: true });+ expect(summary).toEqual([{+ id: 'iss-legacy', title: 'Legacy title', number: 0, seriesId: 'ser-1',+ updatedAt: '2026-02-01T00:00:00.000Z',+ }]);+ await query("UPDATE pipeline_issues SET updated_at = NULL WHERE id = 'iss-legacy'");+ expect((await svc.listRecentIssues({ limit: 1 }))[0].id).not.toBe('iss-legacy');+ await db.writeRaw('iss-invalid-title', I('iss-invalid-title', {+ title: 123, updatedAt: '2026-03-01T00:00:00.000Z',+ }));+ expect(await svc.listRecentIssues({ limit: 1, summary: true })).toEqual([]);+ });+it('upsert updates the record and the mirror columns (series_id/number/status)', async () => {await db.writeRaw('iss-1', I('iss-1', { number: 1, status: 'draft' }));await db.writeRaw('iss-1', I('iss-1', { number: 3, status: 'shipped', updatedAt: '2026-03-03T00:00:00.000Z' }));diff --git a/server/services/pipeline/issuesStore/store.js b/server/services/pipeline/issuesStore/store.jsindex a8dc18f659..01ce4444ab 100644--- a/server/services/pipeline/issuesStore/store.js+++ b/server/services/pipeline/issuesStore/store.js@@ -183,18 +183,19 @@ function createFacade({ dir, sanitizeRecord }) {return sanitizeList(raw, options);},- loadRecent: async (options) => {+ loadRecent: async ({ limit = 10, ...options } = {}) => {const backend = await getBackend();+ let recent;if (backend.listRecentRaw) {- const raw = await backend.listRecentRaw(options);- return options.summary ? raw : sanitizeList(raw, options);+ recent = sanitizeList(await backend.listRecentRaw({ ...options, limit }), options);+ } else {+ // Dev/test file backend has no timestamp index. Sanitize before sorting+ // to retain its legacy-record behavior, then match the HTTP projection.+ const live = sanitizeList(await backend.listRaw(), options)+ .filter((r) => options.includeDeleted || !r.deleted);+ recent = live.sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || ''))+ .slice(0, limit);}- // Dev/test file backend has no timestamp index. Sanitize before sorting- // to retain its legacy-record behavior, then match the HTTP projection.- const live = sanitizeList(await backend.listRaw(), options)- .filter((r) => options.includeDeleted || !r.deleted);- const recent = live.sort((a, b) => (b.updatedAt || '').localeCompare(a.updatedAt || ''))- .slice(0, options.limit);return options.summary? recent.map(({ id, title, number, seriesId, updatedAt }) => ({ id, title, number, seriesId, updatedAt })): recent;