mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2685] [Issue]: Batched agent maxTokens is summed with no model-cap clamp → 400s the entire batch #1330
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1330
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2685
Originally assigned to: @SpicyMarinara on GitHub.
Summary
When multiple agents are batched into one LLM call, the request
max_tokensis the sum of every agent's per-agent budget, with no clamp to the model's hard output ceiling. With several default agents (4096 each) and no connectionmaxTokensOverride, the batch sends amax_tokensfar above a model's real cap (e.g. Claude models that cap at 8192), the provider returns HTTP 400, andexecuteAgentBatch's catch marks every batched agent failed.Expected behavior
The batch (and per-agent)
max_tokensshould be clamped to the model's known output ceiling, so batching agents never produces amax_tokens > model maximumrejection.Actual behavior
executeAgentBatchcomputesrawBatchMaxTokens = perAgentTokens.reduce((sum, t) => sum + t, 0)where each value is>= 128andDEFAULT_AGENT_MAX_TOKENS = 4096.applyProviderMaxTokensOverrideonly caps toprovider.maxTokensOverrideValuewhen one is set; otherwise the raw sum passes through intochatComplete({ maxTokens: batchMaxTokens }). Downstream, the Anthropic provider setsbody.max_tokens = maxTokenswith no model-cap clamp, and OpenAI'sapplyMaxTokensCaponly caps to the override, not the model's hard limit. The individual-call path never sums, so it can't hit this.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/services/agents/agent-executor.ts:649-652—rawBatchMaxTokens = perAgentTokens.reduce(...);:201-203applyProviderMaxTokensOverrideonly caps tomaxTokensOverrideValue; sent at:696-707(maxTokens: batchMaxTokens).DEFAULT_AGENT_MAX_TOKENS = 4096(packages/shared/src/types/agent.ts:463). 6 agents → 24576, 8 → 32768.anthropic.provider.ts:240(body.max_tokens = maxTokens);base-provider.ts:560-563(applyMaxTokensCapcaps only to override).max_tokens > model maximumwith 400, caught atagent-executor.ts:768, which returnsmakeErrorfor every config (:786).Steps to reproduce
maxTokensOverride, pointing at a Claude/Anthropic model with an 8192 output cap.max_tokens = 32768→ Anthropic 400 "max_tokens > model maximum" →executeAgentBatchcatch returns an error result for every agent in the batch.Suggested fix
Clamp the batch (and per-agent)
max_tokensto the model's known output ceiling before sending — e.g.min(rawBatchMaxTokens, knownModelMaxOutputTokens(provider, model))in addition toapplyProviderMaxTokensOverride. (Related to #2665 but distinct: that issue is about the connection override being ignored on some providers; this is the sum exceeding the model's hard cap when no override exists.)Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of the agent subsystem. Reachable on a common config (several enabled agents, no override, a Claude model). Part of a set of agent-pipeline issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Addressed on the issue-sweep branch. Agent resolution now carries each connection's known model maxOutput from the shared model table, and the executor clamps both individual agent maxTokens and summed batch maxTokens by the connection override and known model output cap before calling providers. Batch logging now reports the applied connection/model caps. Final repo checks will run after the sweep.