Skip to content

fix(bot): bound player track state with LRU + 30min TTL - #773

Merged
LucasSantana-Dev merged 2 commits into
mainfrom
fix/player-track-state-lru
Apr 22, 2026
Merged

LucasSantana-Dev merged 2 commits into
mainfrom
fix/player-track-state-lru

Conversation

@LucasSantana-Dev

Copy link
Copy Markdown
Owner

Summary

  • Swaps the three per-guild player-state Maps in packages/bot/src/handlers/player/trackHandlers.ts (lastPlayedTracks, guildTrackStartTimes, recentlyPlayedTracks) to LRUCache with max: MAX_GUILD_ENTRIES and a 30-minute TTL (updateAgeOnGet: true).
  • Matches the pattern already in packages/bot/src/utils/music/duplicateDetection/types.ts — lru-cache ^10.4.3 is already a @lucky/bot dependency.
  • Drops the manual eviction block for lastPlayedTracks (LRU handles size + idle eviction). Keeps the per-guild list trim for recentlyPlayedTracks because each entry is itself a list whose length is independent of the cache key count.

Why

Long-running bot instances would grow these Maps without bound as guilds rotated through playback. LRU + TTL caps memory and evicts idle guilds after 30 min. Existing callers read these as Map-compatible (.get, .set, .delete, .has, .entries()) — LRUCache exposes the same API.

Out of scope / follow-ups

  • duplicateDetection/types.ts exports identically-named lastPlayedTracks / recentlyPlayedTracks as a separate LRU cache instance. Pre-existing duplication; consolidating the two is a larger refactor.
  • Seven unrelated tsc --noEmit errors in @lucky/bot are pre-existing on main (reactionroleHandlers, applyPlan, guildMemberUpdate, interactionHandler, eventHandler, captureGuildState).

Test plan

  • npx jest --testPathPatterns trackHandlers — 20/20 pass.
  • CI: Sonar + typecheck + full bot suite.

🤖 Generated with Claude Code

Swap the three per-guild player-state Maps in trackHandlers
(`lastPlayedTracks`, `guildTrackStartTimes`, `recentlyPlayedTracks`)
to `LRUCache` with `max: MAX_GUILD_ENTRIES` and a 30-minute TTL
with `updateAgeOnGet`. Matches the pattern already used in
`utils/music/duplicateDetection/types.ts`.

Prevents unbounded memory growth on long-running bot instances
and drops the manual eviction block for `lastPlayedTracks` (LRU
handles size + idle eviction). Manual per-guild list trim for
`recentlyPlayedTracks` stays because each entry is a list whose
size is independent of the cache's key count.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Apr 22, 2026 0:13am

Request Review

@LucasSantana-Dev
LucasSantana-Dev enabled auto-merge (squash) April 22, 2026 11:53
@coderabbitai

coderabbitai Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@LucasSantana-Dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 33 minutes and 1 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 33 minutes and 1 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d82590e-bcaa-448a-b2bd-c32fa1d9994a

📥 Commits

Reviewing files that changed from the base of the PR and between 7f41018 and 118b00b.

📒 Files selected for processing (2)
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/player-track-state-lru

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 and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 2a4d1e5 into main Apr 22, 2026
12 checks passed
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
Swap the three per-guild player-state Maps in trackHandlers
(`lastPlayedTracks`, `guildTrackStartTimes`, `recentlyPlayedTracks`)
to `LRUCache` with `max: MAX_GUILD_ENTRIES` and a 30-minute TTL
with `updateAgeOnGet`. Matches the pattern already used in
`utils/music/duplicateDetection/types.ts`.

Prevents unbounded memory growth on long-running bot instances
and drops the manual eviction block for `lastPlayedTracks` (LRU
handles size + idle eviction). Manual per-guild list trim for
`recentlyPlayedTracks` stays because each entry is a list whose
size is independent of the cache's key count.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/player-track-state-lru branch May 14, 2026 02:02

This branch was successfully deployed

1 active deployment
Preview — 118b00b9 Deployed Apr 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant