Skip to content

fix(bot): harden player retry and bridge fallbacks - #550

Merged
LucasSantana-Dev merged 3 commits into
mainfrom
fix/player-replenish-logging
Apr 11, 2026
Merged

LucasSantana-Dev merged 3 commits into
mainfrom
fix/player-replenish-logging

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Apr 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Log failed player replenishment retries and logger failures instead of swallowing them silently.
  • Centralize queue metadata typing and replace local IQueueMetadata drift across player/music paths.
  • Skip SoundCloud bridge fallback stages when provider health has SoundCloud in cooldown.

Verification

  • npm run lint exited 0.
  • npm run build exited 0.
  • npm run test:all exited 0 after rerun with local listener permissions: shared 257, backend 678, bot 1877, frontend 476 tests passed.
  • npm run audit:high exited 0 with 0 vulnerabilities.

Note: the first sandboxed npm run test:all run failed in backend Supertest with listen EPERM: operation not permitted 0.0.0.0; rerunning with approved permissions passed.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added provider health checks to prevent fallback attempts when music providers are unavailable.
  • Bug Fixes

    • Enhanced error logging to capture failures in error handlers and queue replenishment retries.
    • Improved stream creation resilience by short-circuiting unavailable provider fallbacks.
  • Tests

    • Added test coverage for error-handler guards and provider availability scenarios.

@vercel

vercel Bot commented Apr 11, 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 11, 2026 1:18am

Request Review

@github-actions github-actions Bot added the bot label Apr 11, 2026
@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR consolidates queue metadata typing by introducing a shared QueueMetadata type to replace scattered local interfaces, adds provider health availability gating to prevent SoundCloud fallback when unavailable, and enhances error logging in handlers to capture previously-swallowed failures.

Changes

Cohort / File(s) Summary
Type Consolidation: QueueMetadata
packages/bot/src/types/QueueMetadata.ts, packages/bot/src/types/index.ts
Added new shared QueueMetadata interface defining optional channel, requestedBy, and client fields, with re-export from types module.
Type Migration: Handlers
packages/bot/src/handlers/player/errorHandlers.ts, packages/bot/src/handlers/player/trackNowPlaying.ts, packages/bot/src/handlers/player/lifecycleHandlers.ts
Replaced local IQueueMetadata definitions with shared QueueMetadata type; added optional chaining for safer metadata field access.
Type Migration: Utilities
packages/bot/src/utils/music/idleDisconnect.ts, packages/bot/src/utils/music/queueManipulation.ts
Updated metadata type assertions to use `QueueMetadata
Provider Health Gating
packages/bot/src/handlers/player/playerFactory.ts, packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
Added providerHealthService check in createResilientStream to skip SoundCloud fallback when provider unavailable; added corresponding test coverage.
Enhanced Error Logging
packages/bot/src/handlers/player/errorHandlers.ts, packages/bot/src/handlers/player/errorHandlers.spec.ts
Modified error handler catch block to log failures from errorLog function via debugLog; added test verifying error capture and logging.
Enhanced Retry Logging
packages/bot/src/handlers/player/trackHandlers.ts, packages/bot/src/handlers/player/trackHandlers.spec.ts
Added warnLog call in queue replenishment retry path to log failures instead of silently swallowing errors; added test coverage.
Test Setup
packages/bot/tests/handlers/player/playerFactory.test.ts
Added Jest mock for providerHealthService to stub isAvailable() as always returning true during test execution.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

bot, size/m

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.69% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(bot): harden player retry and bridge fallbacks' accurately captures the three main changes: improved logging for player retries, centralized metadata typing, and conditional SoundCloud bridge skipping.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/player-replenish-logging

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

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

🧹 Nitpick comments (4)
packages/bot/src/handlers/player/playerFactory.ts (1)

280-291: Prefer a typed/structured bridge exhaustion error at the new early-exit path.

This new throw is plain Error; consider attaching a stable code and retryability metadata so callers/ops can classify it consistently.

♻️ Suggested adjustment
-        throw new Error(`Bridge exhausted: no stream for "${track.title}"`)
+        throw Object.assign(
+            new Error(`Bridge exhausted: no stream for "${track.title}"`),
+            {
+                code: 'ERR_BRIDGE_EXHAUSTED',
+                retryable: true,
+                details: { provider: 'soundcloud', reason: 'cooldown_open' },
+            },
+        )

As per coding guidelines, "Define clear, stable error codes ... Provide optional metadata ... Mark retryable vs nonRetryable errors where helpful for operations."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/handlers/player/playerFactory.ts` around lines 280 - 291,
The early-exit currently throws a plain Error when
providerHealthService.isAvailable('soundcloud') is false; replace this with a
structured, typed error (e.g., BridgeExhaustedError) that carries a stable code
(like "BRIDGE_EXHAUSTED"), retryability metadata (retryable: false), and
contextual fields (title, cleanedTitle, url) so callers/ops can classify and act
on it. Create or import a BridgeExhaustedError class (or factory) and throw new
BridgeExhaustedError({ message: `no stream for "${track.title}"`, code:
'BRIDGE_EXHAUSTED', retryable: false, meta: { title: track.title, cleanedTitle,
url: track.url }}) in place of the current throw; keep the existing warnLog
call. Ensure the symbol BridgeExhaustedError is exported/typed consistently for
downstream handling.
packages/bot/src/handlers/player/trackHandlers.ts (1)

