Skip to content

th-1cc9fa: model-output ceiling clamp + raise starvation defaults (TypeScript parity)#71

Merged
brentrager merged 1 commit into
mainfrom
th-1cc9fa-ts-ceiling
Jul 8, 2026
Merged

th-1cc9fa: model-output ceiling clamp + raise starvation defaults (TypeScript parity)#71
brentrager merged 1 commit into
mainfrom
th-1cc9fa-ts-ceiling

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Why

A budget/policy max_tokens can exceed what a model can physically emit. When it does, reasoning models burn the whole budget on reasoning_content and return empty content, or the upstream 400s (e.g. groq-compound caps output at 8192). The fix clamps every request's max_tokens to min(configured, model.max_output_tokens), where the per-model ceiling comes from the LiteLLM gateway's /model/info endpoint (model_info.max_output_tokens).

What (TypeScript core)

Mirrors the already-merged Rust reference (rust/smooth-operator-core/src/llm.rs LlmClient::with_model_ceiling / effective_max_tokens; src/agent.rs AgentConfig.model_max_output, PR #69) in TS idioms:

  • AgentOptions gains modelMaxOutput?: number — the active model's hard output ceiling (agent-config threading, the TS analog of AgentConfig.model_max_output).
  • New exported effectiveMaxTokens(configured, ceiling?) = min(configured, ceiling), floored at 1; undefined/0/non-positive ⇒ graceful passthrough (zero behaviour change). This is the TS analog of LlmClient::effective_max_tokens.
  • Both request-build sites — the non-streaming run loop and the streaming runStream loop — now send effectiveMaxTokens(...) for max_tokens.

The ceiling itself is sourced by the consumer (the server) from /model/info and passed in via modelMaxOutput, kept out of the published engine so it takes no LiteLLM-specific HTTP — same split as Rust.

Mirroring Rust

None/unset ⇒ no clamp (passthrough), identical to the Rust reference. The clamp lives at the request build (the TS engine builds the OpenAI request directly rather than through a separate LlmClient wrapper class, so the natural home for the clamp is the agent's request build + AgentOptions, rather than a withModelCeiling builder on a client object).

Tests

  • effectiveMaxTokens: clamp-down (ceiling < budget), passthrough (ceiling ≥ budget, undefined, 0, negative), never returns 0.
  • SmoothAgent: asserts the recorded request body's max_tokens is clamped on both the non-streaming and streaming paths, and unclamped when no ceiling is set.

pnpm typecheck, pnpm build, pnpm test all green (141 tests).

🤖 Generated with Claude Code

Mirror the Rust engine's model-output ceiling clamp in the TypeScript core.
AgentOptions gains `modelMaxOutput?: number`; a new exported
`effectiveMaxTokens(configured, ceiling?)` computes min(maxTokens, ceiling)
(floored at 1; undefined/0 => passthrough). Both the non-streaming `run` and
streaming `runStream` request builds now send the clamped value, so a
budget/policy max_tokens can never exceed what the model can physically emit
(reasoning models otherwise burn the budget on reasoning_content and return
empty; groq-compound 400s at an 8192 output cap). No behaviour change when
modelMaxOutput is unset. EPIC th-1cc9fa.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e7ddcb2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/smooth-operator-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager
brentrager merged commit 8c91101 into main Jul 8, 2026
4 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.

1 participant