[GH-ISSUE #5163] [Issue]: Spotify search sends invalid limit values #2858

Closed
opened 2026-10-21 05:56:59 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @SpicyMarinara on GitHub (Aug 16, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5163

Originally assigned to: @SpicyMarinara, @kolacheee on GitHub.

Summary

Music DJ can send Spotify search limits above Spotify's maximum of 10, causing HTTP 400 errors. The standard Spotify search path permits up to 20, while artist and generic Spotify searches in Game mode can default to 50.

Expected behavior

Marinara should limit Spotify GET /search requests to 10 results per request and use offset-based pagination when more results are needed. The spotify_search tool schema should expose the maximum allowed value.

Actual behavior

The standard spotify_search path forwards limits from 1 through 20 directly to Spotify. In Game mode, artist and generic Spotify search paths can forward a default limit of 50, resulting in a Spotify API 400 "Invalid limit" response.

Steps to reproduce

  1. Use Music DJ and trigger spotify_search with limit=15.
  2. Observe that Marinara sends GET /v1/search with limit=15.
  3. Observe Spotify return HTTP 400 with the message "Invalid limit".
  4. Alternatively, use Game mode with an artist or generic Spotify search source.
  5. Allow the search to use its default limit of 50 and observe the same Spotify API error.

Environment

  • Marinara Engine version: v2.4.2; reported as also present in current main
  • Install type: Not provided
  • OS + version: Not provided
  • Browser or app shell: Not provided

Logs, screenshots, or video

Reported error: Spotify API error (400): {"error": {"status": 400, "message": "Invalid limit" } }. No screenshots or video provided.

Additional context

In packages/server/src/services/tools/tool-executor.ts, spotifySearch() clamps the limit to 1–20 and forwards it unchanged. The spotify_search tool definition has no maximum for limit. In game-spotify-music.service.ts, the limit defaults to 50 and is passed to searchSpotifyTracks() for artist and generic Spotify search sources. According to the report, Spotify reduced the GET /search maximum to 10 in February 2026; requests requiring more results must paginate with offset.

Discord thread: Spotify returning 400 invalid limit
Discord thread link: https://discord.com/channels/1417099416812392641/1538648188225986580
Requested by: kolache (k0lache, Discord ID 220320261780668416)

Discord thread transcript (4 messages)
[2026-08-16T20:38:34.774Z] Snowy Kitsune: Getting the following error a lot when using Music DJ. `Spotify API error (400): {"error": {"status": 400, "message": "Invalid limit" } }`
[Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648188225986580]

[2026-08-16T20:38:35.248Z] Professor Mari [bot]: Howdy!

Thank you for submitting a new bug report/feature request, your support means a lot. A member of the team will look into it as soon as possible, and if they find it valid, they will open a GitHub Issue out of it. You can check whether it was addressed on the staging build of Marinara Engine. **Do not ping any of the developers, this will not speed up the process.**

**Please include a Support Diagnostic in the post if you haven't done it yet.** Otherwise, ignore this step. To grab it, go to the Marinara Engine tab:

`Settings -> Advanced -> Support Diagnostics -> Copy Support Diagnostics.`

Thank you, this will help tremendously.

This is an automated message, but if you reply to it, I will do my best to assist you using my LLM-powered brain. That said, it's best for a human to handle this case.

Cheers!
[Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648190214217850]

[2026-08-16T20:38:55.651Z] Snowy Kitsune: If it helps any I had Sol dig into it to make sure it was a real bug beforehand:
[Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648275790340226]

[2026-08-16T20:39:09.264Z] Snowy Kitsune: Yes. I found it, and there are actually **two bugs**.

`packages/server/src/services/tools/tool-executor.ts`

In **v2.4.2**, `spotifySearch()` does this:

` ` `ts
const limit = clampNumber(args.limit ?? 5, 5, 1, 20);
` ` `

and then sends that value directly to Spotify:

` ` `ts
`https://api.spotify.com/v1/search?${new URLSearchParams({
  q: query,
  type: "track",
  limit: String(limit)
})}`
` ` `

So Marinara considers **1 through 20** valid and forwards it unchanged. 

Spotify, however, changed `GET /search` in February 2026. Its maximum went from **50 to 10**, and its default went from 20 to 5. Spotify specifically says requests needing more than 10 results must paginate with `offset`. ([Spotify for Developers][1])

Therefore:

