← Back to PRs

#21232: fix(heartbeat): preserve real delivery target in session context

by sleitor open 2026-02-19 20:18 View on GitHub →
size: XS
## Problem Heartbeat runner sets `ctx.To = sender`, where `sender` is resolved by `resolveHeartbeatSenderId`. When no allowFrom candidates match, sender falls back to the literal string `"heartbeat"`. `reply/session.ts` then persists this as `lastTo` in the session store: ```typescript const lastToRaw = ctx.OriginatingTo || ctx.To || baseEntry?.lastTo; ``` For **forum-topic sessions**, this corrupts the delivery context: `lastTo` becomes `"heartbeat"` instead of the real Telegram chat id. Subsequent cron announce delivery fails because `resolveDeliveryTarget` cannot resolve a valid outbound target. Fixes #21235 ## Fix Set `OriginatingChannel`, `OriginatingTo`, `AccountId`, and `MessageThreadId` on the heartbeat message context from the resolved delivery target. `reply/session.ts` already prefers `OriginatingTo` over `ctx.To`, so the real chat id is now preserved across heartbeat runs. ## Changes - `src/infra/heartbeat-runner.ts`: Add originating delivery fields to heartbeat message context

Most Similar PRs