141-149: Consider de-duplicating scheduled retry timers per guild.
Rapid consecutive failures can queue multiple 5s retries for the same guild. A small in-memory guard map would keep this bounded.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/handlers/player/trackHandlers.ts` around lines 141 - 149,
Multiple rapid failures can schedule many 5s retries for the same guild; add an
in-memory guard map keyed by queue.guild.id to de-duplicate timers: before
calling setTimeout in the replenish retry block check a Map (e.g.,
scheduledRetryMap) for an existing timer for queue.guild.id, skip scheduling if
present, otherwise store the returned timeout handle in the map and ensure you
remove the key when the timeout handler runs (and after replenishQueue resolves
or rejects) so future retries can be scheduled; reference replenishQueue,
queue.guild.id and warnLog when implementing the guard and cleanup logic.
packages/bot/src/types/QueueMetadata.ts (1)

2-2: Optional cleanup: avoid leaf type importing from barrel.
QueueMetadata.ts importing CustomClient from ./index introduces a barrel dependency loop at the type layer. Consider moving CustomClient to its own module and re-exporting both from index.ts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/types/QueueMetadata.ts` at line 2, QueueMetadata.ts
currently imports the CustomClient type from the barrel index, creating a
type-level dependency loop; create a new module (e.g., customClient.ts) that
exports the CustomClient type, update QueueMetadata.ts to import CustomClient
from that new module instead of './index', and then re-export CustomClient from
index.ts so other code can still import from the barrel without reintroducing
the loop; ensure all references to CustomClient (in QueueMetadata and elsewhere)
are updated to the new module or the re-export as appropriate.
packages/bot/src/handlers/player/errorHandlers.ts (1)

27-27: Optional: Extract a small helper for queue metadata access.

The repeated cast pattern works, but a helper would reduce drift and keep metadata reads consistent across handlers.

