Repository navigation
fix(daemon): fetch senders missing from the cache - #152
Merged
neoromantic merged 2 commits intoNov 13, 2026
Merged
neoromantic merged 2 commits into
neoromantic merged 2 commits into
Conversation
Messages whose sender has no users_cache row (history synced before
0.9.0, live messages from "min" users) show only the sender's ID and
`sender:name` misses them. The scheduler now lists such senders in
sender_lookups on start and once a day (an index walk, ~6 ms on 1.16M
messages), and a fetch_senders job per chat asks Telegram for one
message of each of up to 100 senders by ID; the reply caches the
senders, which re-indexes their messages. The jobs run in a fourth lane
only when catch-up, first pages and history are empty. A sender
Telegram doesn't return is asked again after 30 days. tg status shows
progress.senders { missing, not_found } in total and per account.
Fixes #143
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ers cached since History is written newest first, so the row cached last was often the oldest message; if Telegram had deleted it, the sender stayed missing after every retry. A chat whose waiting senders were cached by another path no longer gets an empty job every refresh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
deleted the
bb/fetch-senders-missing-from-the-cache-143-thr_9ahjhd7wr7
branch
November 13, 2026 16:11
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.
Fixes #143
Problem
A cached message whose sender has no
users_cacherow shows only the sender's ID, andsender:namemisses it. Caches synced before 0.9.0 (#126) have many (about 3% of the messages of a 1.16M-message cache, from about 3,000 senders), and a live message still leaves one when the sender arrives as a "min" user.Change
sender_lookups(src/db/sender-lookups.ts): each user with cached messages and nousers_cacherow, with their newest cached message Telegram can be asked for (not deleted; private chat, basic group, or a channel/supergroup with a cached access hash). The scheduler fills it on start and once a day. The query walksidx_messages_cache_fromfrom one sender to the next (recursive CTE): about 6 ms for 40,000 senders of 1.16M messages, against 200 ms for aDISTINCTover the messages.fetch_senders, one per chat with senders waiting, priority 4, in any chat mode (kept bytg chats syncand the startup cleanup, likerefetch_messages). It asks for up to 100 of those messages by ID (channels.getMessages/messages.getMessages, the existingfetchMessagesByIdRaw) and caches the full users of the reply (cachePageUsers); the users_cache insert re-indexes their messages through the Search: re-index older messages after a person or chat is renamed #93 queue. Messages aren't rewritten.senders, with no slot in the cycle: it only gets a slot when catch-up, first pages and history have nothing due, at the calm pace (a job every 3 s).asked_at; the daily scan lists them again 30 days later with their newest message then.tg status:progress.senders { missing, not_found }, in total and per account; pretty output shows a Senders Missing row (andN senders missingin the per-account line with several accounts).chats_cachekeeps only the account's own chats (sync-strategy.md).Why by ID
Made-up cache shaped like the issue (1.16M messages; 2,960 senders without a row, 37,193 messages = 3.2%, in 341 of 400 supergroups): 349 calls, 0.12 per missing sender, about 17 minutes at the calm pace. One
getHistorypage around each sender's message would take 588 calls even with this generator's clustered messages, and about one per sender when they are spread.users.getUsersneeds an access hash the cache doesn't have.Tests
src/__tests__/fetch-senders.test.ts(fake client): what the scan lists and skips; a job caches the sender andsender:aliciathen finds all three older messages after the re-index queue drains;messages.getMessagesfor a basic group; 30-day retry with the newest message;CHANNEL_PRIVATEmarks the senders asked; a retried error keeps them waiting; 100 per request; one job per chat, picked only after history, calm pace, kept when the chat is turned off; scan on start and once a day.src/__e2e__/status.e2e.test.ts:progress.sendersin JSON (total and per account) and the pretty row.bun run check; targeted unit/e2e suites (478 pass). No live Telegram in this change.🤖 Generated with Claude Code