[GH-ISSUE #3030] [Issue]: Dry-run preview diverges from real generation for stored topP=0 (0 is silently rewritten to 1) #1599

Closed
opened 2026-10-21 05:40:27 +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/3030

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
There are two copies of normalizeChatTopP. The canonical one (used by the real /generate path) preserves a stored topP of 0 as 0. The duplicate copy in the dry-run route rewrites any value <= 0 to 1. Both read the same stored connection/chat parameters, so a user-stored topP of 0 (schema-valid, min 0) resolves to 0 in real generation but to 1 in the Dry Run preview — the preview does not match what the model actually receives.

How to reproduce (try it yourself)

  1. In a connection's or chat's Advanced Parameters, set topP (top_p) to 0 (valid per schema, min 0).
  2. Trigger a real generation via POST /api/generate.
  3. Trigger a Dry Run for the same chat via POST /api/generate/dryRun.

You'll see: the real call sends topP=0 (canonical Math.min(0,1)=0), but the dry-run preview reports/sends topP=1 (if (value <= 0) return 1).
Expected: the dry-run preview resolves topP identically to the real path, preserving 0.

Where it is
packages/server/src/routes/generate/dry-run-route.ts:464-468 (divergent local copy; resolved at call site line 609, applied at 1344-1345) vs canonical packages/server/src/services/generation/generation-parameters.ts:28-32 (real call site generate.routes.ts:3709, applied at 3746-3747). Schema: packages/shared/src/schemas/prompt.schema.ts:39 (topP z.number().min(0).max(1)).

What's happening
dry-run-route.ts defines its own normalizeChatTopP that maps any value <= 0 to 1, while the shared version treats 0 as legitimate (Math.min(0,1)=0). The two drifted, so the preview path no longer mirrors the real path for the boundary value topP=0.

Suggested fix
In packages/server/src/routes/generate/dry-run-route.ts, delete the local normalizeChatTopP (lines 464-468) and import the canonical one: add normalizeChatTopP to a named import from ../../services/generation/generation-parameters.js (same directory already imported for model-access-policy.js). The call site at line 609 is unchanged and now invokes the shared function. The only behavioral change is at topP=0 (the bug); negative values are unreachable here because stored params are validated through generationParametersSchema (min 0), and all other inputs already resolve identically.


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/3030 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** There are two copies of `normalizeChatTopP`. The canonical one (used by the real `/generate` path) preserves a stored topP of 0 as 0. The duplicate copy in the dry-run route rewrites any value `<= 0` to 1. Both read the same stored connection/chat parameters, so a user-stored topP of 0 (schema-valid, min 0) resolves to 0 in real generation but to 1 in the Dry Run preview — the preview does not match what the model actually receives. **How to reproduce (try it yourself)** 1. In a connection's or chat's Advanced Parameters, set topP (top_p) to 0 (valid per schema, min 0). 2. Trigger a real generation via `POST /api/generate`. 3. Trigger a Dry Run for the same chat via `POST /api/generate/dryRun`. You'll see: the real call sends topP=0 (canonical `Math.min(0,1)=0`), but the dry-run preview reports/sends topP=1 (`if (value <= 0) return 1`). Expected: the dry-run preview resolves topP identically to the real path, preserving 0. **Where it is** `packages/server/src/routes/generate/dry-run-route.ts:464-468` (divergent local copy; resolved at call site line 609, applied at 1344-1345) vs canonical `packages/server/src/services/generation/generation-parameters.ts:28-32` (real call site `generate.routes.ts:3709`, applied at 3746-3747). Schema: `packages/shared/src/schemas/prompt.schema.ts:39` (`topP z.number().min(0).max(1)`). **What's happening** `dry-run-route.ts` defines its own `normalizeChatTopP` that maps any value `<= 0` to 1, while the shared version treats 0 as legitimate (`Math.min(0,1)=0`). The two drifted, so the preview path no longer mirrors the real path for the boundary value topP=0. **Suggested fix** In `packages/server/src/routes/generate/dry-run-route.ts`, delete the local `normalizeChatTopP` (lines 464-468) and import the canonical one: add `normalizeChatTopP` to a named import from `../../services/generation/generation-parameters.js` (same directory already imported for `model-access-policy.js`). The call site at line 609 is unchanged and now invokes the shared function. The only behavioral change is at topP=0 (the bug); negative values are unreachable here because stored params are validated through `generationParametersSchema` (min 0), and all other inputs already resolve identically. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@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.

<!-- gh-comment-id:4834698437 --> @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.
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#1599
No description provided.