Skip to content

feat(bot): add probe-based URL validation to /queue rescue (#267) - #278

Merged
LucasSantana-Dev merged 1 commit into
mainfrom
feat/queue-rescue-probe
Mar 15, 2026
Merged

LucasSantana-Dev merged 1 commit into
mainfrom
feat/queue-rescue-probe

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Mar 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements issue #267: enhances /queue rescue with optional probe-based URL validation to detect dead/unresolvable tracks.

  • probeTrackResolvable(): Uses player.search() + setTimeout race to verify each track is resolvable within a configurable timeout (default 5s via QUEUE_RESCUE_PROBE_TIMEOUT_MS)
  • RescueQueueOptions: New type with probeResolvable, probeTimeoutMs, refillThreshold options
  • rescueQueue() enhanced: Supports probe-based filtering on top of existing empty-field detection; refill threshold now env-configurable via QUEUE_RESCUE_REFILL_THRESHOLD (default 3)
  • /queue rescue action: Now passes { probeResolvable: true } to enable live probing
  • 2 new tests: probe removes unresolvable tracks, probe timeout correctly marks track as dead

Closes #267

Summary by CodeRabbit

  • New Features
    • Queue rescue now uses probe-based validation with a configurable timeout to verify track resolvability. Environment variables control validation timeout and queue refill thresholds. The system intelligently filters unresolvable tracks and re-adds only those verified to be playable.

@netlify

netlify Bot commented Mar 15, 2026

Copy link
Copy Markdown

❌ Deploy Preview for regal-bunny-0c8efe failed.

Name Link
🔨 Latest commit 1f77d3f
🔍 Latest deploy log https://app.netlify.com/projects/regal-bunny-0c8efe/deploys/69b6db5e29b6870009f547eb

@vercel

vercel Bot commented Mar 15, 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 Mar 15, 2026 8:19pm

Request Review

@netlify

netlify Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for regal-bunny-0c8efe ready!

Name Link
🔨 Latest commit 3d69ca9
🔍 Latest deploy log https://app.netlify.com/projects/regal-bunny-0c8efe/deploys/69b714112ee74a00084db6ae
😎 Deploy Preview https://deploy-preview-278--regal-bunny-0c8efe.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the bot label Mar 15, 2026
@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Extends /queue rescue command with probe-based track resolvability validation using configurable timeout and refill threshold options, enabling detection and removal of unplayable tracks from music queues.

Changes

Cohort / File(s) Summary
Documentation
CHANGELOG.md
Added entry documenting probe-based URL validation with configurable timeout for /queue rescue command.
Command Handler
packages/bot/src/functions/music/commands/queue/index.spec.ts, packages/bot/src/functions/music/commands/queue/index.ts
Updated /queue rescue invocation to pass { probeResolvable: true } option to rescueQueue function.
Queue Manipulation Core
packages/bot/src/utils/music/queueManipulation.ts
Introduced probe-based resolvability checking with new constants (timeout, refill threshold), added asynchronous probeTrackResolvable function, extended RescueQueueOptions type, and reworked rescueQueue to conditionally probe and filter tracks with configurable thresholds.
Queue Manipulation Tests
packages/bot/src/utils/music/queueManipulation.spec.ts
Updated existing rescue test with refill threshold option; added new test suites for probe-based rescue covering search failures, resolvable/dead track handling, and timeout scenarios.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Cmd as /queue Command
    participant Rescue as rescueQueue()
    participant Probe as probeTrackResolvable()
    participant Player as Player/SearchEngine
    participant Queue as Queue

    User->>Cmd: /queue rescue
    Cmd->>Rescue: rescueQueue(queue, { probeResolvable: true })
    
    loop For each playable track
        Rescue->>Probe: probeTrackResolvable(track, timeout)
        Probe->>Player: player.search(track)
        alt Search succeeds
            Player-->>Probe: match found
            Probe-->>Rescue: true (resolvable)
            Rescue->>Queue: retain track
        else Timeout/Failure
            Probe-->>Rescue: false (unresolvable)
            Rescue->>Queue: remove track
        end
    end
    
    alt queue.size < refillThreshold
        Rescue->>Queue: trigger autoplay refill
    end
    
    Rescue-->>Cmd: QueueRescueResult
    Cmd-->>User: rescue complete message
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Suggested Labels

size/l

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding probe-based URL validation to /queue rescue command.
Linked Issues check ✅ Passed The PR implements core requirements from issue #267: probe-based track validation with configurable timeout, configurable refill threshold, rescueQueue with options, and tests for probe behavior.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing issue #267's probe-based validation and refill threshold features; no unrelated modifications detected.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/queue-rescue-probe
📝 Coding Plan
  • Generate coding plan for human review comments

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.

- Add probeTrackResolvable() helper using player.search + timeout race
- Enhance rescueQueue() with RescueQueueOptions (probeResolvable, probeTimeoutMs, refillThreshold)
- Wire probe=true in /queue rescue action handler
- Add QUEUE_RESCUE_PROBE_TIMEOUT_MS and QUEUE_RESCUE_REFILL_THRESHOLD env constants
- Add 2 new tests: probe removes dead tracks, probe timeout treats as unresolvable
- Update CHANGELOG.md [Unreleased] section

Closes #267
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot added the size/l label Mar 15, 2026
@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 (2)
CHANGELOG.md (1)

17-21: Consider adding issue reference to the changelog entry.

The PR objectives mention this closes issue #267, but the changelog entry doesn't reference it. Adding (#267) at the end would align with other entries in this file (e.g., lines 14-16 reference #271).

As per coding guidelines: "Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs"

📝 Suggested fix
 - `/queue rescue` now uses **probe-based URL validation** (`player.search` with
   configurable timeout, default 5 s) to detect actually unresolvable tracks
   (removed videos, geo-blocked content, dead links) in addition to the existing
-  structural check. Configurable via `QUEUE_RESCUE_PROBE_TIMEOUT_MS` and
-  `QUEUE_RESCUE_REFILL_THRESHOLD` env vars.
+  structural check. Configurable via `QUEUE_RESCUE_PROBE_TIMEOUT_MS` and
+  `QUEUE_RESCUE_REFILL_THRESHOLD` env vars (`#267`).
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 17 - 21, The changelog entry for `/queue rescue`
is missing the issue reference; update the sentence that starts with "/queue
rescue now uses probe-based URL validation" in CHANGELOG.md to append the issue
reference "(`#267`)" at the end of that entry so it matches the other entries
(e.g., the one referencing `#271`) and complies with the guideline to include
issue/PR references; no behavior changes required—only edit the changelog text.
packages/bot/src/utils/music/queueManipulation.ts (1)

417-434: Minor: setTimeout timer not cleared on successful search.

When queue.player.search() resolves before the timeout, the timer continues running until it fires (harmlessly resolving null). While this doesn't cause functional issues, it's a minor resource inefficiency.

Consider using AbortController or clearing the timeout on success if this becomes a hot path.

♻️ Optional improvement using cleanup
 async function probeTrackResolvable(
     queue: GuildQueue,
     track: Track,
     timeoutMs: number,
 ): Promise<boolean> {
     const query = track.url || `${track.title} ${track.author}`.trim()
     try {
-        const result = await Promise.race([
-            queue.player.search(query, { searchEngine: QueryType.AUTO }),
-            new Promise<null>((resolve) =>
-                setTimeout(() => resolve(null), timeoutMs),
-            ),
-        ])
+        let timeoutId: ReturnType<typeof setTimeout> | undefined
+        const result = await Promise.race([
+            queue.player.search(query, { searchEngine: QueryType.AUTO })
+                .finally(() => timeoutId && clearTimeout(timeoutId)),
+            new Promise<null>((resolve) => {
+                timeoutId = setTimeout(() => resolve(null), timeoutMs)
+            }),
+        ])
         return result !== null && result.tracks.length > 0
     } catch {
         return false
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/utils/music/queueManipulation.ts` around lines 417 - 434,
The probeTrackResolvable function leaves the setTimeout timer running if
queue.player.search(...) resolves first; update probeTrackResolvable to cancel
that timer on success by creating a timeoutId for the Promise that resolves
after timeoutMs and clearing that timeout when the search Promise resolves
successfully (or alternatively use an AbortController to abort the search on
timeout); reference probeTrackResolvable, queue.player.search, QueryType.AUTO,
and timeoutMs so you locate and modify the Promise.race logic to clear the
timeout (or use abort) to avoid the stray timer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@CHANGELOG.md`:
- Around line 17-21: The changelog entry for `/queue rescue` is missing the
issue reference; update the sentence that starts with "/queue rescue now uses
probe-based URL validation" in CHANGELOG.md to append the issue reference
"(`#267`)" at the end of that entry so it matches the other entries (e.g., the one
referencing `#271`) and complies with the guideline to include issue/PR
references; no behavior changes required—only edit the changelog text.

In `@packages/bot/src/utils/music/queueManipulation.ts`:
- Around line 417-434: The probeTrackResolvable function leaves the setTimeout
timer running if queue.player.search(...) resolves first; update
probeTrackResolvable to cancel that timer on success by creating a timeoutId for
the Promise that resolves after timeoutMs and clearing that timeout when the
search Promise resolves successfully (or alternatively use an AbortController to
abort the search on timeout); reference probeTrackResolvable,
queue.player.search, QueryType.AUTO, and timeoutMs so you locate and modify the
Promise.race logic to clear the timeout (or use abort) to avoid the stray timer.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50a15575-df56-4149-9ea0-ce6a32155f93

📥 Commits

Reviewing files that changed from the base of the PR and between 99f117a and 3d69ca9.

📒 Files selected for processing (5)
  • CHANGELOG.md
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/utils/music/queueManipulation.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 (24)
{CHANGELOG.md,README.md}

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

ALWAYS update CHANGELOG.md and README.md as changes are made.

Files:

  • CHANGELOG.md
CHANGELOG.md

📄 CodeRabbit inference engine (.cursor/rules/templates-examples.mdc)

CHANGELOG.md must be updated with all changes in pull requests

Always update CHANGELOG.md with all code changes

Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs

Update CHANGELOG.md when behavior or setup changes; use Angular-style commit messages with scope

Files:

  • CHANGELOG.md
{CHANGELOG.md,docs/**}

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

Update CHANGELOG.md and relevant docs/ files when behavior or setup changes

Files:

  • CHANGELOG.md
**/*.{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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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

**/*.{ts,tsx,js,jsx}: Use Prettier with no semicolons, single quotes, 4-space indent, 80 character width
Files must not exceed 250 lines and this is enforced

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

Files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.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}: Functions must be less than 50 lines with cyclomatic complexity less than 10
Do not use any types - ESLint enforces this at error level

**/*.{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)

Use the prisma-redis-lucky skill when adding or modifying database schema, migrations, or Redis operations in the shared package

Files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.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/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.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/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
**/*.spec.ts

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

Unit tests must use naming convention *.spec.ts

Files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.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/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

**/*.ts: Use Discord.js and Discord Player for Discord bot commands and music queue/player functionality; use the discord-commands skill for slash command additions or changes
Use the typescript-advanced-types skill when working with TypeScript types, removing as any casts, and improving type safety
Do not hardcode secrets, IPs, or ports; use .env and docs/ for required environment variables
Add or adjust unit and integration tests when changing behavior; follow patterns in packages/*/tests and root tests/

Files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
packages/bot/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

packages/bot/**/*.ts: Use the moderation-automod skill for moderation commands and AutoModService implementation; use event-handlers skill for bot event wiring (messageCreate, memberAdd, etc.)
Use the management-features skill for embed builder, custom commands, and auto-messages implementation

Files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
packages/bot/src/functions/*/commands/**/*.{ts,tsx}

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

packages/bot/src/functions/*/commands/**/*.{ts,tsx}: Command model must include data (slash builder), execute, and category properties exported from packages/bot/src/models/Command.ts
Use @discordjs/builders for building the data (SlashCommandBuilder) in command definitions
Command execute function must receive { interaction, client } parameters from CommandExecuteParams type
Use interactionReply and createUserFriendlyError utilities from @lucky/shared/general utils for command replies and error handling
Use existing validators from packages/bot/src/utils/command/ for voice channel, queue, and guild validations in commands

Files:

  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/{general,music,download}/commands/**/*.ts

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

packages/bot/src/functions/{general,music,download}/commands/**/*.ts: Apply .cursor/rules/lucky-discord-bot.mdc rules for Discord bot commands and player implementation
Use .cursor/skills/discord-commands/SKILL.md for implementing slash commands

Files:

  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/music/commands/**/*.ts

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

Use .cursor/skills/music-queue-player/SKILL.md for play, queue, skip, volume commands and player lifecycle management

Files:

  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/music/**/*.ts

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

Use existing voice/queue/guild validators before manipulating player or queue state

Files:

  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.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/functions/music/commands/queue/index.ts
🧠 Learnings (8)
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/**/*.ts : Use existing voice/queue/guild validators before manipulating player or queue state

Applied to files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/commands/**/*.ts : Use `.cursor/skills/music-queue-player/SKILL.md` for play, queue, skip, volume commands and player lifecycle management

Applied to files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/**/*.{ts,tsx} : 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

Applied to files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
  • packages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to {packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}} : Add or adjust unit and integration tests when changing behavior; follow existing patterns in `packages/*/tests` and root `tests/` directories

Applied to files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
📚 Learning: 2026-03-15T14:34:47.397Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T14:34:47.397Z
Learning: Applies to **/*.ts : Add or adjust unit and integration tests when changing behavior; follow patterns in `packages/*/tests` and root `tests/`

Applied to files:

  • packages/bot/src/utils/music/queueManipulation.spec.ts
📚 Learning: 2026-03-15T14:34:47.397Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T14:34:47.397Z
Learning: Applies to **/*.ts : Use Discord.js and Discord Player for Discord bot commands and music queue/player functionality; use the `discord-commands` skill for slash command additions or changes

Applied to files:

  • packages/bot/src/functions/music/commands/queue/index.spec.ts
  • packages/bot/src/functions/music/commands/queue/index.ts
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/{general,music,download}/commands/**/*.ts : Apply `.cursor/rules/lucky-discord-bot.mdc` rules for Discord bot commands and player implementation

Applied to files:

  • packages/bot/src/functions/music/commands/queue/index.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/src/functions/*/commands/**/*.{ts,tsx} : Use existing validators from `packages/bot/src/utils/command/` for voice channel, queue, and guild validations in commands

Applied to files:

  • packages/bot/src/functions/music/commands/queue/index.ts
🔇 Additional comments (9)
packages/bot/src/utils/music/queueManipulation.ts (4)

17-24: LGTM!

Environment variable parsing with parseInt and sensible defaults (5s timeout, threshold of 3) aligns with the PR objectives. The radix parameter is correctly specified.


436-440: LGTM!

The RescueQueueOptions type provides a clean interface for the new configurable rescue behavior with sensible optional properties.


457-474: LGTM!

The iterative filtering logic correctly handles both structural validation (isPlayableTrack) and optional probe-based validation. Sequential probing is appropriate here since probing in parallel could overwhelm the search endpoint.


480-484: Rescue queue correctly refills regardless of autoplay mode.

The rescueQueue function intentionally removed the queue.repeatMode === QueueRepeatMode.AUTOPLAY check when calling replenishQueue. This is correct—rescue operations should restore queue health independently of autoplay settings. The condition queue.currentTrack && queue.tracks.size < refillThreshold is sufficient here. Other callers in trackHandlers.ts retain their own AUTOPLAY mode guards where appropriate.

packages/bot/src/utils/music/queueManipulation.spec.ts (3)

495-504: LGTM!

Adding { refillThreshold: 0 } isolates the rescue filtering logic from replenishment, making the test more focused and deterministic.


506-545: LGTM!

Good test coverage for the probe-based rescue feature. The mock correctly simulates search returning results for resolvable tracks and empty results for dead tracks. Assertions verify both track retention and removal.


547-573: LGTM!

Excellent test for the timeout scenario using a never-resolving promise. The short probeTimeoutMs: 50 keeps tests fast while still exercising the timeout path.

packages/bot/src/functions/music/commands/queue/index.spec.ts (1)

143-148: LGTM!

Test correctly updated to verify that the rescue action passes { probeResolvable: true } to rescueQueue, aligning with the implementation change.

packages/bot/src/functions/music/commands/queue/index.ts (1)

107-121: LGTM!

Clean integration of the probe-based rescue feature. The { probeResolvable: true } option enables live track validation, and the response message accurately reports the rescue results to users. Based on learnings: "Use existing voice/queue/guild validators before manipulating player or queue state" - this is properly handled via requireGuild and requireQueue earlier in the execute flow.

@LucasSantana-Dev
LucasSantana-Dev enabled auto-merge (squash) March 15, 2026 20:31
@LucasSantana-Dev
LucasSantana-Dev merged commit f42387b into main Mar 15, 2026
15 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the feat/queue-rescue-probe branch March 15, 2026 21:50
LucasSantana-Dev added a commit that referenced this pull request May 13, 2026
- Add probeTrackResolvable() helper using player.search + timeout race
- Enhance rescueQueue() with RescueQueueOptions (probeResolvable, probeTimeoutMs, refillThreshold)
- Wire probe=true in /queue rescue action handler
- Add QUEUE_RESCUE_PROBE_TIMEOUT_MS and QUEUE_RESCUE_REFILL_THRESHOLD env constants
- Add 2 new tests: probe removes dead tracks, probe timeout treats as unresolvable
- Update CHANGELOG.md [Unreleased] section

Closes #267

This branch was successfully deployed

1 active deployment
Preview — 3d69ca99 Deployed Mar 15, 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.

feat(bot): /queue rescue command for broken/stalled queues

1 participant