[GH-ISSUE #3005] [Issue]: ToolEditor silently strips rich parameter-schema fields (enum/items/min/max/oneOf) on open+save #1577

Closed
opened 2026-10-21 05:39:32 +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/3005

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong

The Tool Editor seeds its parameter list from dbTool.parametersSchema but preserves only each property's type and description, then writes the schema back from that flattened model. Any other JSON-Schema keyword a parameter carries — enum, items (for array params), default, minimum, maximum, multipleOf, nested object properties, or schema-level additionalProperties/oneOf/root description — is silently discarded the moment a user opens the tool and clicks Save (or Export). A custom tool imported with a rich parameter schema (imports preserve the full nested record, and the server stores it verbatim) is therefore destructively flattened to bare {type, description} properties just by being edited. The user cannot see this happening: the editor renders the params as if nothing is wrong, and Save succeeds. The tool's contract sent to the model is now weaker or invalid (e.g. an array param with no items).

How to reproduce (try it yourself)

  1. Import a custom function whose parameters define constraints, e.g. {"type":"object","properties":{"unit":{"type":"string","enum":["c","f"]},"days":{"type":"array","items":{"type":"string"}}},"required":["unit"]}. The import path stores it verbatim in the DB.
  2. Open that tool in the Tool Editor. The reload effect parses only prop.type/prop.description into local params, dropping enum/items.
  3. Make any edit (or none) and click Save.
  4. Reopen/inspect the tool.

You'll see: the enum, items, and any numeric constraints are gone; properties are bare {type, description}.

Expected: opening and saving a tool with a rich parameter schema is non-destructive — constraints round-trip unchanged.

Where it is

packages/client/src/components/agents/ToolEditor.tsx: the seed effect at lines 96-110 (maps each property to {name, type, description, required}, dropping all other keywords) and buildParamsSchema at lines 140-149 (reconstructs each property as only {type, description}). Destructive persist confirmed at packages/server/src/services/storage/custom-tools.storage.ts:61 (updateFields.parametersSchema = JSON.stringify(data.parametersSchema), no merge). The shared ToolParameterProperty/ToolParameterSchema types (packages/shared/src/features/function-calls/tool-definitions.ts:8-27) explicitly support these keywords, and parametersSchema is z.record(z.unknown()) so rich schemas genuinely exist in the DB.

What's happening

The editor models parameters as a lossy ParamDef[] ({name, type, description, required}) instead of round-tripping the full per-property schema and the root schema. Both the read (seed effect) and the write (buildParamsSchema) only know type and description, so every other keyword is dropped on the round-trip, and the server overwrites the stored schema with the flattened result.

Suggested fix

Round-trip the full per-property schema AND the full root schema instead of emitting bare {type, description} objects.

  1. Extend ParamDef with raw?: Record<string, unknown> (the original per-property JSON-Schema), and add const [rawSchema, setRawSchema] = useState<Record<string, unknown>>({});.
  2. In the seed effect, stash the root schema (setRawSchema(schema)) and each property's full object (raw: prop). Reset setRawSchema({}) in the isNew branch alongside setLocalParams([]).
  3. Rebuild buildParamsSchema to merge edits onto the preserved schemas and add rawSchema to its deps:
const buildParamsSchema = useCallback(() => {
  const properties: Record<string, Record<string, unknown>> = {};
  const required: string[] = [];
  for (const p of localParams) {
    if (!p.name.trim()) continue;
    properties[p.name] = { ...(p.raw ?? {}), type: p.type, description: p.description };
    if (p.required) required.push(p.name);
  }
  const { properties: _drop, required: _dropReq, ...rootRest } = rawSchema;
  return { ...rootRest, type: "object", properties, required };
}, [localParams, rawSchema]);
  1. When the user deliberately changes a param's type via the dropdown (ToolEditor.tsx:453-457), clear that param's cached raw (raw: undefined) so stale type-specific keywords (e.g. items on a now-string param) are dropped.

Regression avoided: the original suggested fix stashed only a per-property raw and still rebuilt the root object from scratch — so schema-level additionalProperties/oneOf/root description (which the runtime forwards verbatim to the provider) would still be lost. The corrected fix also preserves the root schema. It also clears cached raw on a deliberate type change so the merge does not re-emit a keyword incompatible with the new type; an untouched open+save round-trips losslessly. No other tool type flows through buildParamsSchema, so static/webhook/script/built-in tools are unaffected.


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/3005 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The Tool Editor seeds its parameter list from `dbTool.parametersSchema` but preserves only each property's `type` and `description`, then writes the schema back from that flattened model. Any other JSON-Schema keyword a parameter carries — `enum`, `items` (for array params), `default`, `minimum`, `maximum`, `multipleOf`, nested object `properties`, or schema-level `additionalProperties`/`oneOf`/root `description` — is silently discarded the moment a user opens the tool and clicks Save (or Export). A custom tool imported with a rich parameter schema (imports preserve the full nested record, and the server stores it verbatim) is therefore destructively flattened to bare `{type, description}` properties just by being edited. The user cannot see this happening: the editor renders the params as if nothing is wrong, and Save succeeds. The tool's contract sent to the model is now weaker or invalid (e.g. an array param with no `items`). **How to reproduce (try it yourself)** 1. Import a custom function whose parameters define constraints, e.g. `{"type":"object","properties":{"unit":{"type":"string","enum":["c","f"]},"days":{"type":"array","items":{"type":"string"}}},"required":["unit"]}`. The import path stores it verbatim in the DB. 2. Open that tool in the Tool Editor. The reload effect parses only `prop.type`/`prop.description` into local params, dropping `enum`/`items`. 3. Make any edit (or none) and click Save. 4. Reopen/inspect the tool. You'll see: the `enum`, `items`, and any numeric constraints are gone; properties are bare `{type, description}`. Expected: opening and saving a tool with a rich parameter schema is non-destructive — constraints round-trip unchanged. **Where it is** `packages/client/src/components/agents/ToolEditor.tsx`: the seed effect at lines 96-110 (maps each property to `{name, type, description, required}`, dropping all other keywords) and `buildParamsSchema` at lines 140-149 (reconstructs each property as only `{type, description}`). Destructive persist confirmed at `packages/server/src/services/storage/custom-tools.storage.ts:61` (`updateFields.parametersSchema = JSON.stringify(data.parametersSchema)`, no merge). The shared `ToolParameterProperty`/`ToolParameterSchema` types (`packages/shared/src/features/function-calls/tool-definitions.ts:8-27`) explicitly support these keywords, and `parametersSchema` is `z.record(z.unknown())` so rich schemas genuinely exist in the DB. **What's happening** The editor models parameters as a lossy `ParamDef[]` (`{name, type, description, required}`) instead of round-tripping the full per-property schema and the root schema. Both the read (seed effect) and the write (`buildParamsSchema`) only know `type` and `description`, so every other keyword is dropped on the round-trip, and the server overwrites the stored schema with the flattened result. **Suggested fix** Round-trip the full per-property schema AND the full root schema instead of emitting bare `{type, description}` objects. 1. Extend `ParamDef` with `raw?: Record<string, unknown>` (the original per-property JSON-Schema), and add `const [rawSchema, setRawSchema] = useState<Record<string, unknown>>({});`. 2. In the seed effect, stash the root schema (`setRawSchema(schema)`) and each property's full object (`raw: prop`). Reset `setRawSchema({})` in the `isNew` branch alongside `setLocalParams([])`. 3. Rebuild `buildParamsSchema` to merge edits onto the preserved schemas and add `rawSchema` to its deps: ```ts const buildParamsSchema = useCallback(() => { const properties: Record<string, Record<string, unknown>> = {}; const required: string[] = []; for (const p of localParams) { if (!p.name.trim()) continue; properties[p.name] = { ...(p.raw ?? {}), type: p.type, description: p.description }; if (p.required) required.push(p.name); } const { properties: _drop, required: _dropReq, ...rootRest } = rawSchema; return { ...rootRest, type: "object", properties, required }; }, [localParams, rawSchema]); ``` 4. When the user deliberately changes a param's type via the dropdown (ToolEditor.tsx:453-457), clear that param's cached `raw` (`raw: undefined`) so stale type-specific keywords (e.g. `items` on a now-string param) are dropped. *Regression avoided:* the original suggested fix stashed only a per-property `raw` and still rebuilt the root object from scratch — so schema-level `additionalProperties`/`oneOf`/root `description` (which the runtime forwards verbatim to the provider) would still be lost. The corrected fix also preserves the root schema. It also clears cached `raw` on a deliberate type change so the merge does not re-emit a keyword incompatible with the new type; an untouched open+save round-trips losslessly. No other tool type flows through `buildParamsSchema`, so static/webhook/script/built-in tools are unaffected. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
bsakaguchi 2026-10-21 05:39:32 +07:00
Author
Owner

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

Fixed in merged staging PR #3018.

<!-- gh-comment-id:4833015825 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3018.
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#1577
No description provided.