[PR #8595] [MERGED] fix(tools): saving a tool sends and checks only what changed; errors name the field #8691

Closed
opened 2026-11-07 17:38:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: staging ← Head: fix/tool-editor-arrow-escape-8516


📝 Commits (2)

  • c13bc1b fix(tools): saving a tool sends and checks only what changed; errors name the field (#8516)
  • f62618c fix(mari-db): tool length limits apply only to values a change sets (#8516)

📊 Changes

7 files changed (+271 additions, -51 deletions)

View changed files

📝 packages/client/src/components/agents/ToolEditor.tsx (+25 -19)
📝 packages/client/src/lib/api-client.ts (+8 -3)
📝 packages/client/src/lib/custom-tool-transfer.ts (+27 -0)
📝 packages/server/src/services/mari-db/mari-db.service.ts (+18 -3)
📝 scripts/regressions/custom-tool-import-security.regression.ts (+29 -0)
📝 scripts/regressions/mari/db-execution-security.regression.ts (+59 -0)
📝 scripts/regressions/persona-client-contract.regression.ts (+105 -26)

📄 Description

Linked issue

Closes #8516

Why this change

  • The report: after saving and reopening a script tool whose description contains ->, any save, even a toggle, fails with "Tool name must be lowercase snake_case" although the name is valid.
  • The reporter's theory doesn't hold: they guessed the editor HTML-escapes on load and validates escaped text, but nothing on the editor's load/save path escapes text, and the name check reads only the name.
    • Traced through storage, routes, request hooks and the editor.
    • Probed through the real routes and the built client in Chromium: a description with ->, =>, & and quotes round-trips exactly, and a toggle-only save returns 200.
  • The symptom has real causes, which this PR fixes:
    1. The editor re-sent and re-checked every field on every save. A value stored by a profile import or by Professor Mari that the editor would reject blocked every later save, including a toggle. Examples: a name with an invisible character that looks valid on screen, or a description over 500 characters.
    2. Server validation errors lost their field. The error handler sends details, which the client never read, so the editor showed a bare "Validation Error" and couldn't say which field failed.
    3. Professor Mari could write such values: it checked the name pattern but not the editor's 100- and 500-character limits.

What changed

  • ToolEditor.tsx: an existing tool now saves only the fields that changed (buildCustomToolPatch in lib/custom-tool-transfer.ts), and only those are checked.
    • The parameters schema is compared as data, so a reopened schema with reordered keys isn't a change.
    • A new tool still sends and checks everything.
  • lib/api-client.ts: formatFirstApiValidationIssue reads the error handler's details as well as issues. The editor uses it, so errors name the field, e.g. description: Too big: expected string to have <=500 characters. This also helps the persona editor and persona import, which already use the helper.
  • mari-db.service.ts: validateCustomToolRow enforces the shared schema's name and description limits, so Mari can't store a tool the editor would refuse.

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

Agent-side checks:

  • Pass: pnpm check (format, lint, types, localization, build).
  • scripts/regressions/custom-tool-import-security.regression.ts: a tool stored with an invisible-character name and a 900-character description of -> and => produces a patch of only {includeHiddenContext: true} for a toggle. An unchanged or key-reordered schema produces nothing, and a name change sends only the name.
  • scripts/regressions/persona-client-contract.regression.ts: a details error with a string path formats as description: Too big. Fails with the old formatter.
  • scripts/regressions/mari/db-execution-security.regression.ts: Mari refuses a 501-character tool description and stores nothing. Fails without the limit.
    • Dottore follow-up (f62618cee): the limits apply only to values a change sets. A stored tool whose description is already over 500 characters accepts a sortOrder-only Mari patch, and a patch that sets a new over-long description is still refused. The regression fails without the fix ("Blocking validation failed" on the sortOrder patch). pnpm check passes, and a local CodeRabbit review of the commit found nothing.

Please verify by hand:

  • Manually verify, with a script tool whose description contains ->, that reopening it, toggling Include hidden context and saving succeeds.
  • Manually verify that saving a tool with an invalid changed field shows an error naming that field.

For the reporter: if their tool still won't save, its exported JSON (or a Support Diagnostic) would show whether the stored name contains a hidden character. With this PR, toggles save regardless, and a real error names its field.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

Owner: @SpicyMarinara (made by Claude).

🤖 Generated with Claude Code


🔄 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/8595 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/tool-editor-arrow-escape-8516` --- ### 📝 Commits (2) - [`c13bc1b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c13bc1b0190f14454860afca752163587e4fe4f9) fix(tools): saving a tool sends and checks only what changed; errors name the field (#8516) - [`f62618c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f62618cee43416ee4704b905b52dc2984e725b6e) fix(mari-db): tool length limits apply only to values a change sets (#8516) ### 📊 Changes **7 files changed** (+271 additions, -51 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/agents/ToolEditor.tsx` (+25 -19) 📝 `packages/client/src/lib/api-client.ts` (+8 -3) 📝 `packages/client/src/lib/custom-tool-transfer.ts` (+27 -0) 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+18 -3) 📝 `scripts/regressions/custom-tool-import-security.regression.ts` (+29 -0) 📝 `scripts/regressions/mari/db-execution-security.regression.ts` (+59 -0) 📝 `scripts/regressions/persona-client-contract.regression.ts` (+105 -26) </details> ### 📄 Description ## Linked issue Closes #8516 ## Why this change - **The report:** after saving and reopening a script tool whose description contains `->`, any save, even a toggle, fails with "Tool name must be lowercase snake_case" although the name is valid. - **The reporter's theory doesn't hold:** they guessed the editor HTML-escapes on load and validates escaped text, but nothing on the editor's load/save path escapes text, and the name check reads only the name. - Traced through storage, routes, request hooks and the editor. - Probed through the real routes and the built client in Chromium: a description with `->`, `=>`, `&` and quotes round-trips exactly, and a toggle-only save returns 200. - **The symptom has real causes**, which this PR fixes: 1. **The editor re-sent and re-checked every field on every save.** A value stored by a profile import or by Professor Mari that the editor would reject blocked every later save, including a toggle. Examples: a name with an invisible character that looks valid on screen, or a description over 500 characters. 2. **Server validation errors lost their field.** The error handler sends `details`, which the client never read, so the editor showed a bare "Validation Error" and couldn't say which field failed. 3. **Professor Mari could write such values:** it checked the name pattern but not the editor's 100- and 500-character limits. ## What changed - **`ToolEditor.tsx`:** an existing tool now saves only the fields that changed (`buildCustomToolPatch` in `lib/custom-tool-transfer.ts`), and only those are checked. - The parameters schema is compared as data, so a reopened schema with reordered keys isn't a change. - A new tool still sends and checks everything. - **`lib/api-client.ts`:** `formatFirstApiValidationIssue` reads the error handler's `details` as well as `issues`. The editor uses it, so errors name the field, e.g. `description: Too big: expected string to have <=500 characters`. This also helps the persona editor and persona import, which already use the helper. - **`mari-db.service.ts`:** `validateCustomToolRow` enforces the shared schema's name and description limits, so Mari can't store a tool the editor would refuse. ## 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 Agent-side checks: - **Pass:** `pnpm check` (format, lint, types, localization, build). - **`scripts/regressions/custom-tool-import-security.regression.ts`:** a tool stored with an invisible-character name and a 900-character description of `->` and `=>` produces a patch of only `{includeHiddenContext: true}` for a toggle. An unchanged or key-reordered schema produces nothing, and a name change sends only the name. - **`scripts/regressions/persona-client-contract.regression.ts`:** a `details` error with a string path formats as `description: Too big`. Fails with the old formatter. - **`scripts/regressions/mari/db-execution-security.regression.ts`:** Mari refuses a 501-character tool description and stores nothing. Fails without the limit. - **Dottore follow-up (f62618cee):** the limits apply only to values a change sets. A stored tool whose description is already over 500 characters accepts a `sortOrder`-only Mari patch, and a patch that sets a new over-long description is still refused. The regression fails without the fix ("Blocking validation failed" on the `sortOrder` patch). `pnpm check` passes, and a local CodeRabbit review of the commit found nothing. Please verify by hand: - [ ] Manually verify, with a script tool whose description contains `->`, that reopening it, toggling **Include hidden context** and saving succeeds. - [ ] Manually verify that saving a tool with an invalid changed field shows an error naming that field. **For the reporter:** if their tool still won't save, its exported JSON (or a Support Diagnostic) would show whether the stored name contains a hidden character. With this PR, toggles save regardless, and a real error names its field. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) Owner: @SpicyMarinara (made by Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:38:58 +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#8691
No description provided.