[GH-ISSUE #2663] [Issue]: top_p = 0 is mishandled — schema rejects the save and normalizers rewrite 0 to 1 (inverts the sampler) #1316

Closed
opened 2026-10-21 05:31:26 +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/2663

Originally assigned to: @SpicyMarinara on GitHub.

Summary

top_p = 0 is handled inconsistently across the stack: the shared schema's exclusive lower bound rejects it (failing the entire preset save), while two normalizers silently rewrite a stored 0 to 1 — the opposite sampler behavior.

Expected behavior

top_p should be treated consistently with sibling samplers (temperature, topK, minP all allow 0). A 0 value should either be accepted and preserved, or rejected — but not both rejected on save in one place and rewritten to 1 in another.

Actual behavior

  • The schema defines topP: z.number().gt(0).max(1).default(1); the exclusive .gt(0) makes 0 invalid, while the client editor's slider allows 0 and includes it in the PATCH body. The server route parses with no try/catch, so topP: 0 throws a ZodError and the entire preset update is rejected.
  • Separately, normalizeChatTopP (and OpenAI's normalizeTopP) return 1 whenever the value is <= 0, so a stored 0 that reaches the request becomes 1 (no nucleus filtering — the opposite of the near-greedy behavior 0 implies).

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • Schema: packages/shared/src/schemas/prompt.schema.ts — topP uses .gt(0) (siblings use .min(0)).
  • Save rejection: the preset-update route parses the body with the schema and no error handling, so topP: 0 fails validation and the whole update is rejected.
  • Normalizer rewrite: packages/server/src/services/generation/generation-parameters.ts:31–35 (normalizeChatTopP returns 1 when value <= 0); packages/server/src/services/llm/providers/openai.provider.ts:187–191 (normalizeTopP returns 1 when topP <= 0, used at :868/:1102/:1536). A preset topP: 0 that bypasses the schema (e.g. via import) is sent as 1.

Steps to reproduce

A — save rejected:

  1. In the preset advanced-parameters editor, drag top_p to 0 and save.
  2. Observe: the PATCH fails schema validation (gt(0)) and the whole preset update is rejected.

B — silent inversion:

  1. Get a stored topP: 0 into a preset/params via a path that bypasses the schema (e.g. import).
  2. Generate.
  3. Observe: the request sends top_p: 1 instead of 0.

Suggested fix

  • Change the schema to topP: z.number().min(0).max(1).default(1) to match the inclusive lower bound used by temperature/minP/topK.
  • Make top_p = 0 handling consistent everywhere: either preserve 0 (and let provider-layer normalization decide the API-valid value), or treat it as "unset" by returning undefined so it falls through to the prior value — but do not silently rewrite 0 → 1. Align normalizeChatTopP and the preset assembler path on the same rule.

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). top_p = 0 is a degenerate/niche value, but the inconsistency (rejected on save vs. silently inverted at send) is a real correctness gap. Related to the parameter-salvage 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/2663 Originally assigned to: @SpicyMarinara on GitHub. ## Summary `top_p = 0` is handled inconsistently across the stack: the shared schema's exclusive lower bound rejects it (failing the entire preset save), while two normalizers silently rewrite a stored `0` to `1` — the opposite sampler behavior. ## Expected behavior `top_p` should be treated consistently with sibling samplers (`temperature`, `topK`, `minP` all allow `0`). A `0` value should either be accepted and preserved, or rejected — but not both rejected on save in one place and rewritten to `1` in another. ## Actual behavior - The schema defines `topP: z.number().gt(0).max(1).default(1)`; the exclusive `.gt(0)` makes `0` invalid, while the client editor's slider allows `0` and includes it in the PATCH body. The server route parses with no try/catch, so `topP: 0` throws a `ZodError` and the **entire** preset update is rejected. - Separately, `normalizeChatTopP` (and OpenAI's `normalizeTopP`) return `1` whenever the value is `<= 0`, so a stored `0` that reaches the request becomes `1` (no nucleus filtering — the opposite of the near-greedy behavior `0` implies). ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - Schema: `packages/shared/src/schemas/prompt.schema.ts` — `topP` uses `.gt(0)` (siblings use `.min(0)`). - Save rejection: the preset-update route parses the body with the schema and no error handling, so `topP: 0` fails validation and the whole update is rejected. - Normalizer rewrite: `packages/server/src/services/generation/generation-parameters.ts:31–35` (`normalizeChatTopP` returns `1` when `value <= 0`); `packages/server/src/services/llm/providers/openai.provider.ts:187–191` (`normalizeTopP` returns `1` when `topP <= 0`, used at `:868`/`:1102`/`:1536`). A preset `topP: 0` that bypasses the schema (e.g. via import) is sent as `1`. ## Steps to reproduce **A — save rejected:** 1. In the preset advanced-parameters editor, drag `top_p` to `0` and save. 2. Observe: the PATCH fails schema validation (`gt(0)`) and the whole preset update is rejected. **B — silent inversion:** 1. Get a stored `topP: 0` into a preset/params via a path that bypasses the schema (e.g. import). 2. Generate. 3. Observe: the request sends `top_p: 1` instead of `0`. ## Suggested fix - Change the schema to `topP: z.number().min(0).max(1).default(1)` to match the inclusive lower bound used by `temperature`/`minP`/`topK`. - Make `top_p = 0` handling consistent everywhere: either preserve `0` (and let provider-layer normalization decide the API-valid value), or treat it as "unset" by returning `undefined` so it falls through to the prior value — but do not silently rewrite `0` → `1`. Align `normalizeChatTopP` and the preset assembler path on the same rule. ## 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`). `top_p = 0` is a degenerate/niche value, but the inconsistency (rejected on save vs. silently inverted at send) is a real correctness gap. Related to the parameter-salvage 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: top_p=0 is accepted by schema and preserved by normalizers instead of being rewritten to 1. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051970 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: top_p=0 is accepted by schema and preserved by normalizers instead of being rewritten to 1. 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#1316
No description provided.