[GH-ISSUE #3020] [Issue]: chatResolvedToolNames includes stripped Spotify tools, bypassing the clean 'not allowed' denial #1591

Closed
opened 2026-10-21 05:40:17 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3020

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

chatResolvedToolNames (the runtime allow-list) is computed from toolDefs BEFORE the Spotify-unavailable filter runs. When Spotify credentials/scope are unavailable, the Spotify tools are removed from toolDefs (so the provider is never told about them), but chatResolvedToolNames still contains those Spotify tool names. That same set is later used as the runtime allow-list in the chat tool loop to decide which model tool calls are permitted. So a (hallucinated or textual) spotify_* call is treated as permitted and executed, returning a generic "Spotify not configured" error from the tool body instead of the cleaner, intended "Tool not allowed in this context" denial.

How to reproduce (try it yourself)

  1. Enable chat tools (enableTools=true) with no activeToolIds filter so toolDefs includes all non-agent-only tools, including the spotify_* tools.
  2. Have Spotify not connected / missing the user-modify-playback-state scope, so spotifyToolsAvailable is false.
  3. Have the model emit a spotify_play call (e.g. via a textual/hallucinated tool call).

You'll see: chatResolvedToolNames.has("spotify_play") is true, so the call is executed and returns { error: "Spotify not configured..." }, rather than the consistent denial { error: "Tool not allowed in this context: spotify_play" }.

Expected: the runtime allow-list matches the tools actually offered to the provider, so a stripped spotify_* call hits the clean "not allowed" denial.

Where it is

packages/server/src/services/generation/tool-resolution-runtime.ts:538 (pre-strip snapshot of chatResolvedToolNames) and :571-577 (toolDefs-only Spotify strip), returned stale at :772. Consumed in packages/server/src/routes/generate.routes.ts:6411-6424 (denial path bypassed). Divergent outcome in packages/server/src/services/tools/tool-executor.ts:1567-1569 (spotifyPlay generic error).

What's happening

Ordering bug: the allow-list chatResolvedToolNames is snapshotted from toolDefs before the Spotify-availability filter mutates toolDefs. The two are meant to be in sync but diverge for stripped Spotify tools.

Suggested fix

Recompute chatResolvedToolNames from toolDefs AFTER the Spotify-unavailable strip. Change line 538 from const to let, then inside the existing if (!spotifyToolsAvailable && toolDefs) { ... } block, after the strip/log:

// Keep the runtime allow-list in sync with the tools actually offered to the
// provider; otherwise stripped Spotify tools stay "permitted" in the chat tool
// loop and bypass the cleaner "Tool not allowed in this context" denial.
chatResolvedToolNames = new Set((toolDefs ?? []).map((toolDef) => toolDef.function.name));

Regression avoided: the recompute must happen INSIDE the !spotifyToolsAvailable block (after the strip), NOT before line 548, because resolveSpotifyToolAvailabilityRequest at line 548 relies on seeing the spotify_* names in the set to decide credentials are required. Filtering the set before that call would break Spotify availability detection entirely (creds never fetched). Recomputing after the strip leaves the happy path (Spotify available) untouched and the agent Spotify path (which uses its own allowedToolNames) unaffected; only the chat-loop allow-list is narrowed.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3020 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `chatResolvedToolNames` (the runtime allow-list) is computed from `toolDefs` BEFORE the Spotify-unavailable filter runs. When Spotify credentials/scope are unavailable, the Spotify tools are removed from `toolDefs` (so the provider is never told about them), but `chatResolvedToolNames` still contains those Spotify tool names. That same set is later used as the runtime allow-list in the chat tool loop to decide which model tool calls are permitted. So a (hallucinated or textual) `spotify_*` call is treated as permitted and executed, returning a generic "Spotify not configured" error from the tool body instead of the cleaner, intended "Tool not allowed in this context" denial. **How to reproduce (try it yourself)** 1. Enable chat tools (`enableTools=true`) with no `activeToolIds` filter so `toolDefs` includes all non-agent-only tools, including the `spotify_*` tools. 2. Have Spotify not connected / missing the `user-modify-playback-state` scope, so `spotifyToolsAvailable` is false. 3. Have the model emit a `spotify_play` call (e.g. via a textual/hallucinated tool call). You'll see: `chatResolvedToolNames.has("spotify_play")` is true, so the call is executed and returns `{ error: "Spotify not configured..." }`, rather than the consistent denial `{ error: "Tool not allowed in this context: spotify_play" }`. Expected: the runtime allow-list matches the tools actually offered to the provider, so a stripped `spotify_*` call hits the clean "not allowed" denial. **Where it is** `packages/server/src/services/generation/tool-resolution-runtime.ts:538` (pre-strip snapshot of `chatResolvedToolNames`) and `:571-577` (`toolDefs`-only Spotify strip), returned stale at `:772`. Consumed in `packages/server/src/routes/generate.routes.ts:6411-6424` (denial path bypassed). Divergent outcome in `packages/server/src/services/tools/tool-executor.ts:1567-1569` (spotifyPlay generic error). **What's happening** Ordering bug: the allow-list `chatResolvedToolNames` is snapshotted from `toolDefs` before the Spotify-availability filter mutates `toolDefs`. The two are meant to be in sync but diverge for stripped Spotify tools. **Suggested fix** Recompute `chatResolvedToolNames` from `toolDefs` AFTER the Spotify-unavailable strip. Change line 538 from `const` to `let`, then inside the existing `if (!spotifyToolsAvailable && toolDefs) { ... }` block, after the strip/log: ```ts // Keep the runtime allow-list in sync with the tools actually offered to the // provider; otherwise stripped Spotify tools stay "permitted" in the chat tool // loop and bypass the cleaner "Tool not allowed in this context" denial. chatResolvedToolNames = new Set((toolDefs ?? []).map((toolDef) => toolDef.function.name)); ``` *Regression avoided:* the recompute must happen INSIDE the `!spotifyToolsAvailable` block (after the strip), NOT before line 548, because `resolveSpotifyToolAvailabilityRequest` at line 548 relies on seeing the `spotify_*` names in the set to decide credentials are required. Filtering the set before that call would break Spotify availability detection entirely (creds never fetched). Recomputing after the strip leaves the happy path (Spotify available) untouched and the agent Spotify path (which uses its own `allowedToolNames`) unaffected; only the chat-loop allow-list is narrowed. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
bsakaguchi 2026-10-21 05:40:17 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3021, now merged into staging. The chat tool allow-list is recomputed after unavailable Spotify tools are stripped, so hallucinated spotify_* calls are denied as not allowed instead of executing.

<!-- gh-comment-id:4833663774 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3021, now merged into staging. The chat tool allow-list is recomputed after unavailable Spotify tools are stripped, so hallucinated spotify_* calls are denied as not allowed instead of executing.
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#1591
No description provided.