Skip to content

feat(updates): add getDifference reason and unknown-peer diagnostics#1781

Merged
ernado merged 1 commit into
mainfrom
feat/updates-getdifference-diagnostics
Jun 15, 2026
Merged

feat(updates): add getDifference reason and unknown-peer diagnostics#1781
ernado merged 1 commit into
mainfrom
feat/updates-getdifference-diagnostics

Conversation

@ernado

@ernado ernado commented Jun 15, 2026

Copy link
Copy Markdown
Member

Motivation

Reports like #1623 ("some UpdateNewMessage updates are not received until I send a message myself") are hard to diagnose from logs. The updates package already logs gap detection in detail, but two crucial things were invisible:

  1. Why a getDifference fired — it is called from ~20 sites (startup, pts/qts/seq gap timeouts, idle timeout, the access-hash peer gates from feat(updates): force getDifference for updates referencing peers with unknown access hash #1738, updatesTooLong, seq-pts-changed, slice/too-long continuations, channel subscribe/too-long/idle) and every one logged the same bare "Getting difference".
  2. Which peer was unresolved — the feat(updates): force getDifference for updates referencing peers with unknown access hash #1738 access-hash gate (userPeersKnown) silently forced a getDifference with no record of the offending user, which is the exact signature of the "stranger messages me first" case.

Changes

  • Thread a reason string through getDifference/getDifferenceLogger for both the common (internalState) and channel (channelState) paths. The "Getting difference" log now includes the reason plus current pts/qts/seq/date (channel_id/pts for channels).
  • Log the offending user_id (and whether it was a hasher error vs. a cache miss) in userPeersKnown when an access hash is unknown.

A #1623-style trace now reads:

User access hash unknown, forcing getDifference  user_id=12345 hasher_error=false
Getting difference  reason=short-message-peer-access-hash-unknown pts=9001 qts=1 seq=42 date=...

reason values are stable kebab-case tokens (pts-gap-timeout, combined-peer-access-hash-unknown, channel-too-long, …) so they are greppable and could later back a metric label.

Notes

  • Diagnostics only — no behavior change to the state machine.
  • All new logging is at Debug level (one existing Error path also gets the reason), consistent with the package style; zero noise unless a debug logger is wired in.

Testing

  • go test ./telegram/updates/ passes
  • go build ./..., go vet, gofmt clean

🤖 Generated with Claude Code

Make update-stream resyncs traceable for issues like #1623 where a user
account stops receiving updates until it acts.

- Thread a reason string through getDifference/getDifferenceLogger for
  both the common and channel state; the "Getting difference" log now
  carries the reason plus current pts/qts/seq/date (channel_id/pts for
  channels), so every resync is attributable to its trigger.
- Log the offending user_id in userPeersKnown when an access hash is
  unknown, the exact signal behind a forced getDifference for an
  unresolved peer.

Diagnostics only, at Debug level; no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.57447% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.39%. Comparing base (4793972) to head (44f77ce).

Files with missing lines Patch % Lines
telegram/updates/state.go 64.00% 8 Missing and 1 partial ⚠️
telegram/updates/state_channel.go 43.75% 9 Missing ⚠️
telegram/updates/state_apply.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1781      +/-   ##
==========================================
+ Coverage   71.32%   71.39%   +0.06%     
==========================================
  Files         504      504              
  Lines       23625    23640      +15     
==========================================
+ Hits        16851    16878      +27     
+ Misses       5542     5533       -9     
+ Partials     1232     1229       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ernado ernado merged commit 0fc5db1 into main Jun 15, 2026
14 checks passed
@ernado ernado deleted the feat/updates-getdifference-diagnostics branch June 15, 2026 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant