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 (rounds 12-13): chunk array join, timeWindow ordering, mtime fallback, validation details
Adam Eivy9fe44e2b816e
diff --git a/client/src/services/apiAsk.js b/client/src/services/apiAsk.jsindex 02cd2fb885..ff07cf5b63 100644--- a/client/src/services/apiAsk.js+++ b/client/src/services/apiAsk.js@@ -27,7 +27,22 @@ export async function streamAskTurn(payload, { onEvent, signal } = {}) {if (!response.ok || !response.body) {const text = await response.text().catch(() => '');let message = `HTTP ${response.status}`;- try { message = JSON.parse(text)?.error || message; } catch { /* not JSON */ }+ // Server includes `{ error, context: { details: [{ path, message }] } }`+ // for zod validation failures — surface the first few field-level+ // messages so users see "question: required" instead of a flat "HTTP 400".+ if (text) {+ try {+ const parsed = JSON.parse(text);+ const baseError = parsed?.error || message;+ const details = parsed?.context?.details;+ if (Array.isArray(details) && details.length) {+ const fieldNotes = details.slice(0, 3).map((d) => d.path ? `${d.path}: ${d.message}` : d.message).filter(Boolean);+ message = fieldNotes.length ? `${baseError} — ${fieldNotes.join('; ')}` : baseError;+ } else {+ message = baseError;+ }+ } catch { /* response body wasn't JSON; keep the HTTP status message */ }+ }throw new Error(message);}diff --git a/server/routes/ask.js b/server/routes/ask.jsindex c6d23717aa..fa271513f9 100644--- a/server/routes/ask.js+++ b/server/routes/ask.js@@ -38,7 +38,10 @@ const askBodySchema = z.object({days: z.number().int().min(1).max(365).optional(),startDate: z.string().datetime().optional(),endDate: z.string().datetime().optional(),- }).optional(),+ }).refine(+ (w) => !(w.startDate && w.endDate) || Date.parse(w.startDate) <= Date.parse(w.endDate),+ { message: 'startDate must be <= endDate', path: ['startDate'] },+ ).optional(),});const promoteBodySchema = z.object({diff --git a/server/services/askConversations.js b/server/services/askConversations.jsindex 7f81f06c3d..ccef0a4cf3 100644--- a/server/services/askConversations.js+++ b/server/services/askConversations.js@@ -105,21 +105,32 @@ export async function listConversations({ limit = 50 } = {}) {for (const id of ids) {const headSlot = summaries.length < limit;let conv = null;+ let mtime = null;if (headSlot) {conv = await readConversation(id);if (!conv) continue;} else {// Cheap check first — only open the JSON if mtime indicates the file// could be expired. atomicWrite touches mtime on every update.- const mtime = await stat(pathFor(id)).then((s) => s.mtimeMs, () => null);+ mtime = await stat(pathFor(id)).then((s) => s.mtimeMs, () => null);if (mtime === null) continue;if ((now - mtime) <= expiryMs) continue;conv = await readConversation(id);if (!conv) continue;}- const updated = safeDate(conv.updatedAt) || safeDate(conv.createdAt);- if (!conv.promoted && updated && (now - updated) > expiryMs) {+ // Fall back to file mtime when the JSON's own timestamps are missing or+ // unparseable — a corrupted record with no usable updatedAt would+ // otherwise live forever because `safeDate(undefined) === 0` made the+ // expiry comparison vacuously false.+ let effectiveTs = safeDate(conv.updatedAt) || safeDate(conv.createdAt);+ if (!effectiveTs) {+ if (mtime === null) {+ mtime = await stat(pathFor(id)).then((s) => s.mtimeMs, () => null);+ }+ if (mtime !== null) effectiveTs = mtime;+ }+ if (!conv.promoted && effectiveTs && (now - effectiveTs) > expiryMs) {// Single-user app — no concurrency races to worry about pruning here.await unlink(pathFor(id)).catch(() => {});continue;diff --git a/server/services/askService.js b/server/services/askService.jsindex a9c52676b6..f72d889256 100644--- a/server/services/askService.js+++ b/server/services/askService.js@@ -619,12 +619,14 @@ export async function* runAsk({// Stream errors are caught here (rather than letting them bubble) so the// route can flush a terminal SSE 'error' frame to the client — once the// stream has started, we can't change to a 5xx response any longer.- let answer = '';+ // Chunks accumulate into an array and join once at the end; `+=` would be+ // O(n²) on long responses where each delta re-allocates the running string.+ const chunks = [];try {for await (const chunk of streamCompletion(provider, effectiveModel, prompt, signal)) {if (signal?.aborted) return;if (!chunk) continue;- answer += chunk;+ chunks.push(chunk);yield { type: 'delta', text: chunk };}} catch (err) {@@ -633,6 +635,7 @@ export async function* runAsk({return;}+ const answer = chunks.join('');console.log(`✅ Ask complete: ${provider.id}/${effectiveModel} ${Date.now() - startedAt}ms ${answer.length} chars`);yield {