Skip to content

fix(agent-runtime): read Perplexity and MiniMax max_tokens ceilings - #2363

Merged
vastsa merged 1 commit into
vastsa:mainfrom
xpeng5278-web:fix/output-ceiling-at-most
Nov 15, 2026
Merged

vastsa merged 1 commit into
vastsa:mainfrom
xpeng5278-web:fix/output-ceiling-at-most

Conversation

@xpeng5278-web

Copy link
Copy Markdown
Contributor

Fixes #2362

Summary

outputTokenCeiling now reads Perplexity's max_tokens must be at most N wording (backticks optional; also max_completion_tokens / max_output_tokens) and MiniMax's does not support max tokens > N. A 400 of either shape takes the existing one-shot clamp repair instead of ending the turn.

Root cause

The ceiling parser already covered OpenAI, Anthropic, proxy <=, DeepSeek / DashScope ranges, and Groq must be less than or equal to, but not these two sentences. isOutputLimitRejection therefore stayed false and the retry factory never clamped the derived output limit.

Fix

  • One pattern for max_tokens must be at most N, with a lookbehind so Prompt tokens plus max_tokens must be at most N (a context sum) is not treated as an output ceiling.
  • One pattern for does not support max tokens > N. The parenthesized MiniMax business code is not captured.

Tests

  • provider-retry.test.ts: Perplexity with and without backticks, max_completion_tokens / max_output_tokens, the official JSON 400, InvalidRequestError: max_tokens must be at most 4096; MiniMax including (2013); isOutputLimitRejection on both 400s and the "plus max_tokens" negative; clamp-and-retry for both payloads (attempts === 2, max_tokens set to 128000 / 196608). Negatives for Prompt tokens plus max_tokens must be at most 131,072 with and without backticks.
  • Before the fix (tests only, on main @ 525ec4986): provider-retry 5 failed / 60 passed (65). After: 65/65.
  • tsc -p packages/agent-runtime/tsconfig.json --noEmit: exit 0.

Scope

provider-retry.ts and its tests.

Perplexity's "max_tokens must be at most N" and MiniMax's
"does not support max tokens > N" are output ceilings, but the
parser did not recognize them. The 400 stayed a terminal provider
error, so the turn never clamped max_tokens and retried. A context
sum worded "plus max_tokens must be at most N" stays unrecognized,
and MiniMax's trailing business code is not the ceiling.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently reproduced the missing ceiling parsing and repair: candidate tests on baseline production module yield 5 failures; candidate and integration pass 187/187 agent-errors/provider-retry tests. Built the production sidecar and ran e2e-provider-retry-idle: abort-backoff, retry-after and stalled-request all passed with expected request counts. Reviewed context-sum negative cases and bounded repair behavior. Refreshed integration after #2359 (SQLite-only): targeted tests pass again; runtime executable inputs unchanged. All six Actions green; no live provider requests.

@vastsa
vastsa merged commit 3221341 into vastsa:main Nov 15, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Perplexity "max_tokens must be at most N" and MiniMax "does not support max tokens > N" 400s end the turn instead of clamping the output ceiling

3 participants