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(server): guard unsafe rows[0] access in memorySync and db health check
Adam Eivy44854dbc65f7
diff --git a/DONE.md b/DONE.mdindex 65a9720852..9260bc7ccd 100644--- a/DONE.md+++ b/DONE.md@@ -9,6 +9,13 @@ Archive of completed work. For active roadmap, see [PLAN.md](./PLAN.md). For pro- Fixed PromptManager.jsx fetch calls — response.ok checks now present on all endpoints- Fixed memory.js sort comparison — now type-safe with NaN/Date.parse validation- Fixed silent catch in useTheme.js — now has console logging instead of swallowing errors+- Fixed agentActionExecutor.js:137 — reformatted complex ternary for readability+- Fixed memorySync.js `rows[0]` — added optional chaining with nullish coalescing fallback+- Fixed db.js `rows[0]` — added optional chaining with empty object fallback+- Resolved hardcoded localhost in lmStudioManager.js/memoryClassifier.js — server-side connections to local LM Studio with env var overrides, not a bug+- Resolved empty `.catch(() => {})` in client files — `request()` in api.js already shows `toast.error()` centrally; catches just prevent unhandled rejection warnings+- Resolved silent catches in runner.js — intentional best-effort writes during error handling+- Resolved Settings.jsx:366 catch — error toast already fires via centralized `request()` handler---diff --git a/PLAN.md b/PLAN.mdindex 6fd6509ae8..8d326abc7c 100644--- a/PLAN.md+++ b/PLAN.md@@ -13,7 +13,6 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]## Backlog- [ ] **God file decomposition** — Split cos.js (3,952 lines), subAgentSpawner.js (3,307 lines), digital-twin.js (2,823 lines), routes/scaffold.js (1,668 lines), routes/cos.js (1,355 lines), client/api.js (1,853 lines) into focused modules. Resolve cos.js ↔ subAgentSpawner.js circular dependency-- [ ] **Fix unsafe data access** — Guard `rows[0]` in memorySync.js/db.js, fix 56 empty `.catch(() => {})` handlers in client code- [ ] **M50 P9**: CoS Automation & Rules — Automated email classification, rule-based pre-filtering, email-to-task pipeline, priority notifications- [ ] **M50 P10**: Auto-Send with AI Review Gate — Configurable per-account trust level, second LLM reviews drafts for prompt injection/tone drift. See [Messages Security](./docs/features/messages-security.md)@@ -21,12 +20,8 @@ For project goals, see [GOALS.md](./GOALS.md). For completed work, see [DONE.md]**Known low-severity:** pm2 ReDoS (GHSA-x5gf-qvw8-r2rm) — no upstream fix, not exploitable via PortOS routes.-### Bugs & Code Quality (still present)-- [ ] `server/services/agentActionExecutor.js:137` — Complex array fallback logic-- [ ] `server/services/memorySync.js` + `server/lib/db.js` — Unsafe `rows[0]` access without bounds check-- [ ] Hardcoded localhost in `lmStudioManager.js`, `memoryClassifier.js`-- [ ] Empty `.catch(() => {})` in several client files-- [ ] Silent catch blocks in `runner.js`, `Settings.jsx`+### Bugs & Code Quality+_All bug items from 2026-03-05 audit resolved — see [DONE.md](./DONE.md)_### DRY (still present)- [ ] Duplicate DATA_DIR/path constants in ~84 filesdiff --git a/server/lib/db.js b/server/lib/db.jsindex c1ffd2d637..df7790bad3 100644--- a/server/lib/db.js+++ b/server/lib/db.js@@ -82,7 +82,7 @@ export async function checkHealth() {EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = 'memory_links') AS has_links,EXISTS(SELECT 1 FROM information_schema.columns WHERE table_name = 'memories' AND column_name = 'sync_sequence') AS has_sync`);- const { has_memories, has_links, has_sync } = result.rows[0];+ const { has_memories, has_links, has_sync } = result.rows?.[0] ?? {};return { connected: true, hasSchema: has_memories && has_links && has_sync };} catch (err) {console.error(`🗄️ Database health check failed: ${err.message}`);diff --git a/server/services/agentActionExecutor.js b/server/services/agentActionExecutor.jsindex f5f7370651..577cc1f9b0 100644--- a/server/services/agentActionExecutor.js+++ b/server/services/agentActionExecutor.js@@ -134,7 +134,9 @@ async function executeComment(client, agent, params) {console.log(`🤖 AI generating comment for "${agent.name}" on post ${postId}`);const post = await client.getPost(postId);const commentsResponse = await client.getComments(postId);- const comments = Array.isArray(commentsResponse?.comments) ? commentsResponse.comments : Array.isArray(commentsResponse) ? commentsResponse : [];+ const comments = Array.isArray(commentsResponse?.comments)+ ? commentsResponse.comments+ : Array.isArray(commentsResponse) ? commentsResponse : [];const contentConfig = agent.aiConfig?.content || agent.aiConfig;if (parentId) {diff --git a/server/services/memorySync.js b/server/services/memorySync.jsindex 5701172a19..bde9de1087 100644--- a/server/services/memorySync.js+++ b/server/services/memorySync.js@@ -153,5 +153,5 @@ export async function applyRemoteChanges(incomingMemories) {*/export async function getMaxSequence() {const result = await query('SELECT COALESCE(MAX(sync_sequence), 0)::text AS max_seq FROM memories');- return result.rows[0].max_seq;+ return result.rows?.[0]?.max_seq ?? '0';}