` ` `text
Music DJ asks spotify_search for limit=15
                    ↓
Marinara clamp: min(20, 15) = 15
                    ↓
GET /v1/search?...&limit=15
                    ↓
Spotify: 400 "Invalid limit"
` ` `

That code is still present in **current `main`**, not just v2.4.2. 

And the tool definition makes this easier for the model to trigger. `spotify_search` describes `limit` merely as a number with a default of 5. It specifies **no `maximum` at all**, so nothing tells the model that 10 is the ceiling. 

### And there's a second, worse version in Game mode

In `game-spotify-music.service.ts`, Marinara does:

` ` `ts
const limit = clampCount(args.limit ?? 50, 50, 1, 50);
` ` `

For playlist/Liked Songs sources, that's okay because it's being used for Marinara's local candidate selection. But when the Music DJ source is an **artist** or generic **Spotify search**, it passes that same `limit` directly into `searchSpotifyTracks()`. 

Then `searchSpotifyTracks()` does:

` ` `ts
`/search?${new URLSearchParams({
  q,
  type: "track",
  limit: String(limit)
})}`
` ` `

So the default is effectively:

` ` `text
limit = 50
↓
Spotify /search?limit=50
↓
400 Invalid limit
` ` `

That one is deterministic if that particular Game-mode path is being used.
[Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648332887400498]

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @SpicyMarinara on GitHub (Aug 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5163 Originally assigned to: @SpicyMarinara, @kolacheee on GitHub. ## Summary Music DJ can send Spotify search limits above Spotify's maximum of 10, causing HTTP 400 errors. The standard Spotify search path permits up to 20, while artist and generic Spotify searches in Game mode can default to 50. ## Expected behavior Marinara should limit Spotify GET /search requests to 10 results per request and use offset-based pagination when more results are needed. The spotify_search tool schema should expose the maximum allowed value. ## Actual behavior The standard spotify_search path forwards limits from 1 through 20 directly to Spotify. In Game mode, artist and generic Spotify search paths can forward a default limit of 50, resulting in a Spotify API 400 "Invalid limit" response. ## Steps to reproduce 1. Use Music DJ and trigger spotify_search with limit=15. 2. Observe that Marinara sends GET /v1/search with limit=15. 3. Observe Spotify return HTTP 400 with the message "Invalid limit". 4. Alternatively, use Game mode with an artist or generic Spotify search source. 5. Allow the search to use its default limit of 50 and observe the same Spotify API error. ## Environment - Marinara Engine version: v2.4.2; reported as also present in current main - Install type: Not provided - OS + version: Not provided - Browser or app shell: Not provided ## Logs, screenshots, or video Reported error: `Spotify API error (400): {"error": {"status": 400, "message": "Invalid limit" } }`. No screenshots or video provided. ## Additional context In `packages/server/src/services/tools/tool-executor.ts`, `spotifySearch()` clamps the limit to 1–20 and forwards it unchanged. The `spotify_search` tool definition has no maximum for `limit`. In `game-spotify-music.service.ts`, the limit defaults to 50 and is passed to `searchSpotifyTracks()` for artist and generic Spotify search sources. According to the report, Spotify reduced the GET /search maximum to 10 in February 2026; requests requiring more results must paginate with `offset`. Discord thread: Spotify returning 400 invalid limit Discord thread link: https://discord.com/channels/1417099416812392641/1538648188225986580 Requested by: kolache (k0lache, Discord ID 220320261780668416) <details> <summary>Discord thread transcript (4 messages)</summary> ```text [2026-08-16T20:38:34.774Z] Snowy Kitsune: Getting the following error a lot when using Music DJ. `Spotify API error (400): {"error": {"status": 400, "message": "Invalid limit" } }` [Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648188225986580] [2026-08-16T20:38:35.248Z] Professor Mari [bot]: Howdy! Thank you for submitting a new bug report/feature request, your support means a lot. A member of the team will look into it as soon as possible, and if they find it valid, they will open a GitHub Issue out of it. You can check whether it was addressed on the staging build of Marinara Engine. **Do not ping any of the developers, this will not speed up the process.** **Please include a Support Diagnostic in the post if you haven't done it yet.** Otherwise, ignore this step. To grab it, go to the Marinara Engine tab: `Settings -> Advanced -> Support Diagnostics -> Copy Support Diagnostics.` Thank you, this will help tremendously. This is an automated message, but if you reply to it, I will do my best to assist you using my LLM-powered brain. That said, it's best for a human to handle this case. Cheers! [Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648190214217850] [2026-08-16T20:38:55.651Z] Snowy Kitsune: If it helps any I had Sol dig into it to make sure it was a real bug beforehand: [Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648275790340226] [2026-08-16T20:39:09.264Z] Snowy Kitsune: Yes. I found it, and there are actually **two bugs**. `packages/server/src/services/tools/tool-executor.ts` In **v2.4.2**, `spotifySearch()` does this: ` ` `ts const limit = clampNumber(args.limit ?? 5, 5, 1, 20); ` ` ` and then sends that value directly to Spotify: ` ` `ts `https://api.spotify.com/v1/search?${new URLSearchParams({ q: query, type: "track", limit: String(limit) })}` ` ` ` So Marinara considers **1 through 20** valid and forwards it unchanged. Spotify, however, changed `GET /search` in February 2026. Its maximum went from **50 to 10**, and its default went from 20 to 5. Spotify specifically says requests needing more than 10 results must paginate with `offset`. ([Spotify for Developers][1]) Therefore: ` ` `text Music DJ asks spotify_search for limit=15 ↓ Marinara clamp: min(20, 15) = 15 ↓ GET /v1/search?...&limit=15 ↓ Spotify: 400 "Invalid limit" ` ` ` That code is still present in **current `main`**, not just v2.4.2. And the tool definition makes this easier for the model to trigger. `spotify_search` describes `limit` merely as a number with a default of 5. It specifies **no `maximum` at all**, so nothing tells the model that 10 is the ceiling. ### And there's a second, worse version in Game mode In `game-spotify-music.service.ts`, Marinara does: ` ` `ts const limit = clampCount(args.limit ?? 50, 50, 1, 50); ` ` ` For playlist/Liked Songs sources, that's okay because it's being used for Marinara's local candidate selection. But when the Music DJ source is an **artist** or generic **Spotify search**, it passes that same `limit` directly into `searchSpotifyTracks()`. Then `searchSpotifyTracks()` does: ` ` `ts `/search?${new URLSearchParams({ q, type: "track", limit: String(limit) })}` ` ` ` So the default is effectively: ` ` `text limit = 50 ↓ Spotify /search?limit=50 ↓ 400 Invalid limit ` ` ` That one is deterministic if that particular Game-mode path is being used. [Discord message: https://discord.com/channels/1417099416812392641/1538648188225986580/1538648332887400498] ``` </details> ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:56:59 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 16, 2026):

I am handling the Game Mode side of this issue in https://github.com/Pasta-Devs/Marinara-Engine/pull/5162

<!-- gh-comment-id:5309580738 --> @kolacheee commented on GitHub (Aug 16, 2026): I am handling the Game Mode side of this issue in https://github.com/Pasta-Devs/Marinara-Engine/pull/5162
Author
Owner

@SpicyMarinara commented on GitHub (Aug 16, 2026):

I'll take care of the RP one.

<!-- gh-comment-id:5309583260 --> @SpicyMarinara commented on GitHub (Aug 16, 2026): I'll take care of the RP one.
Author
Owner

@kolacheee commented on GitHub (Aug 16, 2026):

The Game-mode half of this (the game-spotify-music.service.ts path — artist and generic-search sources passing the candidate pool's default of 50 straight into GET /search, deterministic 400 since Spotify's February 2026 cap of 10) is fixed in PR #5162: searchSpotifyTracks now paginates in pages of 10 with offset up to the requested pool size, so the up-to-50 candidate semantics are preserved.

The Roleplay half (tool-executor.ts spotifySearch clamping 1–20 and forwarding unchanged, plus the tool definition's missing maximum) remains open on this issue for its own fix.

<!-- gh-comment-id:5309602413 --> @kolacheee commented on GitHub (Aug 16, 2026): The **Game-mode half** of this (the `game-spotify-music.service.ts` path — artist and generic-search sources passing the candidate pool's default of 50 straight into `GET /search`, deterministic 400 since Spotify's February 2026 cap of 10) is fixed in PR #5162: `searchSpotifyTracks` now paginates in pages of 10 with `offset` up to the requested pool size, so the up-to-50 candidate semantics are preserved. The **Roleplay half** (`tool-executor.ts` `spotifySearch` clamping 1–20 and forwarding unchanged, plus the tool definition's missing `maximum`) remains open on this issue for its own fix.
Author
Owner

@kolacheee commented on GitHub (Aug 16, 2026):

Game mode half complete

<!-- gh-comment-id:5309879227 --> @kolacheee commented on GitHub (Aug 16, 2026): Game mode half complete
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#2858
No description provided.