♻️ Proposed refactor
+const getQueueMetadata = (queue: GuildQueue): QueueMetadata | undefined =>
+    queue.metadata as QueueMetadata | undefined
+
 async function notifyChannelStreamFailed(
     queue: GuildQueue,
     trackTitle: string,
 ): Promise<void> {
-    const channel = (queue.metadata as QueueMetadata | undefined)?.channel
+    const channel = getQueueMetadata(queue)?.channel
@@
     const requestedBy: User | undefined =
         queue.currentTrack?.requestedBy ??
-        (queue.metadata as QueueMetadata | undefined)?.requestedBy ??
+        getQueueMetadata(queue)?.requestedBy ??
         undefined
@@
     const requestedByUser: User | undefined =
         currentTrack.requestedBy ??
-        (queue.metadata as QueueMetadata | undefined)?.requestedBy ??
+        getQueueMetadata(queue)?.requestedBy ??
         undefined

Also applies to: 186-187, 222-223

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/handlers/player/errorHandlers.ts` at line 27, Extract a
small utility to centralize safe access to the queue metadata (e.g., a function
like getQueueMetadata(queue): QueueMetadata | undefined or
getQueueChannel(queue): string | undefined) and replace the repeated casts such
as "(queue.metadata as QueueMetadata | undefined)?.channel" in the error
handlers with that helper; update all occurrences (including the other spots
noted) to call the helper so metadata reading and casting is consistent and
easier to maintain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bot/src/handlers/player/errorHandlers.ts`:
- Line 27: Extract a small utility to centralize safe access to the queue
metadata (e.g., a function like getQueueMetadata(queue): QueueMetadata |
undefined or getQueueChannel(queue): string | undefined) and replace the
repeated casts such as "(queue.metadata as QueueMetadata | undefined)?.channel"
in the error handlers with that helper; update all occurrences (including the
other spots noted) to call the helper so metadata reading and casting is
consistent and easier to maintain.

In `@packages/bot/src/handlers/player/playerFactory.ts`:
- Around line 280-291: The early-exit currently throws a plain Error when
providerHealthService.isAvailable('soundcloud') is false; replace this with a
structured, typed error (e.g., BridgeExhaustedError) that carries a stable code
(like "BRIDGE_EXHAUSTED"), retryability metadata (retryable: false), and
contextual fields (title, cleanedTitle, url) so callers/ops can classify and act
on it. Create or import a BridgeExhaustedError class (or factory) and throw new
BridgeExhaustedError({ message: `no stream for "${track.title}"`, code:
'BRIDGE_EXHAUSTED', retryable: false, meta: { title: track.title, cleanedTitle,
url: track.url }}) in place of the current throw; keep the existing warnLog
call. Ensure the symbol BridgeExhaustedError is exported/typed consistently for
downstream handling.

In `@packages/bot/src/handlers/player/trackHandlers.ts`:
- Around line 141-149: Multiple rapid failures can schedule many 5s retries for
the same guild; add an in-memory guard map keyed by queue.guild.id to
de-duplicate timers: before calling setTimeout in the replenish retry block
check a Map (e.g., scheduledRetryMap) for an existing timer for queue.guild.id,
skip scheduling if present, otherwise store the returned timeout handle in the
map and ensure you remove the key when the timeout handler runs (and after
replenishQueue resolves or rejects) so future retries can be scheduled;
reference replenishQueue, queue.guild.id and warnLog when implementing the guard
and cleanup logic.

In `@packages/bot/src/types/QueueMetadata.ts`:
- Line 2: QueueMetadata.ts currently imports the CustomClient type from the
barrel index, creating a type-level dependency loop; create a new module (e.g.,
customClient.ts) that exports the CustomClient type, update QueueMetadata.ts to
import CustomClient from that new module instead of './index', and then
re-export CustomClient from index.ts so other code can still import from the
barrel without reintroducing the loop; ensure all references to CustomClient (in
QueueMetadata and elsewhere) are updated to the new module or the re-export as
appropriate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5b06ffc2-b963-43e1-bca5-3f56471525b7

📥 Commits

Reviewing files that changed from the base of the PR and between 9a3a37f and 3d37d21.

📒 Files selected for processing (13)
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
  • packages/bot/src/types/index.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: SonarCloud Scan
  • GitHub Check: Quality Gates
🧰 Additional context used
📓 Path-based instructions (18)
**/*.{js,jsx,ts,tsx,vue,html}

📄 CodeRabbit inference engine (.cursor/rules/accessibility-openness.mdc)

Provide accessible UI components using semantic HTML and ARIA attributes where necessary

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/dependency-injection.mdc)

**/*.{ts,tsx,js,jsx}: Prefer constructor injection for classes that require dependencies
Avoid global mutable singletons unless necessary
Use explicit interfaces for external dependencies to make testing easier

**/*.{ts,tsx,js,jsx}: Include required references in PRs/code for non-trivial logic: TypeScript (official docs), MDN (JavaScript reference), and official docs for any runtime/framework/libraries used (e.g., Node.js, React) as applicable.
Before assuming behavior of an API, include the doc link and a ≤25-word quote when the change relies on it.

**/*.{ts,tsx,js,jsx}: Prefer named exports for clear usage and easier refactors in TypeScript/JavaScript
Keep import order consistent: external first, then internal modules
Remove dead code and unused imports

**/*.{ts,tsx,js,jsx}: Use PascalCase naming convention for React/UI components
Use camelCase naming convention for variables and functions
Use UPPER_SNAKE_CASE naming convention for constants
Maintain consistent import grouping and ordering within the project, keeping third-party imports separate from local imports
For external data sources (HTTP, database), always validate and sanitize input using type guards or schema validators

Implement TypeScript typecheck and linter in CI quality checks

**/*.{ts,tsx,js,jsx}: Use TypeScript for enhanced type safety
Implement error handling and error logging
Avoid commenting code unless extremely necessary - code should explain itself with descriptive names
Leave NO todos, placeholders or missing pieces in the code
Variables and functions must use camelCase
Constants must use UPPER_SNAKE_CASE
Use arrow functions for methods and computed properties
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements
Maintain consistent import grouping/order: external imports first, then internal modules
Use named exports for clear usage and easier refactors
Always validate and sanitize external data (HTTP, DB) at the boundary using type guards ...

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/error-handling.mdc)

