feat: auto-follow basic group → supergroup target migration#9
Merged
Conversation
When a forward target is a basic group that has been upgraded to a supergroup, its id changes (e.g. -4187363166 → -100…) and Telegram rejects forwards with CHANNEL_INVALID/PEER_ID_INVALID. Previously this surfaced as a recurring "Forward failed" error on every source message and required a manual `group edit`. The forwarder now probes such a failed target with getChat: if it was migrated, the new supergroup id is written back to the config and the forward is retried transparently on the new id; a still-healthy target re-raises the original error (it was not the cause); an unreachable target is retired for the session and skipped silently after one warning. - filter.ts: add replacePeer (swap a stored peer id, dedupe) - queue.ts: add SkippedForward sentinel so a deliberate skip is recorded as 'skipped' (warning) rather than 'failed' (error) - forwarder.ts: forwardOne/probeTarget migration handling, injectable persistConfig, per-session deadTargets set, isInvalidTargetError - tests for replacePeer and isInvalidTargetError
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.
Problem
When a forward target is a basic group that later gets upgraded to a
supergroup, its id changes (e.g.
-4187363166→-100…). Telegram thenrejects every forward to the stale id with
CHANNEL_INVALID/PEER_ID_INVALID. Before this change that surfaced as a recurringForward failederror on every source message, and the only fix was tomanually re-run
group edit.What changed
The forwarder now recovers from this automatically. When a forward fails
with an invalid-target error, it probes the target with
getChat:the forward transparently on the new id (logged once, info level).
target was not the cause, so a good target is never wrongly retired.
SkippedForward) and skipit silently after a single warning, instead of spamming the log on every
source message.
FloodWait, deleted-message, and transient network errors are unaffected —
they still flow to the queue's existing retry logic.
Details
filter.ts: addreplacePeer(swap a stored peer id, preserving orderand dropping duplicates).
queue.ts: addSkippedForwardsentinel so a deliberate skip isrecorded as
skipped(warning) rather thanfailed(error).forwarder.ts:forwardOne/probeTargetmigration handling,injectable
persistConfig(defaults to saving the real config),per-session
deadTargetsset, andisInvalidTargetError.Tests
replacePeer: swap / no-op / dedupe / empty.isInvalidTargetError: matches the invalid-peer codes byerrorMessageand message string, and does not swallow FloodWait or deleted-message
errors.
pnpm typecheck,pnpm lint,pnpm test(61 passed),pnpm build, andpnpm knipall pass.