Skip to content

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

refactor([settings-shallow-getsave-callers-tidy]): resolve /config chatId fallback against fresh current

[._.]/ Adam Eivy1568b14d0f3f
diff --git a/server/routes/telegram.js b/server/routes/telegram.js
index f8a87f021f..71df282628 100644
--- a/server/routes/telegram.js
+++ b/server/routes/telegram.js
@@ -122,12 +122,14 @@ router.put('/config', asyncHandler(async (req, res) => {
// 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 || '';
+ // isn't clobbered. The chatId fallback reads `current` (not the stale `settings`
+ // read above) so "keep the existing chatId when none is supplied" resolves
+ // against the freshest persisted value; `finalToken` is request-driven (the
+ // submitted token, else whatever was stored when we validated it).
await updateSettingsWith((current) => ({
...current,
secrets: { ...current.secrets, telegram: { token: finalToken } },
- telegram: { ...current.telegram, chatId: nextChatId }
+ telegram: { ...current.telegram, chatId: chatId || current.telegram?.chatId || '' }
}));
// Initialize bot — send test message only if chatId is configured