18
110
Fork
You've already forked Telethon
30

WIP: SenderPool pop_updates #49

Draft
HBcao wants to merge 4 commits from HBcao/Telethon:updates into v2
pull from: HBcao/Telethon:updates
merge into: Lonami:v2
Lonami:v1
Lonami:v2
Lonami:gh-pages
Lonami:asyncio-protocol-attempt
Lonami:fix-step-hang-until-timeout
Contributor
Copy link
  • Add method SenderPool::pop_updates().
  • Re-added the MessageBox and ChatHashes that I deleted in my last PR.
  • Make the process_socket_updates function asynchronous
  • I only did a simple test of events.Raw and events.NewMessage. The test scripts need to be added (I don't really like writing them).

By the way, should we remove unused PySender python bindings? By doing this, we can remove the dependency on grammers-tl-types.

- Add method `SenderPool::pop_updates()`. - Re-added the MessageBox and ChatHashes that I deleted in my last PR. - Make the `process_socket_updates` function asynchronous - I only did a simple test of `events.Raw` and `events.NewMessage`. The test scripts need to be added (I don't really like writing them). By the way, should we remove unused `PySender` python bindings? By doing this, we can remove the dependency on `grammers-tl-types`.
Lonami left a comment
Copy link

Thanks for the huge amount of work once again.

But from experience update handling is very tricky, and I would really prefer if there was a single source of truth that was able to handle update ordering and gaps correctly. That being grammers-session.

So currently I haven't reviewed any file under message_box/, because I would prefer if we could instead bridge most functionality to grammers. Or even have grammers give us the processed updates in order instead of duplicating that functionality in Telethon.

We would still need to duplicate some of the logic to Python (perhaps a good chunk of Client::next_raw; depends who performs the requests) because we still need a way for Python to initiate the process to getDifference but we would still be reusing a lot more.

Thanks for the huge amount of work once again. But from experience update handling is very tricky, and I would really prefer if there was a single source of truth that was able to handle update ordering and gaps correctly. That being grammers-session. So currently I haven't reviewed any file under `message_box/`, because I would prefer if we could instead bridge most functionality to grammers. Or even have grammers give us the processed updates in order instead of duplicating that functionality in Telethon. We would still need to duplicate some of the logic to Python (perhaps a good chunk of [`Client::next_raw`](https://codeberg.org/Lonami/grammers/src/commit/c34290345a4636ff689cec312e655419e5972609/grammers-client/src/client/updates.rs#L105); depends who performs the requests) because we still need a way for Python to initiate the process to `getDifference` but we would still be reusing a lot more.
@ -16,6 +17,13 @@ if TYPE_CHECKING:
UPDATE_LIMIT_EXCEEDED_LOG_COOLDOWN = 300
UpdatesLike: TypeAlias = (
Owner
Copy link

There's some more we need to worry about, see grammers-session/src/message_box/defs:UpdatesLike.

There's some more we need to worry about, see [grammers-session/src/message_box/defs:UpdatesLike](https://codeberg.org/Lonami/grammers/src/commit/c34290345a4636ff689cec312e655419e5972609/grammers-session/src/message_box/defs.rs#L133).
@ -0,0 +5,4 @@
from ..session import Session
class ChatHashCache:
Owner
Copy link

I think this class is flawed sadly. I also had it in grammers where I tried to be more thorough but it was quite hellish to make sure the code looked absolutely everywhere...

I am also not sure this is the correct approach. I haven't tested this but I don't believe Telegram would send every hash for every peer referenced in an update (some might be very deeply and perhaps for some you're not supposed to know about them).

I think the more correct approach is to make it easier to re-fetch an update (with getDifference) if they believe doing so would give them the peer they are missing. And, Telethon (and grammers) could do some basic checks (peer / sender / forwarder) and auto-refetch based on those.

But definitely not as far as going into places like notify peers.

I think this class is flawed sadly. I also had it in grammers where I tried to be more thorough but it was quite hellish to make sure the code looked absolutely everywhere... I am also not sure this is the correct approach. I haven't tested this but I don't believe Telegram would send *every* hash for every peer referenced in an update (some might be very deeply and perhaps for some you're not supposed to know about them). I think the more correct approach is to make it easier to re-fetch an update (with `getDifference`) if they believe doing so would give them the peer they are missing. And, Telethon (and grammers) could do some basic checks (peer / sender / forwarder) and auto-refetch based on those. But definitely not as far as going into places like notify peers.
Author
Contributor
Copy link

@Lonami wrote in #49 (comment):

Thanks for the huge amount of work once again.

But from experience update handling is very tricky, and I would really prefer if there was a single source of truth that was able to handle update ordering and gaps correctly. That being grammers-session.

So currently I haven't reviewed any file under message_box/, because I would prefer if we could instead bridge most functionality to grammers. Or even have grammers give us the processed updates in order instead of duplicating that functionality in Telethon.

We would still need to duplicate some of the logic to Python (perhaps a good chunk of Client::next_raw; depends who performs the requests) because we still need a way for Python to initiate the process to getDifference but we would still be reusing a lot more.

I don't have in-depth knowledge of updates, so I can only make as few changes as possible to the existing code in v2. I shouldn't have removed the message_box in the last PR, which makes this PR seem like it did a lot of work.

@Lonami wrote in https://codeberg.org/Lonami/Telethon/pulls/49#issuecomment-19138382: > Thanks for the huge amount of work once again. > > But from experience update handling is very tricky, and I would really prefer if there was a single source of truth that was able to handle update ordering and gaps correctly. That being grammers-session. > > So currently I haven't reviewed any file under `message_box/`, because I would prefer if we could instead bridge most functionality to grammers. Or even have grammers give us the processed updates in order instead of duplicating that functionality in Telethon. > > We would still need to duplicate some of the logic to Python (perhaps a good chunk of [`Client::next_raw`](https://codeberg.org/Lonami/grammers/src/commit/c34290345a4636ff689cec312e655419e5972609/grammers-client/src/client/updates.rs#L105); depends who performs the requests) because we still need a way for Python to initiate the process to `getDifference` but we would still be reusing a lot more. I don't have in-depth knowledge of updates, so I can only make as few changes as possible to the existing code in v2. I shouldn't have removed the message_box in the last PR, which makes this PR seem like it did a lot of work.

All the more reason to try to reuse more from grammers then.

Telethon v1 barely did any proper update handling for the longest time. Then came grammers, then Telethon v2. But Telethon v2 stopped receiving changes from me while grammers' update handling continued to evolve.

So I think we should use as much from grammers as possible. This means no Python implementation of the message box (unless we ported it anew from grammers, but that would mean maintaining the logic twice). So rather, I suggest another bridge to grammers' MessageBox.

All the more reason to try to reuse more from grammers then. Telethon v1 barely did any proper update handling for the longest time. Then came grammers, then Telethon v2. But Telethon v2 stopped receiving changes from me while grammers' update handling continued to evolve. So I think we should use as much from grammers as possible. This means no Python implementation of the message box (unless we ported it anew from grammers, but that would mean maintaining the logic twice). So rather, I suggest another bridge to grammers' MessageBox.
Author
Contributor
Copy link

@Lonami wrote in #49 (comment):

All the more reason to try to reuse more from grammers then.

Telethon v1 barely did any proper update handling for the longest time. Then came grammers, then Telethon v2. But Telethon v2 stopped receiving changes from me while grammers' update handling continued to evolve.

So I think we should use as much from grammers as possible. This means no Python implementation of the message box (unless we ported it anew from grammers, but that would mean maintaining the logic twice). So rather, I suggest another bridge to grammers' MessageBox.

Okay, bridge MessageBoxes and UpdateStream.

Should I commit directly under this PR or create a new PR?

@Lonami wrote in https://codeberg.org/Lonami/Telethon/pulls/49#issuecomment-19229252: > All the more reason to try to reuse more from grammers then. > > Telethon v1 barely did any proper update handling for the longest time. Then came grammers, then Telethon v2. But Telethon v2 stopped receiving changes from me while grammers' update handling continued to evolve. > > So I think we should use as much from grammers as possible. This means no Python implementation of the message box (unless we ported it anew from grammers, but that would mean maintaining the logic twice). So rather, I suggest another bridge to grammers' MessageBox. Okay, bridge MessageBoxes and UpdateStream. Should I commit directly under this PR or create a new PR?
HBcao changed title from (削除) SenderPool pop_updates (削除ここまで) to WIP: SenderPool pop_updates 2026年07月15日 13:48:21 +02:00
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u updates:HBcao-updates
git switch HBcao-updates

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch v2
git merge --no-ff HBcao-updates
git switch HBcao-updates
git rebase v2
git switch v2
git merge --ff-only HBcao-updates
git switch HBcao-updates
git rebase v2
git switch v2
git merge --no-ff HBcao-updates
git switch v2
git merge --squash HBcao-updates
git switch v2
git merge --ff-only HBcao-updates
git switch v2
git merge HBcao-updates
git push origin v2
Sign in to join this conversation.
No reviewers
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Lonami/Telethon!49
Reference in a new issue
Lonami/Telethon
No description provided.
Delete branch "HBcao/Telethon:updates"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?