[GH-ISSUE #2665] [Issue]: Connection max-output-tokens cap (maxTokensOverride) is ignored on Anthropic, Google, and Claude-subscription providers #1315

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/2665

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The connection-level max-output-tokens cap (maxTokensOverride) is only enforced on OpenAI-family providers. Anthropic, Google, and Claude-subscription providers receive the override but never apply it, so the cap is silently ignored on 3 of the 4 provider families.

Expected behavior

A connection's max-output-tokens cap should clamp the outgoing max_tokens (downward) on every provider, so a user can reliably bound cost/latency regardless of which provider the connection uses.

Actual behavior

BaseLLMProvider stores the cap (this.maxTokensOverride) and exposes applyMaxTokensCap(tokens), but only OpenAIProvider calls it. Anthropic/Google/Claude-subscription send the preset/per-chat maxTokens (or the 4096 default) uncapped.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • Cap helper: packages/server/src/services/llm/base-provider.ts:560 — applyMaxTokensCap(tokens), populated from the connection's maxTokensOverride via provider-registry.ts (~:40–43).
  • Applied only by OpenAI: packages/server/src/services/llm/providers/openai.provider.ts:814, :821, :1051, :1058.
  • Anthropic: anthropic.provider.ts computes configuredMaxTokens = options.maxTokens ?? 4096 (:324) and sends body.max_tokens (:382) with no cap.
  • Google: google.provider.ts sends maxOutputTokens (~:458/:462) with no cap.
  • Claude-subscription: claude-subscription.provider.ts (~:325) with no cap.

A repo-wide search for applyMaxTokensCap returns only the OpenAI call sites plus the base definition — confirming Anthropic/Google/Claude-subscription never invoke it.

Steps to reproduce

  1. Configure an Anthropic (or Google) connection with a maxTokensOverride of e.g. 256.
  2. Use a preset/chat with maxTokens = 4096.
  3. Send a prompt and inspect the outgoing request body.
  4. Observe: max_tokens is 4096 (uncapped). On an OpenAI connection the same setup correctly caps to 256.

Suggested fix

Apply the cap in the Anthropic, Google, and Claude-subscription chat()/chatComplete() paths, mirroring openai.provider.ts:814/:821 — e.g. const configuredMaxTokens = suppressModelParameters ? undefined : this.applyMaxTokensCap(options.maxTokens ?? 4096) and re-apply to the context-fitted value. Better still: centralize the cap inside the shared context-fit / max_tokens resolution so no provider can forget it.

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 a systematic source-level review of the connection/preset → LLM-request pipeline on staging (refs @ b826f8f4), as a sibling of the auth/param Tier-1 bug set (#2656–#2658). The OpenAI provider already demonstrates the intended pattern.

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/2665 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The connection-level **max-output-tokens cap** (`maxTokensOverride`) is only enforced on OpenAI-family providers. Anthropic, Google, and Claude-subscription providers receive the override but never apply it, so the cap is silently ignored on 3 of the 4 provider families. ## Expected behavior A connection's max-output-tokens cap should clamp the outgoing `max_tokens` (downward) on **every** provider, so a user can reliably bound cost/latency regardless of which provider the connection uses. ## Actual behavior `BaseLLMProvider` stores the cap (`this.maxTokensOverride`) and exposes `applyMaxTokensCap(tokens)`, but only `OpenAIProvider` calls it. Anthropic/Google/Claude-subscription send the preset/per-chat `maxTokens` (or the 4096 default) uncapped. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - Cap helper: `packages/server/src/services/llm/base-provider.ts:560` — `applyMaxTokensCap(tokens)`, populated from the connection's `maxTokensOverride` via `provider-registry.ts` (~`:40–43`). - Applied only by OpenAI: `packages/server/src/services/llm/providers/openai.provider.ts:814`, `:821`, `:1051`, `:1058`. - Anthropic: `anthropic.provider.ts` computes `configuredMaxTokens = options.maxTokens ?? 4096` (~`:324`) and sends `body.max_tokens` (~`:382`) with no cap. - Google: `google.provider.ts` sends `maxOutputTokens` (~`:458`/`:462`) with no cap. - Claude-subscription: `claude-subscription.provider.ts` (~`:325`) with no cap. A repo-wide search for `applyMaxTokensCap` returns only the OpenAI call sites plus the base definition — confirming Anthropic/Google/Claude-subscription never invoke it. ## Steps to reproduce 1. Configure an Anthropic (or Google) connection with a `maxTokensOverride` of e.g. `256`. 2. Use a preset/chat with `maxTokens` = `4096`. 3. Send a prompt and inspect the outgoing request body. 4. Observe: `max_tokens` is `4096` (uncapped). On an OpenAI connection the same setup correctly caps to `256`. ## Suggested fix Apply the cap in the Anthropic, Google, and Claude-subscription `chat()`/`chatComplete()` paths, mirroring `openai.provider.ts:814`/`:821` — e.g. `const configuredMaxTokens = suppressModelParameters ? undefined : this.applyMaxTokensCap(options.maxTokens ?? 4096)` and re-apply to the context-fitted value. Better still: centralize the cap inside the shared context-fit / `max_tokens` resolution so no provider can forget it. ## 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 a systematic source-level review of the connection/preset → LLM-request pipeline on staging (refs @ `b826f8f4`), as a sibling of the auth/param Tier-1 bug set (#2656–#2658). The OpenAI provider already demonstrates the intended pattern. ## 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: maxTokensOverride is now applied outside the OpenAI provider family as well. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051966 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: maxTokensOverride is now applied outside the OpenAI provider family as well. 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#1315
No description provided.