← Back to PRs

#16996: fix(cron): parse Telegram topic target format for announce delivery

by Glucksberg open 2026-02-15 09:18 View on GitHub →
size: S experienced-contributor
Fixes #15787 ## Problem Cron jobs with `delivery.mode: "announce"` targeting Telegram forum topics (e.g. `-1001234567890:topic:123`) silently fail to deliver messages — the job runs successfully but no message reaches Telegram. This happens because the `:topic:NNN` suffix in the target string is never parsed to extract the `messageThreadId`, so the Telegram API call omits the required thread ID parameter. ## Fix Parse the Telegram topic target format at two resolution points using the existing `parseTelegramTarget()` helper: 1. **`src/cron/isolated-agent/delivery-target.ts`** — When resolving the delivery target for isolated cron jobs, extract `messageThreadId` from the `to` field if the channel is `telegram`. The extracted thread ID takes priority over stale session-stored thread IDs. 2. **`src/infra/outbound/targets.ts`** (`resolveSessionDeliveryTarget`) — Same extraction at the session-level target resolver, ensuring explicit topic targets are correctly resolved regardless of the code path. ## Changes - `src/cron/isolated-agent/delivery-target.ts` — Import `parseTelegramTarget`, extract `threadIdFromTarget` from candidate `to` value, use it with highest priority in the `threadId` resolution chain. - `src/infra/outbound/targets.ts` — Same pattern in `resolveSessionDeliveryTarget`: parse explicit `to` for topic thread ID before falling back to stored/explicit values. - `src/cron/isolated-agent/delivery-target.test.ts` — New test: verifies explicit topic targets preserve the thread ID through delivery resolution. - `src/infra/outbound/targets.test.ts` — New test: verifies `resolveSessionDeliveryTarget` extracts topic thread ID from explicit Telegram targets. ## Testing All 4 test cases pass (2 new + 2 existing). The fix is minimal (81 lines) and reuses the existing `parseTelegramTarget` utility — no new parsing logic introduced. <!-- greptile_comment --> <h3>Greptile Summary</h3> Fixes cron job `delivery.mode: "announce"` failures when targeting Telegram forum topics (format `-1001234567890:topic:123`). Previously, messages failed silently because the `:topic:NNN` suffix wasn't parsed, so the required `messageThreadId` parameter was omitted from API calls. The fix reuses the existing `parseTelegramTarget()` utility at two resolution points: - `src/cron/isolated-agent/delivery-target.ts` — Extracts `messageThreadId` from explicit `to` targets during isolated cron delivery resolution - `src/infra/outbound/targets.ts` — Same extraction in `resolveSessionDeliveryTarget` to cover all code paths Thread ID priority: explicit target > stored session thread ID (only when target matches). This prevents stale thread IDs from being sent to different targets. Tests added for both resolution points verify topic thread ID extraction. Changes are minimal (81 lines) and use existing parsing logic. <h3>Confidence Score: 5/5</h3> - Safe to merge — focused bug fix with test coverage - The fix is minimal, well-tested, and reuses existing utilities. The logic correctly prioritizes parsed thread IDs over stale session values, preventing API errors. The implementation mirrors patterns already used elsewhere in the codebase (`message-action-params.ts`, `outbound-session.ts`). - No files require special attention <sub>Last reviewed commit: f9c1c28</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs