Repository navigation
feat!: cache a group's new messages only while the account takes part - #155
Merged
Merged
Conversation
A group (basic group or supergroup) adds new messages to the cache only while the account sent an ordinary message there in the last 90 days. The rule lives in one place, MessagesCache, so live updates, the dialog pass, every sync job, tg messages list/get (--fresh too) and tg send all follow it, whatever the tg chats sync mode. Cached messages stay and are still updated; private chats and channels are unchanged. - group_participation keeps the newest own message per group; group_capture_gaps keeps the pauses, so catch-up and history after a return skip them. An older cache gets its own messages as first facts. - After each dialog pass, one check_group_participation job per group searches for the newest own message of the last 90 days (catch-up lane, P4, usual retries and FLOOD_WAIT handling). - The scheduler queues no work for a group that isn't active and drops its pending jobs; a page whose group went off in flight moves nothing. A page with messages kept out records no history range. - tg messages list/get build API pages in memory, so they show Telegram's page whether the cache took it or not. - tg chats list/sync show group_participation_required/_unknown and lastOwnMessageAt; tg status leaves paused groups out of its progress. BREAKING CHANGE: groups without an own message in the last 90 days no longer add messages to the cache, in any sync mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rticipation rule Resolving a @username kept only the input peer, so a broadcast channel new to the cache had no type, counted as a group and its first page was not cached. Cache the resolved chat (not a min one) before its messages are written, as `tg chats get` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
contacts.resolveUsername carries no last message and often no member count, so the cache upsert cleared what the dialog pass had stored. Co-Authored-By: Claude Opus 5.5 <[email protected]>
neoromantic
marked this pull request as ready for review
November 14, 2026 01:10
…ps, ID offset, header) The merge already runs under the write lock, so the upsert is a plain INSERT OR REPLACE. One schema check helper, the shared channel ID offset, and history progress reads pauses in its own query instead of hasGaps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…worker gate, accurate PAUSED comment CacheWriteResult counts written messages instead of listing them; every caller used only the length. The worker gate reuses CHAT_INDEPENDENT_JOB_TYPES instead of a second list of capture jobs, and the PAUSED comment no longer claims what the write did. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le-row MessagesHistory.get, inline withSync cacheHistoryResponse builds page rows with ChatsCache.getById (one lookup) and UsersCache.getById instead of ad-hoc queries. MessagesHistory.getMany becomes get(chatId, messageId), its only use. chats list inlines withSync into toItem. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…se fixture helpers The e2e now checks the sender and that no history range is recorded, then caches the page once the account took part, in one test. The unit copy of the page test goes. Chat and photo fixtures use fakeDialog, dialogToCacheInput, photoMessage and takePartIn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop takePartIn calls that changed nothing (repeated after a schema init, or before writes to DMs only) and trim the rest to the groups whose messages each test caches. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ement of the rule Other docs, the changelog entry and daemon-bootstrap comments link to the section instead of restating the 90-day rule, its writers and scheduling. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…articipation The Pauses bullet says again that a pause ends at the newest own message the search finds, and the date source says nothing of the search is cached. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… in the changelog The Unreleased entry lists the commands the rule covers instead of "every mode", and says the daemon sends one search per group after each dialog pass. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keep the participation rule in the new paths: the chats list output declaration gets the group_participation reasons and lastOwnMessageAt, live messages still note the chat's newest message, and wait/watch docs say a paused group shows nothing. New tests that write group messages take part in those groups.
neoromantic
added a commit
that referenced
this pull request
Nov 18, 2026
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. fetch.ts: the batch fetch is built on main's shared fetchMessagesByIdRaw, with the peer check kept. README and CHANGELOG: both sides' entries kept. Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. README and CHANGELOG: both sides kept. main dropped MessagesHistory.getMany (neoromantic#174): the item is read with get. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. history.ts and two test files: imports of both sides. CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. skill.ts: main's shared getErrorMessage, the manifest stays removed. CHANGELOG: both sides kept. Fixture groups take part in the tests: main caches a group's new messages only while the account writes there (neoromantic#155). Co-Authored-By: Claude Fable 5.2 <[email protected]>
ertembiyik
added a commit
to ertembiyik/telegram-sync-cli
that referenced
this pull request
Nov 18, 2026
main now has neoromantic#175 (neoromantic#194), neoromantic#174 and neoromantic#155. helpers.ts: the item reader takes main's raw string, with the transcript kept. sql.test.ts uses main's cache helper. CHANGELOG: both sides kept. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This was referenced Nov 18, 2026
Merged
This was referenced Nov 18, 2026
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.
What
A group (basic group or supergroup) adds new messages to the cache only while the account sent an ordinary message there in the last 90 days. Reading a group doesn't count. The rule holds in every path and every
tg chats syncmode; cached messages stay; private chats and channels are unchanged.MessagesCache.upsert/upsertBatchcount own ordinary messages first (oldest first), then insert a new row only ifGroupParticipation.canInsertallows it; cached rows are always updated. Rejected messages write nothing (no attachment row, no search index row). The write returns{ accepted, inserted, skipped }, and counters useinserted.group_participation(newest own message, first check) andgroup_capture_gaps(pauses[start, end)). Merges never lower the date or reopen a pause. An older cache gets its own messages as first facts, once.check_group_participationjob per group (archived ones too, not channels) runsmessages.searchwithfromId: inputPeerSelf,minDate: now - 90 days, in the catch-up lane at P4 with the usual retries and FLOOD_WAIT handling. An error records nothing. The dialog list's own newest message counts at once.top_message_id = NULLfor a catch-up from its old cursor.tg messages list/getbuild API pages in memory, so they show Telegram's page whether the cache took it or not (same output).tg sendresumes a group without a daemon update.tg chats list/syncshowsyncReason: group_participation_required | group_participation_unknownandlastOwnMessageAt;syncEnabledreflects participation.tg statusleaves paused groups out of its counts and history progress, and ignores Telegram's count for a group with a pause.Docs: README,
docs/sync-strategy.md(new section),real-time.md,caching.md,database-schema.md,cli-commands.md,daemon.md, AGENTS project rules, CHANGELOG Unreleased.Checks
Latest head: merged with
main, then simplified after a review of the whole PR. The simplifications cut about 210 lines: a shorterGroupParticipation,CacheWriteResult.written, page rows from the cache getters, one test per behaviour, anddocs/sync-strategy.md#group-participationas the one full statement of the rule.bun run check: passbun run test: 2270 pass, 0 failbun run test:e2e: 376 pass, 0 fail, including the replay test formessages list --freshon a group without participationbun run build: passbun run test:integration: not verified. The test session answers401 AUTH_KEY_UNREGISTERED, and its re-login is in progress separately.Cleanup of pre-existing code is stacked on this PR in #174.
🤖 Generated with Claude Code