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([settings-shallow-getsave-callers-tidy]): queue the telegram + systemHealth nested-merge settings writes
[._.]/ Adam Eivy2458322accc7
diff --git a/server/routes/systemHealth.js b/server/routes/systemHealth.jsindex 70caf507a8..a6aa48e7cd 100644--- a/server/routes/systemHealth.js+++ b/server/routes/systemHealth.js@@ -9,7 +9,7 @@ import { checkHealth } from '../lib/db.js';import { getCurrentVersion } from '../services/updateChecker.js';import { asyncHandler } from '../lib/errorHandler.js';import { getMemoryStats } from '../lib/memoryStats.js';-import { getSettings, updateSettings } from '../services/settings.js';+import { getSettings, updateSettingsWith } from '../services/settings.js';// Defaults are tuned for a real dev machine: memory routinely sits in the// 75-85% band on a host with a couple of LLMs loaded, and big SSDs commonly@@ -277,8 +277,9 @@ router.put('/health/thresholds', asyncHandler(async (req, res) => {return res.status(400).json({ error: 'diskWarn must be less than diskCritical' });}- const current = await getSettings().catch(() => ({}));- await updateSettings({ ...current, health: { ...(current.health || {}), ...next } });+ // Merge the health thresholds against the freshest snapshot inside the write+ // queue so a concurrent settings write isn't clobbered by a stale base.+ await updateSettingsWith((current) => ({ ...current, health: { ...(current.health || {}), ...next } }));res.json(next);}));diff --git a/server/routes/telegram.js b/server/routes/telegram.jsindex 23df89e6a4..f8a87f021f 100644--- a/server/routes/telegram.js+++ b/server/routes/telegram.js@@ -1,7 +1,7 @@import { Router } from 'express';import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { telegramConfigSchema, telegramTestSchema, telegramMethodSchema } from '../lib/telegramValidation.js';-import { getSettings, updateSettings } from '../services/settings.js';+import { getSettings, updateSettingsWith } from '../services/settings.js';import * as telegram from '../services/telegram.js';import * as telegramBridge from '../services/telegramBridge.js';@@ -55,13 +55,13 @@ router.put('/method', asyncHandler(async (req, res) => {const { method } = result.data;const settings = await getSettings();- // Save method preference- await updateSettings({- telegram: {- ...settings.telegram,- method- }- });+ // Save method preference. Merge `telegram` against the FRESHEST snapshot inside+ // the write queue (not the `settings` read above, which can go stale before the+ // queued write lands) so a concurrent settings write isn't clobbered.+ await updateSettingsWith((current) => ({+ ...current,+ telegram: { ...current.telegram, method }+ }));// Switch servicesif (method === 'mcp-bridge') {@@ -120,17 +120,15 @@ router.put('/config', asyncHandler(async (req, res) => {});}- // Store token in secrets, chatId in telegram- await updateSettings({- secrets: {- ...settings.secrets,- telegram: { token: finalToken }- },- telegram: {- ...settings.telegram,- chatId: chatId || settings.telegram?.chatId || ''- }- });+ // Store token in secrets, chatId in telegram. Merge both sub-objects against+ // the freshest snapshot inside the write queue so a concurrent settings write+ // can't be clobbered by the stale `settings` read above.+ const nextChatId = chatId || settings.telegram?.chatId || '';+ await updateSettingsWith((current) => ({+ ...current,+ secrets: { ...current.secrets, telegram: { token: finalToken } },+ telegram: { ...current.telegram, chatId: nextChatId }+ }));// Initialize bot — send test message only if chatId is configuredconst hasChatId = !!(chatId || settings.telegram?.chatId);@@ -155,10 +153,11 @@ router.delete('/config', asyncHandler(async (req, res) => {await telegram.cleanup();}- await updateSettings({+ await updateSettingsWith((current) => ({+ ...current,telegram: null,- secrets: { ...settings.secrets, telegram: undefined }- });+ secrets: { ...current.secrets, telegram: undefined }+ }));res.json({ success: true });}));@@ -198,13 +197,10 @@ router.put('/forward-types', asyncHandler(async (req, res) => {});}- const settings = await getSettings();- await updateSettings({- telegram: {- ...settings.telegram,- forwardTypes- }- });+ await updateSettingsWith((current) => ({+ ...current,+ telegram: { ...current.telegram, forwardTypes }+ }));// Update cache on both services (only the active one matters)telegram.updateCachedForwardTypes(forwardTypes);