Repository navigation
fix(daemon): restore real-time updates and sync after a reconnect - #28
Merged
Merged
Conversation
closeClientSafe looked up a close() method, which mtcute's TelegramClient doesn't have (it closes with destroy()), so the helper silently did nothing. The duplicate-account merge left its connection open, and the reconnect fix needs this helper to really close the old client before a new one opens the same session file. Co-Authored-By: Claude Opus 5.5 <[email protected]>
attemptReconnect opened a new client but never registered the update handlers or started its updates loop, left the old client open on the same session file, and kept the account's sync worker bound to the old client. After one failed health check the daemon still looked connected but quietly stopped caching new messages. A reconnect now removes the old client's handlers, drops its sync worker and closes it before opening the new client. On success it registers the handlers, starts the updates loop and rebuilds the sync worker on the new client. A failed attempt closes the new client and schedules the next retry as before. Sync workers expose the client they call, so tests can check which one a worker uses. Fixes #16 Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
force-pushed
the
fix/daemon-reconnect-16
branch
from
October 21, 2026 12:08
6f36d95 to
c494622
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
After one failed health check,
attemptReconnectopened a new client but:tg statusstill showed the account as connected. On top of that,closeClientSafelooked up aclose()method that mtcute'sTelegramClientdoesn't have (it closes withdestroy()), so it never closed anything.Fix
closeClientSafenow callsclient.destroy(). This also fixes the duplicate-account merge, which left its connection open.rebuildSyncWorkerindaemon-scheduler.ts; it does nothing while the scheduler isn't running).reconnectingbefore the firstawait, so the next health check skips the account.clientthey call, so tests can check which client a worker uses.docs/daemon.md(Error Handling & Resilience),docs/testing.md(mockdestroy, notclose), and a CHANGELOG entry.Tests
rebuildSyncWorkerand forcloseClientSafecallingdestroy().bun run check,bun run testandbun run test:e2epass locally. The live suite was not run.Fixes #16
🤖 Generated with Claude Code