[PR #4359] [MERGED] Validate tool arguments before execution #6348

Closed
opened 2026-10-23 04:09:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4359
Author: @Xelvanis
Created: 7/31/2026
Status: ✅ Merged
Merged: 7/31/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/tool-argument-validation


📝 Commits (2)

  • 32495d3 fix(tools): validate execution arguments and failures
  • 07fa949 Merge branch 'staging' into fix/tool-argument-validation

📊 Changes

9 files changed (+408 additions, -65 deletions)

View changed files

📝 packages/server/package.json (+2 -0)
📝 packages/server/src/routes/generate.routes.ts (+2 -2)
📝 packages/server/src/routes/generate/retry-agents-route.ts (+9 -9)
📝 packages/server/src/services/generation/tool-resolution-runtime.ts (+4 -2)
📝 packages/server/src/services/tools/tool-executor.ts (+148 -44)
📝 packages/shared/src/features/function-calls/tool-definitions.ts (+1 -1)
📝 packages/shared/src/features/function-calls/tools/spotify-play/manifest.ts (+1 -1)
📝 pnpm-lock.yaml (+16 -5)
📝 scripts/regressions/prompt.regression.ts (+225 -1)

📄 Description

Linked issue

Closes #4358

Why this change

  • Provider-generated tool arguments were treated as trusted even though the advertised JSON schema was only advisory. Malformed or schema-invalid calls could reach built-ins, scripts, or webhooks, and execution failures could be returned to the model without a reliable failure signal.

What changed

  • Validate every tool call as valid object-shaped JSON against the same built-in or custom schema advertised to the provider before execution.
  • Preserve explicit execution success, semantic failure, and webhook HTTP status, then format failures consistently for every model-facing tool path.
  • Keep valid successful tool payloads compatible and allow Spotify play calls containing either or both supported target forms.
  • Add deterministic regression coverage for malformed JSON, missing and format-invalid arguments, webhook failures, successful calls, and schema compilation behavior.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • pnpm check passed locally, including localization checks, workspace lint/type checks, and production builds.
  • pnpm regression:prompt passed.
  • Exercised the committed behavior through Marinara's real chat UI using an isolated local Playwright session and deterministic local provider/webhook fixtures.
  • Verified missing required arguments, malformed JSON, invalid email format, HTTP 409 failure propagation, and successful static-tool execution.
  • Confirmed invalid calls were rejected before side effects, the browser console remained clean, and no external provider or user data was used.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

Not applicable; this changes server-side tool validation and result handling without altering the UI.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when using built-in and custom tools by validating arguments before execution.
    • Tool errors now return clearer, consistently formatted responses, including relevant status information.
    • Improved handling of tool results across retries and integrations such as Spotify.
    • Fixed validation for tools requiring one of multiple supported parameters.
  • Tests

    • Added regression coverage for invalid arguments, custom tools, webhook errors, and asynchronous validation scenarios.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4359 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 7/31/2026 **Status:** ✅ Merged **Merged:** 7/31/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/tool-argument-validation` --- ### 📝 Commits (2) - [`32495d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/32495d36f0b60f832d7e47aaebca0cf6b8f99f37) fix(tools): validate execution arguments and failures - [`07fa949`](https://github.com/Pasta-Devs/Marinara-Engine/commit/07fa949473ebb021367b53bd62ff3b298aa8ca59) Merge branch 'staging' into fix/tool-argument-validation ### 📊 Changes **9 files changed** (+408 additions, -65 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/package.json` (+2 -0) 📝 `packages/server/src/routes/generate.routes.ts` (+2 -2) 📝 `packages/server/src/routes/generate/retry-agents-route.ts` (+9 -9) 📝 `packages/server/src/services/generation/tool-resolution-runtime.ts` (+4 -2) 📝 `packages/server/src/services/tools/tool-executor.ts` (+148 -44) 📝 `packages/shared/src/features/function-calls/tool-definitions.ts` (+1 -1) 📝 `packages/shared/src/features/function-calls/tools/spotify-play/manifest.ts` (+1 -1) 📝 `pnpm-lock.yaml` (+16 -5) 📝 `scripts/regressions/prompt.regression.ts` (+225 -1) </details> ### 📄 Description ## Linked issue Closes #4358 ## Why this change - Provider-generated tool arguments were treated as trusted even though the advertised JSON schema was only advisory. Malformed or schema-invalid calls could reach built-ins, scripts, or webhooks, and execution failures could be returned to the model without a reliable failure signal. ## What changed - Validate every tool call as valid object-shaped JSON against the same built-in or custom schema advertised to the provider before execution. - Preserve explicit execution success, semantic failure, and webhook HTTP status, then format failures consistently for every model-facing tool path. - Keep valid successful tool payloads compatible and allow Spotify play calls containing either or both supported target forms. - Add deterministic regression coverage for malformed JSON, missing and format-invalid arguments, webhook failures, successful calls, and schema compilation behavior. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed locally, including localization checks, workspace lint/type checks, and production builds. - `pnpm regression:prompt` passed. - Exercised the committed behavior through Marinara's real chat UI using an isolated local Playwright session and deterministic local provider/webhook fixtures. - Verified missing required arguments, malformed JSON, invalid email format, HTTP 409 failure propagation, and successful static-tool execution. - Confirmed invalid calls were rejected before side effects, the browser console remained clean, and no external provider or user data was used. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) Not applicable; this changes server-side tool validation and result handling without altering the UI. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved reliability when using built-in and custom tools by validating arguments before execution. * Tool errors now return clearer, consistently formatted responses, including relevant status information. * Improved handling of tool results across retries and integrations such as Spotify. * Fixed validation for tools requiring one of multiple supported parameters. * **Tests** * Added regression coverage for invalid arguments, custom tools, webhook errors, and asynchronous validation scenarios. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:09:34 +07:00
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#6348
No description provided.