#21232: fix(heartbeat): preserve real delivery target in session context
size: XS
Cluster:
Session Management Enhancements
## 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
#23759: fix: prevent heartbeat/internal providers from corrupting session l...
by kami-saia · 2026-02-22
69.7%
#12837: fix(heartbeat): suppress HEARTBEAT_OK token delivery
by JBrady · 2026-02-09
69.4%
#20948: fix: propagate accountId from heartbeat delivery context to agent run
by odrobnik · 2026-02-19
68.3%
#23521: heartbeat: prevent model-override from bleeding into main session s...
by harshang03 · 2026-02-22
66.5%
#14241: fix(heartbeat): propagate originating session key for exec event qu...
by aldoeliacim · 2026-02-11
64.0%
#22277: fix: prevent heartbeat model override from bleeding into main session
by zhangjunmengyang · 2026-02-21
63.9%
#21014: fix(cron): suppress main-session summary for HEARTBEAT_OK responses
by nickjlamb · 2026-02-19
63.3%
#9429: fix: skip session model override for heartbeat runs
by dbottme · 2026-02-05
62.4%
#21615: fix(tui): preserve main session model during heartbeat model override
by lailoo · 2026-02-20
62.2%
#21682: fix(heartbeat): propagate sessionKey in exec/hooks to fix async con...
by eviaaaaa · 2026-02-20
61.9%