Skip to content

Disable unused Telegram message history persistence in Redis#402

Merged
techeng322 merged 3 commits into
mainfrom
techengme/myc-5009-telegram-chat-bot-writes-unused-message-history-to-redis
Jul 9, 2026
Merged

Disable unused Telegram message history persistence in Redis#402
techeng322 merged 3 commits into
mainfrom
techengme/myc-5009-telegram-chat-bot-writes-unused-message-history-to-redis

Conversation

@techeng322

@techeng322 techeng322 commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • The Telegram chat adapter defaults persistMessageHistory to true, 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.
  • Nothing in this repo reads that history back (no LLM context use) — it was pure write waste that consumed 3MB/30MB (8.6%) of the Redis plan in a single day.
  • Forces persistMessageHistory = false on the adapter instance at runtime (field is readonly upstream but a plain mutable class field) so writes to msg-history:* stop, while leaving Redis state intact for its actual purpose (dedup locks for media group batching / burst synthesis).

Test plan

  • tsc --noEmit shows no errors for bot.ts
  • Deploy and confirm no new msg-history:telegram:* keys are created in Redis after a Telegram message is sent
  • Confirm dedup locks (media group batching) still work as before

Summary by CodeRabbit

  • Bug Fixes
    • Prevented chat messages from being stored indefinitely, reducing unnecessary backend data growth and keeping bot behavior more efficient.

techeng322 and others added 2 commits July 10, 2026 03:04
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>
@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
in-process-api Ready Ready Preview Jul 9, 2026 5:09pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@techeng322, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7d7666c6-7604-4588-9232-bcbd105d494d

📥 Commits

Reviewing files that changed from the base of the PR and between 21b2a6b and 2368c71.

📒 Files selected for processing (1)
  • src/lib/moment/__tests__/mapMetadataToSupabase.test.ts
📝 Walkthrough

Walkthrough

The Telegram chat bot factory function now explicitly disables the Telegram adapter's message history persistence by force-setting the persistMessageHistory field to false, preventing indefinite writes of incoming messages to Redis.

Changes

Disable Telegram Message History Persistence

Layer / File(s) Summary
Force-disable persistMessageHistory
src/lib/telegram/chat/bot.ts
Adds an in-function override that force-casts the Telegram adapter and sets its persistMessageHistory field to false, stopping message history writes to Redis.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: disabling unused Telegram message history persistence in Redis.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch techengme/myc-5009-telegram-chat-bot-writes-unused-message-history-to-redis

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b3cc3c and 21b2a6b.

📒 Files selected for processing (1)
  • src/lib/telegram/chat/bot.ts

Comment on lines +19 to +21
(
telegramAdapter as { persistMessageHistory: boolean }
).persistMessageHistory = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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.

Suggested change
(
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.

@techeng322 techeng322 merged commit 189ddf1 into main Jul 9, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant