Disable unused Telegram message history persistence in Redis#402
Conversation
The telegram chat adapter defaults persistMessageHistory to true, which writes every message to Redis (msg-history:telegram:<chatId>, up to 100 messages/thread, 7-day TTL) even though nothing in this repo reads that history back. This was pure write waste that consumed 3MB/30MB (8.6%) of the Redis plan in a single day after Redis state was connected for dedup locks. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Telegram chat bot factory function now explicitly disables the Telegram adapter's message history persistence by force-setting the ChangesDisable Telegram Message History Persistence
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/telegram/chat/bot.ts`:
- Around line 19-21: The assignment in bot.ts that sets
telegramAdapter.persistMessageHistory to false should be followed by a runtime
check so startup fails if the property is no longer writable. Update the bot
initialization logic around telegramAdapter to verify the value actually changed
after the assignment, and throw or log an explicit error if it did not. Use the
existing telegramAdapter setup in the chat/bot.ts flow so the assertion sits
immediately after the persistMessageHistory write.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4bfd75c0-3cb0-44ab-b4b4-a6fd64ce8add
📒 Files selected for processing (1)
src/lib/telegram/chat/bot.ts
| ( | ||
| telegramAdapter as { persistMessageHistory: boolean } | ||
| ).persistMessageHistory = false; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Add a runtime assertion to catch silent failure if the field becomes non-writable.
The cast bypasses the readonly type constraint, which is intentional and well-documented. However, if the upstream library later changes persistMessageHistory to a getter-only or non-writable property, the assignment at line 21 would silently fail — no error thrown, but Redis history writes would resume unnoticed. A post-assignment assertion would catch this at startup.
🛡️ Suggested defensive assertion
(
telegramAdapter as { persistMessageHistory: boolean }
).persistMessageHistory = false;
+ if (
+ (telegramAdapter as { persistMessageHistory: boolean }).persistMessageHistory !== false
+ ) {
+ throw new Error(
+ 'Failed to disable persistMessageHistory on Telegram adapter — field may be non-writable'
+ );
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ( | |
| telegramAdapter as { persistMessageHistory: boolean } | |
| ).persistMessageHistory = false; | |
| ( | |
| telegramAdapter as { persistMessageHistory: boolean } | |
| ).persistMessageHistory = false; | |
| if ( | |
| (telegramAdapter as { persistMessageHistory: boolean }).persistMessageHistory !== false | |
| ) { | |
| throw new Error( | |
| 'Failed to disable persistMessageHistory on Telegram adapter — field may be non-writable' | |
| ); | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lib/telegram/chat/bot.ts` around lines 19 - 21, The assignment in bot.ts
that sets telegramAdapter.persistMessageHistory to false should be followed by a
runtime check so startup fails if the property is no longer writable. Update the
bot initialization logic around telegramAdapter to verify the value actually
changed after the assignment, and throw or log an explicit error if it did not.
Use the existing telegramAdapter setup in the chat/bot.ts flow so the assertion
sits immediately after the persistMessageHistory write.
Summary
persistMessageHistorytotrue, so every inbound/outbound message was written to Redis (msg-history:telegram:<chatId>, up to 100 messages/thread, 7-day rolling TTL) after Redis state was connected for dedup locks.persistMessageHistory = falseon the adapter instance at runtime (field isreadonlyupstream but a plain mutable class field) so writes tomsg-history:*stop, while leaving Redis state intact for its actual purpose (dedup locks for media group batching / burst synthesis).Test plan
tsc --noEmitshows no errors forbot.tsmsg-history:telegram:*keys are created in Redis after a Telegram message is sentSummary by CodeRabbit