fix: recover Telegram sends from stale thread ids#12293
Merged
Conversation
Contributor
Author
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.
Summary
message_thread_idwhen Telegram returns400: Bad Request: message thread not foundupdateLastRoutereceives an explicit no-thread delivery contextWhy
The
messagetool could carry stale Telegram thread IDs after topic/forum toggles, causing proactive sends to fail withmessage thread not found.Fixes #11620.
Testing
pnpm checkpnpm vitest src/telegram/send.returns-undefined-empty-input.test.ts src/config/sessions.test.tsGreptile Overview
Greptile Summary
This PR hardens Telegram outbound sends against stale forum-topic thread IDs by retrying text/media/sticker sends once without
message_thread_idwhen Telegram replies with400: Bad Request: message thread not found. It also updates session routing persistence so an explicitly “no-thread” delivery context clears previously persisted thread IDs (instead of inheriting stale state), and adds a changelog entry for #11620.Key touchpoints:
src/telegram/send.tswraps send attempts with a targeted threadless retry while preserving existing behavior for other Telegram errors.src/config/sessions/store.tschangesupdateLastRoutemerge behavior to optionally drop threadId from the fallback (existing session) route.src/telegram/send.returns-undefined-empty-input.test.tsandsrc/config/sessions.test.tscover the new retry and clearing semantics.Confidence Score: 3/5
updateLastRoute’s new “explicit no-thread clears stale threadId” logic depends onhasOwnProperty('threadId')on the raw deliveryContext, while normalization drops undefined threadId keys. Callers that indicate no-thread viathreadId: undefinedmay not actually clear the persisted thread, undermining the main fix. There’s also a smaller robustness issue where the thread-not-found retry wrapper can be triggered even whenmessage_thread_idis present-but-undefined, leading to redundant retries/logging.