[GH-ISSUE #2662] [Issue]: Generation-parameter salvage path forwards out-of-range sampler values unclamped #1313

Closed
opened 2026-10-21 05:31:23 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2662

Originally assigned to: @SpicyMarinara on GitHub.

Summary

When stored generation parameters fail schema validation on one field, the salvage path copies the remaining sampler values checking only Number.isFinite, bypassing the schema's min/max bounds — so out-of-range values (e.g. temperature: 7, topP: 5) flow through to the provider request unclamped.

Expected behavior

Salvaged parameters should be subject to the same per-field bounds as the canonical parse path; an out-of-range value should be rejected or clamped, not forwarded to the model.

Actual behavior

generationParametersSchema.partial().safeParse failing on one malformed field triggers a salvage branch that copies temperature/topP/topK/minP/maxTokens/maxContext/frequencyPenalty/presencePenalty using only typeof value === "number" && Number.isFinite(value), without the schema bounds. Those values are then merged and sent to the provider.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • Salvage branch: packages/server/src/routes/generate/generate-route-utils.ts:819–833 — copies scalars with only a finiteness check.
  • Schema bounds that are bypassed (packages/shared/src/schemas/prompt.schema.ts): temperature min(0).max(2), topP gt(0).max(1), maxTokens int().min(1), penalties min(-2).max(2).
  • Salvaged values flow into applyParameterOverrides (generate.routes.ts:3263–3286) and out to the provider body unclamped (e.g. openai.provider.ts:867 sets body.temperature with no clamp).
  • The write path (connections.storage.ts updateDefaultParameters) does not validate against the schema, so such a blob can be persisted in the first place.

Steps to reproduce

  1. Persist a connection defaultParameters JSON containing temperature: 7 plus one field that fails schema validation (forcing the salvage branch).
  2. Generate.
  3. Observe: temperature: 7 is merged in and sent to the model (provider 400 or degenerate output), with no indication the stored value was invalid.

Suggested fix

In the salvage branch, run each scalar through the same per-field schema (or explicit clamps) used by the canonical path before accepting it, instead of only Number.isFinite. Consider validating on the write path (updateDefaultParameters) as well so an invalid blob cannot be persisted.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Identified via systematic source review on staging (refs @ b826f8f4). Edge-triggered (requires a partially-malformed stored blob) but results in unvalidated sampler values reaching the model. Related to the top_p = 0 handling issue filed concurrently.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2662 Originally assigned to: @SpicyMarinara on GitHub. ## Summary When stored generation parameters fail schema validation on one field, the salvage path copies the remaining sampler values checking only `Number.isFinite`, bypassing the schema's min/max bounds — so out-of-range values (e.g. `temperature: 7`, `topP: 5`) flow through to the provider request unclamped. ## Expected behavior Salvaged parameters should be subject to the same per-field bounds as the canonical parse path; an out-of-range value should be rejected or clamped, not forwarded to the model. ## Actual behavior `generationParametersSchema.partial().safeParse` failing on one malformed field triggers a salvage branch that copies temperature/topP/topK/minP/maxTokens/maxContext/frequencyPenalty/presencePenalty using only `typeof value === "number" && Number.isFinite(value)`, without the schema bounds. Those values are then merged and sent to the provider. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - Salvage branch: `packages/server/src/routes/generate/generate-route-utils.ts:819–833` — copies scalars with only a finiteness check. - Schema bounds that are bypassed (`packages/shared/src/schemas/prompt.schema.ts`): `temperature min(0).max(2)`, `topP gt(0).max(1)`, `maxTokens int().min(1)`, penalties `min(-2).max(2)`. - Salvaged values flow into `applyParameterOverrides` (`generate.routes.ts:3263–3286`) and out to the provider body unclamped (e.g. `openai.provider.ts:867` sets `body.temperature` with no clamp). - The write path (`connections.storage.ts` `updateDefaultParameters`) does not validate against the schema, so such a blob can be persisted in the first place. ## Steps to reproduce 1. Persist a connection `defaultParameters` JSON containing `temperature: 7` plus one field that fails schema validation (forcing the salvage branch). 2. Generate. 3. Observe: `temperature: 7` is merged in and sent to the model (provider 400 or degenerate output), with no indication the stored value was invalid. ## Suggested fix In the salvage branch, run each scalar through the same per-field schema (or explicit clamps) used by the canonical path before accepting it, instead of only `Number.isFinite`. Consider validating on the write path (`updateDefaultParameters`) as well so an invalid blob cannot be persisted. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Identified via systematic source review on staging (refs @ `b826f8f4`). Edge-triggered (requires a partially-malformed stored blob) but results in unvalidated sampler values reaching the model. Related to the `top_p = 0` handling issue filed concurrently. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

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

Implemented on branch codex/spicymarinara-assigned-issues: salvaged stored generation parameters now pass per-field schema bounds, and default-parameter saves validate before persisting. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051980 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: salvaged stored generation parameters now pass per-field schema bounds, and default-parameter saves validate before persisting. Final validation will run after the full assigned sweep per maintainer request.
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#1313
No description provided.