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: clean up abort listener on fetch completion, stabilize sort comparator, import real module in tests
Adam Eivy637ab6d87569
diff --git a/server/lib/fetchWithTimeout.js b/server/lib/fetchWithTimeout.jsindex 80cb4c1a39..053a4e9484 100644--- a/server/lib/fetchWithTimeout.js+++ b/server/lib/fetchWithTimeout.js@@ -11,15 +11,22 @@ export async function fetchWithTimeout(url, options = {}, timeoutMs = 15000) {const timeoutId = setTimeout(() => controller.abort(), timeoutMs);let signal = controller.signal;+ let abortHandler;if (options.signal) {if (typeof AbortSignal !== 'undefined' && typeof AbortSignal.any === 'function') {signal = AbortSignal.any([controller.signal, options.signal]);} else {// Fallback: propagate caller abort to our controller- options.signal.addEventListener('abort', () => controller.abort(), { once: true });+ abortHandler = () => controller.abort();+ options.signal.addEventListener('abort', abortHandler, { once: true });}}return fetch(url, { ...options, signal })- .finally(() => clearTimeout(timeoutId));+ .finally(() => {+ clearTimeout(timeoutId);+ if (options.signal && abortHandler) {+ options.signal.removeEventListener('abort', abortHandler);+ }+ });}diff --git a/server/lib/fetchWithTimeout.test.js b/server/lib/fetchWithTimeout.test.jsindex 94fc3da78f..82f99b301e 100644--- a/server/lib/fetchWithTimeout.test.js+++ b/server/lib/fetchWithTimeout.test.js@@ -1,22 +1,5 @@import { describe, it, expect, vi, beforeEach } from 'vitest';--// Inline implementation to avoid complex module mocking-async function fetchWithTimeout(url, options = {}, timeoutMs = 15000) {- const controller = new AbortController();- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);-- let signal = controller.signal;- if (options.signal) {- if (typeof AbortSignal !== 'undefined' && typeof AbortSignal.any === 'function') {- signal = AbortSignal.any([controller.signal, options.signal]);- } else {- options.signal.addEventListener('abort', () => controller.abort(), { once: true });- }- }-- return fetch(url, { ...options, signal })- .finally(() => clearTimeout(timeoutId));-}+import { fetchWithTimeout } from './fetchWithTimeout.js';describe('fetchWithTimeout', () => {beforeEach(() => {diff --git a/server/services/memory.js b/server/services/memory.jsindex abad97d985..0c81b242cc 100644--- a/server/services/memory.js+++ b/server/services/memory.js@@ -253,9 +253,34 @@ export async function getMemories(options = {}) {memories.sort((a, b) => {const aRaw = a[sortBy];const bRaw = b[sortBy];- const aVal = typeof aRaw === 'string' ? aRaw : (aRaw ?? 0);- const bVal = typeof bRaw === 'string' ? bRaw : (bRaw ?? 0);- return sortOrder === 'desc' ? (bVal > aVal ? 1 : bVal < aVal ? -1 : 0) : (aVal > bVal ? 1 : aVal < bVal ? -1 : 0);++ // Missing values sort last+ const aMissing = aRaw === null || aRaw === undefined;+ const bMissing = bRaw === null || bRaw === undefined;+ if (aMissing && bMissing) return 0;+ if (aMissing) return 1;+ if (bMissing) return -1;++ // Compare as dates if both parse as valid timestamps+ const aTime = (typeof aRaw === 'string' || aRaw instanceof Date) ? Date.parse(aRaw) : NaN;+ const bTime = (typeof bRaw === 'string' || bRaw instanceof Date) ? Date.parse(bRaw) : NaN;+ if (!Number.isNaN(aTime) && !Number.isNaN(bTime)) {+ const diff = aTime - bTime;+ return sortOrder === 'desc' ? (diff === 0 ? 0 : diff < 0 ? 1 : -1) : (diff === 0 ? 0 : diff < 0 ? -1 : 1);+ }++ // Numeric comparison+ if (typeof aRaw === 'number' && typeof bRaw === 'number') {+ const diff = aRaw - bRaw;+ return sortOrder === 'desc' ? (diff === 0 ? 0 : diff < 0 ? 1 : -1) : (diff === 0 ? 0 : diff < 0 ? -1 : 1);+ }++ // String fallback+ const aStr = String(aRaw);+ const bStr = String(bRaw);+ if (aStr === bStr) return 0;+ const cmp = aStr < bStr ? -1 : 1;+ return sortOrder === 'desc' ? -cmp : cmp;});// Paginate