mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3029] [Issue]: Imported/seeded preset generation parameters are never clamped, so out-of-range values (e.g. temperature 99) reach the provider #1600
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1600
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3029
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The interactive preset CRUD routes validate generation parameters against a Zod schema (temperature 0..2, topP 0..1, etc.), but the import and seed paths write parameters straight to storage with no validation, and the assembler's read path performs no clamping either. So a hand-edited or malicious
.marinara.jsonwhoseparameterscontains out-of-range values is stored and later forwarded to the LLM provider unclamped.How to reproduce (try it yourself)
.marinara.jsonpreset envelope withdata.preset.parameters={"temperature":99,"topP":5}.POST /api/import(importMarinara->importPreset->storage.create).You'll see:
parsePresetParametersreturns temperature 99 / topP 5 with no clamping, and those values are forwarded to the provider request (which typically just rejects with a 400).Expected: parameters are clamped/validated to schema ranges before reaching the provider.
Where it is
packages/server/src/services/import/marinara.importer.ts:565(parameters: safeParseJson(p.parameters, {})) and658-668(passthrough);packages/server/src/services/storage/prompts.storage.ts:76(JSON.stringifywith no validation); read pathpackages/server/src/services/prompt/assembler.ts:215-225(parsePresetParameters, no clamp); reaches provider atgenerate.routes.ts:2288-2290and6543-6548. The connection/chat stored-params path DOES clamp viagenerationParametersSchema.partial().safeParse(generate-route-utils.ts:1065), confirming only the preset-assembler path is unclamped.What's happening
The import/seed write paths bypass
generationParametersSchema, and neither storage nor the assembler re-validates the stored object. The Zod range checks only run on the interactive create/update routes.Suggested fix
Clamp at the single read chokepoint
parsePresetParameters()inpackages/server/src/services/prompt/assembler.ts:215-225, using the NON-throwingsafeParsewith per-field salvage, mirroring the existing convention atgenerate-route-utils.ts:1065. This covers import, seed, AND presets already stored from a previously-imported bad file, for all chat modes. AddgenerationParametersSchemato the shared import (line 21) and replace the body so it (1) merges defaults + parsed, (2) triesgenerationParametersSchema.safeParse(merged)and returns.dataon success, (3) on failure re-validates each field individually with the schema's per-fieldsafeParse, keeping valid fields and falling back to the in-range default for any rejected field, and (4) never throws.Regression avoided: do NOT use the throwing
generationParametersSchema.parse(...)—parsePresetParametersandimportPresetcurrently never throw, and a single wrong-TYPED field in a legacy/hand-edited file (e.g.temperature: "hot") would then abort the import or break the chat for every mode. The per-field-salvagesafeParseapproach clamps out-of-range values, tolerates legacy malformed fields, and never throws. (Defense-in-depth: optionally also validate at write time inimportPresetand the seed withgenerationParametersSchema.partial().safeParse, but the read-path clamp alone resolves the bug.)AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed on staging in PR #3031 (merged as
f542e282). Closing manually because GitHub auto-close keywords only close issues when merged into the default branch (main), not staging.