**/*.{js,jsx,ts,tsx}: Never throw strings. Throw Error (or typed subclasses) with descriptive messages
Include causal error as cause when available for better debugging
Define clear, stable error codes (e.g., ERR_AUTH_EXPIRED, ERR_NETWORK_TIMEOUT)
Provide optional metadata (e.g., details, retryable, status, correlationId) in error objects
Use domain error classes per area (e.g., AuthenticationError, ValidationError, NetworkError)
Log errors with structure (message, code, stack, cause, correlationId, user context where appropriate)
Mark retryable vs nonRetryable errors where helpful for operations
Set timeouts and handle aborts/cancellations; avoid dangling requests in API/network code
Implement backoff for transient failures; avoid infinite retries
Map HTTP status → domain errors; 4xx vs 5xx behave differently (e.g., retry for 5xx/network)

**/*.{js,jsx,ts,tsx}: Use functional components with hooks in React/React Native. Avoid class components.
Keep components focused on a single responsibility; extract complex logic into custom hooks.
Keep state local when possible. Use Context/Zustand/Redux only when necessary for state management.
If props or state traverse more than 3 levels, consider using context or a feature-scoped store instead of prop drilling.
Use performance optimization techniques: React.memo, useMemo, useCallback, Suspense (web), and virtualization for long lists; avoid unnecessary re-renders.
Web accessibility: use semantic HTML, labels, focus management, keyboard navigation, and aria-* attributes as needed.
React Native accessibility: use accessibility props (accessible, accessibilityLabel), proper roles and labels.
Identify and extract repetitive UI components proactively to components/ with clear props and minimal coupling.
Web styles: prefer co-located styles or design system tokens; avoid global style leakage.
React Native styles: prefer StyleSheet.create, design tokens, and theme providers; avoid in...

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/index.ts

📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)

Use index.ts only to re-export a small, intentional surface per module

Files:

  • packages/bot/src/types/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)

Introduce interfaces at module boundaries to enable testing and substitutions

**/*.{ts,tsx}: Avoid using any type in TypeScript. If unavoidable, use unknown with type guards and justify with a code comment
Prefer interface for defining public object shapes in TypeScript, use type for unions and utility types
Use TypeScript utility types such as Partial, Pick, Omit, Readonly, and Record when appropriate
Use I{Name} naming convention for interfaces in TypeScript
Use T{Name} naming convention for type aliases and utility types in TypeScript

**/*.{ts,tsx}: Prefer types over interfaces for most cases
Don't ever use any - type safety always
Avoid enums; use const objects instead
For complex types, create a separate file to declare them and import them
Avoid using any type; if unavoidable, use unknown with type guards and justify with code comment
Prefer interface for public API shapes; use type for unions and utility types
Use TypeScript utility types (Partial, Pick, Omit, Readonly, Record)

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)

**/*.{js,ts,tsx,jsx}: Minimize comments in code; explain the 'why' when non-obvious, let code express the 'what' through clear naming
Document trade-offs briefly when deviating from ideal patterns

**/*.{js,ts,tsx,jsx}: Store secrets, ports, and hosts in environment variables (.env, .env.example) and never hardcode them
Avoid redundant or decorative AI comments; code should be self-explanatory and only commented when logic is non-obvious; prefer refactoring over lengthy comments

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
packages/bot/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/lucky-discord-bot.mdc)

packages/bot/**/*.{ts,tsx}: Use useMainPlayer() from discord-player to access the player instance; do not instantiate player directly
Do not duplicate queue or player state outside Discord Player; use shared services from @lucky/shared for persistent data like track history and session information
Use errorLog and debugLog from @lucky/shared/utils for logging throughout the bot package
Use embed and reply utilities from @lucky/shared for consistent message formatting and error sanitization across the bot
Use services from @lucky/shared (DatabaseService, Redis client) for database and cache access; do not instantiate Prisma or Redis directly in the bot package

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
packages/bot/**

📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)

The bot package depends on shared and contains Discord bot commands and player handlers using Discord.js and Discord Player

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/*.{js,mjs,ts,mts}

📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)

Use Node.js version ≥22 with ESM (ECMAScript modules) only; no CommonJS

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
packages/bot/src/**/*.ts

📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)

Use @lucky/shared for database, Redis, logging, and embed utilities instead of implementing them locally

Files:

  • packages/bot/src/types/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/utils/music/idleDisconnect.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
  • packages/bot/src/types/QueueMetadata.ts
**/*.{test,spec}.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend.mdc)

**/*.{test,spec}.{js,jsx,ts,tsx}: Test behavior, not implementation. Prefer Testing Library utilities for testing React/React Native components.
For React Native tests: mock native modules and test component interactions and accessibility labels.

Files:

  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)

**/*.{test,spec}.{ts,tsx,js,jsx}: Test behavior, not implementation details
Prefer unit tests for core logic; add integration tests at meaningful boundaries

Files:

  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
**/*.{test,spec}.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.cursor/rules/testing-quality.mdc)

