#14488: Fix Telegram default account listing and CLI cache-write usage mapping
channel: telegram
agents
stale
size: S
## Summary
- include the `default` Telegram account in `listTelegramAccountIds()` whenever top-level `channels.telegram.botToken` or `tokenFile` is configured, even when named accounts exist
- map Anthropic `cache_creation_input_tokens` to CLI `cacheWrite` usage in `parseCliJson()` / `parseCliJsonl()` so usage + cost reporting is accurate
- add focused regression tests for both fixes in `src/telegram/accounts.test.ts` and new `src/agents/cli-runner.helpers.test.ts`
## Test plan
- [x] `pnpm lint`
- [x] `pnpm exec vitest run src/telegram/accounts.test.ts src/agents/cli-runner.helpers.test.ts`
## Linked issues
- fixes #14366
- fixes #14454
## Notes
- AI-assisted: yes
Made with [Cursor](https://cursor.com)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adjusts two areas:
- **CLI runner usage parsing**: `toUsage()` now maps Anthropic’s `cache_creation_input_tokens` field into the internal `usage.cacheWrite` field so usage/cost reporting counts cache writes correctly.
- **Telegram account enumeration**: `listTelegramAccountIds()` now includes the implicit `default` Telegram account when a top-level `channels.telegram.botToken` or `tokenFile` is configured, even if named accounts exist. This is used by onboarding/inline-buttons flows and other account selection logic.
It also adds targeted Vitest coverage for both behaviors (`src/agents/cli-runner.helpers.test.ts`, `src/telegram/accounts.test.ts`).
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk.
- Changes are small, targeted, and consistent with existing normalization logic (e.g., usage.ts already maps cache_creation_input_tokens). Telegram default-account inclusion is gated on an actual configured top-level token source, preventing spurious IDs while fixing missing-default listings. Added focused tests cover the regressions.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#14359: fix: prefer named Telegram account over orphan 'default' in binding...
by itsGustav · 2026-02-12
85.1%
#8694: Fix Telegram routing when token override omits accountId
by codvik · 2026-02-04
81.7%
#23238: fix(telegram): account named "default" silently breaks inbound polling
by anillBhoi · 2026-02-22
80.7%
#11347: fix: scope Telegram update offset to bot token
by anooprdawar · 2026-02-07
80.2%
#14483: fix(cli-runner): map Anthropic cache_creation_input_tokens
by AlexAnys · 2026-02-12
79.6%
#8166: fix(telegram): lifecycle fixes for duplicate messages and auto-reco...
by cheenu1092-oss · 2026-02-03
79.4%
#8507: fix: preserve accountId for multi-account agent-to-agent messaging
by djh58 · 2026-02-04
79.0%
#6463: fix(telegram): improve timeout handling and prevent channel exits
by ai-fanatic · 2026-02-01
79.0%
#12936: fix(telegram): omit message_thread_id for private DM chats
by omair445 · 2026-02-09
78.2%
#3186: fix(telegram): sanitize update offset + lock polling
by daxiong888 · 2026-01-28
77.9%