mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3017] [Issue]: spotify_set_volume sends volume_percent=NaN for non-numeric input instead of falling back to a valid value #1589
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1589
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3017
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
spotifySetVolumecomputesconst volume = Math.max(0, Math.min(100, Number(args.volume ?? 50)));. The intent is that a missing/invalid volume falls back to 50 and otherwise clamps to [0,100]. But the clamp does not guard NaN: ifargs.volumeis non-numeric,Number(args.volume)is NaN,Math.min(100, NaN)is NaN, andMath.max(0, NaN)is NaN. The NaN is interpolated into the request URL asvolume_percent=NaN, which Spotify rejects with HTTP 400, so the tool returns an error instead of applying a sane default. (args.volume ?? 50only rescues null/undefined, not a non-numeric string.)How to reproduce (try it yourself)
spotify_set_volumewith{ "volume": "loud" }(a non-numeric the model can emit, especially via text-mode tool-call parsing where args are not type-validated).You'll see:
Number("loud")→ NaN;Math.max(0, Math.min(100, NaN))→ NaN; the request URL becomeshttps://api.spotify.com/v1/me/player/volume?volume_percent=NaN; Spotify returns 400; the tool returns{ error: "Spotify volume failed (400): ..." }.Expected: a non-numeric volume clamps to the 50 default and the volume is set, rather than producing
volume_percent=NaNand a 400.Where it is
packages/server/src/services/tools/tool-executor.ts:1785(spotifySetVolume); the URL interpolation at line 1789. The arg-parse entry point with no validation isexecuteToolCallsattool-executor.ts:190(JSON.parsewith no type coercion). The finite-guarded helperclampNumberis at lines 814-818.What's happening
Volume normalization uses
Math.max(0, Math.min(100, Number(...)))which does not handle NaN; an invalidNumber()result passes through to the API call instead of using theclampNumberhelper that falls back on non-finite input.Suggested fix
Replace line 1785:
with:
clampNumber(lines 814-818) guards non-finite results (if (!Number.isFinite(num)) return fallback;), so a non-numericargs.volumefalls back to 50 instead of producingvolume_percent=NaN. This matches the existing idiomatic call sites (e.g. line 1490,clampNumber(args.limit ?? 30, 30, 1, 50)).Regression note: this is the source finding's exact suggested fix (no correction needed).
clampNumberadditionally appliesMath.round, which is an improvement, not a regression — Spotify'svolume_percentis an integer and the companion REST handler atpackages/server/src/routes/spotify-auth.routes.ts:684already rounds. The happy path (null/undefined → 50; valid numbers clamped to [0,100]) is preserved, and only thespotify_set_volumedispatch reaches this function.Note: v2.0.7 (origin/staging) already applied this exact
clampNumberfix to the siblingspotify_searchandspotify_get_playlistslimits (tool-executor.ts:780, 1531) but leftspotify_set_volumeunchanged — so this is a consistent, already-established follow-up.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in merged staging PR #3018.