**/*.{test,spec}.{js,ts,jsx,tsx}: Use Jest + a React testing library for unit and component tests as applicable
Test behavior, not implementation details

Files:

  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
{packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}}

📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)

Add or adjust unit and integration tests when changing behavior; follow existing patterns in packages/*/tests and root tests/ directories

Files:

  • packages/bot/tests/handlers/player/playerFactory.test.ts
**/*.{spec,test}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)

**/*.{spec,test}.{ts,tsx,js,jsx}: Use Jest for unit and integration tests
Test behavior, not implementation details
Run unit, integration tests, and coverage report in CI quality checks

Files:

  • packages/bot/tests/handlers/player/playerFactory.test.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
packages/bot/src/handlers/player/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/lucky-discord-bot.mdc)

Track handling, errors, and lifecycle must be managed through dedicated handlers in packages/bot/src/handlers/player/ (trackHandlers, errorHandlers, lifecycleHandlers)

Files:

  • packages/bot/src/handlers/player/trackHandlers.ts
  • packages/bot/src/handlers/player/lifecycleHandlers.ts
  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.ts
  • packages/bot/src/handlers/player/errorHandlers.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/bot/src/handlers/player/trackNowPlaying.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)

Unit tests must use naming convention *.spec.ts

Files:

  • packages/bot/src/handlers/player/errorHandlers.spec.ts
  • packages/bot/src/handlers/player/trackHandlers.spec.ts
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
**/[A-Z]*.{ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)

Components must use PascalCase naming

Files:

  • packages/bot/src/types/QueueMetadata.ts
🔇 Additional comments (13)
packages/bot/tests/handlers/player/playerFactory.test.ts (1)

37-41: Good provider-health mock baseline for this suite.

Defaulting isAvailable to true keeps existing playerFactory tests stable while accommodating the new cooldown gate path.

packages/bot/src/handlers/player/playerFactory.bridge.spec.ts (2)

9-9: Nice test-control injection for provider availability.

Using providerIsAvailableMock makes availability branching explicit and easy to steer per test.

Also applies to: 43-47


373-375: Strong coverage for the new SoundCloud-cooldown branch.

This validates both outcomes: expected rejection and zero SoundCloud fallback calls when the provider is unavailable.

Also applies to: 410-421

packages/bot/src/types/index.ts (1)

25-25: Good re-export to centralize the queue metadata type surface.
This keeps consumers aligned on a single metadata contract.

packages/bot/src/utils/music/queueManipulation.ts (1)

307-309: Typed metadata fallback is cleaner and safer here.
The updated QueueMetadata | undefined handling preserves behavior while removing local-shape drift.

packages/bot/src/handlers/player/lifecycleHandlers.ts (1)

36-41: Nice metadata typing consolidation in session restore path.
No functional regression and better consistency with the shared queue metadata model.

packages/bot/src/handlers/player/trackHandlers.ts (1)

142-148: Great improvement: retry failures are no longer silent.
Including guildId in the warning payload will materially help incident triage.

packages/bot/src/handlers/player/errorHandlers.spec.ts (1)

347-361: Solid regression test for logger-failure hardening.
This covers the exact guarded-path behavior the PR introduces.

packages/bot/src/handlers/player/trackHandlers.spec.ts (1)

305-327: Good behavioral test for failed retry logging path.
Verifying both call count (2) and warning payload makes this change robust against regressions.

packages/bot/src/utils/music/idleDisconnect.ts (1)

48-55: Nice consistency update on idle disconnect metadata access.
The shared QueueMetadata cast plus guarded channel.send path is clean and safe.

packages/bot/src/handlers/player/errorHandlers.ts (1)

73-75: Good hardening of logger failure path.

Catching logger failures and emitting a fallback debug log removes silent failure behavior and improves operability.

packages/bot/src/handlers/player/trackNowPlaying.ts (2)

43-44: Requester fallback update looks correct.

Using shared QueueMetadata for queue-level requester fallback keeps this path aligned with the player handlers.


68-69: Nice defensive guard before channel usage.

Early return on missing metadata.channel prevents avoidable runtime failures in now-playing message send/edit flow.

@LucasSantana-Dev
LucasSantana-Dev merged commit 2352ea0 into main Apr 11, 2026
12 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the fix/player-replenish-logging branch April 11, 2026 01:42
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
* fix(bot): log player retry failures

* fix(bot): share queue metadata type

* fix(bot): skip unhealthy soundcloud bridge

This branch was successfully deployed

1 active deployment
Preview — 3d37d215 Deployed Apr 11, 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