[GH-ISSUE #2765] [Issue]: Sampler params silently dropped per provider/path — Anthropic top_p, Gemini default topK=0 (400), dry-run minP/stop/top_p, Responses stop, claude-subscription all #1403

Closed
opened 2026-10-21 05:33:13 +07:00 by bsakaguchi · 3 comments
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The same class as the already-fixed #2668 (minP) / #2658 (stop): a configured sampler param is silently dropped on a specific provider or send-path, diverging from preset intent and from the same preset's behavior elsewhere. Several distinct missed instances remain.

Sub-bug 1: Anthropic never sends top_p (missed-instance)

(a) options.topP is resolved and clamped by the pipeline but the Anthropic body builder only sets temperature, top_k, stop_sequences — never top_p. The only top_p reference is delete body.top_p in stripAnthropicSamplingParameters (a defensive delete that never fires from topP). OpenAI and Google both send it, so the same preset behaves differently on Claude.
(b) Set a non-default topP in a preset/connection; run a native Anthropic generation; top_p is absent from the request.
(c) anthropic.provider.ts:284-294 (chatComplete body — VERIFIED: temperature/top_k/stop_sequences only at 291-293, no top_p), 413-441 (chat body), 30-34 (strip). topP reaches options via generate.routes.ts:3468/6083. Kind: missed-instance.

Sub-bug 2: Gemini sends default topK=0 sentinel (new-bug)

(a) DEFAULT_GENERATION_PARAMS.topK = 0 is the 'disabled' sentinel. resolveProviderTopK returns normalized (0) for google/google_vertex while every other provider maps 0 -> undefined. The Google body builder's guard is typeof number && Number.isFinite (true for 0), so it emits generationConfig.topK: 0. NOTE: this is partly documented (CHANGELOG 1.6.1 intentionally sends 0 as 'disabled'); the public Gemini API appears lenient, but Vertex documents topK min 1, so this is a real risk on google_vertex and an inconsistency worth resolving.
(b) Use a google_vertex connection with a default preset (topK unset); generate.
(c) generate-route-utils.ts:199-206 (VERIFIED — google branch returns normalized without > 0 guard); google.provider.ts:459-461 (VERIFIED — guard passes for 0) and 614-616 (streaming). Kind: new-bug (disputed-intentional for public Gemini, real for Vertex).

Sub-bug 3: Dry-run never forwards minP (missed-instance)

(a) The dry-run/prompt-preview path has no minP variable at all; the real path declares/applies/sends it. Preview diverges from real generation on min_p-honoring backends.
(c) dry-run-route.ts has zero minP references (defaults block, applyParameterOverrides, both chatComplete calls); contrast generate.routes.ts:1684/2076/3470/6087. Kind: missed-instance.

Sub-bug 4: Dry-run drops stopSequences (missed-instance)

(a) Dry-run applyParameterOverrides has no stopSequences branch and neither chatComplete call passes stop. Preset stop sequences don't truncate the preview.
(c) dry-run-route.ts:534-548 (no stop branch), 1572-1591 / 1635-1653 (no stop); contrast generate.routes.ts:2086-2088/3482-3484/6088. Kind: missed-instance.

Sub-bug 5: Dry-run local normalizeChatTopP regresses top_p=0 -> 1 (regression)

(a) dry-run-route.ts defines a STALE local copy if (value <= 0) return 1, while the canonical services/generation/generation-parameters.ts was fixed for #2663 (if (value < 0) return undefined; return Math.min(value, 1)). The dry-run path (preview AND its real streaming/non-streaming chatComplete calls) rewrites a stored top_p of 0 to 1.
(c) dry-run-route.ts:394-398 (local copy), 538 (applied); canonical generation-parameters.ts:28-32. Kind: regression (the #2663 fix did not propagate to the duplicated helper).

Sub-bug 6: OpenAI Responses API drops stop sequences (missed-instance)

(a) buildResponsesBody never reads options.stop. Models forced onto /responses (GPT-5.5, gpt-5.4, codex, openai-chatgpt) silently ignore preset stop sequences honored on the Chat Completions path. (Caveat: the Responses API's stop support is limited; at minimum surface a warning if it cannot be honored.)
(c) openai.provider.ts:1511-1614 (no stop); contrast 858/1104. Kind: missed-instance.

Sub-bug 7: claude_subscription drops all sampler params (new-bug, SDK-bounded)

(a) The Agent-SDK provider only forwards model/thinking/effort/maxTokens; temperature/topP/topK/minP/penalties are never forwarded (the SDK exposes no such knobs — VERIFIED against the bundled @anthropic-ai/claude-agent-sdk type defs). Same preset honors samplers on the API-key Anthropic connection but silently ignores them here, with no warning logged.
(c) claude-subscription.provider.ts:340-424. Kind: new-bug (forced SDK limitation; fix is a one-time warn, not a wire change).

Suggested Fix

  • Anthropic: add if (typeof options.topP === "number") body.top_p = options.topP to both chat()/chatComplete() bodies (use typeof not truthy so 0 survives), keeping the strip for adaptive-only models.
  • Gemini: make resolveProviderTopK return undefined when normalized <= 0 for google too (or change the provider guard to options.topK > 0).
  • Dry-run: import the canonical normalizeChatTopP (delete the local copy); add minP and stopSequences resolution+forwarding mirroring generate.routes.ts.
  • Responses API: gate/document stop; or map it if supported.
  • claude_subscription: emit a one-time warn when non-default sampler params are present so users know they're inert.

Template

  • Anthropic top_p sent and topP=0 preserved
  • Gemini no longer emits topK:0 (verify default-preset Vertex request)
  • Dry-run forwards minP and stopSequences
  • Dry-run shares the canonical normalizeChatTopP (top_p=0 preserved in preview)
  • Responses-path stop handled or warned
  • claude_subscription warns on inert sampler params
  • pnpm check passes

Affected files

  • packages/server/src/services/llm/providers/anthropic.provider.ts
  • packages/server/src/services/llm/providers/google.provider.ts
  • packages/server/src/routes/generate/generate-route-utils.ts
  • packages/server/src/routes/generate/dry-run-route.ts
  • packages/server/src/services/llm/providers/openai.provider.ts
  • packages/server/src/services/llm/providers/claude-subscription.provider.ts

Audit provenance

Found by a multi-agent re-review of the connection/preset subsystem (editors UI + send-pipeline) against the merged staging tree (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). The prior #2656-#2668 fixes were re-verified as HELD on their primary paths. Severity: HIGH.

AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2765 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The same class as the already-fixed #2668 (minP) / #2658 (stop): a configured sampler param is silently dropped on a specific provider or send-path, diverging from preset intent and from the same preset's behavior elsewhere. Several distinct missed instances remain. ## Sub-bug 1: Anthropic never sends top_p (missed-instance) **(a)** `options.topP` is resolved and clamped by the pipeline but the Anthropic body builder only sets temperature, top_k, stop_sequences — never `top_p`. The only `top_p` reference is `delete body.top_p` in `stripAnthropicSamplingParameters` (a defensive delete that never fires from topP). OpenAI and Google both send it, so the same preset behaves differently on Claude. **(b)** Set a non-default topP in a preset/connection; run a native Anthropic generation; top_p is absent from the request. **(c)** anthropic.provider.ts:284-294 (chatComplete body — VERIFIED: temperature/top_k/stop_sequences only at 291-293, no top_p), 413-441 (chat body), 30-34 (strip). topP reaches options via generate.routes.ts:3468/6083. Kind: missed-instance. ## Sub-bug 2: Gemini sends default topK=0 sentinel (new-bug) **(a)** `DEFAULT_GENERATION_PARAMS.topK = 0` is the 'disabled' sentinel. `resolveProviderTopK` returns `normalized` (0) for google/google_vertex while every other provider maps 0 -> undefined. The Google body builder's guard is `typeof number && Number.isFinite` (true for 0), so it emits `generationConfig.topK: 0`. NOTE: this is partly documented (CHANGELOG 1.6.1 intentionally sends 0 as 'disabled'); the public Gemini API appears lenient, but Vertex documents topK min 1, so this is a real risk on google_vertex and an inconsistency worth resolving. **(b)** Use a google_vertex connection with a default preset (topK unset); generate. **(c)** generate-route-utils.ts:199-206 (VERIFIED — google branch returns `normalized` without `> 0` guard); google.provider.ts:459-461 (VERIFIED — guard passes for 0) and 614-616 (streaming). Kind: new-bug (disputed-intentional for public Gemini, real for Vertex). ## Sub-bug 3: Dry-run never forwards minP (missed-instance) **(a)** The dry-run/prompt-preview path has no minP variable at all; the real path declares/applies/sends it. Preview diverges from real generation on min_p-honoring backends. **(c)** dry-run-route.ts has zero minP references (defaults block, applyParameterOverrides, both chatComplete calls); contrast generate.routes.ts:1684/2076/3470/6087. Kind: missed-instance. ## Sub-bug 4: Dry-run drops stopSequences (missed-instance) **(a)** Dry-run applyParameterOverrides has no stopSequences branch and neither chatComplete call passes `stop`. Preset stop sequences don't truncate the preview. **(c)** dry-run-route.ts:534-548 (no stop branch), 1572-1591 / 1635-1653 (no `stop`); contrast generate.routes.ts:2086-2088/3482-3484/6088. Kind: missed-instance. ## Sub-bug 5: Dry-run local normalizeChatTopP regresses top_p=0 -> 1 (regression) **(a)** dry-run-route.ts defines a STALE local copy `if (value <= 0) return 1`, while the canonical `services/generation/generation-parameters.ts` was fixed for #2663 (`if (value < 0) return undefined; return Math.min(value, 1)`). The dry-run path (preview AND its real streaming/non-streaming chatComplete calls) rewrites a stored top_p of 0 to 1. **(c)** dry-run-route.ts:394-398 (local copy), 538 (applied); canonical generation-parameters.ts:28-32. Kind: regression (the #2663 fix did not propagate to the duplicated helper). ## Sub-bug 6: OpenAI Responses API drops stop sequences (missed-instance) **(a)** `buildResponsesBody` never reads `options.stop`. Models forced onto /responses (GPT-5.5, gpt-5.4, codex, openai-chatgpt) silently ignore preset stop sequences honored on the Chat Completions path. (Caveat: the Responses API's stop support is limited; at minimum surface a warning if it cannot be honored.) **(c)** openai.provider.ts:1511-1614 (no stop); contrast 858/1104. Kind: missed-instance. ## Sub-bug 7: claude_subscription drops all sampler params (new-bug, SDK-bounded) **(a)** The Agent-SDK provider only forwards model/thinking/effort/maxTokens; temperature/topP/topK/minP/penalties are never forwarded (the SDK exposes no such knobs — VERIFIED against the bundled `@anthropic-ai/claude-agent-sdk` type defs). Same preset honors samplers on the API-key Anthropic connection but silently ignores them here, with no warning logged. **(c)** claude-subscription.provider.ts:340-424. Kind: new-bug (forced SDK limitation; fix is a one-time warn, not a wire change). ## Suggested Fix - Anthropic: add `if (typeof options.topP === "number") body.top_p = options.topP` to both chat()/chatComplete() bodies (use typeof not truthy so 0 survives), keeping the strip for adaptive-only models. - Gemini: make `resolveProviderTopK` return `undefined` when `normalized <= 0` for google too (or change the provider guard to `options.topK > 0`). - Dry-run: import the canonical `normalizeChatTopP` (delete the local copy); add minP and stopSequences resolution+forwarding mirroring generate.routes.ts. - Responses API: gate/document stop; or map it if supported. - claude_subscription: emit a one-time warn when non-default sampler params are present so users know they're inert. ## Template - [ ] Anthropic top_p sent and topP=0 preserved - [ ] Gemini no longer emits topK:0 (verify default-preset Vertex request) - [ ] Dry-run forwards minP and stopSequences - [ ] Dry-run shares the canonical normalizeChatTopP (top_p=0 preserved in preview) - [ ] Responses-path stop handled or warned - [ ] claude_subscription warns on inert sampler params - [ ] `pnpm check` passes --- ### Affected files - `packages/server/src/services/llm/providers/anthropic.provider.ts` - `packages/server/src/services/llm/providers/google.provider.ts` - `packages/server/src/routes/generate/generate-route-utils.ts` - `packages/server/src/routes/generate/dry-run-route.ts` - `packages/server/src/services/llm/providers/openai.provider.ts` - `packages/server/src/services/llm/providers/claude-subscription.provider.ts` ### Audit provenance Found by a multi-agent re-review of the connection/preset subsystem (editors UI + send-pipeline) against the merged `staging` tree (Round 1 + round-2 gap sweep + completeness critic, each finding adversarially verified). The prior #2656-#2668 fixes were re-verified as HELD on their primary paths. Severity: **HIGH**. > AI-drafted from a static read; validation/test-plan boxes intentionally left UNCHECKED for a human to verify before close.
Author
Owner

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

Anthropic doesn't support Top P at all.

<!-- gh-comment-id:4763259008 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Anthropic doesn't support Top P at all.
Author
Owner

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

Let's do only Gemini one, skip the others.

<!-- gh-comment-id:4763305995 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Let's do only Gemini one, skip the others.
Author
Owner

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

Fixed the maintainer-approved subset in PR #2747.\n\nApplied:\n- Gemini/Google Vertex now treats topK <= 0 as the disabled sentinel in resolveProviderTopK, so default topK=0 is omitted instead of serialized into generationConfig.topK.\n\nSkipped intentionally:\n- Anthropic top_p, dry-run minP/stop/top_p, OpenAI Responses stop, and claude_subscription sampler warnings were left unchanged per maintainer comment: "Let's do only Gemini one, skip the others."\n\nDeferred pnpm/check validation until the end of the issue sweep per maintainer request.

<!-- gh-comment-id:4763379590 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed the maintainer-approved subset in PR #2747.\n\nApplied:\n- Gemini/Google Vertex now treats topK <= 0 as the disabled sentinel in resolveProviderTopK, so default topK=0 is omitted instead of serialized into generationConfig.topK.\n\nSkipped intentionally:\n- Anthropic top_p, dry-run minP/stop/top_p, OpenAI Responses stop, and claude_subscription sampler warnings were left unchanged per maintainer comment: "Let's do only Gemini one, skip the others."\n\nDeferred pnpm/check validation until the end of the issue 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#1403
No description provided.