Skip to content

fix(telegram): post stale/missed as new messages instead of editing bubble - #41

Merged
robster7674 merged 1 commit into
glucodroidfrom
fix/telegram-stale-post-send
Jun 9, 2026
Merged

fix(telegram): post stale/missed as new messages instead of editing bubble#41
robster7674 merged 1 commit into
glucodroidfrom
fix/telegram-stale-post-send

Conversation

@robster7674

Copy link
Copy Markdown
Owner

Root cause

TelegramStaleCheckWork used editMessageText to overwrite the glucose bubble with "⚠️ Stale" or "⚪ Missed reading" text. Once the bubble showed stale text, the suppress-delta logic (suppressDeltaBelowMgdl = 1) would suppress flat-glucose readings from re-editing it back to a glucose value — leaving the bubble stuck at "⚠️ Stale" indefinitely. Users saw this as "no telegram message".

Fix

Replace postEdit (editMessageText) with postSend (sendMessage). Stale/missed alerts now appear as new messages rather than overwriting the glucose bubble. The original bubble retains the last valid reading at all times.

Changes:

  • Rename postEditpostSend; drop editMessageText URL rewriting and message_id body field
  • Rename messageId guard to hasActiveBubble to reflect that the ID is used only as a sentinel, not passed to the API
  • Keep STALE_THROTTLE_MS = 70s, TRANSIENT_RETRY_DELAY_MS = 60s and retry scheduling from the previous PR

Test plan

  • CGM reading sends glucose bubble to Telegram
  • After stale threshold (~10 min), a new "⚠️ Stale" message appears; bubble still shows glucose value
  • Next CGM reading edits the bubble back to the new glucose value (within refresh window)
  • After missed threshold, a new "⚪ Missed reading." message appears
  • Transient network error retries after 60s; throttle prevents double-posting to already-notified recipients

🤖 Generated with Claude Code

…ubble

Previously TelegramStaleCheckWork edited the existing bubble in-place for
stale and missed transitions. This caused the last valid glucose reading to
be overwritten with "⚠️ Stale" text. When combined with the suppress-delta
logic (which suppresses flat-glucose readings from re-editing the bubble
back to a glucose value), the bubble would get stuck showing "⚠️ Stale"
indefinitely — appearing to the user as "no telegram message".

Now stale and missed alerts are posted as new sendMessage calls. The original
bubble retains the last reading, and each stale/missed event appears as a
distinct, timestamped message in the chat timeline. This is also more robust:
postSend cannot return "not modified" and does not require messageId manipulation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a "stuck at stale" bug where the suppress-delta logic prevented re-editing the Telegram glucose bubble back to a glucose value after editMessageText had overwritten it with a stale/missed alert. Stale and missed alerts now post as new messages, leaving the original bubble intact.

  • Replaces postEdit (editMessageText) with postSend (sendMessage): drops URL rewriting and the message_id request body field so only chat_id and text are sent.
  • Renames the messageId guard to hasActiveBubble to clarify that the stored message ID is now used only as a sentinel (to confirm at least one successful send has occurred) and is no longer forwarded to the API.

Confidence Score: 5/5

Safe to merge — the change is narrow, addresses a clearly reproducible user-visible defect, and preserves all existing retry and throttle logic.

The diff touches exactly one method: postEdit is replaced by postSend with the URL rewriting and message_id body field removed. The hasActiveBubble rename is cosmetic only and carries no behavioral change. Throttle constants, retry scheduling, and error-handling branches are unchanged. The root-cause explanation in the PR description matches what the code was doing, and the fix directly removes the problematic edit path.

No files require special attention.

Important Files Changed

Filename Overview
Common/src/main/java/tk/glucodata/TelegramStaleCheckWork.kt Minimal, well-scoped change: postEdit → postSend, URL rewriting removed, message_id body field dropped, messageId guard renamed to hasActiveBubble. Throttle, retry, and scheduling logic are preserved and correct.

Sequence Diagram

sequenceDiagram
    participant CGM as CGM Reading
    participant OA as OutboundApi
    participant TG as Telegram API
    participant SW as TelegramStaleCheckWork

    CGM->>OA: sendTelegram(reading)
    OA->>TG: sendMessage or editMessageText (bubble)
    TG-->>OA: ok + message_id
    OA->>SW: schedule(destinationId, staleDelayMs)

    Note over SW: stale threshold elapsed
    SW->>SW: hasActiveBubble check
    SW->>TG: sendMessage(Stale) - NEW message
    TG-->>SW: 2xx
    SW->>SW: recordStaleAt, reschedule for missed threshold

    Note over SW: missed threshold elapsed
    SW->>TG: sendMessage(Missed reading) - NEW message
    TG-->>SW: 2xx
    SW->>SW: recordStaleAt, no further reschedule

    Note over OA: next CGM reading arrives
    CGM->>OA: sendTelegram(reading)
    OA->>TG: editMessageText(bubble) - bubble still intact
    TG-->>OA: ok
Loading

Reviews (1): Last reviewed commit: "fix(telegram): post stale/missed as new ..." | Re-trigger Greptile

@robster7674
robster7674 merged commit 829849b into glucodroid Jun 9, 2026
5 checks passed
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