Skip to content

fix(chat): propagate toolApprovalLevel through agentic auto-sends#2464

Open
tlgimenes wants to merge 2 commits intomainfrom
fix/tool-approve
Open

fix(chat): propagate toolApprovalLevel through agentic auto-sends#2464
tlgimenes wants to merge 2 commits intomainfrom
fix/tool-approve

Conversation

@tlgimenes
Copy link
Contributor

@tlgimenes tlgimenes commented Feb 19, 2026

What is this contribution about?

When a user sets tool approval to "yolo" (disabled) in settings, GATEWAY_SEARCH_TOOLS and GATEWAY_DESCRIBE_TOOLS still prompted for approval on subsequent agentic steps.

Root cause: toolApprovalLevel was only sent in the initial requestMetadata, which is populated on user-initiated sends. The AI SDK's sendAutomaticallyWhen auto-sends fire with empty requestMetadata, so the field was absent from the request. The server then defaulted it to "none", causing toolNeedsApproval("none", true) to return true even for read-only gateway tools.

Fix — follow the existing agent/models/thread_id fallback pattern:

  1. Store toolApprovalLevel in the user-message metadata (messageMetadata) so it rides along in messages.at(-1)?.metadata for all subsequent auto-sends.
  2. Echo toolApprovalLevel from the server in the assistant-message metadata (messageMetadata callback on part.type === "start"), completing the fallback chain for multi-turn flows.
  3. In prepareSendMessagesRequest, read toolApprovalLevel from lastMsgMeta (last message metadata) instead of requestMetadata, and remove the now-unnecessary intersection type cast.

Screenshots/Demonstration

N/A — no UI changes.

How to Test

  1. Open the app and go to Settings → Tool Approval → set to "yolo" (disabled).
  2. Select an agent in smart_tool_selection or code_execution mode.
  3. Send a message that triggers tool discovery — verify no approval dialog appears for GATEWAY_SEARCH_TOOLS or GATEWAY_DESCRIBE_TOOLS.
  4. Let the agent run through multiple agentic steps (auto-sends) — verify approval is still not requested on subsequent steps.
  5. Change approval to "readonly" and send a new message — verify gateway tools (readOnlyHint: true) are auto-approved but non-readonly tools still prompt.
  6. Change approval to "none" and send a new message — verify all tools prompt for approval.

Migration Notes

No database migrations or configuration changes required.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Ensure agent auto-sends inherit toolApprovalLevel, temperature, and windowSize from the last message metadata, preventing unwanted approval prompts and resets to server defaults.

  • Bug Fixes
    • Persist toolApprovalLevel, temperature, and windowSize in message metadata; read them from lastMsgMeta for auto-sends instead of requestMetadata.
    • Echo these values in assistant start metadata; send windowSize under memory with thread_id when available.

Written for commit c748693. Summary will update on new commits.

Store toolApprovalLevel in user-message metadata so it is available
via messages.at(-1)?.metadata on every subsequent auto-send (where
requestMetadata is empty). Echo the value back from the server in the
assistant-message metadata so the fallback chain is complete for
multi-turn agentic flows.

Without this fix, GATEWAY_SEARCH_TOOLS and GATEWAY_DESCRIBE_TOOLS
always asked for approval on auto-sends even when the user had set
approval to "yolo", because the server defaulted toolApprovalLevel
to "none" when the field was absent from the request.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 19, 2026

Release Options

Should a new version be published when this PR is merged?

React with an emoji to vote on the release type:

Reaction Type Next Version
👍 Prerelease 2.106.1-alpha.1
🎉 Patch 2.106.1
❤️ Minor 2.107.0
🚀 Major 3.0.0

Current version: 2.106.0

Deployment

  • Deploy to production (triggers ArgoCD sync after Docker image is published)

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Both fields had server-side defaults (0.5 and DEFAULT_WINDOW_SIZE=50)
and were absent from the message-metadata fallback chain, meaning every
AI SDK auto-send (tool result → next step) silently reset them to their
defaults rather than preserving the values from the originating request.

Apply the same three-step pattern used for toolApprovalLevel:
1. Add temperature and windowSize to the Metadata interface so they
   can be carried in message metadata.
2. Echo both values from the server in the assistant-message metadata
   (part.type === "start") so they survive the round-trip.
3. Read them from lastMsgMeta in prepareSendMessagesRequest so every
   auto-send inherits the last-known values.

windowSize is reconstructed into the memory object (which also requires
thread_id) to satisfy the MemoryConfigSchema on the server.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant